From c6dd7830c94568fb4554a509d3c5022410a87617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Mon, 3 Jan 2022 10:50:58 +0800 Subject: [PATCH] update wechatminiprogram --- .../cgi-bin.wxaapp.createwxaqrcode.go | 40 +++++++++++++++++++ service/wechatminiprogram/wxa.getwxacode.go | 37 +++++++++++++++++ .../wxa.getwxacodeunlimit.go | 37 +++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 service/wechatminiprogram/cgi-bin.wxaapp.createwxaqrcode.go create mode 100644 service/wechatminiprogram/wxa.getwxacode.go create mode 100644 service/wechatminiprogram/wxa.getwxacodeunlimit.go diff --git a/service/wechatminiprogram/cgi-bin.wxaapp.createwxaqrcode.go b/service/wechatminiprogram/cgi-bin.wxaapp.createwxaqrcode.go new file mode 100644 index 00000000..e48becba --- /dev/null +++ b/service/wechatminiprogram/cgi-bin.wxaapp.createwxaqrcode.go @@ -0,0 +1,40 @@ +package wechatminiprogram + +import ( + "encoding/json" + "fmt" + "net/http" +) + +type CgiBinWxaAppCreateWxaQrCodeResponse struct { + Errcode int `json:"errcode"` + Errmsg string `json:"errmsg"` + ContentType string `json:"contentType"` + Buffer interface{} `json:"buffer"` +} + +type CgiBinWxaAppCreateWxaQrCodeResult struct { + Result CgiBinWxaAppCreateWxaQrCodeResponse // 结果 + Body []byte // 内容 + Err error // 错误 +} + +func NewCgiBinWxaAppCreateWxaQrCodeResult(result CgiBinWxaAppCreateWxaQrCodeResponse, body []byte, err error) *CgiBinWxaAppCreateWxaQrCodeResult { + return &CgiBinWxaAppCreateWxaQrCodeResult{Result: result, Body: body, Err: err} +} + +// CgiBinWxaAppCreateWxaQrCode 获取小程序二维码,适用于需要的码数量较少的业务场景。通过该接口生成的小程序码,永久有效,有数量限制 +// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.createQRCode.html +func (app *App) CgiBinWxaAppCreateWxaQrCode(path string, width int) *CgiBinWxaAppCreateWxaQrCodeResult { + // 参数 + param := NewParams() + param.Set("path", path) + param.Set("width", width) + params := app.NewParamsWith(param) + // 请求 + body, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=%s", app.AccessToken), params, http.MethodPost) + // 定义 + var response CgiBinWxaAppCreateWxaQrCodeResponse + err = json.Unmarshal(body, &response) + return NewCgiBinWxaAppCreateWxaQrCodeResult(response, body, err) +} diff --git a/service/wechatminiprogram/wxa.getwxacode.go b/service/wechatminiprogram/wxa.getwxacode.go new file mode 100644 index 00000000..c98a8569 --- /dev/null +++ b/service/wechatminiprogram/wxa.getwxacode.go @@ -0,0 +1,37 @@ +package wechatminiprogram + +import ( + "encoding/json" + "fmt" + "net/http" +) + +type WxaGetWxaCodeResponse struct { + Errcode int `json:"errcode"` + Errmsg string `json:"errmsg"` + ContentType string `json:"contentType"` + Buffer interface{} `json:"buffer"` +} + +type WxaGetWxaCodeResult struct { + Result WxaGetWxaCodeResponse // 结果 + Body []byte // 内容 + Err error // 错误 +} + +func NewWxaGetWxaCodeResult(result WxaGetWxaCodeResponse, body []byte, err error) *WxaGetWxaCodeResult { + return &WxaGetWxaCodeResult{Result: result, Body: body, Err: err} +} + +// WxaGetWxaCode 获取小程序码,适用于需要的码数量较少的业务场景。通过该接口生成的小程序码,永久有效,有数量限制 +// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.get.html +func (app *App) WxaGetWxaCode(notMustParams ...Params) *WxaGetWxaCodeResult { + // 参数 + params := app.NewParamsWith(notMustParams...) + // 请求 + body, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/getwxacode?access_token=%s", app.AccessToken), params, http.MethodPost) + // 定义 + var response WxaGetWxaCodeResponse + err = json.Unmarshal(body, &response) + return NewWxaGetWxaCodeResult(response, body, err) +} diff --git a/service/wechatminiprogram/wxa.getwxacodeunlimit.go b/service/wechatminiprogram/wxa.getwxacodeunlimit.go new file mode 100644 index 00000000..8d78364d --- /dev/null +++ b/service/wechatminiprogram/wxa.getwxacodeunlimit.go @@ -0,0 +1,37 @@ +package wechatminiprogram + +import ( + "encoding/json" + "fmt" + "net/http" +) + +type WxaGetWxaCodeUnLimitResponse struct { + Errcode int `json:"errcode"` + Errmsg string `json:"errmsg"` + ContentType string `json:"contentType"` + Buffer interface{} `json:"buffer"` +} + +type WxaGetWxaCodeUnLimitResult struct { + Result WxaGetWxaCodeUnLimitResponse // 结果 + Body []byte // 内容 + Err error // 错误 +} + +func NewWxaGetWxaCodeUnLimitResult(result WxaGetWxaCodeUnLimitResponse, body []byte, err error) *WxaGetWxaCodeUnLimitResult { + return &WxaGetWxaCodeUnLimitResult{Result: result, Body: body, Err: err} +} + +// WxaGetWxaCodeUnLimit 获取小程序码,适用于需要的码数量极多的业务场景。通过该接口生成的小程序码,永久有效,数量暂无限制 +// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.getUnlimited.html +func (app *App) WxaGetWxaCodeUnLimit(notMustParams ...Params) *WxaGetWxaCodeUnLimitResult { + // 参数 + params := app.NewParamsWith(notMustParams...) + // 请求 + body, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=%s", app.AccessToken), params, http.MethodPost) + // 定义 + var response WxaGetWxaCodeUnLimitResponse + err = json.Unmarshal(body, &response) + return NewWxaGetWxaCodeUnLimitResult(response, body, err) +}