parent
4094a91645
commit
50011b492a
@ -0,0 +1,54 @@
|
||||
package wechatopen
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/dtapps/go-library/utils/gojson"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type CgiBinOpenapiRidGetResponse struct {
|
||||
Errcode int `json:"errcode"`
|
||||
Errmsg string `json:"errmsg"`
|
||||
Request struct {
|
||||
InvokeTime int `json:"invoke_time"` // 发起请求的时间戳
|
||||
CostInMs int `json:"cost_in_ms"` // 请求毫秒级耗时
|
||||
RequestUrl string `json:"request_url"` // 请求的URL参数
|
||||
RequestBody string `json:"request_body"` // post请求的请求参数
|
||||
ResponseBody string `json:"response_body"` // 接口请求返回参数
|
||||
ClientIp string `json:"client_ip"` // 接口请求的客户端ip
|
||||
} `json:"request"`
|
||||
}
|
||||
|
||||
type CgiBinOpenapiRidGetResult struct {
|
||||
Result CgiBinOpenapiRidGetResponse // 结果
|
||||
Body []byte // 内容
|
||||
Http gorequest.Response // 请求
|
||||
}
|
||||
|
||||
func newCgiBinOpenapiRidGetResult(result CgiBinOpenapiRidGetResponse, body []byte, http gorequest.Response) *CgiBinOpenapiRidGetResult {
|
||||
return &CgiBinOpenapiRidGetResult{Result: result, Body: body, Http: http}
|
||||
}
|
||||
|
||||
// CgiBinOpenapiRidGet 查询rid信息
|
||||
// https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/openapi/getRidInfo.html
|
||||
func (c *Client) CgiBinOpenapiRidGet(ctx context.Context, rid string, notMustParams ...gorequest.Params) (*CgiBinOpenapiRidGetResult, error) {
|
||||
// 检查
|
||||
if err := c.checkAuthorizerConfig(ctx); err != nil {
|
||||
return newCgiBinOpenapiRidGetResult(CgiBinOpenapiRidGetResponse{}, []byte{}, gorequest.Response{}), err
|
||||
}
|
||||
// 参数
|
||||
params := gorequest.NewParamsWith(notMustParams...)
|
||||
if rid != "" {
|
||||
params.Set("rid", rid)
|
||||
}
|
||||
// 请求
|
||||
request, err := c.request(ctx, apiUrl+"/cgi-bin/openapi/rid/get?access_token="+c.GetAuthorizerAccessToken(ctx), params, http.MethodPost)
|
||||
if err != nil {
|
||||
return newCgiBinOpenapiRidGetResult(CgiBinOpenapiRidGetResponse{}, request.ResponseBody, request), err
|
||||
}
|
||||
// 定义
|
||||
var response CgiBinOpenapiRidGetResponse
|
||||
err = gojson.Unmarshal(request.ResponseBody, &response)
|
||||
return newCgiBinOpenapiRidGetResult(response, request.ResponseBody, request), err
|
||||
}
|
@ -1,21 +1,26 @@
|
||||
package wechatopen
|
||||
|
||||
func (c *Client) checkComponentIsConfig() error {
|
||||
componentAppId := c.GetComponentAppId()
|
||||
if componentAppId == "" {
|
||||
return componentAppIdNoConfig
|
||||
}
|
||||
componentAppSecret := c.GetComponentAppSecret()
|
||||
if componentAppSecret == "" {
|
||||
return componentAppSecretNoConfig
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
)
|
||||
|
||||
func (c *Client) checkAuthorizerIsConfig(ctx context.Context) error {
|
||||
authorizerAppid := c.GetAuthorizerAppid(ctx)
|
||||
if authorizerAppid == "" {
|
||||
return errors.New("请配置 authorizerAppid")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) checkAuthorizerIsConfig() error {
|
||||
authorizerAppid := c.GetAuthorizerAppid()
|
||||
func (c *Client) checkAuthorizerConfig(ctx context.Context) error {
|
||||
authorizerAppid := c.GetAuthorizerAppid(ctx)
|
||||
if authorizerAppid == "" {
|
||||
return authorizerAppidNoConfig
|
||||
return errors.New("请配置 authorizerAppid")
|
||||
}
|
||||
authorizerAccessToken := c.GetAuthorizerAccessToken(ctx)
|
||||
if authorizerAccessToken == "" {
|
||||
return errors.New("请配置 authorizerAccessToken")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
package wechatopen
|
||||
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
redisCachePrefixNoConfig = errors.New("请配置 RedisCachePrefix")
|
||||
)
|
||||
|
||||
var (
|
||||
componentAppIdNoConfig = errors.New("请配置 ComponentAppId")
|
||||
componentAppSecretNoConfig = errors.New("请配置 ComponentAppSecret")
|
||||
)
|
||||
|
||||
var (
|
||||
authorizerAppidNoConfig = errors.New("请配置 AuthorizerAppid 或 ConfigAuthorizer")
|
||||
)
|
@ -1,47 +1,60 @@
|
||||
package wechatopen
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
import (
|
||||
"context"
|
||||
"github.com/dtapps/go-library/utils/golog"
|
||||
)
|
||||
|
||||
//func (c *Client) GetComponentAccessToken() string {
|
||||
// return c.config.componentAccessToken
|
||||
//}
|
||||
// GetComponentAppId 获取第三方平台appid
|
||||
func (c *Client) GetComponentAppId(ctx context.Context) string {
|
||||
return c.config.componentAppId
|
||||
}
|
||||
|
||||
//func (c *Client) GetComponentVerifyTicket() string {
|
||||
// return c.config.componentVerifyTicket
|
||||
//}
|
||||
// GetComponentAppSecret 获取第三方平台app_secret
|
||||
func (c *Client) GetComponentAppSecret(ctx context.Context) string {
|
||||
return c.config.componentAppSecret
|
||||
}
|
||||
|
||||
//func (c *Client) GetPreAuthCode() string {
|
||||
// return c.config.preAuthCode
|
||||
//}
|
||||
// GetMessageToken 获取第三方平台消息令牌
|
||||
func (c *Client) GetMessageToken(ctx context.Context) string {
|
||||
return c.config.messageToken
|
||||
}
|
||||
|
||||
//func (c *Client) GetAuthorizerAccessToken() string {
|
||||
// return c.config.authorizerAccessToken
|
||||
//}
|
||||
// GetMessageKey 获取第三方平台消息密钥
|
||||
func (c *Client) GetMessageKey(ctx context.Context) string {
|
||||
return c.config.messageKey
|
||||
}
|
||||
|
||||
func (c *Client) GetAuthorizerRefreshToken() string {
|
||||
return c.config.authorizerRefreshToken
|
||||
// GetComponentAccessToken 获取第三方平台access_token
|
||||
func (c *Client) GetComponentAccessToken(ctx context.Context) string {
|
||||
return c.config.componentAccessToken
|
||||
}
|
||||
|
||||
func (c *Client) GetAuthorizerAppid() string {
|
||||
return c.config.authorizerAppid
|
||||
// GetComponentVerifyTicket 获取第三方平台推送ticket
|
||||
func (c *Client) GetComponentVerifyTicket(ctx context.Context) string {
|
||||
return c.config.componentVerifyTicket
|
||||
}
|
||||
|
||||
func (c *Client) GetComponentAppId() string {
|
||||
return c.config.componentAppId
|
||||
// GetPreAuthCode 获取第三方平台预授权码
|
||||
func (c *Client) GetPreAuthCode(ctx context.Context) string {
|
||||
return c.config.preAuthCode
|
||||
}
|
||||
|
||||
func (c *Client) GetComponentAppSecret() string {
|
||||
return c.config.componentAppSecret
|
||||
// GetAuthorizerAppid 获取授权方appid
|
||||
func (c *Client) GetAuthorizerAppid(ctx context.Context) string {
|
||||
return c.config.authorizerAppid
|
||||
}
|
||||
|
||||
func (c *Client) GetMessageToken() string {
|
||||
return c.config.messageToken
|
||||
// GetAuthorizerAccessToken 获取授权方access_token
|
||||
func (c *Client) GetAuthorizerAccessToken(ctx context.Context) string {
|
||||
return c.config.authorizerAccessToken
|
||||
}
|
||||
|
||||
func (c *Client) GetMessageKey() string {
|
||||
return c.config.messageKey
|
||||
// GetAuthorizerRefreshToken 获取授权方refresh_token
|
||||
func (c *Client) GetAuthorizerRefreshToken(ctx context.Context) string {
|
||||
return c.config.authorizerRefreshToken
|
||||
}
|
||||
|
||||
func (c *Client) GetLog() *golog.ApiClient {
|
||||
func (c *Client) GetLog(ctx context.Context) *golog.ApiClient {
|
||||
return c.log.client
|
||||
}
|
||||
|
@ -1,151 +0,0 @@
|
||||
package wechatopen
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 微信后台推送的ticke
|
||||
func (c *Client) getComponentVerifyTicketCacheKeyName() string {
|
||||
return c.cache.componentVerifyTicketPrefix + c.GetComponentAppId()
|
||||
}
|
||||
|
||||
// SetComponentVerifyTicket 设置微信后台推送的ticke
|
||||
func (c *Client) SetComponentVerifyTicket(ctx context.Context, componentVerifyTicket string) string {
|
||||
if componentVerifyTicket == "" {
|
||||
return ""
|
||||
}
|
||||
c.cache.redisClient.Set(ctx, c.getComponentVerifyTicketCacheKeyName(), componentVerifyTicket, time.Hour*12)
|
||||
return c.GetComponentVerifyTicket(ctx)
|
||||
}
|
||||
|
||||
// GetComponentVerifyTicket 获取微信后台推送的ticke
|
||||
func (c *Client) GetComponentVerifyTicket(ctx context.Context) string {
|
||||
if c.cache.redisClient.GetDb() == nil {
|
||||
return c.config.componentVerifyTicket
|
||||
}
|
||||
result, _ := c.cache.redisClient.Get(ctx, c.getComponentVerifyTicketCacheKeyName()).Result()
|
||||
return result
|
||||
}
|
||||
|
||||
// 令牌
|
||||
func (c *Client) getComponentAccessTokenCacheKeyName() string {
|
||||
return c.cache.componentAccessTokenPrefix + c.GetComponentAppId()
|
||||
}
|
||||
|
||||
// SetComponentAccessToken 设置令牌
|
||||
func (c *Client) SetComponentAccessToken(ctx context.Context, componentAccessToken string) string {
|
||||
if componentAccessToken == "" {
|
||||
return ""
|
||||
}
|
||||
c.cache.redisClient.Set(ctx, c.getComponentAccessTokenCacheKeyName(), componentAccessToken, time.Second*7200)
|
||||
return c.GetComponentAccessToken(ctx)
|
||||
}
|
||||
|
||||
// GetComponentAccessToken 获取令牌
|
||||
func (c *Client) GetComponentAccessToken(ctx context.Context) string {
|
||||
if c.cache.redisClient.GetDb() == nil {
|
||||
return c.config.componentAccessToken
|
||||
}
|
||||
result, _ := c.cache.redisClient.GetDb().Get(ctx, c.getComponentAccessTokenCacheKeyName()).Result()
|
||||
return result
|
||||
}
|
||||
|
||||
// MonitorComponentAccessToken 监控令牌
|
||||
func (c *Client) MonitorComponentAccessToken(ctx context.Context) (string, error) {
|
||||
// 查询
|
||||
componentAccessToken := c.GetComponentAccessToken(ctx)
|
||||
// 判断
|
||||
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 c.SetComponentAccessToken(ctx, resp.Result.ComponentAccessToken), err
|
||||
}
|
||||
|
||||
// 授权方令牌
|
||||
func (c *Client) getAuthorizerAccessTokenCacheKeyName() string {
|
||||
return c.cache.authorizerAccessTokenPrefix + c.GetComponentAppId() + ":" + c.GetAuthorizerAppid()
|
||||
}
|
||||
|
||||
// SetAuthorizerAccessToken 设置授权方令牌
|
||||
func (c *Client) SetAuthorizerAccessToken(ctx context.Context, authorizerAccessToken string) string {
|
||||
if authorizerAccessToken == "" {
|
||||
return ""
|
||||
}
|
||||
c.cache.redisClient.Set(ctx, c.getAuthorizerAccessTokenCacheKeyName(), authorizerAccessToken, time.Hour*2)
|
||||
return c.GetComponentAccessToken(ctx)
|
||||
}
|
||||
|
||||
// GetAuthorizerAccessToken 获取授权方令牌
|
||||
func (c *Client) GetAuthorizerAccessToken(ctx context.Context) string {
|
||||
if c.cache.redisClient.GetDb() == nil {
|
||||
return c.config.authorizerAccessToken
|
||||
}
|
||||
result, _ := c.cache.redisClient.Get(ctx, c.getAuthorizerAccessTokenCacheKeyName()).Result()
|
||||
return result
|
||||
}
|
||||
|
||||
// MonitorAuthorizerAccessToken 监控授权方令牌
|
||||
func (c *Client) MonitorAuthorizerAccessToken(ctx context.Context, authorizerRefreshToken string) (string, error) {
|
||||
// 查询
|
||||
authorizerAccessToken := c.GetAuthorizerAccessToken(ctx)
|
||||
// 判断
|
||||
if authorizerAccessToken != "" {
|
||||
return authorizerAccessToken, nil
|
||||
}
|
||||
// 重新获取
|
||||
resp, err := c.CgiBinComponentApiAuthorizerToken(ctx, authorizerRefreshToken)
|
||||
if resp.Result.AuthorizerRefreshToken == "" {
|
||||
return authorizerAccessToken, errors.New(fmt.Sprintf("获取失败:%v", err))
|
||||
}
|
||||
return c.SetAuthorizerAccessToken(ctx, resp.Result.AuthorizerAccessToken), err
|
||||
}
|
||||
|
||||
// 预授权码
|
||||
func (c *Client) getPreAuthCodeCacheKeyName() string {
|
||||
return c.cache.preAuthCodePrefix + c.GetComponentAppId()
|
||||
}
|
||||
|
||||
// SetPreAuthCode 设置预授权码
|
||||
func (c *Client) SetPreAuthCode(ctx context.Context, preAuthCode string) string {
|
||||
if preAuthCode == "" {
|
||||
return ""
|
||||
}
|
||||
c.cache.redisClient.Set(ctx, c.getPreAuthCodeCacheKeyName(), preAuthCode, time.Second*1700)
|
||||
return c.GetComponentAccessToken(ctx)
|
||||
}
|
||||
|
||||
// GetPreAuthCode 获取预授权码
|
||||
func (c *Client) GetPreAuthCode(ctx context.Context) string {
|
||||
if c.cache.redisClient.GetDb() == nil {
|
||||
return c.config.authorizerAccessToken
|
||||
}
|
||||
result, _ := c.cache.redisClient.Get(ctx, c.getPreAuthCodeCacheKeyName()).Result()
|
||||
return result
|
||||
}
|
||||
|
||||
// DelPreAuthCode 删除预授权码
|
||||
func (c *Client) DelPreAuthCode(ctx context.Context) error {
|
||||
return c.cache.redisClient.Del(ctx, c.getPreAuthCodeCacheKeyName()).Err()
|
||||
}
|
||||
|
||||
// MonitorPreAuthCode 监控预授权码
|
||||
func (c *Client) MonitorPreAuthCode(ctx context.Context) (string, error) {
|
||||
// 查询
|
||||
preAuthCode := c.GetPreAuthCode(ctx)
|
||||
// 判断
|
||||
if preAuthCode != "" {
|
||||
return preAuthCode, nil
|
||||
}
|
||||
// 重新获取
|
||||
resp, err := c.CgiBinComponentApiCreatePreAuthCoden(ctx)
|
||||
return c.SetPreAuthCode(ctx, resp.Result.PreAuthCode), err
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package wechatopen
|
||||
|
||||
import "context"
|
||||
|
||||
// SetComponentAccessToken 设置第三方平台access_token
|
||||
func (c *Client) SetComponentAccessToken(ctx context.Context, componentAccessToken string) {
|
||||
c.config.componentAccessToken = componentAccessToken
|
||||
}
|
||||
|
||||
// SetComponentVerifyTicket 设置第三方平台推送ticket
|
||||
func (c *Client) SetComponentVerifyTicket(ctx context.Context, componentVerifyTicket string) {
|
||||
c.config.componentVerifyTicket = componentVerifyTicket
|
||||
}
|
||||
|
||||
// SetPreAuthCode 设置第三方平台预授权码
|
||||
func (c *Client) SetPreAuthCode(ctx context.Context, preAuthCode string) {
|
||||
c.config.preAuthCode = preAuthCode
|
||||
}
|
||||
|
||||
// SetAuthorizerAppid 设置授权方appid
|
||||
func (c *Client) SetAuthorizerAppid(ctx context.Context, authorizerAppid string) {
|
||||
c.config.authorizerAppid = authorizerAppid
|
||||
}
|
||||
|
||||
// SetAuthorizerAccessToken 设置授权方access_token
|
||||
func (c *Client) SetAuthorizerAccessToken(ctx context.Context, authorizerAccessToken string) {
|
||||
c.config.authorizerAccessToken = authorizerAccessToken
|
||||
}
|
||||
|
||||
// SetAuthorizerRefreshToken 设置授权方refresh_token
|
||||
func (c *Client) SetAuthorizerRefreshToken(ctx context.Context, authorizerRefreshToken string) {
|
||||
c.config.authorizerRefreshToken = authorizerRefreshToken
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package wechatopen
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/dtapps/go-library/utils/gojson"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type WxaGetDefaultamsInfoAgencyGetCustomShareRatioResponse struct {
|
||||
Ret int `json:"ret"`
|
||||
ErrMsg string `json:"err_msg"`
|
||||
ShareRatio int `json:"share_ratio"`
|
||||
}
|
||||
|
||||
type WxaGetDefaultamsInfoAgencyGetCustomShareRatioResult struct {
|
||||
Result WxaGetDefaultamsInfoAgencyGetCustomShareRatioResponse // 结果
|
||||
Body []byte // 内容
|
||||
Http gorequest.Response // 请求
|
||||
}
|
||||
|
||||
func newWxaGetDefaultamsInfoAgencyGetCustomShareRatioResult(result WxaGetDefaultamsInfoAgencyGetCustomShareRatioResponse, body []byte, http gorequest.Response) *WxaGetDefaultamsInfoAgencyGetCustomShareRatioResult {
|
||||
return &WxaGetDefaultamsInfoAgencyGetCustomShareRatioResult{Result: result, Body: body, Http: http}
|
||||
}
|
||||
|
||||
// WxaGetDefaultamsInfoAgencyGetCustomShareRatio 查询自定义分账比例
|
||||
// https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/ams/percentage/GetCustomShareRatio.html
|
||||
func (c *Client) WxaGetDefaultamsInfoAgencyGetCustomShareRatio(ctx context.Context, notMustParams ...gorequest.Params) (*WxaGetDefaultamsInfoAgencyGetCustomShareRatioResult, error) {
|
||||
// 检查
|
||||
if err := c.checkAuthorizerConfig(ctx); err != nil {
|
||||
return newWxaGetDefaultamsInfoAgencyGetCustomShareRatioResult(WxaGetDefaultamsInfoAgencyGetCustomShareRatioResponse{}, []byte{}, gorequest.Response{}), err
|
||||
}
|
||||
// 参数
|
||||
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)
|
||||
if err != nil {
|
||||
return newWxaGetDefaultamsInfoAgencyGetCustomShareRatioResult(WxaGetDefaultamsInfoAgencyGetCustomShareRatioResponse{}, request.ResponseBody, request), err
|
||||
}
|
||||
// 定义
|
||||
var response WxaGetDefaultamsInfoAgencyGetCustomShareRatioResponse
|
||||
err = gojson.Unmarshal(request.ResponseBody, &response)
|
||||
return newWxaGetDefaultamsInfoAgencyGetCustomShareRatioResult(response, request.ResponseBody, request), err
|
||||
}
|
||||
|
||||
// ErrcodeInfo 错误描述
|
||||
func (resp *WxaGetDefaultamsInfoAgencyGetCustomShareRatioResult) ErrcodeInfo() string {
|
||||
switch resp.Result.Ret {
|
||||
case -202:
|
||||
return "内部错误"
|
||||
case 1700:
|
||||
return "参数错误"
|
||||
case 1701:
|
||||
return "参数错误"
|
||||
case 1735:
|
||||
return "商户未完成协议签署流程"
|
||||
case 1737:
|
||||
return "操作过快"
|
||||
case 2056:
|
||||
return "服务商未在变现专区开通账户"
|
||||
case 2061:
|
||||
return "不存在为该appid设置的个性化分成比例"
|
||||
}
|
||||
return "系统繁忙"
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package wechatopen
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/dtapps/go-library/utils/gojson"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type WxaGetDefaultamsInfoGetShareRatioResponse struct {
|
||||
Ret int `json:"ret"`
|
||||
ErrMsg string `json:"err_msg"`
|
||||
}
|
||||
|
||||
type WxaGetDefaultamsInfoGetShareRatioResult struct {
|
||||
Result WxaGetDefaultamsInfoGetShareRatioResponse // 结果
|
||||
Body []byte // 内容
|
||||
Http gorequest.Response // 请求
|
||||
}
|
||||
|
||||
func newWxaGetDefaultamsInfoGetShareRatioResult(result WxaGetDefaultamsInfoGetShareRatioResponse, body []byte, http gorequest.Response) *WxaGetDefaultamsInfoGetShareRatioResult {
|
||||
return &WxaGetDefaultamsInfoGetShareRatioResult{Result: result, Body: body, Http: http}
|
||||
}
|
||||
|
||||
// WxaGetDefaultamsInfoGetShareRatio 查询分账比例
|
||||
// https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/ams/percentage/GetShareRatio.html
|
||||
func (c *Client) WxaGetDefaultamsInfoGetShareRatio(ctx context.Context, notMustParams ...gorequest.Params) (*WxaGetDefaultamsInfoGetShareRatioResult, error) {
|
||||
// 检查
|
||||
if err := c.checkAuthorizerConfig(ctx); err != nil {
|
||||
return newWxaGetDefaultamsInfoGetShareRatioResult(WxaGetDefaultamsInfoGetShareRatioResponse{}, []byte{}, gorequest.Response{}), err
|
||||
}
|
||||
// 参数
|
||||
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)
|
||||
if err != nil {
|
||||
return newWxaGetDefaultamsInfoGetShareRatioResult(WxaGetDefaultamsInfoGetShareRatioResponse{}, request.ResponseBody, request), err
|
||||
}
|
||||
// 定义
|
||||
var response WxaGetDefaultamsInfoGetShareRatioResponse
|
||||
err = gojson.Unmarshal(request.ResponseBody, &response)
|
||||
return newWxaGetDefaultamsInfoGetShareRatioResult(response, request.ResponseBody, request), err
|
||||
}
|
||||
|
||||
// ErrcodeInfo 错误描述
|
||||
func (resp *WxaGetDefaultamsInfoGetShareRatioResult) ErrcodeInfo() string {
|
||||
switch resp.Result.Ret {
|
||||
case -202:
|
||||
return "内部错误"
|
||||
case 1700:
|
||||
return "参数错误"
|
||||
case 1701:
|
||||
return "参数错误"
|
||||
case 1735:
|
||||
return "商户未完成协议签署流程"
|
||||
case 1737:
|
||||
return "操作过快"
|
||||
case 2056:
|
||||
return "服务商未在变现专区开通账户"
|
||||
}
|
||||
return "系统繁忙"
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package wechatopen
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/dtapps/go-library/utils/gojson"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type WxaOperationamsAgencyCheckCanOpenPublisherResponse struct {
|
||||
Ret int `json:"ret"`
|
||||
ErrMsg string `json:"err_msg"`
|
||||
Status int `json:"status"`
|
||||
}
|
||||
|
||||
type WxaOperationamsAgencyCheckCanOpenPublisherResult struct {
|
||||
Result WxaOperationamsAgencyCheckCanOpenPublisherResponse // 结果
|
||||
Body []byte // 内容
|
||||
Http gorequest.Response // 请求
|
||||
}
|
||||
|
||||
func newWxaOperationamsAgencyCheckCanOpenPublisherResult(result WxaOperationamsAgencyCheckCanOpenPublisherResponse, body []byte, http gorequest.Response) *WxaOperationamsAgencyCheckCanOpenPublisherResult {
|
||||
return &WxaOperationamsAgencyCheckCanOpenPublisherResult{Result: result, Body: body, Http: http}
|
||||
}
|
||||
|
||||
// WxaOperationamsAgencyCheckCanOpenPublisher 检测是否能开通流量主
|
||||
// https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/ams/open/AgencyCheckCanOpenPublisher.html
|
||||
func (c *Client) WxaOperationamsAgencyCheckCanOpenPublisher(ctx context.Context, notMustParams ...gorequest.Params) (*WxaOperationamsAgencyCheckCanOpenPublisherResult, error) {
|
||||
// 检查
|
||||
if err := c.checkAuthorizerConfig(ctx); err != nil {
|
||||
return newWxaOperationamsAgencyCheckCanOpenPublisherResult(WxaOperationamsAgencyCheckCanOpenPublisherResponse{}, []byte{}, gorequest.Response{}), err
|
||||
}
|
||||
// 参数
|
||||
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)
|
||||
if err != nil {
|
||||
return newWxaOperationamsAgencyCheckCanOpenPublisherResult(WxaOperationamsAgencyCheckCanOpenPublisherResponse{}, request.ResponseBody, request), err
|
||||
}
|
||||
// 定义
|
||||
var response WxaOperationamsAgencyCheckCanOpenPublisherResponse
|
||||
err = gojson.Unmarshal(request.ResponseBody, &response)
|
||||
return newWxaOperationamsAgencyCheckCanOpenPublisherResult(response, request.ResponseBody, request), err
|
||||
}
|
||||
|
||||
// ErrcodeInfo 错误描述
|
||||
func (resp *WxaOperationamsAgencyCheckCanOpenPublisherResult) ErrcodeInfo() string {
|
||||
switch resp.Result.Ret {
|
||||
case 1700:
|
||||
return "参数错误"
|
||||
case 1701:
|
||||
return "参数错误"
|
||||
case 1735:
|
||||
return "商户未完成协议签署流程"
|
||||
case 1737:
|
||||
return "操作过快"
|
||||
case 2056:
|
||||
return "服务商未在变现专区开通账户"
|
||||
}
|
||||
return "系统繁忙"
|
||||
}
|
@ -0,0 +1 @@
|
||||
package wechatopen
|
@ -0,0 +1,63 @@
|
||||
package wechatopen
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/dtapps/go-library/utils/gojson"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type WxaSetDefaultamsInfoAgencySetCustomShareRatioResponse struct {
|
||||
Ret int `json:"ret"`
|
||||
ErrMsg string `json:"err_msg"`
|
||||
}
|
||||
|
||||
type WxaSetDefaultamsInfoAgencySetCustomShareRatioResult struct {
|
||||
Result WxaSetDefaultamsInfoAgencySetCustomShareRatioResponse // 结果
|
||||
Body []byte // 内容
|
||||
Http gorequest.Response // 请求
|
||||
}
|
||||
|
||||
func newWxaSetDefaultamsInfoAgencySetCustomShareRatioResult(result WxaSetDefaultamsInfoAgencySetCustomShareRatioResponse, body []byte, http gorequest.Response) *WxaSetDefaultamsInfoAgencySetCustomShareRatioResult {
|
||||
return &WxaSetDefaultamsInfoAgencySetCustomShareRatioResult{Result: result, Body: body, Http: http}
|
||||
}
|
||||
|
||||
// WxaSetDefaultamsInfoAgencySetCustomShareRatio 设置自定义分账比例
|
||||
// https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/ams/percentage/SetCustomShareRatio.html
|
||||
func (c *Client) WxaSetDefaultamsInfoAgencySetCustomShareRatio(ctx context.Context, shareRatio int64, notMustParams ...gorequest.Params) (*WxaSetDefaultamsInfoAgencySetCustomShareRatioResult, error) {
|
||||
// 检查
|
||||
if err := c.checkAuthorizerConfig(ctx); err != nil {
|
||||
return newWxaSetDefaultamsInfoAgencySetCustomShareRatioResult(WxaSetDefaultamsInfoAgencySetCustomShareRatioResponse{}, []byte{}, gorequest.Response{}), err
|
||||
}
|
||||
// 参数
|
||||
params := gorequest.NewParamsWith(notMustParams...)
|
||||
if shareRatio > 0 {
|
||||
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)
|
||||
if err != nil {
|
||||
return newWxaSetDefaultamsInfoAgencySetCustomShareRatioResult(WxaSetDefaultamsInfoAgencySetCustomShareRatioResponse{}, request.ResponseBody, request), err
|
||||
}
|
||||
// 定义
|
||||
var response WxaSetDefaultamsInfoAgencySetCustomShareRatioResponse
|
||||
err = gojson.Unmarshal(request.ResponseBody, &response)
|
||||
return newWxaSetDefaultamsInfoAgencySetCustomShareRatioResult(response, request.ResponseBody, request), err
|
||||
}
|
||||
|
||||
// ErrcodeInfo 错误描述
|
||||
func (resp *WxaSetDefaultamsInfoAgencySetCustomShareRatioResult) ErrcodeInfo() string {
|
||||
switch resp.Result.Ret {
|
||||
case -202:
|
||||
return "内部错误"
|
||||
case 1700:
|
||||
return "参数错误"
|
||||
case 1701:
|
||||
return "参数错误"
|
||||
case 1737:
|
||||
return "操作过快"
|
||||
case 2056:
|
||||
return "服务商未在变现专区开通账户"
|
||||
}
|
||||
return "系统繁忙"
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package wechatopen
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/dtapps/go-library/utils/gojson"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type WxaSetDefaultamsInfoSetShareRatioResponse struct {
|
||||
Ret int `json:"ret"`
|
||||
ErrMsg string `json:"err_msg"`
|
||||
}
|
||||
|
||||
type WxaSetDefaultamsInfoSetShareRatioResult struct {
|
||||
Result WxaSetDefaultamsInfoSetShareRatioResponse // 结果
|
||||
Body []byte // 内容
|
||||
Http gorequest.Response // 请求
|
||||
}
|
||||
|
||||
func newWxaSetDefaultamsInfoSetShareRatioResult(result WxaSetDefaultamsInfoSetShareRatioResponse, body []byte, http gorequest.Response) *WxaSetDefaultamsInfoSetShareRatioResult {
|
||||
return &WxaSetDefaultamsInfoSetShareRatioResult{Result: result, Body: body, Http: http}
|
||||
}
|
||||
|
||||
// WxaSetDefaultamsInfoSetShareRatio 设置默认分账比例
|
||||
// https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/ams/percentage/SetShareRatio.html
|
||||
func (c *Client) WxaSetDefaultamsInfoSetShareRatio(ctx context.Context, shareRatio int64, notMustParams ...gorequest.Params) (*WxaSetDefaultamsInfoSetShareRatioResult, error) {
|
||||
// 检查
|
||||
if err := c.checkAuthorizerConfig(ctx); err != nil {
|
||||
return newWxaSetDefaultamsInfoSetShareRatioResult(WxaSetDefaultamsInfoSetShareRatioResponse{}, []byte{}, gorequest.Response{}), err
|
||||
}
|
||||
// 参数
|
||||
params := gorequest.NewParamsWith(notMustParams...)
|
||||
if shareRatio > 0 {
|
||||
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)
|
||||
if err != nil {
|
||||
return newWxaSetDefaultamsInfoSetShareRatioResult(WxaSetDefaultamsInfoSetShareRatioResponse{}, request.ResponseBody, request), err
|
||||
}
|
||||
// 定义
|
||||
var response WxaSetDefaultamsInfoSetShareRatioResponse
|
||||
err = gojson.Unmarshal(request.ResponseBody, &response)
|
||||
return newWxaSetDefaultamsInfoSetShareRatioResult(response, request.ResponseBody, request), err
|
||||
}
|
||||
|
||||
// ErrcodeInfo 错误描述
|
||||
func (resp *WxaSetDefaultamsInfoSetShareRatioResult) ErrcodeInfo() string {
|
||||
switch resp.Result.Ret {
|
||||
case -202:
|
||||
return "内部错误"
|
||||
case 1700:
|
||||
return "参数错误"
|
||||
case 1701:
|
||||
return "参数错误"
|
||||
case 1737:
|
||||
return "操作过快"
|
||||
case 2056:
|
||||
return "服务商未在变现专区开通账户"
|
||||
}
|
||||
return "系统繁忙"
|
||||
}
|
Loading…
Reference in new issue