From 9ee6fe2dfa49ff7425a818b39128c9f1cf340776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Sat, 18 Jun 2022 10:35:06 +0800 Subject: [PATCH] - update service/wechatminiprogram --- service/wechatminiprogram/app.go | 89 ----------------- .../cgi-bin.getcallbackip.go | 5 +- .../cgi-bin.message.subscribe.send.go | 7 +- service/wechatminiprogram/cgi-bin.token.go | 4 +- .../cgi-bin.token.monitor.go | 12 +-- .../wechatminiprogram/cgi-bin.token.rdb.go | 16 ++-- .../cgi-bin.wxaapp.createwxaqrcode.go | 7 +- service/wechatminiprogram/client.go | 95 +++++++++++++++++++ service/wechatminiprogram/get.go | 14 +++ service/wechatminiprogram/params.go | 2 +- service/wechatminiprogram/pgsql.go | 4 +- service/wechatminiprogram/save_img.go | 2 +- service/wechatminiprogram/sign.go | 8 +- .../wechatminiprogram/sns.jscode2session.go | 4 +- service/wechatminiprogram/user_info.go | 8 +- service/wechatminiprogram/user_phone.go | 8 +- .../wxa.business.getliveinfo.go | 7 +- .../wxa.business.getuserphonenumber.go | 7 +- .../wechatminiprogram/wxa.generate_urllink.go | 7 +- .../wechatminiprogram/wxa.generatescheme.go | 7 +- service/wechatminiprogram/wxa.getwxacode.go | 7 +- .../wxa.getwxacodeunlimit.go | 7 +- .../wechatminiprogram/wxa.query_urllink.go | 7 +- service/wechatminiprogram/wxa.queryscheme.go | 7 +- .../wechatminiprogram/wxaapi.feedback.list.go | 9 +- 25 files changed, 179 insertions(+), 171 deletions(-) delete mode 100644 service/wechatminiprogram/app.go create mode 100644 service/wechatminiprogram/client.go create mode 100644 service/wechatminiprogram/get.go diff --git a/service/wechatminiprogram/app.go b/service/wechatminiprogram/app.go deleted file mode 100644 index f8d5d2aa..00000000 --- a/service/wechatminiprogram/app.go +++ /dev/null @@ -1,89 +0,0 @@ -package wechatminiprogram - -import ( - "go.dtapp.net/library/utils/golog" - "go.dtapp.net/library/utils/goredis" - "go.dtapp.net/library/utils/gorequest" - "gorm.io/gorm" -) - -const ( - WECHAT_API_URL = "https://api.weixin.qq.com" - WECHAT_MP_URL = "https://mp.weixin.qq.com" - CGIUrl = WECHAT_API_URL + "/cgi-bin" - UnionUrl = WECHAT_API_URL + "/union" -) - -// App 微信小程序服务 -type App struct { - appId string // 小程序唯一凭证,即 appId - appSecret string // 小程序唯一凭证密钥,即 appSecret - accessToken string // 接口调用凭证 - jsapiTicket string // 签名凭证 - redis goredis.App // 缓存数据库 - db *gorm.DB // 令牌数据库 - pgsql *gorm.DB // pgsql数据库 - client *gorequest.App // 请求客户端 - log *golog.Api // 日志服务 - logTableName string // 日志表名 - logStatus bool // 日志状态 -} - -// NewApp 实例化 -func NewApp(appId, appSecret string, redis goredis.App, db *gorm.DB, pgsql *gorm.DB) *App { - app := &App{appId: appId, appSecret: appSecret, redis: redis, db: db} - app.client = gorequest.NewHttp() - if pgsql != nil { - app.pgsql = pgsql - app.logStatus = true - app.logTableName = "wechatminiprogram" - app.log = golog.NewApi(&golog.ApiConfig{ - Db: pgsql, - TableName: app.logTableName, - }) - } - return app -} - -// Config 配置 -func (app *App) Config(appId, appSecret string) *App { - app.appId = appId - app.appSecret = appSecret - return app -} - -// 请求接口 -func (app *App) request(url string, params map[string]interface{}, method string) (resp gorequest.Response, err error) { - - // 创建请求 - client := app.client - - // 设置请求地址 - client.SetUri(url) - - // 设置方式 - client.SetMethod(method) - - // 设置格式 - client.SetContentTypeJson() - - // 设置参数 - client.SetParams(params) - - // 发起请求 - request, err := client.Request() - if err != nil { - return gorequest.Response{}, err - } - - // 日志 - if app.logStatus == true { - go app.postgresqlLog(request) - } - - return request, err -} - -func (app *App) GetAppId() string { - return app.appId -} diff --git a/service/wechatminiprogram/cgi-bin.getcallbackip.go b/service/wechatminiprogram/cgi-bin.getcallbackip.go index 0ba99ccf..0cf8e1ad 100644 --- a/service/wechatminiprogram/cgi-bin.getcallbackip.go +++ b/service/wechatminiprogram/cgi-bin.getcallbackip.go @@ -25,10 +25,9 @@ func NewGetCallBackIpResult(result GetCallBackIpResponse, body []byte, http gore // GetCallBackIp 获取微信callback IP地址 // callback IP即微信调用开发者服务器所使用的出口IP。 // https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_the_WeChat_server_IP_address.html#2.%20%E8%8E%B7%E5%8F%96%E5%BE%AE%E4%BF%A1callback%20IP%E5%9C%B0%E5%9D%80 -func (app *App) GetCallBackIp() *GetCallBackIpResult { - app.accessToken = app.GetAccessToken() +func (c *Client) GetCallBackIp() *GetCallBackIpResult { // 请求 - request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=%s", app.accessToken), map[string]interface{}{}, http.MethodGet) + request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=%s", c.getAccessToken()), map[string]interface{}{}, http.MethodGet) // 定义 var response GetCallBackIpResponse err = json.Unmarshal(request.ResponseBody, &response) diff --git a/service/wechatminiprogram/cgi-bin.message.subscribe.send.go b/service/wechatminiprogram/cgi-bin.message.subscribe.send.go index 2a7b69d0..46cb903c 100644 --- a/service/wechatminiprogram/cgi-bin.message.subscribe.send.go +++ b/service/wechatminiprogram/cgi-bin.message.subscribe.send.go @@ -25,12 +25,11 @@ func NewSubscribeMessageSendResult(result SubscribeMessageSendResponse, body []b // SubscribeMessageSend 发送订阅消息 // https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html -func (app *App) SubscribeMessageSend(notMustParams ...Params) *SubscribeMessageSendResult { - app.accessToken = app.GetAccessToken() +func (c *Client) SubscribeMessageSend(notMustParams ...Params) *SubscribeMessageSendResult { // 参数 - params := app.NewParamsWith(notMustParams...) + params := c.NewParamsWith(notMustParams...) // 请求 - request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=%s", app.accessToken), params, http.MethodPost) + request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=%s", c.getAccessToken()), params, http.MethodPost) // 定义 var response SubscribeMessageSendResponse err = json.Unmarshal(request.ResponseBody, &response) diff --git a/service/wechatminiprogram/cgi-bin.token.go b/service/wechatminiprogram/cgi-bin.token.go index d371858e..f798c417 100644 --- a/service/wechatminiprogram/cgi-bin.token.go +++ b/service/wechatminiprogram/cgi-bin.token.go @@ -28,9 +28,9 @@ func NewCgiBinTokenResult(result CgiBinTokenResponse, body []byte, http goreques // CgiBinToken // 接口调用凭证 // https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html -func (app *App) CgiBinToken() *CgiBinTokenResult { +func (c *Client) CgiBinToken() *CgiBinTokenResult { // 请求 - request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", app.appId, app.appSecret), map[string]interface{}{}, http.MethodGet) + request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", c.getAppId(), c.getAppSecret()), map[string]interface{}{}, http.MethodGet) // 定义 var response CgiBinTokenResponse err = json.Unmarshal(request.ResponseBody, &response) diff --git a/service/wechatminiprogram/cgi-bin.token.monitor.go b/service/wechatminiprogram/cgi-bin.token.monitor.go index d8a1e97f..744ca925 100644 --- a/service/wechatminiprogram/cgi-bin.token.monitor.go +++ b/service/wechatminiprogram/cgi-bin.token.monitor.go @@ -6,15 +6,15 @@ import ( "time" ) -func (app *App) GetAccessTokenMonitor() (string, error) { - if app.redis.Db == nil { +func (c *Client) GetAccessTokenMonitor() (string, error) { + if c.config.RedisClient.Db == nil { return "", errors.New("驱动没有初始化") } - result := app.GetCallBackIp() + result := c.GetCallBackIp() if len(result.Result.IpList) <= 0 { - token := app.CgiBinToken() - app.redis.Db.Set(context.Background(), app.getAccessTokenCacheKeyName(), token.Result.AccessToken, time.Second*7000) + token := c.CgiBinToken() + c.config.RedisClient.Db.Set(context.Background(), c.getAccessTokenCacheKeyName(), token.Result.AccessToken, time.Second*7000) return token.Result.AccessToken, nil } - return app.accessToken, nil + return c.config.AccessToken, nil } diff --git a/service/wechatminiprogram/cgi-bin.token.rdb.go b/service/wechatminiprogram/cgi-bin.token.rdb.go index 6d66215a..bc98f996 100644 --- a/service/wechatminiprogram/cgi-bin.token.rdb.go +++ b/service/wechatminiprogram/cgi-bin.token.rdb.go @@ -5,18 +5,18 @@ import ( "time" ) -func (app *App) GetAccessToken() string { - if app.redis.Db == nil { - return app.accessToken +func (c *Client) GetAccessToken() string { + if c.config.RedisClient.Db == nil { + return c.config.AccessToken } - newCache := app.redis.NewSimpleStringCache(app.redis.NewStringOperation(), time.Second*7000) + newCache := c.config.RedisClient.NewSimpleStringCache(c.config.RedisClient.NewStringOperation(), time.Second*7000) newCache.DBGetter = func() string { - token := app.CgiBinToken() + token := c.CgiBinToken() return token.Result.AccessToken } - return newCache.GetCache(app.getAccessTokenCacheKeyName()) + return newCache.GetCache(c.getAccessTokenCacheKeyName()) } -func (app *App) getAccessTokenCacheKeyName() string { - return fmt.Sprintf("wechat_access_token:%v", app.appId) +func (c *Client) getAccessTokenCacheKeyName() string { + return fmt.Sprintf("wechat_access_token:%v", c.config.AppId) } diff --git a/service/wechatminiprogram/cgi-bin.wxaapp.createwxaqrcode.go b/service/wechatminiprogram/cgi-bin.wxaapp.createwxaqrcode.go index acf9b3e7..ceac5cb1 100644 --- a/service/wechatminiprogram/cgi-bin.wxaapp.createwxaqrcode.go +++ b/service/wechatminiprogram/cgi-bin.wxaapp.createwxaqrcode.go @@ -27,12 +27,11 @@ func NewCgiBinWxaAppCreateWxaQrCodeResult(result CgiBinWxaAppCreateWxaQrCodeResp // CgiBinWxaAppCreateWxaQrCode 获取小程序二维码,适用于需要的码数量较少的业务场景。通过该接口生成的小程序码,永久有效,有数量限制 // https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.createQRCode.html -func (app *App) CgiBinWxaAppCreateWxaQrCode(notMustParams ...Params) *CgiBinWxaAppCreateWxaQrCodeResult { - app.accessToken = app.GetAccessToken() +func (c *Client) CgiBinWxaAppCreateWxaQrCode(notMustParams ...Params) *CgiBinWxaAppCreateWxaQrCodeResult { // 参数 - params := app.NewParamsWith(notMustParams...) + params := c.NewParamsWith(notMustParams...) // 请求 - request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=%s", app.accessToken), params, http.MethodPost) + request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=%s", c.getAccessToken()), params, http.MethodPost) // 定义 var response CgiBinWxaAppCreateWxaQrCodeResponse err = json.Unmarshal(request.ResponseBody, &response) diff --git a/service/wechatminiprogram/client.go b/service/wechatminiprogram/client.go new file mode 100644 index 00000000..d20db4fd --- /dev/null +++ b/service/wechatminiprogram/client.go @@ -0,0 +1,95 @@ +package wechatminiprogram + +import ( + "go.dtapp.net/library/utils/dorm" + "go.dtapp.net/library/utils/golog" + "go.dtapp.net/library/utils/gorequest" + "gorm.io/gorm" +) + +const ( + WECHAT_API_URL = "https://api.weixin.qq.com" + WECHAT_MP_URL = "https://mp.weixin.qq.com" + CGIUrl = WECHAT_API_URL + "/cgi-bin" + UnionUrl = WECHAT_API_URL + "/union" +) + +type ConfigClient struct { + AppId string // 小程序唯一凭证,即 appId + AppSecret string // 小程序唯一凭证密钥,即 appSecret + AccessToken string // 接口调用凭证 + JsapiTicket string // 签名凭证 + RedisClient *dorm.RedisClient // 缓存数据库 + TokenDb *gorm.DB // 令牌数据库 + PgsqlDb *gorm.DB // pgsql数据库 + +} + +// 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 = "wechatminiprogram" + c.log = golog.NewApi(&golog.ApiConfig{ + Db: c.config.PgsqlDb, + TableName: c.logTableName, + }) + } + + return c +} + +// ConfigApp 配置 +func (c *Client) ConfigApp(appId, appSecret string) *Client { + c.config.AppId = appId + c.config.AppSecret = appSecret + return c +} + +// 请求接口 +func (c *Client) request(url string, params map[string]interface{}, method string) (resp gorequest.Response, err error) { + + // 创建请求 + client := c.client + + // 设置请求地址 + client.SetUri(url) + + // 设置方式 + client.SetMethod(method) + + // 设置格式 + client.SetContentTypeJson() + + // 设置参数 + client.SetParams(params) + + // 发起请求 + request, err := client.Request() + if err != nil { + return gorequest.Response{}, err + } + + // 日志 + if c.logStatus == true { + go c.postgresqlLog(request) + } + + return request, err +} + +func (c *Client) GetAppId() string { + return c.config.AppId +} diff --git a/service/wechatminiprogram/get.go b/service/wechatminiprogram/get.go new file mode 100644 index 00000000..cc4b1eb6 --- /dev/null +++ b/service/wechatminiprogram/get.go @@ -0,0 +1,14 @@ +package wechatminiprogram + +func (c *Client) getAppId() string { + return c.config.AppId +} + +func (c *Client) getAppSecret() string { + return c.config.AppSecret +} + +func (c *Client) getAccessToken() string { + c.config.AccessToken = c.GetAccessToken() + return c.config.AccessToken +} diff --git a/service/wechatminiprogram/params.go b/service/wechatminiprogram/params.go index 615df229..abf5027d 100644 --- a/service/wechatminiprogram/params.go +++ b/service/wechatminiprogram/params.go @@ -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) diff --git a/service/wechatminiprogram/pgsql.go b/service/wechatminiprogram/pgsql.go index a7dcc8fb..b5e97a88 100644 --- a/service/wechatminiprogram/pgsql.go +++ b/service/wechatminiprogram/pgsql.go @@ -8,7 +8,7 @@ import ( ) // 记录日志 -func (app *App) postgresqlLog(request gorequest.Response) { +func (c *Client) postgresqlLog(request gorequest.Response) { body := golog.ApiPostgresqlLog{} body.RequestTime = golog.TimeString{Time: request.RequestTime} //【请求】时间 body.RequestUri = request.RequestUri //【请求】链接 @@ -25,5 +25,5 @@ func (app *App) postgresqlLog(request gorequest.Response) { } else { body.ResponseBody = request.ResponseBody //【返回】内容 } - app.log.Record(body) + c.log.Record(body) } diff --git a/service/wechatminiprogram/save_img.go b/service/wechatminiprogram/save_img.go index 77e62675..11391eea 100644 --- a/service/wechatminiprogram/save_img.go +++ b/service/wechatminiprogram/save_img.go @@ -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目录 diff --git a/service/wechatminiprogram/sign.go b/service/wechatminiprogram/sign.go index d511c865..9081d232 100644 --- a/service/wechatminiprogram/sign.go +++ b/service/wechatminiprogram/sign.go @@ -2,20 +2,20 @@ package wechatminiprogram import "errors" -func (app *App) pkcs7Unpaid(data []byte, blockSize int) ([]byte, error) { +func (c *Client) pkcs7Unpaid(data []byte, blockSize int) ([]byte, error) { if blockSize <= 0 { return nil, errors.New("invalid block size") } if len(data)%blockSize != 0 || len(data) == 0 { return nil, errors.New("invalid PKCS7 data") } - c := data[len(data)-1] - n := int(c) + d := data[len(data)-1] + n := int(d) if n == 0 || n > len(data) { return nil, errors.New("invalid padding on input") } for i := 0; i < n; i++ { - if data[len(data)-n+i] != c { + if data[len(data)-n+i] != d { return nil, errors.New("invalid padding on input") } } diff --git a/service/wechatminiprogram/sns.jscode2session.go b/service/wechatminiprogram/sns.jscode2session.go index 48a33952..f3a24d67 100644 --- a/service/wechatminiprogram/sns.jscode2session.go +++ b/service/wechatminiprogram/sns.jscode2session.go @@ -28,9 +28,9 @@ func NewSnsJsCode2sessionResult(result SnsJsCode2sessionResponse, body []byte, h // SnsJsCode2session 登录凭证校验 // https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html -func (app *App) SnsJsCode2session(jsCode string) *SnsJsCode2sessionResult { +func (c *Client) SnsJsCode2session(jsCode string) *SnsJsCode2sessionResult { // 请求 - request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code", app.appId, app.appSecret, jsCode), map[string]interface{}{}, http.MethodGet) + request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code", c.getAppId(), c.getAppSecret(), jsCode), map[string]interface{}{}, http.MethodGet) // 定义 var response SnsJsCode2sessionResponse err = json.Unmarshal(request.ResponseBody, &response) diff --git a/service/wechatminiprogram/user_info.go b/service/wechatminiprogram/user_info.go index 062b2aca..9fe717c3 100644 --- a/service/wechatminiprogram/user_info.go +++ b/service/wechatminiprogram/user_info.go @@ -40,7 +40,7 @@ func NewUserInfoResult(result UserInfoResponse, err error) *UserInfoResult { } // UserInfo 解密用户信息 -func (app *App) UserInfo(param UserInfo) *UserInfoResult { +func (c *Client) UserInfo(param UserInfo) *UserInfoResult { var response UserInfoResponse aesKey, err := base64.StdEncoding.DecodeString(param.SessionKey) if err != nil { @@ -60,7 +60,7 @@ func (app *App) UserInfo(param UserInfo) *UserInfoResult { } mode := cipher.NewCBCDecrypter(block, ivBytes) mode.CryptBlocks(cipherText, cipherText) - cipherText, err = app.pkcs7Unpaid(cipherText, block.BlockSize()) + cipherText, err = c.pkcs7Unpaid(cipherText, block.BlockSize()) if err != nil { return NewUserInfoResult(response, err) } @@ -68,8 +68,8 @@ func (app *App) UserInfo(param UserInfo) *UserInfoResult { if err != nil { return NewUserInfoResult(response, err) } - if response.Watermark.AppID != app.appId { - return NewUserInfoResult(response, errors.New("app id not match")) + if response.Watermark.AppID != c.getAppId() { + return NewUserInfoResult(response, errors.New("c id not match")) } return NewUserInfoResult(response, err) } diff --git a/service/wechatminiprogram/user_phone.go b/service/wechatminiprogram/user_phone.go index caec188e..cc8288e4 100644 --- a/service/wechatminiprogram/user_phone.go +++ b/service/wechatminiprogram/user_phone.go @@ -34,7 +34,7 @@ func NewUserPhoneResult(result UserPhoneResponse, err error) *UserPhoneResult { } // UserPhone 解密手机号信息 -func (app *App) UserPhone(param UserPhone) *UserPhoneResult { +func (c *Client) UserPhone(param UserPhone) *UserPhoneResult { var response UserPhoneResponse aesKey, err := base64.StdEncoding.DecodeString(param.SessionKey) if err != nil { @@ -54,7 +54,7 @@ func (app *App) UserPhone(param UserPhone) *UserPhoneResult { } mode := cipher.NewCBCDecrypter(block, ivBytes) mode.CryptBlocks(cipherText, cipherText) - cipherText, err = app.pkcs7Unpaid(cipherText, block.BlockSize()) + cipherText, err = c.pkcs7Unpaid(cipherText, block.BlockSize()) if err != nil { return NewUserPhoneResult(response, err) } @@ -62,8 +62,8 @@ func (app *App) UserPhone(param UserPhone) *UserPhoneResult { if err != nil { return NewUserPhoneResult(response, err) } - if response.Watermark.AppID != app.appId { - return NewUserPhoneResult(response, errors.New("app id not match")) + if response.Watermark.AppID != c.getAppId() { + return NewUserPhoneResult(response, errors.New("c id not match")) } return NewUserPhoneResult(response, err) } diff --git a/service/wechatminiprogram/wxa.business.getliveinfo.go b/service/wechatminiprogram/wxa.business.getliveinfo.go index bda45a7d..7fb6b9a9 100644 --- a/service/wechatminiprogram/wxa.business.getliveinfo.go +++ b/service/wechatminiprogram/wxa.business.getliveinfo.go @@ -56,12 +56,11 @@ func NewBusinessGetLiveInfoResult(result BusinessGetLiveInfoResponse, body []byt // BusinessGetLiveInfo 获取直播间列表 // 调用此接口获取直播间列表及直播间信息 // https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/liveplayer/studio-api.html -func (app *App) BusinessGetLiveInfo(notMustParams ...Params) *BusinessGetLiveInfoResult { - app.accessToken = app.GetAccessToken() +func (c *Client) BusinessGetLiveInfo(notMustParams ...Params) *BusinessGetLiveInfoResult { // 参数 - params := app.NewParamsWith(notMustParams...) + params := c.NewParamsWith(notMustParams...) // 请求 - request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=%s", app.accessToken), params, http.MethodPost) + request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=%s", c.getAccessToken()), params, http.MethodPost) // 定义 var response BusinessGetLiveInfoResponse err = json.Unmarshal(request.ResponseBody, &response) diff --git a/service/wechatminiprogram/wxa.business.getuserphonenumber.go b/service/wechatminiprogram/wxa.business.getuserphonenumber.go index 82d1fbf0..22622cfb 100644 --- a/service/wechatminiprogram/wxa.business.getuserphonenumber.go +++ b/service/wechatminiprogram/wxa.business.getuserphonenumber.go @@ -34,14 +34,13 @@ 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 { - app.accessToken = app.GetAccessToken() +func (c *Client) WxaBusinessGetUserPhoneNumber(code string) *WxaBusinessGetUserPhoneNumberResult { // 参数 param := NewParams() param.Set("code", code) - params := app.NewParamsWith(param) + params := c.NewParamsWith(param) // 请求 - request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=%s", app.accessToken), params, http.MethodPost) + request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=%s", c.getAccessToken()), params, http.MethodPost) // 定义 var response WxaBusinessGetUserPhoneNumberResponse err = json.Unmarshal(request.ResponseBody, &response) diff --git a/service/wechatminiprogram/wxa.generate_urllink.go b/service/wechatminiprogram/wxa.generate_urllink.go index c43e90a3..5d4fe280 100644 --- a/service/wechatminiprogram/wxa.generate_urllink.go +++ b/service/wechatminiprogram/wxa.generate_urllink.go @@ -26,12 +26,11 @@ func NewWxaGenerateUrlLinkResult(result WxaGenerateUrlLinkResponse, body []byte, // WxaGenerateUrlLink 获取小程序 URL Link,适用于短信、邮件、网页、微信内等拉起小程序的业务场景。通过该接口,可以选择生成到期失效和永久有效的小程序链接,有数量限制,目前仅针对国内非个人主体的小程序开放 // https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-link/urllink.generate.html -func (app *App) WxaGenerateUrlLink(notMustParams ...Params) *WxaGenerateUrlLinkResult { - app.accessToken = app.GetAccessToken() +func (c *Client) WxaGenerateUrlLink(notMustParams ...Params) *WxaGenerateUrlLinkResult { // 参数 - params := app.NewParamsWith(notMustParams...) + params := c.NewParamsWith(notMustParams...) // 请求 - request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/generate_urllink?access_token=%s", app.accessToken), params, http.MethodPost) + request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/generate_urllink?access_token=%s", c.getAccessToken()), params, http.MethodPost) // 定义 var response WxaGenerateUrlLinkResponse err = json.Unmarshal(request.ResponseBody, &response) diff --git a/service/wechatminiprogram/wxa.generatescheme.go b/service/wechatminiprogram/wxa.generatescheme.go index 237f7af8..97b3df22 100644 --- a/service/wechatminiprogram/wxa.generatescheme.go +++ b/service/wechatminiprogram/wxa.generatescheme.go @@ -26,12 +26,11 @@ func NewWxaGenerateSchemeResult(result WxaGenerateSchemeResponse, body []byte, h // WxaGenerateScheme 获取小程序 scheme 码,适用于短信、邮件、外部网页、微信内等拉起小程序的业务场景。通过该接口,可以选择生成到期失效和永久有效的小程序码,有数量限制,目前仅针对国内非个人主体的小程序开放 // https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.generate.html -func (app *App) WxaGenerateScheme(notMustParams ...Params) *WxaGenerateSchemeResult { - app.accessToken = app.GetAccessToken() +func (c *Client) WxaGenerateScheme(notMustParams ...Params) *WxaGenerateSchemeResult { // 参数 - params := app.NewParamsWith(notMustParams...) + params := c.NewParamsWith(notMustParams...) // 请求 - request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/generatescheme?access_token=%s", app.accessToken), params, http.MethodPost) + request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/generatescheme?access_token=%s", c.getAccessToken()), params, http.MethodPost) // 定义 var response WxaGenerateSchemeResponse err = json.Unmarshal(request.ResponseBody, &response) diff --git a/service/wechatminiprogram/wxa.getwxacode.go b/service/wechatminiprogram/wxa.getwxacode.go index 81361343..e804aa84 100644 --- a/service/wechatminiprogram/wxa.getwxacode.go +++ b/service/wechatminiprogram/wxa.getwxacode.go @@ -30,12 +30,11 @@ func NewWxaGetWxaCodeResult(result WxaGetWxaCodeResponse, body []byte, http gore // WxaGetWxaCode 获取小程序码,适用于需要的码数量较少的业务场景。通过该接口生成的小程序码,永久有效,有数量限制 // https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.get.html -func (app *App) WxaGetWxaCode(notMustParams ...Params) *WxaGetWxaCodeResult { - app.accessToken = app.GetAccessToken() +func (c *Client) WxaGetWxaCode(notMustParams ...Params) *WxaGetWxaCodeResult { // 参数 - params := app.NewParamsWith(notMustParams...) + params := c.NewParamsWith(notMustParams...) // 请求 - request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/getwxacode?access_token=%s", app.accessToken), params, http.MethodPost) + request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/getwxacode?access_token=%s", c.getAccessToken()), params, http.MethodPost) // 定义 var response WxaGetWxaCodeResponse err = json.Unmarshal(request.ResponseBody, &response) diff --git a/service/wechatminiprogram/wxa.getwxacodeunlimit.go b/service/wechatminiprogram/wxa.getwxacodeunlimit.go index a35efbeb..8f286ef5 100644 --- a/service/wechatminiprogram/wxa.getwxacodeunlimit.go +++ b/service/wechatminiprogram/wxa.getwxacodeunlimit.go @@ -30,12 +30,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 { - app.accessToken = app.GetAccessToken() +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.accessToken), params, http.MethodPost) + request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=%s", c.getAccessToken()), params, http.MethodPost) // 定义 var response WxaGetWxaCodeUnLimitResponse err = json.Unmarshal(request.ResponseBody, &response) diff --git a/service/wechatminiprogram/wxa.query_urllink.go b/service/wechatminiprogram/wxa.query_urllink.go index 9ac8e857..44e61fc6 100644 --- a/service/wechatminiprogram/wxa.query_urllink.go +++ b/service/wechatminiprogram/wxa.query_urllink.go @@ -44,14 +44,13 @@ func NewWxaQueryUrlLinkResult(result WxaQueryUrlLinkResponse, body []byte, http // WxaQueryUrlLink 查询小程序 url_link 配置,及长期有效 quota // https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-link/urllink.query.html -func (app *App) WxaQueryUrlLink(urlLink string) *WxaQueryUrlLinkResult { - app.accessToken = app.GetAccessToken() +func (c *Client) WxaQueryUrlLink(urlLink string) *WxaQueryUrlLinkResult { // 参数 param := NewParams() param.Set("url_link", urlLink) - params := app.NewParamsWith(param) + params := c.NewParamsWith(param) // 请求 - request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/query_urllink?access_token=%s", app.accessToken), params, http.MethodPost) + request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/query_urllink?access_token=%s", c.getAccessToken()), params, http.MethodPost) // 定义 var response WxaQueryUrlLinkResponse err = json.Unmarshal(request.ResponseBody, &response) diff --git a/service/wechatminiprogram/wxa.queryscheme.go b/service/wechatminiprogram/wxa.queryscheme.go index 2cda3872..68560e29 100644 --- a/service/wechatminiprogram/wxa.queryscheme.go +++ b/service/wechatminiprogram/wxa.queryscheme.go @@ -37,12 +37,11 @@ func NewWxaQuerySchemeResult(result WxaQuerySchemeResponse, body []byte, http go // WxaQueryScheme 查询小程序 scheme 码,及长期有效 quota // https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.query.html -func (app *App) WxaQueryScheme(notMustParams ...Params) *WxaQuerySchemeResult { - app.accessToken = app.GetAccessToken() +func (c *Client) WxaQueryScheme(notMustParams ...Params) *WxaQuerySchemeResult { // 参数 - params := app.NewParamsWith(notMustParams...) + params := c.NewParamsWith(notMustParams...) // 请求 - request, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/queryscheme?access_token=%s", app.accessToken), params, http.MethodPost) + request, err := c.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/queryscheme?access_token=%s", c.getAccessToken()), params, http.MethodPost) // 定义 var response WxaQuerySchemeResponse err = json.Unmarshal(request.ResponseBody, &response) diff --git a/service/wechatminiprogram/wxaapi.feedback.list.go b/service/wechatminiprogram/wxaapi.feedback.list.go index ec469605..a385422c 100644 --- a/service/wechatminiprogram/wxaapi.feedback.list.go +++ b/service/wechatminiprogram/wxaapi.feedback.list.go @@ -36,13 +36,12 @@ func NewWxaApiFeedbackListResult(result WxaApiFeedbackListResponse, body []byte, // WxaApiFeedbackList 获取用户反馈列表 // https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/operation/operation.getFeedback.html -func (app *App) WxaApiFeedbackList(notMustParams ...Params) *WxaApiFeedbackListResult { - app.accessToken = app.GetAccessToken() +func (c *Client) WxaApiFeedbackList(notMustParams ...Params) *WxaApiFeedbackListResult { // 参数 - params := app.NewParamsWith(notMustParams...) - params.Set("access_token", app.accessToken) + params := c.NewParamsWith(notMustParams...) + params.Set("access_token", c.getAccessToken()) // 请求 - request, err := app.request("https://api.weixin.qq.com/wxaapi/feedback/list", params, http.MethodGet) + request, err := c.request("https://api.weixin.qq.com/wxaapi/feedback/list", params, http.MethodGet) // 定义 var response WxaApiFeedbackListResponse err = json.Unmarshal(request.ResponseBody, &response)