- update request

master v1.0.2
李光春 2 years ago
parent 966110f0d2
commit 65e3b8aed4

@ -1,6 +1,7 @@
package wechatminiprogram
import (
"context"
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
@ -25,9 +26,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 (c *Client) GetCallBackIp() *GetCallBackIpResult {
func (c *Client) GetCallBackIp(ctx context.Context) *GetCallBackIpResult {
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/cgi-bin/getcallbackip?access_token=%s", c.getAccessToken()), map[string]interface{}{}, http.MethodGet)
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/cgi-bin/getcallbackip?access_token=%s", c.getAccessToken(ctx)), map[string]interface{}{}, http.MethodGet)
// 定义
var response GetCallBackIpResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package wechatminiprogram
import (
"context"
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
@ -25,11 +26,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 (c *Client) SubscribeMessageSend(notMustParams ...gorequest.Params) *SubscribeMessageSendResult {
func (c *Client) SubscribeMessageSend(ctx context.Context, notMustParams ...gorequest.Params) *SubscribeMessageSendResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/cgi-bin/message/subscribe/send?access_token=%s", c.getAccessToken()), params, http.MethodPost)
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/cgi-bin/message/subscribe/send?access_token=%s", c.getAccessToken(ctx)), params, http.MethodPost)
// 定义
var response SubscribeMessageSendResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package wechatminiprogram
import (
"context"
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
@ -28,9 +29,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 (c *Client) CgiBinToken() *CgiBinTokenResult {
func (c *Client) CgiBinToken(ctx context.Context) *CgiBinTokenResult {
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", c.getAppId(), c.getAppSecret()), map[string]interface{}{}, http.MethodGet)
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/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)

@ -6,14 +6,14 @@ import (
"time"
)
func (c *Client) GetAccessTokenMonitor() (string, error) {
func (c *Client) GetAccessTokenMonitor(ctx context.Context) (string, error) {
if c.config.RedisClient.Db == nil {
return "", errors.New("驱动没有初始化")
}
result := c.GetCallBackIp()
result := c.GetCallBackIp(ctx)
if len(result.Result.IpList) <= 0 {
token := c.CgiBinToken()
c.config.RedisClient.Db.Set(context.Background(), c.getAccessTokenCacheKeyName(), token.Result.AccessToken, time.Second*7000)
token := c.CgiBinToken(ctx)
c.config.RedisClient.Set(ctx, c.getAccessTokenCacheKeyName(), token.Result.AccessToken, time.Second*7000)
return token.Result.AccessToken, nil
}
return c.config.AccessToken, nil

@ -1,17 +1,18 @@
package wechatminiprogram
import (
"context"
"fmt"
"time"
)
func (c *Client) GetAccessToken() string {
func (c *Client) GetAccessToken(ctx context.Context) string {
if c.config.RedisClient.Db == nil {
return c.config.AccessToken
}
newCache := c.config.RedisClient.NewSimpleStringCache(c.config.RedisClient.NewStringOperation(), time.Second*7000)
newCache.DBGetter = func() string {
token := c.CgiBinToken()
token := c.CgiBinToken(ctx)
return token.Result.AccessToken
}
return newCache.GetCache(c.getAccessTokenCacheKeyName())

@ -1,6 +1,7 @@
package wechatminiprogram
import (
"context"
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
@ -27,11 +28,11 @@ func newCgiBinWxaAppCreateWxaQrCodeResult(result CgiBinWxaAppCreateWxaQrCodeResp
// CgiBinWxaAppCreateWxaQrCode 获取小程序二维码,适用于需要的码数量较少的业务场景。通过该接口生成的小程序码,永久有效,有数量限制
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.createQRCode.html
func (c *Client) CgiBinWxaAppCreateWxaQrCode(notMustParams ...gorequest.Params) *CgiBinWxaAppCreateWxaQrCodeResult {
func (c *Client) CgiBinWxaAppCreateWxaQrCode(ctx context.Context, notMustParams ...gorequest.Params) *CgiBinWxaAppCreateWxaQrCodeResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/cgi-bin/wxaapp/createwxaqrcode?access_token=%s", c.getAccessToken()), params, http.MethodPost)
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/cgi-bin/wxaapp/createwxaqrcode?access_token=%s", c.getAccessToken(ctx)), params, http.MethodPost)
// 定义
var response CgiBinWxaAppCreateWxaQrCodeResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -8,4 +8,4 @@ const (
logTable = "wechatminiprogram"
)
const Version = "1.0.1"
const Version = "1.0.2"

@ -1,5 +1,7 @@
package wechatminiprogram
import "context"
func (c *Client) getAppId() string {
return c.config.AppId
}
@ -8,8 +10,8 @@ func (c *Client) getAppSecret() string {
return c.config.AppSecret
}
func (c *Client) getAccessToken() string {
c.config.AccessToken = c.GetAccessToken()
func (c *Client) getAccessToken(ctx context.Context) string {
c.config.AccessToken = c.GetAccessToken(ctx)
return c.config.AccessToken
}

@ -3,8 +3,8 @@ module go.dtapp.net/wechatminiprogram
go 1.19
require (
go.dtapp.net/dorm v1.0.14
go.dtapp.net/golog v1.0.21
go.dtapp.net/dorm v1.0.17
go.dtapp.net/golog v1.0.22
go.dtapp.net/gorequest v1.0.24
go.dtapp.net/gostorage v1.0.11
gorm.io/gorm v1.23.8
@ -12,7 +12,7 @@ require (
require (
github.com/aliyun/aliyun-oss-go-sdk v2.2.4+incompatible // indirect
github.com/aws/aws-sdk-go v1.44.73 // indirect
github.com/aws/aws-sdk-go v1.44.75 // indirect
github.com/baidubce/bce-sdk-go v0.9.132 // indirect
github.com/basgys/goxml2json v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
@ -84,14 +84,14 @@ require (
go.dtapp.net/gotime v1.0.5 // indirect
go.dtapp.net/goxml v1.0.1 // indirect
go.mongodb.org/mongo-driver v1.10.1 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.22.0 // indirect
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced // indirect
golang.org/x/net v0.0.0-20220811182439-13a9a731de15 // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect
google.golang.org/protobuf v1.28.1 // indirect

@ -33,8 +33,8 @@ github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQ
github.com/aws/aws-sdk-go v1.25.3/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.42.27/go.mod h1:OGr6lGMAKGlG9CVrYnWYDKIyb829c6EVBRjxqjmPepc=
github.com/aws/aws-sdk-go v1.44.73 h1:dfvXVwi4A5/GxsmtsWI6ryjSIqM9SG0DKyGrB7q0NV8=
github.com/aws/aws-sdk-go v1.44.73/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
github.com/aws/aws-sdk-go v1.44.75 h1:mSJZvyqpU1YlXGi0Sv78im2lg1GqYuIiz3qXbis8j1w=
github.com/aws/aws-sdk-go v1.44.75/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/baidubce/bce-sdk-go v0.9.132 h1:UNJvRcvHKDu/UKpUUvJfPwbKmB6K1nvIWHHqHQehNKQ=
github.com/baidubce/bce-sdk-go v0.9.132/go.mod h1:zbYJMQwE4IZuyrJiFO8tO8NbtYiKTFTbwh4eIsqjVdg=
@ -546,14 +546,14 @@ github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
go.dtapp.net/dorm v1.0.14 h1:HDsaMwKGlKFKt59Y3hPI9aVnSjfXOyjoHw2uoXErKEo=
go.dtapp.net/dorm v1.0.14/go.mod h1:bHG7BmgeLaAlc56myYF63lwZAIuMeWRAqHBb/L84dLM=
go.dtapp.net/dorm v1.0.17 h1:3VQKUl05CDxFg3T1c/M8wYf2I+H+oVGBDh4NCV30nn0=
go.dtapp.net/dorm v1.0.17/go.mod h1:bHG7BmgeLaAlc56myYF63lwZAIuMeWRAqHBb/L84dLM=
go.dtapp.net/goip v1.0.24 h1:62k3xt9I/YLUwA5tLp7YC8XPskkswc4RJrvxRRxjwIY=
go.dtapp.net/goip v1.0.24/go.mod h1:tps0yoq5kSykLGDb01vuai47hzAQ6nYUPFWLdlQA2Oo=
go.dtapp.net/gojson v1.0.1 h1:MHeSGlq1KxzL7rCkm18fhwW4GNORHohdDMmxY5PupKY=
go.dtapp.net/gojson v1.0.1/go.mod h1:TkkpTNxHBKxul0e7gC5MrL1K4ICFB9mQ7wHzjBah3/k=
go.dtapp.net/golog v1.0.21 h1:pSGmDz3SJTH7M/NvVLZb+YJd8uNl5g18aORibuaY2JU=
go.dtapp.net/golog v1.0.21/go.mod h1:Wxm2Kh77JN5zFDZ72el9E9c/YkoJnOvHVusB7SqvoC8=
go.dtapp.net/golog v1.0.22 h1:sOJr5f/iLk/6irT/RuwTQSTwvL2DR8SIhzMsKdHo0Ic=
go.dtapp.net/golog v1.0.22/go.mod h1:sbn2WQXmlukcZ4T3Kz9iWOSznL8H3RCkD+1nicZHMfI=
go.dtapp.net/gorandom v1.0.1 h1:IWfMClh1ECPvyUjlqD7MwLq4mZdUusD1qAwAdsvEJBs=
go.dtapp.net/gorandom v1.0.1/go.mod h1:ZPdgalKpvFV/ATQqR0k4ns/F/IpITAZpx6WkWirr5Y8=
go.dtapp.net/gorequest v1.0.24 h1:N2RJOpCXPWbsjfQ8iYJI1EYC2se3I4QhK1l94DSJsuE=
@ -578,8 +578,8 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
@ -652,8 +652,8 @@ golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced h1:3dYNDff0VT5xj+mbj2XucFst9WKk6PdGOrb9n+SbIvw=
golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.0.0-20220811182439-13a9a731de15 h1:cik0bxZUSJVDyaHf1hZPSDsU8SZHGQZQMeueXCE7yBQ=
golang.org/x/net v0.0.0-20220811182439-13a9a731de15/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@ -701,8 +701,8 @@ golang.org/x/sys v0.0.0-20211020174200-9d6173849985/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 h1:v1W7bwXHsnLLloWYTVEdvGvA7BHMeBYsPcF0GLDxIRs=
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=

@ -1,9 +1,12 @@
package wechatminiprogram
import "go.dtapp.net/gorequest"
import (
"context"
"go.dtapp.net/gorequest"
)
// 请求接口
func (c *Client) request(url string, params map[string]interface{}, method string) (gorequest.Response, error) {
func (c *Client) request(ctx context.Context, url string, params map[string]interface{}, method string) (gorequest.Response, error) {
// 创建请求
client := c.client
@ -28,7 +31,7 @@ func (c *Client) request(url string, params map[string]interface{}, method strin
// 日志
if c.config.PgsqlDb != nil {
go c.log.GormMiddleware(request, Version)
go c.log.GormMiddleware(ctx, request, Version)
}
if c.config.MongoDb != nil {
go c.log.MongoMiddleware(request)

@ -1,6 +1,7 @@
package wechatminiprogram
import (
"context"
"go.dtapp.net/gorequest"
"log"
"os"
@ -11,7 +12,7 @@ type SaveImgResponse struct {
Name string
}
func (c *Client) SaveImg(resp gorequest.Response, dir, saveName string) SaveImgResponse {
func (c *Client) SaveImg(ctx context.Context, resp gorequest.Response, dir, saveName string) SaveImgResponse {
// 返回是二进制图片或者json错误
if resp.ResponseHeader.Get("Content-Type") == "image/jpeg" || resp.ResponseHeader.Get("Content-Type") == "image/png" {
// 保存在output目录

@ -1,6 +1,7 @@
package wechatminiprogram
import (
"context"
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
@ -28,9 +29,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 (c *Client) SnsJsCode2session(jsCode string) *SnsJsCode2sessionResult {
func (c *Client) SnsJsCode2session(ctx context.Context, jsCode string) *SnsJsCode2sessionResult {
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code", c.getAppId(), c.getAppSecret(), jsCode), map[string]interface{}{}, http.MethodGet)
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/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)

@ -1,6 +1,7 @@
package wechatminiprogram
import (
"context"
"crypto/aes"
"crypto/cipher"
"encoding/base64"
@ -40,7 +41,7 @@ func newUserInfoResult(result UserInfoResponse, err error) *UserInfoResult {
}
// UserInfo 解密用户信息
func (c *Client) UserInfo(param UserInfo) *UserInfoResult {
func (c *Client) UserInfo(ctx context.Context, param UserInfo) *UserInfoResult {
var response UserInfoResponse
aesKey, err := base64.StdEncoding.DecodeString(param.SessionKey)
if err != nil {

@ -1,6 +1,7 @@
package wechatminiprogram
import (
"context"
"crypto/aes"
"crypto/cipher"
"encoding/base64"
@ -34,7 +35,7 @@ func newUserPhoneResult(result UserPhoneResponse, err error) *UserPhoneResult {
}
// UserPhone 解密手机号信息
func (c *Client) UserPhone(param UserPhone) *UserPhoneResult {
func (c *Client) UserPhone(ctx context.Context, param UserPhone) *UserPhoneResult {
var response UserPhoneResponse
aesKey, err := base64.StdEncoding.DecodeString(param.SessionKey)
if err != nil {

@ -1,6 +1,7 @@
package wechatminiprogram
import (
"context"
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
@ -56,11 +57,11 @@ func newBusinessGetLiveInfoResult(result BusinessGetLiveInfoResponse, body []byt
// BusinessGetLiveInfo 获取直播间列表
// 调用此接口获取直播间列表及直播间信息
// https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/liveplayer/studio-api.html
func (c *Client) BusinessGetLiveInfo(notMustParams ...gorequest.Params) *BusinessGetLiveInfoResult {
func (c *Client) BusinessGetLiveInfo(ctx context.Context, notMustParams ...gorequest.Params) *BusinessGetLiveInfoResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/wxa/business/getliveinfo?access_token=%s", c.getAccessToken()), params, http.MethodPost)
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/wxa/business/getliveinfo?access_token=%s", c.getAccessToken(ctx)), params, http.MethodPost)
// 定义
var response BusinessGetLiveInfoResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package wechatminiprogram
import (
"context"
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
@ -34,13 +35,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 (c *Client) WxaBusinessGetUserPhoneNumber(code string) *WxaBusinessGetUserPhoneNumberResult {
func (c *Client) WxaBusinessGetUserPhoneNumber(ctx context.Context, code string) *WxaBusinessGetUserPhoneNumberResult {
// 参数
param := gorequest.NewParams()
param.Set("code", code)
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/wxa/business/getuserphonenumber?access_token=%s", c.getAccessToken()), params, http.MethodPost)
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/wxa/business/getuserphonenumber?access_token=%s", c.getAccessToken(ctx)), params, http.MethodPost)
// 定义
var response WxaBusinessGetUserPhoneNumberResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package wechatminiprogram
import (
"context"
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
@ -26,11 +27,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 (c *Client) WxaGenerateUrlLink(notMustParams ...gorequest.Params) *WxaGenerateUrlLinkResult {
func (c *Client) WxaGenerateUrlLink(ctx context.Context, notMustParams ...gorequest.Params) *WxaGenerateUrlLinkResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/wxa/generate_urllink?access_token=%s", c.getAccessToken()), params, http.MethodPost)
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/wxa/generate_urllink?access_token=%s", c.getAccessToken(ctx)), params, http.MethodPost)
// 定义
var response WxaGenerateUrlLinkResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package wechatminiprogram
import (
"context"
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
@ -26,11 +27,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 (c *Client) WxaGenerateScheme(notMustParams ...gorequest.Params) *WxaGenerateSchemeResult {
func (c *Client) WxaGenerateScheme(ctx context.Context, notMustParams ...gorequest.Params) *WxaGenerateSchemeResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/wxa/generatescheme?access_token=%s", c.getAccessToken()), params, http.MethodPost)
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/wxa/generatescheme?access_token=%s", c.getAccessToken(ctx)), params, http.MethodPost)
// 定义
var response WxaGenerateSchemeResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -2,6 +2,7 @@ package wechatminiprogram
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
@ -30,11 +31,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 (c *Client) WxaGetWxaCode(notMustParams ...gorequest.Params) *WxaGetWxaCodeResult {
func (c *Client) WxaGetWxaCode(ctx context.Context, notMustParams ...gorequest.Params) *WxaGetWxaCodeResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/wxa/getwxacode?access_token=%s", c.getAccessToken()), params, http.MethodPost)
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/wxa/getwxacode?access_token=%s", c.getAccessToken(ctx)), params, http.MethodPost)
// 定义
var response WxaGetWxaCodeResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -2,6 +2,7 @@ package wechatminiprogram
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
@ -30,11 +31,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 (c *Client) WxaGetWxaCodeUnLimit(notMustParams ...gorequest.Params) *WxaGetWxaCodeUnLimitResult {
func (c *Client) WxaGetWxaCodeUnLimit(ctx context.Context, notMustParams ...gorequest.Params) *WxaGetWxaCodeUnLimitResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/wxa/getwxacodeunlimit?access_token=%s", c.getAccessToken()), params, http.MethodPost)
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/wxa/getwxacodeunlimit?access_token=%s", c.getAccessToken(ctx)), params, http.MethodPost)
// 定义
var response WxaGetWxaCodeUnLimitResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package wechatminiprogram
import (
"context"
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
@ -44,13 +45,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 (c *Client) WxaQueryUrlLink(urlLink string) *WxaQueryUrlLinkResult {
func (c *Client) WxaQueryUrlLink(ctx context.Context, urlLink string) *WxaQueryUrlLinkResult {
// 参数
param := gorequest.NewParams()
param.Set("url_link", urlLink)
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/wxa/query_urllink?access_token=%s", c.getAccessToken()), params, http.MethodPost)
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/wxa/query_urllink?access_token=%s", c.getAccessToken(ctx)), params, http.MethodPost)
// 定义
var response WxaQueryUrlLinkResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package wechatminiprogram
import (
"context"
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
@ -37,11 +38,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 (c *Client) WxaQueryScheme(notMustParams ...gorequest.Params) *WxaQuerySchemeResult {
func (c *Client) WxaQueryScheme(ctx context.Context, notMustParams ...gorequest.Params) *WxaQuerySchemeResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(fmt.Sprintf(apiUrl+"/wxa/queryscheme?access_token=%s", c.getAccessToken()), params, http.MethodPost)
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/wxa/queryscheme?access_token=%s", c.getAccessToken(ctx)), params, http.MethodPost)
// 定义
var response WxaQuerySchemeResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package wechatminiprogram
import (
"context"
"encoding/json"
"go.dtapp.net/gorequest"
"net/http"
@ -36,12 +37,12 @@ func newWxaApiFeedbackListResult(result WxaApiFeedbackListResponse, body []byte,
// WxaApiFeedbackList 获取用户反馈列表
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/operation/operation.getFeedback.html
func (c *Client) WxaApiFeedbackList(notMustParams ...gorequest.Params) *WxaApiFeedbackListResult {
func (c *Client) WxaApiFeedbackList(ctx context.Context, notMustParams ...gorequest.Params) *WxaApiFeedbackListResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
params.Set("access_token", c.getAccessToken())
params.Set("access_token", c.getAccessToken(ctx))
// 请求
request, err := c.request(apiUrl+"/wxaapi/feedback/list", params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/wxaapi/feedback/list", params, http.MethodGet)
// 定义
var response WxaApiFeedbackListResponse
err = json.Unmarshal(request.ResponseBody, &response)

Loading…
Cancel
Save