|
|
@ -12,20 +12,20 @@ func (c *Client) getComponentVerifyTicketCacheKeyName() string {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// SetComponentVerifyTicket 设置微信后台推送的ticke
|
|
|
|
// SetComponentVerifyTicket 设置微信后台推送的ticke
|
|
|
|
func (c *Client) SetComponentVerifyTicket(componentVerifyTicket string) string {
|
|
|
|
func (c *Client) SetComponentVerifyTicket(ctx context.Context, componentVerifyTicket string) string {
|
|
|
|
if componentVerifyTicket == "" {
|
|
|
|
if componentVerifyTicket == "" {
|
|
|
|
return ""
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.config.RedisClient.Db.Set(context.Background(), c.getComponentVerifyTicketCacheKeyName(), componentVerifyTicket, time.Hour*12)
|
|
|
|
c.config.RedisClient.Set(ctx, c.getComponentVerifyTicketCacheKeyName(), componentVerifyTicket, time.Hour*12)
|
|
|
|
return c.GetComponentVerifyTicket()
|
|
|
|
return c.GetComponentVerifyTicket(ctx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetComponentVerifyTicket 获取微信后台推送的ticke
|
|
|
|
// GetComponentVerifyTicket 获取微信后台推送的ticke
|
|
|
|
func (c *Client) GetComponentVerifyTicket() string {
|
|
|
|
func (c *Client) GetComponentVerifyTicket(ctx context.Context) string {
|
|
|
|
if c.config.RedisClient.Db == nil {
|
|
|
|
if c.config.RedisClient.Db == nil {
|
|
|
|
return c.config.ComponentVerifyTicket
|
|
|
|
return c.config.ComponentVerifyTicket
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result, _ := c.config.RedisClient.Db.Get(context.Background(), c.getComponentVerifyTicketCacheKeyName()).Result()
|
|
|
|
result, _ := c.config.RedisClient.Get(ctx, c.getComponentVerifyTicketCacheKeyName()).Result()
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -35,34 +35,34 @@ func (c *Client) getComponentAccessTokenCacheKeyName() string {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// SetComponentAccessToken 设置令牌
|
|
|
|
// SetComponentAccessToken 设置令牌
|
|
|
|
func (c *Client) SetComponentAccessToken(componentAccessToken string) string {
|
|
|
|
func (c *Client) SetComponentAccessToken(ctx context.Context, componentAccessToken string) string {
|
|
|
|
if componentAccessToken == "" {
|
|
|
|
if componentAccessToken == "" {
|
|
|
|
return ""
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.config.RedisClient.Db.Set(context.Background(), c.getComponentAccessTokenCacheKeyName(), componentAccessToken, time.Second*7200)
|
|
|
|
c.config.RedisClient.Set(ctx, c.getComponentAccessTokenCacheKeyName(), componentAccessToken, time.Second*7200)
|
|
|
|
return c.GetComponentAccessToken()
|
|
|
|
return c.GetComponentAccessToken(ctx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetComponentAccessToken 获取令牌
|
|
|
|
// GetComponentAccessToken 获取令牌
|
|
|
|
func (c *Client) GetComponentAccessToken() string {
|
|
|
|
func (c *Client) GetComponentAccessToken(ctx context.Context) string {
|
|
|
|
if c.config.RedisClient.Db == nil {
|
|
|
|
if c.config.RedisClient.Db == nil {
|
|
|
|
return c.config.ComponentAccessToken
|
|
|
|
return c.config.ComponentAccessToken
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result, _ := c.config.RedisClient.Db.Get(context.Background(), c.getComponentAccessTokenCacheKeyName()).Result()
|
|
|
|
result, _ := c.config.RedisClient.Db.Get(ctx, c.getComponentAccessTokenCacheKeyName()).Result()
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MonitorComponentAccessToken 监控令牌
|
|
|
|
// MonitorComponentAccessToken 监控令牌
|
|
|
|
func (c *Client) MonitorComponentAccessToken() string {
|
|
|
|
func (c *Client) MonitorComponentAccessToken(ctx context.Context) string {
|
|
|
|
// 查询
|
|
|
|
// 查询
|
|
|
|
componentAccessToken := c.GetComponentAccessToken()
|
|
|
|
componentAccessToken := c.GetComponentAccessToken(ctx)
|
|
|
|
// 判断
|
|
|
|
// 判断
|
|
|
|
result := c.CgiBinGetApiDomainIp(componentAccessToken)
|
|
|
|
result := c.CgiBinGetApiDomainIp(ctx, componentAccessToken)
|
|
|
|
if len(result.Result.IpList) > 0 {
|
|
|
|
if len(result.Result.IpList) > 0 {
|
|
|
|
return componentAccessToken
|
|
|
|
return componentAccessToken
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 重新获取
|
|
|
|
// 重新获取
|
|
|
|
return c.SetComponentAccessToken(c.CgiBinComponentApiComponentToken().Result.ComponentAccessToken)
|
|
|
|
return c.SetComponentAccessToken(ctx, c.CgiBinComponentApiComponentToken(ctx).Result.ComponentAccessToken)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 授权方令牌
|
|
|
|
// 授权方令牌
|
|
|
@ -71,33 +71,33 @@ func (c *Client) getAuthorizerAccessTokenCacheKeyName() string {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// SetAuthorizerAccessToken 设置授权方令牌
|
|
|
|
// SetAuthorizerAccessToken 设置授权方令牌
|
|
|
|
func (c *Client) SetAuthorizerAccessToken(authorizerAccessToken string) string {
|
|
|
|
func (c *Client) SetAuthorizerAccessToken(ctx context.Context, authorizerAccessToken string) string {
|
|
|
|
if authorizerAccessToken == "" {
|
|
|
|
if authorizerAccessToken == "" {
|
|
|
|
return ""
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.config.RedisClient.Db.Set(context.Background(), c.getAuthorizerAccessTokenCacheKeyName(), authorizerAccessToken, time.Hour*2)
|
|
|
|
c.config.RedisClient.Set(ctx, c.getAuthorizerAccessTokenCacheKeyName(), authorizerAccessToken, time.Hour*2)
|
|
|
|
return c.GetComponentAccessToken()
|
|
|
|
return c.GetComponentAccessToken(ctx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetAuthorizerAccessToken 获取授权方令牌
|
|
|
|
// GetAuthorizerAccessToken 获取授权方令牌
|
|
|
|
func (c *Client) GetAuthorizerAccessToken() string {
|
|
|
|
func (c *Client) GetAuthorizerAccessToken(ctx context.Context) string {
|
|
|
|
if c.config.RedisClient.Db == nil {
|
|
|
|
if c.config.RedisClient.Db == nil {
|
|
|
|
return c.config.AuthorizerAccessToken
|
|
|
|
return c.config.AuthorizerAccessToken
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result, _ := c.config.RedisClient.Db.Get(context.Background(), c.getAuthorizerAccessTokenCacheKeyName()).Result()
|
|
|
|
result, _ := c.config.RedisClient.Get(ctx, c.getAuthorizerAccessTokenCacheKeyName()).Result()
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MonitorAuthorizerAccessToken 监控授权方令牌
|
|
|
|
// MonitorAuthorizerAccessToken 监控授权方令牌
|
|
|
|
func (c *Client) MonitorAuthorizerAccessToken(authorizerRefreshToken string) string {
|
|
|
|
func (c *Client) MonitorAuthorizerAccessToken(ctx context.Context, authorizerRefreshToken string) string {
|
|
|
|
// 查询
|
|
|
|
// 查询
|
|
|
|
authorizerAccessToken := c.GetAuthorizerAccessToken()
|
|
|
|
authorizerAccessToken := c.GetAuthorizerAccessToken(ctx)
|
|
|
|
// 判断
|
|
|
|
// 判断
|
|
|
|
if authorizerAccessToken != "" {
|
|
|
|
if authorizerAccessToken != "" {
|
|
|
|
return authorizerAccessToken
|
|
|
|
return authorizerAccessToken
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 重新获取
|
|
|
|
// 重新获取
|
|
|
|
return c.SetAuthorizerAccessToken(c.CgiBinComponentApiAuthorizerToken(authorizerRefreshToken).Result.AuthorizerAccessToken)
|
|
|
|
return c.SetAuthorizerAccessToken(ctx, c.CgiBinComponentApiAuthorizerToken(ctx, authorizerRefreshToken).Result.AuthorizerAccessToken)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 预授权码
|
|
|
|
// 预授权码
|
|
|
@ -106,36 +106,36 @@ func (c *Client) getPreAuthCodeCacheKeyName() string {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// SetPreAuthCode 设置预授权码
|
|
|
|
// SetPreAuthCode 设置预授权码
|
|
|
|
func (c *Client) SetPreAuthCode(preAuthCode string) string {
|
|
|
|
func (c *Client) SetPreAuthCode(ctx context.Context, preAuthCode string) string {
|
|
|
|
if preAuthCode == "" {
|
|
|
|
if preAuthCode == "" {
|
|
|
|
return ""
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.config.RedisClient.Db.Set(context.Background(), c.getPreAuthCodeCacheKeyName(), preAuthCode, time.Second*1700)
|
|
|
|
c.config.RedisClient.Set(ctx, c.getPreAuthCodeCacheKeyName(), preAuthCode, time.Second*1700)
|
|
|
|
return c.GetComponentAccessToken()
|
|
|
|
return c.GetComponentAccessToken(ctx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetPreAuthCode 获取预授权码
|
|
|
|
// GetPreAuthCode 获取预授权码
|
|
|
|
func (c *Client) GetPreAuthCode() string {
|
|
|
|
func (c *Client) GetPreAuthCode(ctx context.Context) string {
|
|
|
|
if c.config.RedisClient.Db == nil {
|
|
|
|
if c.config.RedisClient.Db == nil {
|
|
|
|
return c.config.AuthorizerAccessToken
|
|
|
|
return c.config.AuthorizerAccessToken
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result, _ := c.config.RedisClient.Db.Get(context.Background(), c.getPreAuthCodeCacheKeyName()).Result()
|
|
|
|
result, _ := c.config.RedisClient.Get(ctx, c.getPreAuthCodeCacheKeyName()).Result()
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// DelPreAuthCode 删除预授权码
|
|
|
|
// DelPreAuthCode 删除预授权码
|
|
|
|
func (c *Client) DelPreAuthCode() error {
|
|
|
|
func (c *Client) DelPreAuthCode(ctx context.Context) error {
|
|
|
|
return c.config.RedisClient.Db.Del(context.Background(), c.getPreAuthCodeCacheKeyName()).Err()
|
|
|
|
return c.config.RedisClient.Del(ctx, c.getPreAuthCodeCacheKeyName()).Err()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MonitorPreAuthCode 监控预授权码
|
|
|
|
// MonitorPreAuthCode 监控预授权码
|
|
|
|
func (c *Client) MonitorPreAuthCode() string {
|
|
|
|
func (c *Client) MonitorPreAuthCode(ctx context.Context) string {
|
|
|
|
// 查询
|
|
|
|
// 查询
|
|
|
|
preAuthCode := c.GetPreAuthCode()
|
|
|
|
preAuthCode := c.GetPreAuthCode(ctx)
|
|
|
|
// 判断
|
|
|
|
// 判断
|
|
|
|
if preAuthCode != "" {
|
|
|
|
if preAuthCode != "" {
|
|
|
|
return preAuthCode
|
|
|
|
return preAuthCode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 重新获取
|
|
|
|
// 重新获取
|
|
|
|
return c.SetPreAuthCode(c.CgiBinComponentApiCreatePreAuthCoden().Result.PreAuthCode)
|
|
|
|
return c.SetPreAuthCode(ctx, c.CgiBinComponentApiCreatePreAuthCoden(ctx).Result.PreAuthCode)
|
|
|
|
}
|
|
|
|
}
|
|
|
|