- update
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

master v1.0.3
李光春 2 years ago
parent a3664d42b0
commit 321a6d5b00

@ -55,9 +55,9 @@ func NewCgiBinAccountGetAccountBasicInfoResult(result CgiBinAccountGetAccountBas
// CgiBinAccountGetAccountBasicInfo 获取基本信息
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Mini_Program_Basic_Info/Mini_Program_Information_Settings.html
func (app *App) CgiBinAccountGetAccountBasicInfo() *CgiBinAccountGetAccountBasicInfoResult {
func (c *Client) CgiBinAccountGetAccountBasicInfo() *CgiBinAccountGetAccountBasicInfoResult {
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/account/getaccountbasicinfo?access_token=%v", app.GetAuthorizerAccessToken()), map[string]interface{}{}, http.MethodGet)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/account/getaccountbasicinfo?access_token=%v", c.GetAuthorizerAccessToken()), map[string]interface{}{}, http.MethodGet)
// 定义
var response CgiBinAccountGetAccountBasicInfoResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -27,17 +27,17 @@ func NewCgiBinComponentApiAuthorizerTokenResult(result CgiBinComponentApiAuthori
// CgiBinComponentApiAuthorizerToken 获取/刷新接口调用令牌
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/api_authorizer_token.html
func (app *App) CgiBinComponentApiAuthorizerToken(authorizerRefreshToken string) *CgiBinComponentApiAuthorizerTokenResult {
func (c *Client) CgiBinComponentApiAuthorizerToken(authorizerRefreshToken string) *CgiBinComponentApiAuthorizerTokenResult {
// 参数
param := NewParams()
param["component_appid"] = app.componentAppId // 第三方平台 appid
param["authorizer_appid"] = app.authorizerAppid // 授权方 appid
param["component_appid"] = c.config.ComponentAppId // 第三方平台 appid
param["authorizer_appid"] = c.config.AuthorizerAppid // 授权方 appid
param["authorizer_refresh_token"] = authorizerRefreshToken // 授权码, 会在授权成功时返回给第三方平台
params := app.NewParamsWith(param)
params := c.NewParamsWith(param)
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=%v", app.GetComponentAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=%v", c.GetComponentAccessToken()), params, http.MethodPost)
// 定义
var response CgiBinComponentApiAuthorizerTokenResponse
err = json.Unmarshal(request.ResponseBody, &response)
return NewCgiBinComponentApiAuthorizerTokenResult(response, request.ResponseBody, request, err, app.authorizerAppid)
return NewCgiBinComponentApiAuthorizerTokenResult(response, request.ResponseBody, request, err, c.config.AuthorizerAppid)
}

@ -24,15 +24,15 @@ func NewCgiBinComponentApiComponentTokenResult(result CgiBinComponentApiComponen
// CgiBinComponentApiComponentToken 令牌
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/component_access_token.html
func (app *App) CgiBinComponentApiComponentToken() *CgiBinComponentApiComponentTokenResult {
func (c *Client) CgiBinComponentApiComponentToken() *CgiBinComponentApiComponentTokenResult {
// 参数
param := NewParams()
param["component_appid"] = app.componentAppId // 第三方平台 appid
param["component_appsecret"] = app.componentAppSecret // 第三方平台 appsecret
param["component_verify_ticket"] = app.GetComponentVerifyTicket() // 微信后台推送的 ticket
params := app.NewParamsWith(param)
param["component_appid"] = c.config.ComponentAppId // 第三方平台 appid
param["component_appsecret"] = c.config.ComponentAppSecret // 第三方平台 appsecret
param["component_verify_ticket"] = c.GetComponentVerifyTicket() // 微信后台推送的 ticket
params := c.NewParamsWith(param)
// 请求
request, err := app.request("https://api.weixin.qq.com/cgi-bin/component/api_component_token", params, http.MethodPost)
request, err := c.request("https://api.weixin.qq.com/cgi-bin/component/api_component_token", params, http.MethodPost)
// 定义
var response CgiBinComponentApiComponentTokenResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -25,13 +25,13 @@ func NewCgiBinComponentApiCreatePreAuthCodenResult(result CgiBinComponentApiCrea
// CgiBinComponentApiCreatePreAuthCoden 预授权码
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/pre_auth_code.html
func (app *App) CgiBinComponentApiCreatePreAuthCoden() *CgiBinComponentApiCreatePreAuthCodenResult {
func (c *Client) CgiBinComponentApiCreatePreAuthCoden() *CgiBinComponentApiCreatePreAuthCodenResult {
// 参数
param := NewParams()
param["component_appid"] = app.componentAppId // 第三方平台 appid
params := app.NewParamsWith(param)
param["component_appid"] = c.config.ComponentAppId // 第三方平台 appid
params := c.NewParamsWith(param)
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=%v", app.GetComponentAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=%v", c.GetComponentAccessToken()), params, http.MethodPost)
// 定义
var response CgiBinComponentApiCreatePreAuthCodenResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -83,14 +83,14 @@ func NewCgiBinComponentApiGetAuthorizerInfoResult(result CgiBinComponentApiGetAu
// CgiBinComponentApiGetAuthorizerInfo 获取授权帐号详情
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/api_get_authorizer_info.html
func (app *App) CgiBinComponentApiGetAuthorizerInfo() *CgiBinComponentApiGetAuthorizerInfoResult {
func (c *Client) CgiBinComponentApiGetAuthorizerInfo() *CgiBinComponentApiGetAuthorizerInfoResult {
// 参数
param := NewParams()
param["component_appid"] = app.componentAppId // 第三方平台 appid
param["authorizer_appid"] = app.authorizerAppid // 授权方 appid
params := app.NewParamsWith(param)
param["component_appid"] = c.config.ComponentAppId // 第三方平台 appid
param["authorizer_appid"] = c.config.AuthorizerAppid // 授权方 appid
params := c.NewParamsWith(param)
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=%v", app.GetComponentAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=%v", c.GetComponentAccessToken()), params, http.MethodPost)
// 定义
var response CgiBinComponentApiGetAuthorizerInfoResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -39,14 +39,14 @@ func NewCgiBinComponentApiQueryAuthResult(result CgiBinComponentApiQueryAuthResp
// CgiBinComponentApiQueryAuth 使用授权码获取授权信息
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/authorization_info.html
func (app *App) CgiBinComponentApiQueryAuth(authorizationCode string) *CgiBinComponentApiQueryAuthResult {
func (c *Client) CgiBinComponentApiQueryAuth(authorizationCode string) *CgiBinComponentApiQueryAuthResult {
// 参数
param := NewParams()
param["component_appid"] = app.componentAppId // 第三方平台 appid
param["authorization_code"] = authorizationCode // 授权码, 会在授权成功时返回给第三方平台
params := app.NewParamsWith(param)
param["component_appid"] = c.config.ComponentAppId // 第三方平台 appid
param["authorization_code"] = authorizationCode // 授权码, 会在授权成功时返回给第三方平台
params := c.NewParamsWith(param)
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=%v", app.GetComponentAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=%v", c.GetComponentAccessToken()), params, http.MethodPost)
// 定义
var response CgiBinComponentApiQueryAuthResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -26,14 +26,14 @@ func NewCgiBinComponentApiStartPushTicketResult(result CgiBinComponentApiStartPu
// CgiBinComponentApiStartPushTicket 启动ticket推送服务
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/component_verify_ticket_service.html
func (app *App) CgiBinComponentApiStartPushTicket() *CgiBinComponentApiStartPushTicketResult {
func (c *Client) CgiBinComponentApiStartPushTicket() *CgiBinComponentApiStartPushTicketResult {
// 参数
param := NewParams()
param["component_appid"] = app.componentAppId // 平台型第三方平台的appid
param["component_secret"] = app.componentAppSecret // 平台型第三方平台的APPSECRET
params := app.NewParamsWith(param)
param["component_appid"] = c.config.ComponentAppId // 平台型第三方平台的appid
param["component_secret"] = c.config.ComponentAppSecret // 平台型第三方平台的APPSECRET
params := c.NewParamsWith(param)
// 请求
request, err := app.request("https://api.weixin.qq.com/cgi-bin/component/api_start_push_ticket", params, http.MethodPost)
request, err := c.request("https://api.weixin.qq.com/cgi-bin/component/api_start_push_ticket", params, http.MethodPost)
// 定义
var response CgiBinComponentApiStartPushTicketResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -58,12 +58,12 @@ func NewCgiBinComponentGetPrivacySettingResult(result CgiBinComponentGetPrivacyS
// CgiBinComponentGetPrivacySetting 查询小程序用户隐私保护指引
// @privacyVer 1表示现网版本传1则该接口返回的内容是现网版本的2表示开发版传2则该接口返回的内容是开发版本的。默认是2。
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/privacy_config/get_privacy_setting.html
func (app *App) CgiBinComponentGetPrivacySetting(privacyVer int) *CgiBinComponentGetPrivacySettingResult {
func (c *Client) CgiBinComponentGetPrivacySetting(privacyVer int) *CgiBinComponentGetPrivacySettingResult {
// 参数
params := NewParams()
params["privacy_ver"] = privacyVer
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/component/getprivacysetting?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/component/getprivacysetting?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodPost)
// 定义
var response CgiBinComponentGetPrivacySettingResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -25,11 +25,11 @@ func NewCgiBinComponentSetPrivacySettingResult(result CgiBinComponentSetPrivacyS
// CgiBinComponentSetPrivacySetting 配置小程序用户隐私保护指引
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/privacy_config/set_privacy_setting.html
func (app *App) CgiBinComponentSetPrivacySetting(notMustParams ...Params) *CgiBinComponentSetPrivacySettingResult {
func (c *Client) CgiBinComponentSetPrivacySetting(notMustParams ...Params) *CgiBinComponentSetPrivacySettingResult {
// 参数
params := app.NewParamsWith(notMustParams...)
params := c.NewParamsWith(notMustParams...)
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/component/setprivacysetting?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/component/setprivacysetting?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodPost)
// 定义
var response CgiBinComponentSetPrivacySettingResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -24,9 +24,9 @@ func NewGetCallBackIpResult(result GetCallBackIpResponse, body []byte, http gore
// CgiBinGetApiDomainIp 获取微信服务器IP地址
// https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_the_WeChat_server_IP_address.html
func (app *App) CgiBinGetApiDomainIp(componentAccessToken string) *GetCallBackIpResult {
func (c *Client) CgiBinGetApiDomainIp(componentAccessToken string) *GetCallBackIpResult {
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/get_api_domain_ip?access_token=%s", componentAccessToken), map[string]interface{}{}, http.MethodGet)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/get_api_domain_ip?access_token=%s", componentAccessToken), map[string]interface{}{}, http.MethodGet)
// 定义
var response GetCallBackIpResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -26,13 +26,13 @@ func NewCgiBinShortUrlResult(result CgiBinShortUrlResponse, body []byte, http go
// CgiBinShortUrl 将二维码长链接转成短链接
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/qrcode/shorturl.html
func (app *App) CgiBinShortUrl(longUrl string) *CgiBinShortUrlResult {
func (c *Client) CgiBinShortUrl(longUrl string) *CgiBinShortUrlResult {
// 参数
params := NewParams()
params["action"] = "long2short" // 此处填long2short代表长链接转短链接
params["long_url"] = longUrl // 需要转换的长链接支持http://、https://、weixin://wxpay 格式的url
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/shorturl?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/shorturl?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodPost)
// 定义
var response CgiBinShortUrlResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -25,11 +25,11 @@ func NewCgiBinWxOpenQrCodeJumpAddResult(result CgiBinWxOpenQrCodeJumpAddResponse
// CgiBinWxOpenQrCodeJumpAdd 增加或修改二维码规则
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/qrcode/qrcodejumpadd.html
func (app *App) CgiBinWxOpenQrCodeJumpAdd(notMustParams ...Params) *CgiBinWxOpenQrCodeJumpAddResult {
func (c *Client) CgiBinWxOpenQrCodeJumpAdd(notMustParams ...Params) *CgiBinWxOpenQrCodeJumpAddResult {
// 参数
params := app.NewParamsWith(notMustParams...)
params := c.NewParamsWith(notMustParams...)
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/wxopen/qrcodejumpadd?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/wxopen/qrcodejumpadd?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodPost)
// 定义
var response CgiBinWxOpenQrCodeJumpAddResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -25,12 +25,12 @@ func NewCgiBinWxOpenQrCodeJumpDeleteResult(result CgiBinWxOpenQrCodeJumpDeleteRe
// CgiBinWxOpenQrCodeJumpDelete 删除已设置的二维码规则
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/qrcode/qrcodejumpdelete.html
func (app *App) CgiBinWxOpenQrCodeJumpDelete(prefix string) *CgiBinWxOpenQrCodeJumpDeleteResult {
func (c *Client) CgiBinWxOpenQrCodeJumpDelete(prefix string) *CgiBinWxOpenQrCodeJumpDeleteResult {
// 参数
params := NewParams()
params["prefix"] = prefix
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/wxopen/qrcodejumpdelete?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/wxopen/qrcodejumpdelete?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodPost)
// 定义
var response CgiBinWxOpenQrCodeJumpDeleteResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -27,11 +27,11 @@ func NewCgiBinWxOpenQrCodeJumpDownloadResult(result CgiBinWxOpenQrCodeJumpDownlo
// CgiBinWxOpenQrCodeJumpDownload 获取校验文件名称及内容
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/qrcode/qrcodejumpdownload.html
func (app *App) CgiBinWxOpenQrCodeJumpDownload() *CgiBinWxOpenQrCodeJumpDownloadResult {
func (c *Client) CgiBinWxOpenQrCodeJumpDownload() *CgiBinWxOpenQrCodeJumpDownloadResult {
// 参数
params := NewParams()
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/wxopen/qrcodejumpdownload?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/wxopen/qrcodejumpdownload?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodPost)
// 定义
var response CgiBinWxOpenQrCodeJumpDownloadResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -36,11 +36,11 @@ func NewCgiBinWxOpenQrCodeJumpGetResult(result CgiBinWxOpenQrCodeJumpGetResponse
// CgiBinWxOpenQrCodeJumpGet 获取已设置的二维码规则
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/qrcode/qrcodejumpadd.html
func (app *App) CgiBinWxOpenQrCodeJumpGet() *CgiBinWxOpenQrCodeJumpGetResult {
func (c *Client) CgiBinWxOpenQrCodeJumpGet() *CgiBinWxOpenQrCodeJumpGetResult {
// 参数
params := NewParams()
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/wxopen/qrcodejumpget?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/wxopen/qrcodejumpget?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodPost)
// 定义
var response CgiBinWxOpenQrCodeJumpGetResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -25,12 +25,12 @@ func NewCgiBinWxOpenQrCodeJumpPublishResult(result CgiBinWxOpenQrCodeJumpPublish
// CgiBinWxOpenQrCodeJumpPublish 发布已设置的二维码规则
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/qrcode/qrcodejumppublish.html
func (app *App) CgiBinWxOpenQrCodeJumpPublish(prefix string) *CgiBinWxOpenQrCodeJumpPublishResult {
func (c *Client) CgiBinWxOpenQrCodeJumpPublish(prefix string) *CgiBinWxOpenQrCodeJumpPublishResult {
// 参数
params := NewParams()
params["prefix"] = prefix
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/wxopen/qrcodejumppublish?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/wxopen/qrcodejumppublish?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodPost)
// 定义
var response CgiBinWxOpenQrCodeJumpPublishResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,5 +1,5 @@
package wechatopen
func (app *App) GetComponentAppId() string {
return app.componentAppId
func (c *Client) GetComponentAppId() string {
return c.config.ComponentAppId
}

@ -8,8 +8,8 @@ import (
)
// 记录日志
func (app *App) postgresqlLog(request gorequest.Response) {
app.log.Record(golog.ApiPostgresqlLog{
func (c *Client) postgresqlLog(request gorequest.Response) {
c.log.Record(golog.ApiPostgresqlLog{
RequestTime: golog.TimeString{Time: request.RequestTime}, //【请求】时间
RequestUri: request.RequestUri, //【请求】链接
RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接

@ -8,7 +8,7 @@ func NewParams() Params {
return p
}
func (app *App) NewParamsWith(params ...Params) Params {
func (c *Client) NewParamsWith(params ...Params) Params {
p := make(Params)
for _, v := range params {
p.SetParams(v)

@ -7,135 +7,135 @@ import (
)
// 微信后台推送的ticke
func (app *App) getComponentVerifyTicketCacheKeyName() string {
return fmt.Sprintf("wechat_open:component_verify_ticket:%v", app.componentAppId)
func (c *Client) getComponentVerifyTicketCacheKeyName() string {
return fmt.Sprintf("wechat_open:component_verify_ticket:%v", c.config.ComponentAppId)
}
// SetComponentVerifyTicket 设置微信后台推送的ticke
func (app *App) SetComponentVerifyTicket(componentVerifyTicket string) string {
func (c *Client) SetComponentVerifyTicket(componentVerifyTicket string) string {
if componentVerifyTicket == "" {
return ""
}
app.redis.Db.Set(context.Background(), app.getComponentVerifyTicketCacheKeyName(), componentVerifyTicket, time.Hour*12)
return app.GetComponentVerifyTicket()
c.config.RedisClient.Db.Set(context.Background(), c.getComponentVerifyTicketCacheKeyName(), componentVerifyTicket, time.Hour*12)
return c.GetComponentVerifyTicket()
}
// GetComponentVerifyTicket 获取微信后台推送的ticke
func (app *App) GetComponentVerifyTicket() string {
if app.redis.Db == nil {
return app.componentVerifyTicket
func (c *Client) GetComponentVerifyTicket() string {
if c.config.RedisClient.Db == nil {
return c.config.ComponentVerifyTicket
}
result, _ := app.redis.Db.Get(context.Background(), app.getComponentVerifyTicketCacheKeyName()).Result()
result, _ := c.config.RedisClient.Db.Get(context.Background(), c.getComponentVerifyTicketCacheKeyName()).Result()
return result
}
// 令牌
func (app *App) getComponentAccessTokenCacheKeyName() string {
return fmt.Sprintf("wechat_open:component_access_token:%v", app.componentAppId)
func (c *Client) getComponentAccessTokenCacheKeyName() string {
return fmt.Sprintf("wechat_open:component_access_token:%v", c.config.ComponentAppId)
}
// SetComponentAccessToken 设置令牌
func (app *App) SetComponentAccessToken(componentAccessToken string) string {
func (c *Client) SetComponentAccessToken(componentAccessToken string) string {
if componentAccessToken == "" {
return ""
}
app.redis.Db.Set(context.Background(), app.getComponentAccessTokenCacheKeyName(), componentAccessToken, time.Second*7200)
return app.GetComponentAccessToken()
c.config.RedisClient.Db.Set(context.Background(), c.getComponentAccessTokenCacheKeyName(), componentAccessToken, time.Second*7200)
return c.GetComponentAccessToken()
}
// GetComponentAccessToken 获取令牌
func (app *App) GetComponentAccessToken() string {
if app.redis.Db == nil {
return app.componentAccessToken
func (c *Client) GetComponentAccessToken() string {
if c.config.RedisClient.Db == nil {
return c.config.ComponentAccessToken
}
result, _ := app.redis.Db.Get(context.Background(), app.getComponentAccessTokenCacheKeyName()).Result()
result, _ := c.config.RedisClient.Db.Get(context.Background(), c.getComponentAccessTokenCacheKeyName()).Result()
return result
}
// MonitorComponentAccessToken 监控令牌
func (app *App) MonitorComponentAccessToken() string {
func (c *Client) MonitorComponentAccessToken() string {
// 查询
componentAccessToken := app.GetComponentAccessToken()
componentAccessToken := c.GetComponentAccessToken()
// 判断
result := app.CgiBinGetApiDomainIp(componentAccessToken)
result := c.CgiBinGetApiDomainIp(componentAccessToken)
if len(result.Result.IpList) > 0 {
return componentAccessToken
}
// 重新获取
return app.SetComponentAccessToken(app.CgiBinComponentApiComponentToken().Result.ComponentAccessToken)
return c.SetComponentAccessToken(c.CgiBinComponentApiComponentToken().Result.ComponentAccessToken)
}
// 授权方令牌
func (app *App) getAuthorizerAccessTokenCacheKeyName() string {
return fmt.Sprintf("wechat_open:authorizer_access_token:%v:%v", app.componentAppId, app.authorizerAppid)
func (c *Client) getAuthorizerAccessTokenCacheKeyName() string {
return fmt.Sprintf("wechat_open:authorizer_access_token:%v:%v", c.config.ComponentAppId, c.config.AuthorizerAppid)
}
// SetAuthorizerAccessToken 设置授权方令牌
func (app *App) SetAuthorizerAccessToken(authorizerAccessToken string) string {
func (c *Client) SetAuthorizerAccessToken(authorizerAccessToken string) string {
if authorizerAccessToken == "" {
return ""
}
app.redis.Db.Set(context.Background(), app.getAuthorizerAccessTokenCacheKeyName(), authorizerAccessToken, time.Hour*2)
return app.GetComponentAccessToken()
c.config.RedisClient.Db.Set(context.Background(), c.getAuthorizerAccessTokenCacheKeyName(), authorizerAccessToken, time.Hour*2)
return c.GetComponentAccessToken()
}
// GetAuthorizerAccessToken 获取授权方令牌
func (app *App) GetAuthorizerAccessToken() string {
if app.redis.Db == nil {
return app.authorizerAccessToken
func (c *Client) GetAuthorizerAccessToken() string {
if c.config.RedisClient.Db == nil {
return c.config.AuthorizerAccessToken
}
result, _ := app.redis.Db.Get(context.Background(), app.getAuthorizerAccessTokenCacheKeyName()).Result()
result, _ := c.config.RedisClient.Db.Get(context.Background(), c.getAuthorizerAccessTokenCacheKeyName()).Result()
return result
}
// MonitorAuthorizerAccessToken 监控授权方令牌
func (app *App) MonitorAuthorizerAccessToken(authorizerRefreshToken string) string {
func (c *Client) MonitorAuthorizerAccessToken(authorizerRefreshToken string) string {
// 查询
authorizerAccessToken := app.GetAuthorizerAccessToken()
authorizerAccessToken := c.GetAuthorizerAccessToken()
// 判断
if authorizerAccessToken != "" {
return authorizerAccessToken
}
// 重新获取
return app.SetAuthorizerAccessToken(app.CgiBinComponentApiAuthorizerToken(authorizerRefreshToken).Result.AuthorizerAccessToken)
return c.SetAuthorizerAccessToken(c.CgiBinComponentApiAuthorizerToken(authorizerRefreshToken).Result.AuthorizerAccessToken)
}
// 预授权码
func (app *App) getPreAuthCodeCacheKeyName() string {
return fmt.Sprintf("wechat_open:pre_auth_code:%v", app.componentAppId)
func (c *Client) getPreAuthCodeCacheKeyName() string {
return fmt.Sprintf("wechat_open:pre_auth_code:%v", c.config.ComponentAppId)
}
// SetPreAuthCode 设置预授权码
func (app *App) SetPreAuthCode(preAuthCode string) string {
func (c *Client) SetPreAuthCode(preAuthCode string) string {
if preAuthCode == "" {
return ""
}
app.redis.Db.Set(context.Background(), app.getPreAuthCodeCacheKeyName(), preAuthCode, time.Second*1700)
return app.GetComponentAccessToken()
c.config.RedisClient.Db.Set(context.Background(), c.getPreAuthCodeCacheKeyName(), preAuthCode, time.Second*1700)
return c.GetComponentAccessToken()
}
// GetPreAuthCode 获取预授权码
func (app *App) GetPreAuthCode() string {
if app.redis.Db == nil {
return app.authorizerAccessToken
func (c *Client) GetPreAuthCode() string {
if c.config.RedisClient.Db == nil {
return c.config.AuthorizerAccessToken
}
result, _ := app.redis.Db.Get(context.Background(), app.getPreAuthCodeCacheKeyName()).Result()
result, _ := c.config.RedisClient.Db.Get(context.Background(), c.getPreAuthCodeCacheKeyName()).Result()
return result
}
// DelPreAuthCode 删除预授权码
func (app *App) DelPreAuthCode() error {
return app.redis.Db.Del(context.Background(), app.getPreAuthCodeCacheKeyName()).Err()
func (c *Client) DelPreAuthCode() error {
return c.config.RedisClient.Db.Del(context.Background(), c.getPreAuthCodeCacheKeyName()).Err()
}
// MonitorPreAuthCode 监控预授权码
func (app *App) MonitorPreAuthCode() string {
func (c *Client) MonitorPreAuthCode() string {
// 查询
preAuthCode := app.GetPreAuthCode()
preAuthCode := c.GetPreAuthCode()
// 判断
if preAuthCode != "" {
return preAuthCode
}
// 重新获取
return app.SetPreAuthCode(app.CgiBinComponentApiCreatePreAuthCoden().Result.PreAuthCode)
return c.SetPreAuthCode(c.CgiBinComponentApiCreatePreAuthCoden().Result.PreAuthCode)
}

@ -11,7 +11,7 @@ type SaveImgResponse struct {
Name string
}
func (app *App) SaveImg(resp gorequest.Response, dir, saveName string) SaveImgResponse {
func (c *Client) SaveImg(resp gorequest.Response, dir, saveName string) SaveImgResponse {
// 返回是二进制图片或者json错误
if resp.ResponseHeader.Get("Content-Type") == "image/jpeg" || resp.ResponseHeader.Get("Content-Type") == "image/png" {
// 保存在output目录

@ -7,7 +7,7 @@ import (
)
// ServeHttpAuthorizerAppid 授权跳转
func (app *App) ServeHttpAuthorizerAppid(r *http.Request) (resp CgiBinComponentApiQueryAuthResponse, agentUserId string, err error) {
func (c *Client) ServeHttpAuthorizerAppid(r *http.Request) (resp CgiBinComponentApiQueryAuthResponse, agentUserId string, err error) {
var (
query = r.URL.Query()
@ -25,7 +25,7 @@ func (app *App) ServeHttpAuthorizerAppid(r *http.Request) (resp CgiBinComponentA
return resp, agentUserId, errors.New("找不到过期时间参数")
}
info := app.CgiBinComponentApiQueryAuth(authCode)
info := c.CgiBinComponentApiQueryAuth(authCode)
if info.Result.AuthorizationInfo.AuthorizerAppid == "" {
return resp, agentUserId, errors.New("获取失败")
}

@ -26,7 +26,7 @@ type cipherRequestHttpBody struct {
}
// ServeHttpVerifyTicket 验证票据推送
func (app *App) ServeHttpVerifyTicket(r *http.Request) (resp *ResponseServeHttpVerifyTicket, err error) {
func (c *Client) ServeHttpVerifyTicket(r *http.Request) (resp *ResponseServeHttpVerifyTicket, err error) {
var (
query = r.URL.Query()
@ -57,7 +57,7 @@ func (app *App) ServeHttpVerifyTicket(r *http.Request) (resp *ResponseServeHttpV
return resp, errors.New("未找到随机数参数")
}
wantSignature = Sign(app.messageToken, timestamp, nonce)
wantSignature = Sign(c.config.MessageToken, timestamp, nonce)
if haveSignature != wantSignature {
return resp, errors.New("签名错误")
}
@ -96,7 +96,7 @@ func (app *App) ServeHttpVerifyTicket(r *http.Request) (resp *ResponseServeHttpV
return resp, errors.New(fmt.Sprintf("Encrypt 解码字符串错误:%v", err))
}
AesKey, err := base64.StdEncoding.DecodeString(app.messageKey + "=")
AesKey, err := base64.StdEncoding.DecodeString(c.config.MessageKey + "=")
if err != nil {
return resp, errors.New(fmt.Sprintf("messageKey 解码字符串错误:%v", err))
}

@ -1,7 +1,7 @@
package wechatopen
// SetAuthorizerAppid 设置代理商小程序
func (app *App) SetAuthorizerAppid(authorizerAppid string) {
app.authorizerAppid = authorizerAppid
func (c *Client) SetAuthorizerAppid(authorizerAppid string) {
c.config.AuthorizerAppid = authorizerAppid
return
}

@ -30,16 +30,16 @@ func NewSnsComponentJsCode2sessionResult(result SnsComponentJsCode2sessionRespon
// SnsComponentJsCode2session 小程序登录
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/others/WeChat_login.html
func (app *App) SnsComponentJsCode2session(jsCode string) *SnsComponentJsCode2sessionResult {
func (c *Client) SnsComponentJsCode2session(jsCode string) *SnsComponentJsCode2sessionResult {
// 参数
params := NewParams()
params["appid"] = app.authorizerAppid // 小程序的 appId
params["js_code"] = jsCode // wx.login 获取的 code
params["grant_type"] = "authorization_code" // 填 authorization_code
params["component_appid"] = app.componentAppId // 第三方平台 appid
params["component_access_token"] = app.GetComponentAccessToken() // 第三方平台的component_access_token
params["appid"] = c.config.AuthorizerAppid // 小程序的 appId
params["js_code"] = jsCode // wx.login 获取的 code
params["grant_type"] = "authorization_code" // 填 authorization_code
params["component_appid"] = c.config.ComponentAppId // 第三方平台 appid
params["component_access_token"] = c.GetComponentAccessToken() // 第三方平台的component_access_token
// 请求
request, err := app.request("https://api.weixin.qq.com/sns/component/jscode2session", params, http.MethodGet)
request, err := c.request("https://api.weixin.qq.com/sns/component/jscode2session", params, http.MethodGet)
// 定义
var response SnsComponentJsCode2sessionResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,3 +1,3 @@
package wechatopen
const Version = "1.0.2"
const Version = "1.0.3"

@ -7,59 +7,64 @@ import (
"gorm.io/gorm"
)
// App 微信公众号服务
type App struct {
componentAccessToken string // 第三方平台 access_token
componentVerifyTicket string // 微信后台推送的 ticket
preAuthCode string // 预授权码
authorizerAccessToken string // 接口调用令牌
authorizerRefreshToken string // 刷新令牌
authorizerAppid string // 授权方 appid
componentAppId string // 第三方平台 appid
componentAppSecret string // 第三方平台 app_secret
messageToken string
messageKey string
redis *dorm.RedisClient // 缓存数据库
pgsql *gorm.DB // pgsql数据库
client *gorequest.App // 请求客户端
log *golog.Api // 日志服务
logTableName string // 日志表名
logStatus bool // 日志状态
type ConfigClient struct {
ComponentAccessToken string // 第三方平台 access_token
ComponentVerifyTicket string // 微信后台推送的 ticket
PreAuthCode string // 预授权码
AuthorizerAccessToken string // 接口调用令牌
AuthorizerRefreshToken string // 刷新令牌
AuthorizerAppid string // 授权方 appid
ComponentAppId string // 第三方平台 appid
ComponentAppSecret string // 第三方平台 app_secret
MessageToken string
MessageKey string
RedisClient *dorm.RedisClient // 缓存数据库
PgsqlDb *gorm.DB // pgsql数据库
}
// NewApp 实例化
func NewApp(componentAppId string, componentAppSecret string, messageToken string, messageKey string, redis *dorm.RedisClient, pgsql *gorm.DB) *App {
app := &App{componentAppId: componentAppId, componentAppSecret: componentAppSecret, messageToken: messageToken, messageKey: messageKey, redis: redis}
app.client = gorequest.NewHttp()
if pgsql != nil {
app.pgsql = pgsql
app.logStatus = true
app.logTableName = "wechatopen"
app.log = golog.NewApi(&golog.ApiConfig{
Db: pgsql,
TableName: app.logTableName,
// Client 微信公众号服务
type Client struct {
client *gorequest.App // 请求客户端
log *golog.Api // 日志服务
logTableName string // 日志表名
logStatus bool // 日志状态
config *ConfigClient // 配置
}
func NewClient(config *ConfigClient) *Client {
c := &Client{config: config}
c.client = gorequest.NewHttp()
if c.config.PgsqlDb != nil {
c.logStatus = true
c.logTableName = "wechatopen"
c.log = golog.NewApi(&golog.ApiConfig{
Db: c.config.PgsqlDb,
TableName: c.logTableName,
})
}
return app
return c
}
// Config 配置
func (app *App) Config(componentAppId, componentAppSecret string) *App {
app.componentAppId = componentAppId
app.componentAppSecret = componentAppSecret
return app
// ConfigComponent 配置
func (c *Client) ConfigComponent(componentAppId, componentAppSecret string) *Client {
c.config.ComponentAppId = componentAppId
c.config.ComponentAppSecret = componentAppSecret
return c
}
// ConfigAuthorizer 配置第三方
func (app *App) ConfigAuthorizer(authorizerAppid string) *App {
app.authorizerAppid = authorizerAppid
return app
func (c *Client) ConfigAuthorizer(authorizerAppid string) *Client {
c.config.AuthorizerAppid = authorizerAppid
return c
}
func (app *App) request(url string, params map[string]interface{}, method string) (resp gorequest.Response, err error) {
func (c *Client) request(url string, params map[string]interface{}, method string) (resp gorequest.Response, err error) {
// 创建请求
client := app.client
client := c.client
// 设置请求地址
client.SetUri(url)
@ -80,8 +85,8 @@ func (app *App) request(url string, params map[string]interface{}, method string
}
// 日志
if app.logStatus == true {
go app.postgresqlLog(request)
if c.logStatus == true {
go c.postgresqlLog(request)
}
return request, err

@ -25,13 +25,13 @@ func NewWxaAddToTemplateResult(result WxaAddToTemplateResponse, body []byte, htt
// WxaAddToTemplate 将草稿添加到代码模板库
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/code_template/addtotemplate.html
func (app *App) WxaAddToTemplate(draftId string, templateType int) *WxaAddToTemplateResult {
func (c *Client) WxaAddToTemplate(draftId string, templateType int) *WxaAddToTemplateResult {
// 参数
params := NewParams()
params["draft_id"] = draftId
params["template_type"] = templateType
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/addtotemplate?access_token=%s", app.GetComponentAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/addtotemplate?access_token=%s", c.GetComponentAccessToken()), params, http.MethodPost)
// 定义
var response WxaAddToTemplateResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -26,12 +26,12 @@ func NewWxaBindTesterResult(result WxaBindTesterResponse, body []byte, http gore
// WxaBindTester 绑定微信用户为体验者
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Mini_Program_AdminManagement/Admin.html
func (app *App) WxaBindTester(wechatid string) *WxaBindTesterResult {
func (c *Client) WxaBindTester(wechatid string) *WxaBindTesterResult {
// 参数
params := NewParams()
params["wechatid"] = wechatid
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/bind_tester?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/bind_tester?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodPost)
// 定义
var response WxaBindTesterResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -34,12 +34,12 @@ func NewWxaBusinessGetUserPhoneNumberResult(result WxaBusinessGetUserPhoneNumber
// WxaBusinessGetUserPhoneNumber code换取用户手机号。 每个 code 只能使用一次code的有效期为5min
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/phonenumber/phonenumber.getPhoneNumber.html
func (app *App) WxaBusinessGetUserPhoneNumber(code string) *WxaBusinessGetUserPhoneNumberResult {
func (c *Client) WxaBusinessGetUserPhoneNumber(code string) *WxaBusinessGetUserPhoneNumberResult {
// 参数
params := gorequest.NewParams()
params.Set("code", code)
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodPost)
// 定义
var response WxaBusinessGetUserPhoneNumberResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -25,11 +25,11 @@ func NewWxaCommitResult(result WxaCommitResponse, body []byte, http gorequest.Re
// WxaCommit 上传小程序代码并生成体验版
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/code/commit.html
func (app *App) WxaCommit(notMustParams ...gorequest.Params) *WxaCommitResult {
func (c *Client) WxaCommit(notMustParams ...gorequest.Params) *WxaCommitResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/commit?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/commit?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodPost)
// 定义
var response WxaCommitResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -25,12 +25,12 @@ func NewWxaDeleteTemplateResult(result WxaDeleteTemplateResponse, body []byte, h
// WxaDeleteTemplate 删除指定代码模板
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/code_template/deletetemplate.html
func (app *App) WxaDeleteTemplate(templateId string) *WxaDeleteTemplateResult {
func (c *Client) WxaDeleteTemplate(templateId string) *WxaDeleteTemplateResult {
// 参数
params := NewParams()
params.Set("template_id", templateId)
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/deletetemplate?access_token=%s", app.GetComponentAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/deletetemplate?access_token=%s", c.GetComponentAccessToken()), params, http.MethodPost)
// 定义
var response WxaDeleteTemplateResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -29,12 +29,12 @@ func NewWxaGetAuditStatusResult(result WxaGetAuditStatusResponse, body []byte, h
// WxaGetAuditStatus 查询指定发布审核单的审核状态
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/code/get_auditstatus.html
func (app *App) WxaGetAuditStatus(auditid int64) *WxaGetAuditStatusResult {
func (c *Client) WxaGetAuditStatus(auditid int64) *WxaGetAuditStatusResult {
// 参数
params := app.NewParamsWith()
params := c.NewParamsWith()
params.Set("auditid", auditid)
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/get_auditstatus?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/get_auditstatus?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodPost)
// 定义
var response WxaGetAuditStatusResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -33,9 +33,9 @@ func NewWxaGetCategoryResult(result WxaGetCategoryResponse, body []byte, http go
// WxaGetCategory 获取审核时可填写的类目信息
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/category/get_category.html
func (app *App) WxaGetCategory() *WxaGetCategoryResult {
func (c *Client) WxaGetCategory() *WxaGetCategoryResult {
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/get_category?access_token=%s", app.GetAuthorizerAccessToken()), map[string]interface{}{}, http.MethodGet)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/get_category?access_token=%s", c.GetAuthorizerAccessToken()), map[string]interface{}{}, http.MethodGet)
// 定义
var response WxaGetCategoryResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -49,11 +49,11 @@ func NewWxaGetEffectiveDomainResult(result WxaGetEffectiveDomainResponse, body [
// WxaGetEffectiveDomain 获取发布后生效服务器域名列表
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Mini_Program_Basic_Info/get_effective_domain.html
func (app *App) WxaGetEffectiveDomain(notMustParams ...Params) *WxaGetEffectiveDomainResult {
func (c *Client) WxaGetEffectiveDomain(notMustParams ...Params) *WxaGetEffectiveDomainResult {
// 参数
params := app.NewParamsWith(notMustParams...)
params := c.NewParamsWith(notMustParams...)
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/get_effective_domain?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/get_effective_domain?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodPost)
// 定义
var response WxaGetEffectiveDomainResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -29,9 +29,9 @@ func NewWxaGetLatestAuditStatusResult(result WxaGetLatestAuditStatusResponse, bo
// WxaGetLatestAuditStatus 查询最新一次提交的审核状态
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/code/get_auditstatus.html
func (app *App) WxaGetLatestAuditStatus() *WxaGetLatestAuditStatusResult {
func (c *Client) WxaGetLatestAuditStatus() *WxaGetLatestAuditStatusResult {
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/get_latest_auditstatus?access_token=%s", app.GetAuthorizerAccessToken()), map[string]interface{}{}, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/get_latest_auditstatus?access_token=%s", c.GetAuthorizerAccessToken()), map[string]interface{}{}, http.MethodPost)
// 定义
var response WxaGetLatestAuditStatusResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -26,9 +26,9 @@ func NewWxaGetPageResult(result WxaGetPageResponse, body []byte, http gorequest.
// WxaGetPage 获取已上传的代码的页面列表
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/code/get_page.html
func (app *App) WxaGetPage() *WxaGetPageResult {
func (c *Client) WxaGetPage() *WxaGetPageResult {
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/get_page?access_token=%s", app.GetAuthorizerAccessToken()), map[string]interface{}{}, http.MethodGet)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/get_page?access_token=%s", c.GetAuthorizerAccessToken()), map[string]interface{}{}, http.MethodGet)
// 定义
var response WxaGetPageResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -25,14 +25,14 @@ func NewWxaGetQrcodeResult(result WxaGetQrcodeResponse, body []byte, http gorequ
// WxaGetQrcode 获取体验版二维码
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/code/get_qrcode.html
func (app *App) WxaGetQrcode(path string) *WxaGetQrcodeResult {
func (c *Client) WxaGetQrcode(path string) *WxaGetQrcodeResult {
// 参数
params := NewParams()
if path != "" {
params["path"] = path // 指定二维码扫码后直接进入指定页面并可同时带上参数)
}
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/get_qrcode?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodGet)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/get_qrcode?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodGet)
// 定义
var response WxaGetQrcodeResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -35,9 +35,9 @@ func NewWxaGetTemplateDraftListResult(result WxaGetTemplateDraftListResponse, bo
// WxaGetTemplateDraftList 获取代码草稿列表
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/code_template/gettemplatedraftlist.html
func (app *App) WxaGetTemplateDraftList() *WxaGetTemplateDraftListResult {
func (c *Client) WxaGetTemplateDraftList() *WxaGetTemplateDraftListResult {
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/gettemplatedraftlist?access_token=%s", app.GetComponentAccessToken()), map[string]interface{}{}, http.MethodGet)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/gettemplatedraftlist?access_token=%s", c.GetComponentAccessToken()), map[string]interface{}{}, http.MethodGet)
// 定义
var response WxaGetTemplateDraftListResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -36,9 +36,9 @@ func NewWxaGetTemplateListResult(result WxaGetTemplateListResponse, body []byte,
// WxaGetTemplateList 获取代码模板列表
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/code_template/gettemplatelist.html
func (app *App) WxaGetTemplateList() *WxaGetTemplateListResult {
func (c *Client) WxaGetTemplateList() *WxaGetTemplateListResult {
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/gettemplatelist?access_token=%s", app.GetComponentAccessToken()), map[string]interface{}{}, http.MethodGet)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/gettemplatelist?access_token=%s", c.GetComponentAccessToken()), map[string]interface{}{}, http.MethodGet)
// 定义
var response WxaGetTemplateListResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -36,13 +36,13 @@ func NewWxaGetVersionInfoResult(result WxaGetVersionInfoResponse, body []byte, h
// WxaGetVersionInfo 查询小程序版本信息
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/code/get_versioninfo.html
func (app *App) WxaGetVersionInfo() *WxaGetVersionInfoResult {
accessToken := app.GetAuthorizerAccessToken()
func (c *Client) WxaGetVersionInfo() *WxaGetVersionInfoResult {
accessToken := c.GetAuthorizerAccessToken()
if accessToken == "" {
return NewWxaGetVersionInfoResult(WxaGetVersionInfoResponse{}, nil, gorequest.Response{}, errors.New("访问令牌为空"))
}
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/getversioninfo?access_token=%s", accessToken), map[string]interface{}{}, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/getversioninfo?access_token=%s", accessToken), map[string]interface{}{}, http.MethodPost)
// 定义
var response WxaGetVersionInfoResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -27,11 +27,11 @@ func NewWxaGetWxaCodeUnLimitResult(result WxaGetWxaCodeUnLimitResponse, body []b
// WxaGetWxaCodeUnLimit 获取小程序码,适用于需要的码数量极多的业务场景。通过该接口生成的小程序码,永久有效,数量暂无限制
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.getUnlimited.html
func (app *App) WxaGetWxaCodeUnLimit(notMustParams ...Params) *WxaGetWxaCodeUnLimitResult {
func (c *Client) WxaGetWxaCodeUnLimit(notMustParams ...Params) *WxaGetWxaCodeUnLimitResult {
// 参数
params := app.NewParamsWith(notMustParams...)
params := c.NewParamsWith(notMustParams...)
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodPost)
// 定义
var response WxaGetWxaCodeUnLimitResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -29,8 +29,8 @@ func NewWxaMemberAuthResult(result WxaMemberAuthResponse, body []byte, http gore
// WxaMemberAuth 获取体验者列表
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Mini_Program_AdminManagement/memberauth.html
func (app *App) WxaMemberAuth() *WxaMemberAuthResult {
accessToken := app.GetAuthorizerAccessToken()
func (c *Client) WxaMemberAuth() *WxaMemberAuthResult {
accessToken := c.GetAuthorizerAccessToken()
if accessToken == "" {
return NewWxaMemberAuthResult(WxaMemberAuthResponse{}, nil, gorequest.Response{}, errors.New("访问令牌为空"))
}
@ -38,7 +38,7 @@ func (app *App) WxaMemberAuth() *WxaMemberAuthResult {
params := NewParams()
params["action"] = "get_experiencer"
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/memberauth?access_token=%s", accessToken), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/memberauth?access_token=%s", accessToken), params, http.MethodPost)
// 定义
var response WxaMemberAuthResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -38,11 +38,11 @@ func NewWxaModifyDomainResult(result WxaModifyDomainResponse, body []byte, http
// WxaModifyDomain 设置服务器域名
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Mini_Program_Basic_Info/Server_Address_Configuration.html
func (app *App) WxaModifyDomain(notMustParams ...Params) *WxaModifyDomainResult {
func (c *Client) WxaModifyDomain(notMustParams ...Params) *WxaModifyDomainResult {
// 参数
params := app.NewParamsWith(notMustParams...)
params := c.NewParamsWith(notMustParams...)
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/modify_domain?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/modify_domain?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodPost)
// 定义
var response WxaModifyDomainResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -25,11 +25,11 @@ func NewWxaModifyDomainDirectlyResult(result WxaModifyDomainDirectlyResponse, bo
// WxaModifyDomainDirectly 快速设置小程序服务器域名
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Mini_Program_Basic_Info/modify_domain_directly.html
func (app *App) WxaModifyDomainDirectly(notMustParams ...Params) *WxaModifyDomainDirectlyResult {
func (c *Client) WxaModifyDomainDirectly(notMustParams ...Params) *WxaModifyDomainDirectlyResult {
// 参数
params := app.NewParamsWith(notMustParams...)
params := c.NewParamsWith(notMustParams...)
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/modify_domain_directly?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/modify_domain_directly?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodPost)
// 定义
var response WxaModifyDomainDirectlyResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -25,11 +25,11 @@ func NewWxaReleaseResult(result WxaReleaseResponse, body []byte, http gorequest.
// WxaRelease 发布已通过审核的小程序
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/code/release.html
func (app *App) WxaRelease() *WxaReleaseResult {
func (c *Client) WxaRelease() *WxaReleaseResult {
// 参数
params := NewParams()
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/release?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/release?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodPost)
// 定义
var response WxaReleaseResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -26,11 +26,11 @@ func NewWxaSecurityApplyPrivacyInterfaceResult(result WxaSecurityApplyPrivacyInt
// WxaSecurityApplyPrivacyInterface 申请接口
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/apply_api/apply_privacy_interface.html
func (app *App) WxaSecurityApplyPrivacyInterface(notMustParams ...Params) *WxaSecurityApplyPrivacyInterfaceResult {
func (c *Client) WxaSecurityApplyPrivacyInterface(notMustParams ...Params) *WxaSecurityApplyPrivacyInterfaceResult {
// 参数
params := app.NewParamsWith(notMustParams...)
params := c.NewParamsWith(notMustParams...)
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/security/apply_privacy_interface?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/security/apply_privacy_interface?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodPost)
// 定义
var response WxaSecurityApplyPrivacyInterfaceResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -36,11 +36,11 @@ func NewWxaSecurityGetPrivacyInterfaceResult(result WxaSecurityGetPrivacyInterfa
// WxaSecurityGetPrivacyInterface 获取接口列表
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/apply_api/get_privacy_interface.html
func (app *App) WxaSecurityGetPrivacyInterface() *WxaSecurityGetPrivacyInterfaceResult {
func (c *Client) WxaSecurityGetPrivacyInterface() *WxaSecurityGetPrivacyInterfaceResult {
// 参数
params := NewParams()
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/security/get_privacy_interface?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodGet)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/security/get_privacy_interface?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodGet)
// 定义
var response WxaSecurityGetPrivacyInterfaceResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -26,11 +26,11 @@ func NewWxaSubmitAuditResult(result WxaSubmitAuditResponse, body []byte, http go
// WxaSubmitAudit 提交审核
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/code/submit_audit.html
func (app *App) WxaSubmitAudit(notMustParams ...Params) *WxaSubmitAuditResult {
func (c *Client) WxaSubmitAudit(notMustParams ...Params) *WxaSubmitAuditResult {
// 参数
params := app.NewParamsWith(notMustParams...)
params := c.NewParamsWith(notMustParams...)
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/submit_audit?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/submit_audit?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodPost)
// 定义
var response WxaSubmitAuditResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -25,7 +25,7 @@ func NewWxaUnbindTesterResult(result WxaUnbindTesterResponse, body []byte, http
// WxaUnbindTester 解除绑定体验者
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Mini_Program_AdminManagement/unbind_tester.html
func (app *App) WxaUnbindTester(wechatid, userstr string) *WxaUnbindTesterResult {
func (c *Client) WxaUnbindTester(wechatid, userstr string) *WxaUnbindTesterResult {
// 参数
params := NewParams()
if wechatid != "" {
@ -33,7 +33,7 @@ func (app *App) WxaUnbindTester(wechatid, userstr string) *WxaUnbindTesterResult
}
params["userstr"] = userstr
// 请求
request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/unbind_tester?access_token=%s", app.GetAuthorizerAccessToken()), params, http.MethodPost)
request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/unbind_tester?access_token=%s", c.GetAuthorizerAccessToken()), params, http.MethodPost)
// 定义
var response WxaUnbindTesterResponse
err = json.Unmarshal(request.ResponseBody, &response)

Loading…
Cancel
Save