- update log
continuous-integration/drone/push Build is failing Details
continuous-integration/drone/tag Build is failing Details

master v1.0.12
李光春 2 years ago
parent 0f9a19f832
commit ca0fe58783

@ -17,16 +17,18 @@ type ConfigClient struct {
ComponentAppSecret string // 第三方平台 app_secret ComponentAppSecret string // 第三方平台 app_secret
MessageToken string MessageToken string
MessageKey string MessageKey string
GormClient *dorm.GormClient // 日志数据库 RedisClient *dorm.RedisClient // 缓存数据库
LogClient *golog.GoLog // 日志驱动 GormClient *dorm.GormClient // 日志数据库
LogDebug bool // 日志开关 LogClient *golog.GoLog // 日志驱动
LogDebug bool // 日志开关
} }
// Client 微信公众号服务 // Client 微信公众号服务
type Client struct { type Client struct {
requestClient *gorequest.App // 请求服务 requestClient *gorequest.App // 请求服务
logClient *golog.ApiClient // 日志服务 redisClient *dorm.RedisClient // 缓存服务
config *ConfigClient // 配置 logClient *golog.ApiClient // 日志服务
config *ConfigClient // 配置
} }
func NewClient(config *ConfigClient) (*Client, error) { func NewClient(config *ConfigClient) (*Client, error) {
@ -36,6 +38,8 @@ func NewClient(config *ConfigClient) (*Client, error) {
c.requestClient = gorequest.NewHttp() c.requestClient = gorequest.NewHttp()
c.redisClient = config.RedisClient
if c.config.GormClient.Db != nil { if c.config.GormClient.Db != nil {
c.logClient, err = golog.NewApiClient(&golog.ApiClientConfig{ c.logClient, err = golog.NewApiClient(&golog.ApiClientConfig{
GormClient: c.config.GormClient, GormClient: c.config.GormClient,

@ -8,4 +8,4 @@ const (
logTable = "wechatopen" logTable = "wechatopen"
) )
const Version = "1.0.11" const Version = "1.0.12"

@ -16,16 +16,16 @@ func (c *Client) SetComponentVerifyTicket(ctx context.Context, componentVerifyTi
if componentVerifyTicket == "" { if componentVerifyTicket == "" {
return "" return ""
} }
c.config.RedisClient.Set(ctx, c.getComponentVerifyTicketCacheKeyName(), componentVerifyTicket, time.Hour*12) c.redisClient.Set(ctx, c.getComponentVerifyTicketCacheKeyName(), componentVerifyTicket, time.Hour*12)
return c.GetComponentVerifyTicket(ctx) return c.GetComponentVerifyTicket(ctx)
} }
// GetComponentVerifyTicket 获取微信后台推送的ticke // GetComponentVerifyTicket 获取微信后台推送的ticke
func (c *Client) GetComponentVerifyTicket(ctx context.Context) string { func (c *Client) GetComponentVerifyTicket(ctx context.Context) string {
if c.config.RedisClient.Db == nil { if c.redisClient.Db == nil {
return c.config.ComponentVerifyTicket return c.config.ComponentVerifyTicket
} }
result, _ := c.config.RedisClient.Get(ctx, c.getComponentVerifyTicketCacheKeyName()).Result() result, _ := c.redisClient.Get(ctx, c.getComponentVerifyTicketCacheKeyName()).Result()
return result return result
} }
@ -39,16 +39,16 @@ func (c *Client) SetComponentAccessToken(ctx context.Context, componentAccessTok
if componentAccessToken == "" { if componentAccessToken == "" {
return "" return ""
} }
c.config.RedisClient.Set(ctx, c.getComponentAccessTokenCacheKeyName(), componentAccessToken, time.Second*7200) c.redisClient.Set(ctx, c.getComponentAccessTokenCacheKeyName(), componentAccessToken, time.Second*7200)
return c.GetComponentAccessToken(ctx) return c.GetComponentAccessToken(ctx)
} }
// GetComponentAccessToken 获取令牌 // GetComponentAccessToken 获取令牌
func (c *Client) GetComponentAccessToken(ctx context.Context) string { func (c *Client) GetComponentAccessToken(ctx context.Context) string {
if c.config.RedisClient.Db == nil { if c.redisClient.Db == nil {
return c.config.ComponentAccessToken return c.config.ComponentAccessToken
} }
result, _ := c.config.RedisClient.Db.Get(ctx, c.getComponentAccessTokenCacheKeyName()).Result() result, _ := c.redisClient.Db.Get(ctx, c.getComponentAccessTokenCacheKeyName()).Result()
return result return result
} }
@ -75,16 +75,16 @@ func (c *Client) SetAuthorizerAccessToken(ctx context.Context, authorizerAccessT
if authorizerAccessToken == "" { if authorizerAccessToken == "" {
return "" return ""
} }
c.config.RedisClient.Set(ctx, c.getAuthorizerAccessTokenCacheKeyName(), authorizerAccessToken, time.Hour*2) c.redisClient.Set(ctx, c.getAuthorizerAccessTokenCacheKeyName(), authorizerAccessToken, time.Hour*2)
return c.GetComponentAccessToken(ctx) return c.GetComponentAccessToken(ctx)
} }
// GetAuthorizerAccessToken 获取授权方令牌 // GetAuthorizerAccessToken 获取授权方令牌
func (c *Client) GetAuthorizerAccessToken(ctx context.Context) string { func (c *Client) GetAuthorizerAccessToken(ctx context.Context) string {
if c.config.RedisClient.Db == nil { if c.redisClient.Db == nil {
return c.config.AuthorizerAccessToken return c.config.AuthorizerAccessToken
} }
result, _ := c.config.RedisClient.Get(ctx, c.getAuthorizerAccessTokenCacheKeyName()).Result() result, _ := c.redisClient.Get(ctx, c.getAuthorizerAccessTokenCacheKeyName()).Result()
return result return result
} }
@ -110,22 +110,22 @@ func (c *Client) SetPreAuthCode(ctx context.Context, preAuthCode string) string
if preAuthCode == "" { if preAuthCode == "" {
return "" return ""
} }
c.config.RedisClient.Set(ctx, c.getPreAuthCodeCacheKeyName(), preAuthCode, time.Second*1700) c.redisClient.Set(ctx, c.getPreAuthCodeCacheKeyName(), preAuthCode, time.Second*1700)
return c.GetComponentAccessToken(ctx) return c.GetComponentAccessToken(ctx)
} }
// GetPreAuthCode 获取预授权码 // GetPreAuthCode 获取预授权码
func (c *Client) GetPreAuthCode(ctx context.Context) string { func (c *Client) GetPreAuthCode(ctx context.Context) string {
if c.config.RedisClient.Db == nil { if c.redisClient.Db == nil {
return c.config.AuthorizerAccessToken return c.config.AuthorizerAccessToken
} }
result, _ := c.config.RedisClient.Get(ctx, c.getPreAuthCodeCacheKeyName()).Result() result, _ := c.redisClient.Get(ctx, c.getPreAuthCodeCacheKeyName()).Result()
return result return result
} }
// DelPreAuthCode 删除预授权码 // DelPreAuthCode 删除预授权码
func (c *Client) DelPreAuthCode(ctx context.Context) error { func (c *Client) DelPreAuthCode(ctx context.Context) error {
return c.config.RedisClient.Del(ctx, c.getPreAuthCodeCacheKeyName()).Err() return c.redisClient.Del(ctx, c.getPreAuthCodeCacheKeyName()).Err()
} }
// MonitorPreAuthCode 监控预授权码 // MonitorPreAuthCode 监控预授权码

Loading…
Cancel
Save