- update wechatopen

master
李光春 1 year ago
parent 61d1c2f975
commit b40a8afea0

@ -10,13 +10,13 @@ require (
github.com/basgys/goxml2json v1.1.0
github.com/bytedance/sonic v1.8.8
github.com/gin-gonic/gin v1.9.0
github.com/go-co-op/gocron v1.23.0
github.com/go-co-op/gocron v1.25.0
github.com/go-playground/locales v0.14.1
github.com/go-playground/universal-translator v0.18.1
github.com/go-playground/validator/v10 v10.13.0
github.com/go-sql-driver/mysql v1.7.1
github.com/goccy/go-json v0.10.2
github.com/gogf/gf/v2 v2.4.0
github.com/gogf/gf/v2 v2.4.1
github.com/json-iterator/go v1.1.12
github.com/lib/pq v1.10.9
github.com/mitchellh/mapstructure v1.5.0

@ -106,8 +106,8 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.9.0 h1:OjyFBKICoexlu99ctXNR2gg+c5pKrKMuyjgARg9qeY8=
github.com/gin-gonic/gin v1.9.0/go.mod h1:W1Me9+hsUSyj3CePGrd1/QrKJMSJ1Tu/0hFEH89961k=
github.com/go-co-op/gocron v1.23.0 h1:cD8PCSsa88HKJSC8XhSWATSEKdgfKjrlnDu8zX+Jce4=
github.com/go-co-op/gocron v1.23.0/go.mod h1:gEQbrsoOV+HAp59D3LmYFgENQDeYp2QHsHT8N/Wzs/U=
github.com/go-co-op/gocron v1.25.0 h1:pzAdtily1JVIf6lGby6K0JKzhishgLOllQgNxoYbR+8=
github.com/go-co-op/gocron v1.25.0/go.mod h1:JHrQDY4iE1HZPkgTyoccY4xtDgLbrUwL+xODIbEQdnc=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgOZ7o=
@ -146,8 +146,8 @@ github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogf/gf/v2 v2.4.0 h1:Tem4xKVI52h92XlKxKTxlID9hzzmTOVSI226vDJRZ1c=
github.com/gogf/gf/v2 v2.4.0/go.mod h1:tsbmtwcAl2chcYoq/fP9W2FZf06aw4i89X34nbSHo9Y=
github.com/gogf/gf/v2 v2.4.1 h1:snsuvDhNFiRoAuWBbKfIIng0KyMaRA87Qr03GLir5j8=
github.com/gogf/gf/v2 v2.4.1/go.mod h1:tsbmtwcAl2chcYoq/fP9W2FZf06aw4i89X34nbSHo9Y=
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
@ -462,8 +462,8 @@ github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzG
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=

@ -1,5 +1,5 @@
package go_library
func Version() string {
return "1.0.136"
return "1.0.137"
}

@ -62,7 +62,7 @@ func (c *Client) CgiBinAccountGetAccountBasicInfo(ctx context.Context, notMustPa
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/cgi-bin/account/getaccountbasicinfo?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/cgi-bin/account/getaccountbasicinfo?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodGet)
if err != nil {
return newCgiBinAccountGetAccountBasicInfoResult(CgiBinAccountGetAccountBasicInfoResponse{}, request.ResponseBody, request), err
}

@ -37,7 +37,7 @@ func (c *Client) CgiBinComponentApiAuthorizerToken(ctx context.Context, authoriz
params.Set("authorizer_appid", c.GetAuthorizerAppid(ctx)) // 授权方appid
params.Set("authorizer_refresh_token", authorizerRefreshToken) // 授权码会在授权成功时返回给第三方平台
// 请求
request, err := c.request(ctx, apiUrl+"/cgi-bin/component/api_authorizer_token?component_access_token="+c.GetComponentAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/cgi-bin/component/api_authorizer_token?component_access_token="+GetComponentAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newCgiBinComponentApiAuthorizerTokenResult(CgiBinComponentApiAuthorizerTokenResponse{}, request.ResponseBody, request, params.Get("authorizer_appid").(string)), err
}

@ -29,7 +29,7 @@ func (c *Client) CgiBinComponentApiCreatePreAuthCoden(ctx context.Context, notMu
params := gorequest.NewParamsWith(notMustParams...)
params.Set("component_appid", c.GetComponentAppId(ctx)) // 第三方平台appid
// 请求
request, err := c.request(ctx, apiUrl+"/cgi-bin/component/api_create_preauthcode?component_access_token="+c.GetComponentAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/cgi-bin/component/api_create_preauthcode?component_access_token="+GetComponentAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newCgiBinComponentApiCreatePreAuthCodenResult(CgiBinComponentApiCreatePreAuthCodenResponse{}, request.ResponseBody, request), err
}

@ -92,7 +92,7 @@ func (c *Client) CgiBinComponentApiGetAuthorizerInfo(ctx context.Context, notMus
params.Set("component_appid", c.GetComponentAppId(ctx)) // 第三方平台appid
params.Set("authorizer_appid", c.GetAuthorizerAppid(ctx)) // 授权方appid
// 请求
request, err := c.request(ctx, apiUrl+"/cgi-bin/component/api_get_authorizer_info?component_access_token="+c.GetComponentAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/cgi-bin/component/api_get_authorizer_info?component_access_token="+GetComponentAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newCgiBinComponentApiGetAuthorizerInfoResult(CgiBinComponentApiGetAuthorizerInfoResponse{}, request.ResponseBody, request), err
}

@ -44,7 +44,7 @@ func (c *Client) CgiBinComponentApiQueryAuth(ctx context.Context, authorizationC
params.Set("component_appid", c.GetComponentAppId(ctx)) // 第三方平台appid
params.Set("authorization_code", authorizationCode) // 授权码会在授权成功时返回给第三方平台
// 请求
request, err := c.request(ctx, apiUrl+"/cgi-bin/component/api_query_auth?component_access_token="+c.GetComponentAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/cgi-bin/component/api_query_auth?component_access_token="+GetComponentAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newCgiBinComponentApiQueryAuthResult(CgiBinComponentApiQueryAuthResponse{}, request.ResponseBody, request), err
}

@ -29,7 +29,7 @@ func (c *Client) CgiBinComponentFastRegisterWeAppCreate(ctx context.Context, not
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/cgi-bin/component/fastregisterweapp?action=create&component_access_token="+c.GetComponentAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/cgi-bin/component/fastregisterweapp?action=create&component_access_token="+GetComponentAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newCgiBinComponentFastRegisterWeAppCreateResult(CgiBinComponentFastRegisterWeAppCreateResponse{}, request.ResponseBody, request), err
}

@ -29,7 +29,7 @@ func (c *Client) CgiBinComponentFastRegisterWeAppSearch(ctx context.Context, not
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/cgi-bin/component/fastregisterweapp?action=search&component_access_token="+c.GetComponentAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/cgi-bin/component/fastregisterweapp?action=search&component_access_token="+GetComponentAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newCgiBinComponentFastRegisterWeAppSearchResult(CgiBinComponentFastRegisterWeAppSearchResponse{}, request.ResponseBody, request), err
}

@ -66,7 +66,7 @@ func (c *Client) CgiBinComponentGetPrivacySetting(ctx context.Context, privacyVe
params := gorequest.NewParamsWith(notMustParams...)
params.Set("privacy_ver", privacyVer)
// 请求
request, err := c.request(ctx, apiUrl+"/cgi-bin/component/getprivacysetting?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/cgi-bin/component/getprivacysetting?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newCgiBinComponentGetPrivacySettingResult(CgiBinComponentGetPrivacySettingResponse{}, request.ResponseBody, request), err
}

@ -32,7 +32,7 @@ func (c *Client) CgiBinComponentSetPrivacySetting(ctx context.Context, notMustPa
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/cgi-bin/component/setprivacysetting?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/cgi-bin/component/setprivacysetting?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newCgiBinComponentSetPrivacySettingResult(CgiBinComponentSetPrivacySettingResponse{}, request.ResponseBody, request), err
}

@ -36,7 +36,7 @@ func (c *Client) CgiBinMaterialGetMaterial(ctx context.Context, mediaId string,
params := gorequest.NewParamsWith(notMustParams...)
params.Set("media_id", mediaId) // 要获取的素材的media_id
// 请求
request, err := c.request(ctx, apiUrl+"/cgi-bin/material/get_material?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/cgi-bin/material/get_material?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newCgiBinMaterialGetMaterialResult(CgiBinMaterialGetMaterialResponse{}, request.ResponseBody, request), err
}

@ -29,7 +29,7 @@ func (c *Client) CgiBinOpenSameEnTity(ctx context.Context, notMustParams ...gore
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/cgi-bin/open/sameentity?access_token="+c.GetComponentAccessToken(ctx), params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/cgi-bin/open/sameentity?access_token="+GetComponentAccessToken(ctx, c), params, http.MethodGet)
if err != nil {
return newCgiBinOpenSameEnTityResult(CgiBinOpenSameEnTityResponse{}, request.ResponseBody, request), err
}

@ -43,7 +43,7 @@ func (c *Client) CgiBinOpenapiRidGet(ctx context.Context, rid string, notMustPar
params.Set("rid", rid)
}
// 请求
request, err := c.request(ctx, apiUrl+"/cgi-bin/openapi/rid/get?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/cgi-bin/openapi/rid/get?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newCgiBinOpenapiRidGetResult(CgiBinOpenapiRidGetResponse{}, request.ResponseBody, request), err
}

@ -35,7 +35,7 @@ func (c *Client) CgiBinShortUrl(ctx context.Context, longUrl string, notMustPara
params.Set("action", "long2short") // 此处填long2short代表长链接转短链接
params.Set("long_url", longUrl) // 需要转换的长链接支持http://、https://、weixin://wxpay 格式的url
// 请求
request, err := c.request(ctx, apiUrl+"/cgi-bin/shorturl?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/cgi-bin/shorturl?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newCgiBinShortUrlResult(CgiBinShortUrlResponse{}, request.ResponseBody, request), err
}

@ -32,7 +32,7 @@ func (c *Client) CgiBinWxOpenQrCodeJumpAdd(ctx context.Context, notMustParams ..
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/cgi-bin/wxopen/qrcodejumpadd?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/cgi-bin/wxopen/qrcodejumpadd?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newCgiBinWxOpenQrCodeJumpAddResult(CgiBinWxOpenQrCodeJumpAddResponse{}, request.ResponseBody, request), err
}

@ -33,7 +33,7 @@ func (c *Client) CgiBinWxOpenQrCodeJumpDelete(ctx context.Context, prefix string
params := gorequest.NewParamsWith(notMustParams...)
params.Set("prefix", prefix)
// 请求
request, err := c.request(ctx, apiUrl+"/cgi-bin/wxopen/qrcodejumpdelete?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/cgi-bin/wxopen/qrcodejumpdelete?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newCgiBinWxOpenQrCodeJumpDeleteResult(CgiBinWxOpenQrCodeJumpDeleteResponse{}, request.ResponseBody, request), err
}

@ -34,7 +34,7 @@ func (c *Client) CgiBinWxOpenQrCodeJumpDownload(ctx context.Context, notMustPara
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/cgi-bin/wxopen/qrcodejumpdownload?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/cgi-bin/wxopen/qrcodejumpdownload?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newCgiBinWxOpenQrCodeJumpDownloadResult(CgiBinWxOpenQrCodeJumpDownloadResponse{}, request.ResponseBody, request), err
}

@ -43,7 +43,7 @@ func (c *Client) CgiBinWxOpenQrCodeJumpGet(ctx context.Context, notMustParams ..
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/cgi-bin/wxopen/qrcodejumpget?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/cgi-bin/wxopen/qrcodejumpget?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newCgiBinWxOpenQrCodeJumpGetResult(CgiBinWxOpenQrCodeJumpGetResponse{}, request.ResponseBody, request), err
}

@ -33,7 +33,7 @@ func (c *Client) CgiBinWxOpenQrCodeJumpPublish(ctx context.Context, prefix strin
params := gorequest.NewParamsWith(notMustParams...)
params.Set("prefix", prefix)
// 请求
request, err := c.request(ctx, apiUrl+"/cgi-bin/wxopen/qrcodejumppublish?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/cgi-bin/wxopen/qrcodejumppublish?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newCgiBinWxOpenQrCodeJumpPublishResult(CgiBinWxOpenQrCodeJumpPublishResponse{}, request.ResponseBody, request), err
}

@ -18,7 +18,7 @@ func (c *Client) checkAuthorizerConfig(ctx context.Context) error {
if authorizerAppid == "" {
return errors.New("请配置 authorizerAppid")
}
authorizerAccessToken := c.GetAuthorizerAccessToken(ctx)
authorizerAccessToken := GetAuthorizerAccessToken(ctx, c)
if authorizerAccessToken == "" {
return errors.New("请配置 authorizerAccessToken")
}

@ -2,16 +2,26 @@ package wechatopen
import (
"errors"
"github.com/dtapps/go-library/utils/dorm"
"github.com/dtapps/go-library/utils/golog"
"github.com/dtapps/go-library/utils/gorequest"
)
// 缓存前缀
// wechat_open:component_verify_ticket:
// wechat_open:component_access_token:
// wechat_open:authorizer_access_token:
// wechat_open:pre_auth_code:
type redisCachePrefixFun func() (componentVerifyTicket, componentAccessToken, authorizerAccessToken, preAuthCode string)
// ClientConfig 实例配置
type ClientConfig struct {
ComponentAppId string `json:"component_app_id"` // 第三方平台appid
ComponentAppSecret string `json:"component_app_secret"` // 第三方平台app_secret
MessageToken string `json:"message_token"` // 第三方平台消息令牌
MessageKey string `json:"message_key"` // 第三方平台消息密钥
ComponentAppId string `json:"component_app_id"` // 第三方平台appid
ComponentAppSecret string `json:"component_app_secret"` // 第三方平台app_secret
MessageToken string `json:"message_token"` // 第三方平台消息令牌
MessageKey string `json:"message_key"` // 第三方平台消息密钥
RedisClient *dorm.RedisClient `json:"redis_client"` // 缓存数据库
RedisCachePrefixFun redisCachePrefixFun `json:"redis_cache_prefix_fun"` // 缓存前缀
}
// Client 实例
@ -29,6 +39,13 @@ type Client struct {
authorizerAccessToken string // 授权方access_token
authorizerRefreshToken string // 授权方refresh_token
}
cache struct {
redisClient *dorm.RedisClient // 缓存数据库
componentVerifyTicketPrefix string
componentAccessTokenPrefix string
authorizerAccessTokenPrefix string
preAuthCodePrefix string
}
log struct {
status bool // 状态
client *golog.ApiClient // 日志服务
@ -62,5 +79,12 @@ func NewClient(config *ClientConfig) (*Client, error) {
c.requestClient = gorequest.NewHttp()
c.cache.redisClient = config.RedisClient
c.cache.componentVerifyTicketPrefix, c.cache.componentAccessTokenPrefix, c.cache.authorizerAccessTokenPrefix, c.cache.preAuthCodePrefix = config.RedisCachePrefixFun()
if c.cache.componentVerifyTicketPrefix == "" || c.cache.componentAccessTokenPrefix == "" || c.cache.authorizerAccessTokenPrefix == "" || c.cache.preAuthCodePrefix == "" {
return nil, errors.New("请配置 RedisCachePrefixFun")
}
return c, nil
}

@ -2,6 +2,19 @@ package wechatopen
import "github.com/dtapps/go-library/utils/golog"
// ConfigComponent 配置
func (c *Client) ConfigComponent(componentAppId, componentAppSecret string) *Client {
c.config.componentAppId = componentAppId
c.config.componentAppSecret = componentAppSecret
return c
}
// ConfigAuthorizer 配置第三方
func (c *Client) ConfigAuthorizer(authorizerAppid string) *Client {
c.config.authorizerAppid = authorizerAppid
return c
}
// ConfigApiClientFun 日志配置
func (c *Client) ConfigApiClientFun(apiClientFun golog.ApiClientFun) {
apiClient := apiClientFun()

@ -41,7 +41,7 @@ func (c *Client) DataCubeGetWeAnAlySisAppidDailyRetainInfo(ctx context.Context,
params.Set("begin_date", beginDate)
params.Set("end_date", endDate)
// 请求
request, err := c.request(ctx, apiUrl+"/datacube/getweanalysisappiddailyretaininfo?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/datacube/getweanalysisappiddailyretaininfo?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newDataCubeGetWeAnAlySisAppidDailyRetainInfoResult(DataCubeGetWeAnAlySisAppidDailyRetainInfoResponse{}, request.ResponseBody, request), err
}

@ -38,7 +38,7 @@ func (c *Client) DataCubeGetWeAnAlySisAppidDailySummaryTrend(ctx context.Context
params.Set("begin_date", beginDate)
params.Set("end_date", endDate)
// 请求
request, err := c.request(ctx, apiUrl+"/datacube/getweanalysisappiddailysummarytrend?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/datacube/getweanalysisappiddailysummarytrend?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newDataCubeGetWeAnAlySisAppidDailySummaryTrendResult(DataCubeGetWeAnAlySisAppidDailySummaryTrendResponse{}, request.ResponseBody, request), err
}

@ -42,7 +42,7 @@ func (c *Client) DataCubeGetWeAnAlySisAppidDailyVisitTrend(ctx context.Context,
params.Set("begin_date", beginDate)
params.Set("end_date", endDate)
// 请求
request, err := c.request(ctx, apiUrl+"/datacube/getweanalysisappiddailyvisittrend?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/datacube/getweanalysisappiddailyvisittrend?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newDataCubeGetWeAnAlySisAppidDailyVisitTrendResult(DataCubeGetWeAnAlySisAppidDailyVisitTrendResponse{}, request.ResponseBody, request), err
}

@ -41,7 +41,7 @@ func (c *Client) DataCubeGetWeAnAlySisAppidMonthlyRetainInfo(ctx context.Context
params.Set("begin_date", beginDate)
params.Set("end_date", endDate)
// 请求
request, err := c.request(ctx, apiUrl+"/datacube/getweanalysisappidmonthlyretaininfo?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/datacube/getweanalysisappidmonthlyretaininfo?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newDataCubeGetWeAnAlySisAppidMonthlyRetainInfoResult(DataCubeGetWeAnAlySisAppidMonthlyRetainInfoResponse{}, request.ResponseBody, request), err
}

@ -42,7 +42,7 @@ func (c *Client) DataCubeGetWeAnAlySisAppidMonthlyVisitTrend(ctx context.Context
params.Set("begin_date", beginDate)
params.Set("end_date", endDate)
// 请求
request, err := c.request(ctx, apiUrl+"/datacube/getweanalysisappidmonthlyvisittrend?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/datacube/getweanalysisappidmonthlyvisittrend?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newDataCubeGetWeAnAlySisAppidMonthlyVisitTrendResult(DataCubeGetWeAnAlySisAppidMonthlyVisitTrendResponse{}, request.ResponseBody, request), err
}

@ -95,7 +95,7 @@ func (c *Client) DataCubeGetWeAnAlySisAppidUserPortrait(ctx context.Context, beg
params.Set("begin_date", beginDate)
params.Set("end_date", endDate)
// 请求
request, err := c.request(ctx, apiUrl+"/datacube/getweanalysisappiduserportrait?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/datacube/getweanalysisappiduserportrait?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newDataCubeGetWeAnAlySisAppidUserPortraitResult(DataCubeGetWeAnAlySisAppidUserPortraitResponse{}, request.ResponseBody, request), err
}

@ -40,7 +40,7 @@ func (c *Client) DataCubeGetWeAnAlysIsAppidVisitDistribution(ctx context.Context
params.Set("begin_date", beginDate)
params.Set("end_date", endDate)
// 请求
request, err := c.request(ctx, apiUrl+"/datacube/getweanalysisappidvisitdistribution?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/datacube/getweanalysisappidvisitdistribution?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newDataCubeGetWeAnAlysIsAppidVisitDistributionResult(DataCubeGetWeAnAlysIsAppidVisitDistributionResponse{}, request.ResponseBody, request), err
}

@ -43,7 +43,7 @@ func (c *Client) DataCubeGetWeAnAlySisAppidVisitPage(ctx context.Context, beginD
params.Set("begin_date", beginDate)
params.Set("end_date", endDate)
// 请求
request, err := c.request(ctx, apiUrl+"/datacube/getweanalysisappidvisitpage?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/datacube/getweanalysisappidvisitpage?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newDataCubeGetWeAnAlySisAppidVisitPageResult(DataCubeGetWeAnAlySisAppidVisitPageResponse{}, request.ResponseBody, request), err
}

@ -41,7 +41,7 @@ func (c *Client) DataCubeGetWeAnAlySisAppidWeeklyRetainInfo(ctx context.Context,
params.Set("begin_date", beginDate)
params.Set("end_date", endDate)
// 请求
request, err := c.request(ctx, apiUrl+"/datacube/getweanalysisappidweeklyretaininfo?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/datacube/getweanalysisappidweeklyretaininfo?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newDataCubeGetWeAnAlySisAppidWeeklyRetainInfoResult(DataCubeGetWeAnAlySisAppidWeeklyRetainInfoResponse{}, request.ResponseBody, request), err
}

@ -42,7 +42,7 @@ func (c *Client) DataCubeGetWeAnAlySisAppidWeeklyVisitTrend(ctx context.Context,
params.Set("begin_date", beginDate)
params.Set("end_date", endDate)
// 请求
request, err := c.request(ctx, apiUrl+"/datacube/getweanalysisappidweeklyvisittrend?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/datacube/getweanalysisappidweeklyvisittrend?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newDataCubeGetWeAnAlySisAppidWeeklyVisitTrendResult(DataCubeGetWeAnAlySisAppidWeeklyVisitTrendResponse{}, request.ResponseBody, request), err
}

@ -10,23 +10,43 @@ func (c *Client) GetComponentAppId(ctx context.Context) string {
return c.config.componentAppId
}
// NewGetComponentAppId 获取第三方平台appid
func (c *Client) NewGetComponentAppId(ctx context.Context) string {
return c.config.componentAppId
}
// GetComponentAppSecret 获取第三方平台app_secret
func (c *Client) GetComponentAppSecret(ctx context.Context) string {
return c.config.componentAppSecret
}
// NewGetComponentAppSecret 获取第三方平台app_secret
func (c *Client) NewGetComponentAppSecret(ctx context.Context) string {
return c.config.componentAppSecret
}
// GetMessageToken 获取第三方平台消息令牌
func (c *Client) GetMessageToken(ctx context.Context) string {
return c.config.messageToken
}
// NewGetMessageToken 获取第三方平台消息令牌
func (c *Client) NewGetMessageToken(ctx context.Context) string {
return c.config.messageToken
}
// GetMessageKey 获取第三方平台消息密钥
func (c *Client) GetMessageKey(ctx context.Context) string {
return c.config.messageKey
}
// GetComponentAccessToken 获取第三方平台access_token
func (c *Client) GetComponentAccessToken(ctx context.Context) string {
// NewGetMessageKey 获取第三方平台消息密钥
func (c *Client) NewGetMessageKey(ctx context.Context) string {
return c.config.messageKey
}
// NewGetComponentAccessToken 获取第三方平台access_token
func (c *Client) NewGetComponentAccessToken(ctx context.Context) string {
return c.config.componentAccessToken
}
@ -35,8 +55,13 @@ func (c *Client) GetComponentVerifyTicket(ctx context.Context) string {
return c.config.componentVerifyTicket
}
// GetPreAuthCode 获取第三方平台预授权码
func (c *Client) GetPreAuthCode(ctx context.Context) string {
// NewGetComponentVerifyTicket 获取第三方平台推送ticket
func (c *Client) NewGetComponentVerifyTicket(ctx context.Context) string {
return c.config.componentVerifyTicket
}
// NewGetPreAuthCode 获取第三方平台预授权码
func (c *Client) NewGetPreAuthCode(ctx context.Context) string {
return c.config.preAuthCode
}
@ -45,13 +70,18 @@ func (c *Client) GetAuthorizerAppid(ctx context.Context) string {
return c.config.authorizerAppid
}
// GetAuthorizerAccessToken 获取授权方access_token
func (c *Client) GetAuthorizerAccessToken(ctx context.Context) string {
// NewGetAuthorizerAppid 获取授权方appid
func (c *Client) NewGetAuthorizerAppid(ctx context.Context) string {
return c.config.authorizerAppid
}
// NewGetAuthorizerAccessToken 获取授权方access_token
func (c *Client) NewGetAuthorizerAccessToken(ctx context.Context) string {
return c.config.authorizerAccessToken
}
// GetAuthorizerRefreshToken 获取授权方refresh_token
func (c *Client) GetAuthorizerRefreshToken(ctx context.Context) string {
// NewGetAuthorizerRefreshToken 获取授权方refresh_token
func (c *Client) NewGetAuthorizerRefreshToken(ctx context.Context) string {
return c.config.authorizerRefreshToken
}

@ -0,0 +1,52 @@
package wechatopen
import (
"context"
"errors"
"fmt"
"time"
)
// GetAuthorizerAccessTokenCacheKeyName 授权方access_token 缓存名称
func GetAuthorizerAccessTokenCacheKeyName(ctx context.Context, c *Client) string {
return c.cache.authorizerAccessTokenPrefix + c.GetComponentAppId(ctx) + ":" + c.GetAuthorizerAppid(ctx)
}
// GetAuthorizerAccessToken 授权方access_token
func GetAuthorizerAccessToken(ctx context.Context, c *Client) string {
if c.cache.redisClient.GetDb() == nil {
return c.config.authorizerAccessToken
}
result, _ := c.cache.redisClient.Get(ctx, GetAuthorizerAccessTokenCacheKeyName(ctx, c)).Result()
return result
}
// SetAuthorizerAccessToken 授权方access_token
func SetAuthorizerAccessToken(ctx context.Context, c *Client, authorizerAccessToken string) string {
if authorizerAccessToken == "" {
return ""
}
c.cache.redisClient.Set(ctx, GetAuthorizerAccessTokenCacheKeyName(ctx, c), authorizerAccessToken, time.Hour*2)
return GetAuthorizerAccessToken(ctx, c)
}
// DelAuthorizerAccessToken 授权方access_token 删除
func DelAuthorizerAccessToken(ctx context.Context, c *Client) error {
return c.cache.redisClient.Del(ctx, GetAuthorizerAccessTokenCacheKeyName(ctx, c)).Err()
}
// MonitorAuthorizerAccessToken 授权方access_token 监控
func MonitorAuthorizerAccessToken(ctx context.Context, c *Client, authorizerRefreshToken string) (string, error) {
// 查询
authorizerAccessToken := GetAuthorizerAccessToken(ctx, c)
// 判断
if authorizerAccessToken != "" {
return authorizerAccessToken, nil
}
// 重新获取
resp, err := c.CgiBinComponentApiAuthorizerToken(ctx, authorizerRefreshToken)
if resp.Result.AuthorizerRefreshToken == "" {
return authorizerAccessToken, errors.New(fmt.Sprintf("获取失败:%v", err))
}
return SetAuthorizerAccessToken(ctx, c, resp.Result.AuthorizerAccessToken), err
}

@ -0,0 +1,51 @@
package wechatopen
import (
"context"
"time"
)
// GetComponentAccessTokenCacheKeyName 第三方平台access_token 缓存名称
func GetComponentAccessTokenCacheKeyName(ctx context.Context, c *Client) string {
return c.cache.componentAccessTokenPrefix + c.GetComponentAppId(ctx)
}
// GetComponentAccessToken 第三方平台access_token 获取
func GetComponentAccessToken(ctx context.Context, c *Client) string {
if c.cache.redisClient.GetDb() == nil {
return c.config.componentAccessToken
}
result, _ := c.cache.redisClient.GetDb().Get(ctx, GetComponentAccessTokenCacheKeyName(ctx, c)).Result()
return result
}
// SetComponentAccessToken 第三方平台access_token 设置
func SetComponentAccessToken(ctx context.Context, c *Client, componentAccessToken string) string {
if componentAccessToken == "" {
return ""
}
c.cache.redisClient.Set(ctx, GetComponentAccessTokenCacheKeyName(ctx, c), componentAccessToken, time.Second*7200)
return GetComponentAccessToken(ctx, c)
}
// DelComponentAccessToken 第三方平台access_token 删除
func DelComponentAccessToken(ctx context.Context, c *Client) error {
return c.cache.redisClient.Del(ctx, GetComponentAccessTokenCacheKeyName(ctx, c)).Err()
}
// MonitorComponentAccessToken 第三方平台access_token 监控
func MonitorComponentAccessToken(ctx context.Context, c *Client) (string, error) {
// 查询
componentAccessToken := GetComponentAccessToken(ctx, c)
// 判断
result, err := c.CgiBinGetApiDomainIp(ctx, componentAccessToken)
if err != nil {
return "", err
}
if len(result.Result.IpList) > 0 {
return componentAccessToken, err
}
// 重新获取
resp, err := c.CgiBinComponentApiComponentToken(ctx)
return SetComponentAccessToken(ctx, c, resp.Result.ComponentAccessToken), err
}

@ -0,0 +1,34 @@
package wechatopen
import (
"context"
"time"
)
// GetComponentVerifyTicketCacheKeyName 第三方平台推送ticket 缓存名称
func GetComponentVerifyTicketCacheKeyName(ctx context.Context, c *Client) string {
return c.cache.componentVerifyTicketPrefix + c.GetComponentAppId(ctx)
}
// GetComponentVerifyTicket 第三方平台推送ticket 获取
func GetComponentVerifyTicket(ctx context.Context, c *Client) string {
if c.cache.redisClient.GetDb() == nil {
return c.config.componentVerifyTicket
}
result, _ := c.cache.redisClient.Get(ctx, GetComponentVerifyTicketCacheKeyName(ctx, c)).Result()
return result
}
// SetComponentVerifyTicket 第三方平台推送ticket 设置
func SetComponentVerifyTicket(ctx context.Context, c *Client, componentVerifyTicket string) string {
if componentVerifyTicket == "" {
return ""
}
c.cache.redisClient.Set(ctx, GetComponentVerifyTicketCacheKeyName(ctx, c), componentVerifyTicket, time.Hour*12)
return GetComponentVerifyTicket(ctx, c)
}
// DelComponentVerifyTicket 第三方平台推送ticket 删除
func DelComponentVerifyTicket(ctx context.Context, c *Client) error {
return c.cache.redisClient.Del(ctx, GetComponentVerifyTicketCacheKeyName(ctx, c)).Err()
}

@ -0,0 +1,47 @@
package wechatopen
import (
"context"
"time"
)
// GetPreAuthCodeCacheKeyName 第三方平台预授权码 缓存名称
func GetPreAuthCodeCacheKeyName(ctx context.Context, c *Client) string {
return c.cache.preAuthCodePrefix + c.GetComponentAppId(ctx)
}
// GetPreAuthCode 第三方平台预授权码 获取
func GetPreAuthCode(ctx context.Context, c *Client) string {
if c.cache.redisClient.GetDb() == nil {
return c.config.authorizerAccessToken
}
result, _ := c.cache.redisClient.Get(ctx, GetPreAuthCodeCacheKeyName(ctx, c)).Result()
return result
}
// SetPreAuthCode 第三方平台预授权码 设置
func SetPreAuthCode(ctx context.Context, c *Client, preAuthCode string) string {
if preAuthCode == "" {
return ""
}
c.cache.redisClient.Set(ctx, GetPreAuthCodeCacheKeyName(ctx, c), preAuthCode, time.Second*1700)
return GetPreAuthCode(ctx, c)
}
// DelPreAuthCode 第三方平台预授权码 删除
func DelPreAuthCode(ctx context.Context, c *Client) error {
return c.cache.redisClient.Del(ctx, GetPreAuthCodeCacheKeyName(ctx, c)).Err()
}
// MonitorPreAuthCode 第三方平台预授权码 监控
func MonitorPreAuthCode(ctx context.Context, c *Client) (string, error) {
// 查询
preAuthCode := GetPreAuthCode(ctx, c)
// 判断
if preAuthCode != "" {
return preAuthCode, nil
}
// 重新获取
resp, err := c.CgiBinComponentApiCreatePreAuthCoden(ctx)
return SetPreAuthCode(ctx, c, resp.Result.PreAuthCode), err
}

@ -2,32 +2,32 @@ package wechatopen
import "context"
// SetComponentAccessToken 设置第三方平台access_token
func (c *Client) SetComponentAccessToken(ctx context.Context, componentAccessToken string) {
// NewSetComponentAccessToken 设置第三方平台access_token
func (c *Client) NewSetComponentAccessToken(ctx context.Context, componentAccessToken string) {
c.config.componentAccessToken = componentAccessToken
}
// SetComponentVerifyTicket 设置第三方平台推送ticket
func (c *Client) SetComponentVerifyTicket(ctx context.Context, componentVerifyTicket string) {
// NewSetComponentVerifyTicket 设置第三方平台推送ticket
func (c *Client) NewSetComponentVerifyTicket(ctx context.Context, componentVerifyTicket string) {
c.config.componentVerifyTicket = componentVerifyTicket
}
// SetPreAuthCode 设置第三方平台预授权码
func (c *Client) SetPreAuthCode(ctx context.Context, preAuthCode string) {
// NewSetPreAuthCode 设置第三方平台预授权码
func (c *Client) NewSetPreAuthCode(ctx context.Context, preAuthCode string) {
c.config.preAuthCode = preAuthCode
}
// SetAuthorizerAppid 设置授权方appid
func (c *Client) SetAuthorizerAppid(ctx context.Context, authorizerAppid string) {
// NewSetAuthorizerAppid 设置授权方appid
func (c *Client) NewSetAuthorizerAppid(ctx context.Context, authorizerAppid string) {
c.config.authorizerAppid = authorizerAppid
}
// SetAuthorizerAccessToken 设置授权方access_token
func (c *Client) SetAuthorizerAccessToken(ctx context.Context, authorizerAccessToken string) {
// NewSetAuthorizerAccessToken 设置授权方access_token
func (c *Client) NewSetAuthorizerAccessToken(ctx context.Context, authorizerAccessToken string) {
c.config.authorizerAccessToken = authorizerAccessToken
}
// SetAuthorizerRefreshToken 设置授权方refresh_token
func (c *Client) SetAuthorizerRefreshToken(ctx context.Context, authorizerRefreshToken string) {
// NewSetAuthorizerRefreshToken 设置授权方refresh_token
func (c *Client) NewSetAuthorizerRefreshToken(ctx context.Context, authorizerRefreshToken string) {
c.config.authorizerRefreshToken = authorizerRefreshToken
}

@ -37,11 +37,11 @@ func (c *Client) SnsComponentJsCode2session(ctx context.Context, jsCode string,
}
// 参数
params := gorequest.NewParamsWith(notMustParams...)
params["appid"] = c.GetAuthorizerAppid(ctx) // 小程序的 appId
params["js_code"] = jsCode // wx.login 获取的 code
params["grant_type"] = "authorization_code" // 填 authorization_code
params["component_appid"] = c.GetComponentAppId(ctx) // 第三方平台 appid
params["component_access_token"] = c.GetComponentAccessToken(ctx) // 第三方平台的component_access_token
params["appid"] = c.GetAuthorizerAppid(ctx) // 小程序的 appId
params["js_code"] = jsCode // wx.login 获取的 code
params["grant_type"] = "authorization_code" // 填 authorization_code
params["component_appid"] = c.GetComponentAppId(ctx) // 第三方平台 appid
params["component_access_token"] = GetComponentAccessToken(ctx, c) // 第三方平台的component_access_token
// 请求
request, err := c.request(ctx, apiUrl+"/sns/component/jscode2session", params, http.MethodGet)
if err != nil {

@ -36,7 +36,7 @@ func (c *Client) TckWxPayList(ctx context.Context, notMustParams ...gorequest.Pa
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/tcb/wxpaylist?access_token="+c.GetComponentAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/tcb/wxpaylist?access_token="+GetComponentAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newTckWxPayListResult(TckWxPayListResponse{}, request.ResponseBody, request), err
}

@ -30,7 +30,7 @@ func (c *Client) WxaAddToTemplate(ctx context.Context, draftId string, templateT
params.Set("draft_id", draftId)
params.Set("template_type", templateType)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/addtotemplate?access_token="+c.GetComponentAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/addtotemplate?access_token="+GetComponentAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaAddToTemplateResult(WxaAddToTemplateResponse{}, request.ResponseBody, request), err
}

@ -34,7 +34,7 @@ func (c *Client) WxaBindTester(ctx context.Context, wechatid string, notMustPara
params := gorequest.NewParamsWith(notMustParams...)
params["wechatid"] = wechatid
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/bind_tester?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/bind_tester?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaBindTesterResult(WxaBindTesterResponse{}, request.ResponseBody, request), err
}

@ -42,7 +42,7 @@ func (c *Client) WxaBusinessGetUserPhoneNumber(ctx context.Context, code string,
params := gorequest.NewParamsWith(notMustParams...)
params.Set("code", code)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/business/getuserphonenumber?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/business/getuserphonenumber?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaBusinessGetUserPhoneNumberResult(WxaBusinessGetUserPhoneNumberResponse{}, request.ResponseBody, request), err
}

@ -32,7 +32,7 @@ func (c *Client) WxaCommit(ctx context.Context, notMustParams ...gorequest.Param
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/commit?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/commit?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaCommitResult(WxaCommitResponse{}, request.ResponseBody, request), err
}

@ -33,7 +33,7 @@ func (c *Client) WxaDeleteTemplate(ctx context.Context, templateId string, notMu
params := gorequest.NewParamsWith(notMustParams...)
params.Set("template_id", templateId)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/deletetemplate?access_token="+c.GetComponentAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/deletetemplate?access_token="+GetComponentAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaDeleteTemplateResult(WxaDeleteTemplateResponse{}, request.ResponseBody, request), err
}

@ -37,7 +37,7 @@ func (c *Client) WxaGetAuditStatus(ctx context.Context, auditid int64, notMustPa
params := gorequest.NewParamsWith(notMustParams...)
params.Set("auditid", auditid)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/get_auditstatus?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/get_auditstatus?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaGetAuditStatusResult(WxaGetAuditStatusResponse{}, request.ResponseBody, request), err
}

@ -40,7 +40,7 @@ func (c *Client) WxaGetCategory(ctx context.Context, notMustParams ...gorequest.
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/get_category?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/wxa/get_category?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodGet)
if err != nil {
return newWxaGetCategoryResult(WxaGetCategoryResponse{}, request.ResponseBody, request), err
}

@ -56,7 +56,7 @@ func (c *Client) WxaGetEffectiveDomain(ctx context.Context, notMustParams ...gor
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/get_effective_domain?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/get_effective_domain?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaGetEffectiveDomainResult(WxaGetEffectiveDomainResponse{}, request.ResponseBody, request), err
}

@ -39,7 +39,7 @@ func (c *Client) WxaGetLatestAuditStatus(ctx context.Context, notMustParams ...g
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/get_latest_auditstatus?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/wxa/get_latest_auditstatus?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodGet)
if err != nil {
return newWxaGetLatestAuditStatusResult(WxaGetLatestAuditStatusResponse{}, request.ResponseBody, request), err
}

@ -33,7 +33,7 @@ func (c *Client) WxaGetPage(ctx context.Context, notMustParams ...gorequest.Para
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/get_page?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/wxa/get_page?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodGet)
if err != nil {
return newWxaGetPageResult(WxaGetPageResponse{}, request.ResponseBody, request), err
}

@ -38,7 +38,7 @@ func (c *Client) WxaGetQrcode(ctx context.Context, path string, notMustParams ..
params.Set("path", path) // 指定二维码扫码后直接进入指定页面并可同时带上参数)
}
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/get_qrcode?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/wxa/get_qrcode?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodGet)
if err != nil {
return newWxaGetQrcodeResult(WxaGetQrcodeResponse{}, request.ResponseBody, request), err
}

@ -34,7 +34,7 @@ func (c *Client) WxaGetDefaultamsInfoAgencyGetCustomShareRatio(ctx context.Conte
params := gorequest.NewParamsWith(notMustParams...)
params.Set("appid", c.GetAuthorizerAppid(ctx))
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/getdefaultamsinfo?action=agency_get_custom_share_ratio&access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/getdefaultamsinfo?action=agency_get_custom_share_ratio&access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaGetDefaultamsInfoAgencyGetCustomShareRatioResult(WxaGetDefaultamsInfoAgencyGetCustomShareRatioResponse{}, request.ResponseBody, request), err
}

@ -33,7 +33,7 @@ func (c *Client) WxaGetDefaultamsInfoGetShareRatio(ctx context.Context, notMustP
params := gorequest.NewParamsWith(notMustParams...)
params.Set("appid", c.GetAuthorizerAppid(ctx))
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/getdefaultamsinfo?action=get_share_ratio&access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/getdefaultamsinfo?action=get_share_ratio&access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaGetDefaultamsInfoGetShareRatioResult(WxaGetDefaultamsInfoGetShareRatioResponse{}, request.ResponseBody, request), err
}

@ -38,7 +38,7 @@ func (c *Client) WxaGetTemplateDraftList(ctx context.Context, notMustParams ...g
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/gettemplatedraftlist?access_token="+c.GetComponentAccessToken(ctx), params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/wxa/gettemplatedraftlist?access_token="+GetComponentAccessToken(ctx, c), params, http.MethodGet)
if err != nil {
return newWxaGetTemplateDraftListResult(WxaGetTemplateDraftListResponse{}, request.ResponseBody, request), err
}

@ -39,7 +39,7 @@ func (c *Client) WxaGetTemplateList(ctx context.Context, notMustParams ...gorequ
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/gettemplatelist?access_token="+c.GetComponentAccessToken(ctx), params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/wxa/gettemplatelist?access_token="+GetComponentAccessToken(ctx, c), params, http.MethodGet)
if err != nil {
return newWxaGetTemplateListResult(WxaGetTemplateListResponse{}, request.ResponseBody, request), err
}

@ -35,7 +35,7 @@ func (c *Client) WxaGetUserRiskRank(ctx context.Context, notMustParams ...gorequ
params := gorequest.NewParamsWith(notMustParams...)
params.Set("appid", c.GetAuthorizerAppid(ctx))
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/getuserriskrank?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/getuserriskrank?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaGetUserRiskRankResult(WxaGetUserRiskRankResponse{}, request.ResponseBody, request), err
}

@ -42,7 +42,7 @@ func (c *Client) WxaGetVersionInfo(ctx context.Context, notMustParams ...goreque
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/getversioninfo?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/getversioninfo?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaGetVersionInfoResult(WxaGetVersionInfoResponse{}, request.ResponseBody, request), err
}

@ -34,7 +34,7 @@ func (c *Client) WxaGetWxaCodeUnLimit(ctx context.Context, notMustParams ...gore
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/getwxacodeunlimit?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/getwxacodeunlimit?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaGetWxaCodeUnLimitResult(WxaGetWxaCodeUnLimitResponse{}, request.ResponseBody, request), err
}

@ -51,7 +51,7 @@ func (c *Client) WxaMediaCheckAsync(ctx context.Context, notMustParams ...gorequ
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/media_check_async?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/media_check_async?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaMediaCheckAsyncResult(WxaMediaCheckAsyncResponse{}, request.ResponseBody, request), err
}

@ -36,7 +36,7 @@ func (c *Client) WxaMemberAuth(ctx context.Context, notMustParams ...gorequest.P
params := gorequest.NewParamsWith(notMustParams...)
params.Set("action", "get_experiencer")
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/memberauth?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/memberauth?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaMemberAuthResult(WxaMemberAuthResponse{}, request.ResponseBody, request), err
}

@ -45,7 +45,7 @@ func (c *Client) WxaModifyDomain(ctx context.Context, notMustParams ...gorequest
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/modify_domain?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/modify_domain?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaModifyDomainResult(WxaModifyDomainResponse{}, request.ResponseBody, request), err
}

@ -45,7 +45,7 @@ func (c *Client) WxaModifyDomainDirectly(ctx context.Context, notMustParams ...g
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/modify_domain_directly?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/modify_domain_directly?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaModifyDomainDirectlyResult(WxaModifyDomainDirectlyResponse{}, request.ResponseBody, request), err
}

@ -46,7 +46,7 @@ func (c *Client) WxaMsgSecCheck(ctx context.Context, notMustParams ...gorequest.
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/msg_sec_check?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/msg_sec_check?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaMsgSecCheckResult(WxaMsgSecCheckResponse{}, request.ResponseBody, request), err
}

@ -33,7 +33,7 @@ func (c *Client) WxaOperationamsAgencyCheckCanOpenPublisher(ctx context.Context,
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/operationams?action=agency_check_can_open_publisher&access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/operationams?action=agency_check_can_open_publisher&access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaOperationamsAgencyCheckCanOpenPublisherResult(WxaOperationamsAgencyCheckCanOpenPublisherResponse{}, request.ResponseBody, request), err
}

@ -32,7 +32,7 @@ func (c *Client) WxaOperationamsAgencyCreatePublisher(ctx context.Context, notMu
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/operationams?action=agency_check_can_open_publisher&access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/operationams?action=agency_check_can_open_publisher&access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaOperationamsAgencyCreatePublisherResult(WxaOperationamsAgencyCreatePublisherResponse{}, request.ResponseBody, request), err
}

@ -32,7 +32,7 @@ func (c *Client) WxaRelease(ctx context.Context, notMustParams ...gorequest.Para
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/release?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/release?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaReleaseResult(WxaReleaseResponse{}, request.ResponseBody, request), err
}

@ -38,7 +38,7 @@ func (c *Client) WxaRevertCodeRelease(ctx context.Context, notMustParams ...gore
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/revertcoderelease?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/wxa/revertcoderelease?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodGet)
if err != nil {
return newWxaRevertCodeReleaseResult(WxaRevertCodeReleaseResponse{}, request.ResponseBody, request), err
}

@ -33,7 +33,7 @@ func (c *Client) WxaSecurityApplyPrivacyInterface(ctx context.Context, notMustPa
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/security/apply_privacy_interface?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/security/apply_privacy_interface?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaSecurityApplyPrivacyInterfaceResult(WxaSecurityApplyPrivacyInterfaceResponse{}, request.ResponseBody, request), err
}

@ -32,7 +32,7 @@ func (c *Client) WxaSecurityApplySetOrderPathInfo(ctx context.Context, notMustPa
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/security/applysetorderpathinfo?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/security/applysetorderpathinfo?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaSecurityApplySetOrderPathInfoResult(WxaSecurityApplySetOrderPathInfoResponse{}, request.ResponseBody, request), err
}

@ -43,7 +43,7 @@ func (c *Client) WxaSecurityGetPrivacyInterface(ctx context.Context, notMustPara
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/security/get_privacy_interface?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/wxa/security/get_privacy_interface?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodGet)
if err != nil {
return newWxaSecurityGetPrivacyInterfaceResult(WxaSecurityGetPrivacyInterfaceResponse{}, request.ResponseBody, request), err
}

@ -43,7 +43,7 @@ func (c *Client) WxaSecurityGetOrderPathInfo(ctx context.Context, infoType int,
params := gorequest.NewParamsWith(notMustParams...)
params.Set("info_type", infoType)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/security/getorderpathinfo?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/security/getorderpathinfo?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaSecurityGetOrderPathInfoResult(WxaSecurityGetOrderPathInfoResponse{}, request.ResponseBody, request), err
}

@ -35,7 +35,7 @@ func (c *Client) WxaSetDefaultamsInfoAgencySetCustomShareRatio(ctx context.Conte
params.Set("share_ratio", shareRatio)
}
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/setdefaultamsinfo?action=agency_set_custom_share_ratio&access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/setdefaultamsinfo?action=agency_set_custom_share_ratio&access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaSetDefaultamsInfoAgencySetCustomShareRatioResult(WxaSetDefaultamsInfoAgencySetCustomShareRatioResponse{}, request.ResponseBody, request), err
}

@ -35,7 +35,7 @@ func (c *Client) WxaSetDefaultamsInfoSetShareRatio(ctx context.Context, shareRat
params.Set("share_ratio", shareRatio)
}
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/setdefaultamsinfo?action=set_share_ratio&access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/setdefaultamsinfo?action=set_share_ratio&access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaSetDefaultamsInfoSetShareRatioResult(WxaSetDefaultamsInfoSetShareRatioResponse{}, request.ResponseBody, request), err
}

@ -32,7 +32,7 @@ func (c *Client) WxaSetWebViewDoMain(ctx context.Context, notMustParams ...goreq
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/setwebviewdomain?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/setwebviewdomain?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaSetWebViewDoMainResult(WxaSetWebViewDoMainResponse{}, request.ResponseBody, request), err
}

@ -33,7 +33,7 @@ func (c *Client) WxaSubmitAudit(ctx context.Context, notMustParams ...gorequest.
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/submit_audit?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/submit_audit?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaSubmitAuditResult(WxaSubmitAuditResponse{}, request.ResponseBody, request), err
}

@ -36,7 +36,7 @@ func (c *Client) WxaUnbindTester(ctx context.Context, wechatid, userstr string,
}
params.Set("userstr", userstr)
// 请求
request, err := c.request(ctx, apiUrl+"/wxa/unbind_tester?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxa/unbind_tester?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaUnbindTesterResult(WxaUnbindTesterResponse{}, request.ResponseBody, request), err
}

@ -32,7 +32,7 @@ func (c *Client) WxaApiWxaembeddedAddEmbedded(ctx context.Context, notMustParams
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxaapi/wxaembedded/add_embedded?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxaapi/wxaembedded/add_embedded?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaApiWxaembeddedAddEmbeddedResult(WxaApiWxaembeddedAddEmbeddedResponse{}, request.ResponseBody, request), err
}

@ -32,7 +32,7 @@ func (c *Client) WxaApiWxaembeddedDelEmbedded(ctx context.Context, notMustParams
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxaapi/wxaembedded/del_embedded?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxaapi/wxaembedded/del_embedded?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaApiWxaembeddedDelEmbeddedResult(WxaApiWxaembeddedDelEmbeddedResponse{}, request.ResponseBody, request), err
}

@ -32,7 +32,7 @@ func (c *Client) WxaApiWxaembeddedDelAuthorize(ctx context.Context, notMustParam
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxaapi/wxaembedded/del_authorize?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxaapi/wxaembedded/del_authorize?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaApiWxaembeddedDelAuthorizeResult(WxaApiWxaembeddedDelAuthorizeResponse{}, request.ResponseBody, request), err
}

@ -41,7 +41,7 @@ func (c *Client) WxaApiWxaembeddedGetList(ctx context.Context, notMustParams ...
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxaapi/wxaembedded/get_list?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/wxaapi/wxaembedded/get_list?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodGet)
if err != nil {
return newWxaApiWxaembeddedGetListResult(WxaApiWxaembeddedGetListResponse{}, request.ResponseBody, request), err
}

@ -41,7 +41,7 @@ func (c *Client) WxaApiWxAembeddedGetOwnList(ctx context.Context, notMustParams
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxaapi/wxaembedded/get_own_list?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/wxaapi/wxaembedded/get_own_list?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodGet)
if err != nil {
return newWxaApiWxAembeddedGetOwnListResult(WxaApiWxAembeddedGetOwnListResponse{}, request.ResponseBody, request), err
}

@ -33,7 +33,7 @@ func (c *Client) WxaApiWxAembeddedSetAuthorize(ctx context.Context, notMustParam
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, apiUrl+"/wxaapi/wxaembedded/set_authorize?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/wxaapi/wxaembedded/set_authorize?access_token="+GetAuthorizerAccessToken(ctx, c), params, http.MethodPost)
if err != nil {
return newWxaApiWxAembeddedSetAuthorizeResult(WxaApiWxAembeddedSetAuthorizeResponse{}, request.ResponseBody, request), err
}

@ -17,12 +17,14 @@ linters:
- bodyclose
- errcheck
- gofmt
- revive
- gofumpt
- goimports
- gosec
- gosimple
- govet
- ineffassign
- misspell
- revive
- staticcheck
- typecheck
- unused
@ -44,3 +46,5 @@ output:
linters-settings:
golint:
min-confidence: 0.8
fix: true

@ -6,6 +6,7 @@ fmt:
@go list -f {{.Dir}} ./... | xargs -I{} gofmt -w -s {}
lint:
@grep "^func " example_test.go | sort -c
@golangci-lint run
test:

@ -32,7 +32,10 @@ If you want to chat, you can find us at Slack!
```golang
s := gocron.NewScheduler(time.UTC)
s.Every(5).Seconds().Do(func(){ ... })
job, err := s.Every(5).Seconds().Do(func(){ ... })
if err != nil {
// handle the error related to setting up the job
}
// strings parse to duration
s.Every("5m").Do(func(){ ... })
@ -82,11 +85,16 @@ For more examples, take a look in our [go docs](https://pkg.go.dev/github.com/go
There are several options available to restrict how jobs run:
| Mode | Function | Behavior |
| --------------- | ------------------------ | ------------------------------------------------------------------------------- |
| Default | | jobs are rescheduled at every interval |
| Job singleton | `SingletonMode()` | a long running job will not be rescheduled until the current run is completed |
| Scheduler limit | `SetMaxConcurrentJobs()` | set a collective maximum number of concurrent jobs running across the scheduler |
| Mode | Function | Behavior |
|----------------------------|---------------------------|------------------------------------------------------------------------------------------------------|
| Default | | jobs are rescheduled at every interval |
| Job singleton | `SingletonMode()` | a long running job will not be rescheduled until the current run is completed |
| Scheduler limit | `SetMaxConcurrentJobs()` | set a collective maximum number of concurrent jobs running across the scheduler |
| Distributed locking (BETA) | `WithDistributedLocker()` | prevents the same job from being run more than once when running multiple instances of the scheduler |
## Distributed Locker Implementations
- Redis: [redis.go](lockers/redislock/redislock.go) `go get github.com/go-co-op/gocron/lockers/redislock`
## Tags
@ -113,7 +121,9 @@ s.RunByTag("tag")
## FAQ
- Q: I'm running multiple pods on a distributed environment. How can I make a job not run once per pod causing duplication?
- A: We recommend using your own lock solution within the jobs themselves (you could use [Redis](https://redis.io/topics/distlock), for example)
- We recommend using your own lock solution within the jobs themselves (you could use [Redis](https://redis.io/topics/distlock), for example)
- A2: Currently in BETA (please provide feedback): Use the scheduler option `WithDistributedLocker` and either use an implemented backend
or implement your own and contribute it back in a PR (we hope)!
- Q: I've removed my job from the scheduler, but how can I stop a long-running job that has already been triggered?
- A: We recommend using a means of canceling your job, e.g. a `context.WithCancel()`.

@ -0,0 +1,5 @@
version: "3.8"
services:
redis:
image: redis:6.2-alpine

@ -4,6 +4,7 @@ import (
"context"
"sync"
"sync/atomic"
"time"
)
const (
@ -49,6 +50,8 @@ type executor struct {
limitModeQueue chan jobFunction // pass job functions to the limit mode workers
limitModeRunningJobs *atomic.Int64 // tracks the count of running jobs to check against the max
stopped *atomic.Bool // allow workers to drain the buffered limitModeQueue
distributedLocker Locker // support running jobs across multiple instances
}
func newExecutor() executor {
@ -170,6 +173,23 @@ func (e *executor) run() {
switch f.runConfig.mode {
case defaultMode:
if e.distributedLocker != nil {
l, err := e.distributedLocker.Lock(f.ctx, f.name)
if err != nil || l == nil {
return
}
defer func() {
durationToNextRun := time.Until(f.jobFuncNextRun)
if durationToNextRun > time.Second*5 {
durationToNextRun = time.Second * 5
}
if durationToNextRun > time.Millisecond*100 {
timeToSleep := time.Duration(float64(durationToNextRun) * 0.9)
time.Sleep(timeToSleep)
}
_ = l.Unlock(f.ctx)
}()
}
runJob(f)
case singletonMode:
e.singletonWgs.Store(f.singletonWg, struct{}{})

@ -37,24 +37,24 @@ func SetPanicHandler(handler PanicHandlerFunc) {
// Error declarations for gocron related errors
var (
ErrNotAFunction = errors.New("only functions can be scheduled into the job queue")
ErrNotScheduledWeekday = errors.New("job not scheduled weekly on a weekday")
ErrJobNotFoundWithTag = errors.New("no jobs found with given tag")
ErrUnsupportedTimeFormat = errors.New("the given time format is not supported")
ErrInvalidInterval = errors.New(".Every() interval must be greater than 0")
ErrInvalidIntervalType = errors.New(".Every() interval must be int, time.Duration, or string")
ErrInvalidIntervalUnitsSelection = errors.New(".Every(time.Duration) and .Cron() cannot be used with units (e.g. .Seconds())")
ErrInvalidFunctionParameters = errors.New("length of function parameters must match job function parameters")
ErrNotAFunction = errors.New("gocron: only functions can be scheduled into the job queue")
ErrNotScheduledWeekday = errors.New("gocron: job not scheduled weekly on a weekday")
ErrJobNotFoundWithTag = errors.New("gocron: no jobs found with given tag")
ErrUnsupportedTimeFormat = errors.New("gocron: the given time format is not supported")
ErrInvalidInterval = errors.New("gocron: .Every() interval must be greater than 0")
ErrInvalidIntervalType = errors.New("gocron: .Every() interval must be int, time.Duration, or string")
ErrInvalidIntervalUnitsSelection = errors.New("gocron: .Every(time.Duration) and .Cron() cannot be used with units (e.g. .Seconds())")
ErrInvalidFunctionParameters = errors.New("gocron: length of function parameters must match job function parameters")
ErrAtTimeNotSupported = errors.New("the At() method is not supported for this time unit")
ErrWeekdayNotSupported = errors.New("weekday is not supported for time unit")
ErrInvalidDayOfMonthEntry = errors.New("only days 1 through 28 are allowed for monthly schedules")
ErrTagsUnique = func(tag string) error { return fmt.Errorf("a non-unique tag was set on the job: %s", tag) }
ErrWrongParams = errors.New("wrong list of params")
ErrDoWithJobDetails = errors.New("DoWithJobDetails expects a function whose last parameter is a gocron.Job")
ErrUpdateCalledWithoutJob = errors.New("a call to Scheduler.Update() requires a call to Scheduler.Job() first")
ErrCronParseFailure = errors.New("cron expression failed to be parsed")
ErrInvalidDaysOfMonthDuplicateValue = errors.New("duplicate days of month is not allowed in Month() and Months() methods")
ErrAtTimeNotSupported = errors.New("gocron: the At() method is not supported for this time unit")
ErrWeekdayNotSupported = errors.New("gocron: weekday is not supported for time unit")
ErrInvalidDayOfMonthEntry = errors.New("gocron: only days 1 through 28 are allowed for monthly schedules")
ErrTagsUnique = func(tag string) error { return fmt.Errorf("gocron: a non-unique tag was set on the job: %s", tag) }
ErrWrongParams = errors.New("gocron: wrong list of params")
ErrDoWithJobDetails = errors.New("gocron: DoWithJobDetails expects a function whose last parameter is a gocron.Job")
ErrUpdateCalledWithoutJob = errors.New("gocron: a call to Scheduler.Update() requires a call to Scheduler.Job() first")
ErrCronParseFailure = errors.New("gocron: cron expression failed to be parsed")
ErrInvalidDaysOfMonthDuplicateValue = errors.New("gocron: duplicate days of month is not allowed in Month() and Months() methods")
)
func wrapOrError(toWrap error, err error) error {

@ -55,7 +55,8 @@ type jobFunction struct {
runStartCount *atomic.Int64 // number of times the job was started
runFinishCount *atomic.Int64 // number of times the job was finished
singletonWg *sync.WaitGroup // used by singleton runner
stopped *atomic.Bool
stopped *atomic.Bool // tracks whether the job is currently stopped
jobFuncNextRun time.Time // the next time the job is scheduled to run
}
type eventListeners struct {
@ -84,6 +85,7 @@ func (jf *jobFunction) copy() jobFunction {
singletonWg: jf.singletonWg,
singletonRunnerOn: jf.singletonRunnerOn,
stopped: jf.stopped,
jobFuncNextRun: jf.jobFuncNextRun,
}
cp.parameters = append(cp.parameters, jf.parameters...)
return cp
@ -435,6 +437,7 @@ func (j *Job) setNextRun(t time.Time) {
j.mu.Lock()
defer j.mu.Unlock()
j.nextRun = t
j.jobFunction.jobFuncNextRun = t
}
// RunCount returns the number of times the job has been started
@ -469,7 +472,7 @@ func (j *Job) IsRunning() bool {
return j.isRunning.Load()
}
// you must lock the job before calling copy
// you must Lock the job before calling copy
func (j *Job) copy() Job {
return Job{
mu: &jobMutex{},

@ -0,0 +1,23 @@
package gocron
import (
"context"
"errors"
)
var (
ErrFailedToConnectToRedis = errors.New("gocron: failed to connect to redis")
ErrFailedToObtainLock = errors.New("gocron: failed to obtain lock")
ErrFailedToReleaseLock = errors.New("gocron: failed to release lock")
)
// Locker represents the required interface to lock jobs when running multiple schedulers.
type Locker interface {
// Lock if an error is returned by lock, the job will not be scheduled.
Lock(ctx context.Context, key string) (Lock, error)
}
// Lock represents an obtained lock
type Lock interface {
Unlock(ctx context.Context) error
}

@ -15,7 +15,7 @@ import (
type limitMode int8
// Scheduler struct stores a list of Jobs and the location of time used by the Scheduler,
// and implements the sort. any for sorting Jobs, by the time of nextRun
// and implements the sort. any for sorting Jobs, by the time of jobFuncNextRun
type Scheduler struct {
jobsMutex sync.RWMutex
jobs []*Job
@ -1385,3 +1385,23 @@ func (s *Scheduler) StopBlockingChan() {
}
s.startBlockingStopChanMutex.Unlock()
}
// WithDistributedLocker prevents the same job from being run more than once
// when multiple schedulers are trying to schedule the same job.
//
// NOTE - This is currently in BETA. Please provide any feedback on your usage
// and open bugs with any issues.
//
// One strategy to reduce splay in the job execution times when using
// intervals (e.g. 1s, 1m, 1h), on each scheduler instance, is to use
// StartAt with time.Now().Round(interval) to start the job at the
// next interval boundary.
//
// Another strategy is to use the Cron or CronWithSeconds methods as they
// use the same behavior described above using StartAt.
//
// NOTE - the Locker will NOT lock jobs using any of the limiting functions:
// SingletonMode, SingletonModeAll or SetMaxConcurrentJobs
func (s *Scheduler) WithDistributedLocker(l Locker) {
s.executor.distributedLocker = l
}

@ -352,7 +352,7 @@ func (l *Logger) getFilePointer(ctx context.Context, path string) *gfpool.File {
return file
}
// getFilePointer retrieves and returns a file pointer from file pool.
// getOpenedFilePointer retrieves and returns a file pointer from file pool.
func (l *Logger) getOpenedFilePointer(ctx context.Context, path string) *gfpool.File {
file := gfpool.Get(
path,

@ -541,13 +541,28 @@ func bindVarToReflectValue(structFieldValue reflect.Value, value interface{}, ma
}
}
} else {
reflectArray = reflect.MakeSlice(structFieldValue.Type(), 1, 1)
var (
elem reflect.Value
elemType = reflectArray.Index(0).Type()
elemType = structFieldValue.Type().Elem()
elemTypeName = elemType.Name()
converted bool
)
switch reflectValue.Kind() {
case reflect.String:
// Value is empty string.
if reflectValue.IsZero() {
var elemKind = elemType.Kind()
// Try to find the original type kind of the slice element.
if elemKind == reflect.Ptr {
elemKind = elemType.Elem().Kind()
}
switch elemKind {
case reflect.String:
// Empty string cannot be assigned to string slice.
return nil
}
}
}
if elemTypeName == "" {
elemTypeName = elemType.String()
}
@ -572,6 +587,7 @@ func bindVarToReflectValue(structFieldValue reflect.Value, value interface{}, ma
// Before it sets the `elem` to array, do pointer converting if necessary.
elem = elem.Addr()
}
reflectArray = reflect.MakeSlice(structFieldValue.Type(), 1, 1)
reflectArray.Index(0).Set(elem)
}
structFieldValue.Set(reflectArray)

@ -75,7 +75,7 @@ github.com/gin-gonic/gin/binding
github.com/gin-gonic/gin/internal/bytesconv
github.com/gin-gonic/gin/internal/json
github.com/gin-gonic/gin/render
# github.com/go-co-op/gocron v1.23.0
# github.com/go-co-op/gocron v1.25.0
## explicit; go 1.20
github.com/go-co-op/gocron
# github.com/go-logr/logr v1.2.4
@ -117,7 +117,7 @@ github.com/goccy/go-json/internal/encoder/vm_color_indent
github.com/goccy/go-json/internal/encoder/vm_indent
github.com/goccy/go-json/internal/errors
github.com/goccy/go-json/internal/runtime
# github.com/gogf/gf/v2 v2.4.0
# github.com/gogf/gf/v2 v2.4.1
## explicit; go 1.15
github.com/gogf/gf/v2/container/garray
github.com/gogf/gf/v2/container/glist

Loading…
Cancel
Save