mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
添加小程序获取红包封面接口 (#760)
* ADD 获取红包封面 * Update redpacketcover.go * MOD 修改为统一错误方法 * Update go.yml
This commit is contained in:
2
.github/workflows/go.yml
vendored
2
.github/workflows/go.yml
vendored
@@ -10,7 +10,7 @@ jobs:
|
|||||||
golangci:
|
golangci:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
go-version: [ '1.16','1.17','1.18','1.19','1.20','1.21.4' ]
|
go-version: [ '1.16','1.17','1.18','1.19','1.20','1.21.4' ]
|
||||||
name: golangci-lint
|
name: golangci-lint
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/silenceper/wechat/v2/miniprogram/order"
|
"github.com/silenceper/wechat/v2/miniprogram/order"
|
||||||
"github.com/silenceper/wechat/v2/miniprogram/privacy"
|
"github.com/silenceper/wechat/v2/miniprogram/privacy"
|
||||||
"github.com/silenceper/wechat/v2/miniprogram/qrcode"
|
"github.com/silenceper/wechat/v2/miniprogram/qrcode"
|
||||||
|
"github.com/silenceper/wechat/v2/miniprogram/redpacketcover"
|
||||||
"github.com/silenceper/wechat/v2/miniprogram/riskcontrol"
|
"github.com/silenceper/wechat/v2/miniprogram/riskcontrol"
|
||||||
"github.com/silenceper/wechat/v2/miniprogram/security"
|
"github.com/silenceper/wechat/v2/miniprogram/security"
|
||||||
"github.com/silenceper/wechat/v2/miniprogram/shortlink"
|
"github.com/silenceper/wechat/v2/miniprogram/shortlink"
|
||||||
@@ -155,3 +156,8 @@ func (miniProgram *MiniProgram) GetShipping() *order.Shipping {
|
|||||||
func (miniProgram *MiniProgram) GetMiniDrama() *minidrama.MiniDrama {
|
func (miniProgram *MiniProgram) GetMiniDrama() *minidrama.MiniDrama {
|
||||||
return minidrama.NewMiniDrama(miniProgram.ctx)
|
return minidrama.NewMiniDrama(miniProgram.ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRedPacketCover 小程序微信红包封面 API
|
||||||
|
func (miniProgram *MiniProgram) GetRedPacketCover() *redpacketcover.RedPacketCover {
|
||||||
|
return redpacketcover.NewRedPacketCover(miniProgram.ctx)
|
||||||
|
}
|
||||||
|
|||||||
59
miniprogram/redpacketcover/redpacketcover.go
Normal file
59
miniprogram/redpacketcover/redpacketcover.go
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package redpacketcover
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/silenceper/wechat/v2/miniprogram/context"
|
||||||
|
"github.com/silenceper/wechat/v2/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
getRedPacketCoverURL = "https://api.weixin.qq.com/redpacketcover/wxapp/cover_url/get_by_token?access_token=%s"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RedPacketCover struct
|
||||||
|
type RedPacketCover struct {
|
||||||
|
*context.Context
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewRedPacketCover 实例
|
||||||
|
func NewRedPacketCover(context *context.Context) *RedPacketCover {
|
||||||
|
redPacketCover := new(RedPacketCover)
|
||||||
|
redPacketCover.Context = context
|
||||||
|
return redPacketCover
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRedPacketCoverRequest 获取微信红包封面参数
|
||||||
|
type GetRedPacketCoverRequest struct {
|
||||||
|
// openid 可领取用户的openid
|
||||||
|
OpenID string `json:"openid"`
|
||||||
|
// ctoken 在红包封面平台获取发放ctoken(需要指定可以发放的appid)
|
||||||
|
CToken string `json:"ctoken"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRedPacketCoverResp 获取微信红包封面
|
||||||
|
type GetRedPacketCoverResp struct {
|
||||||
|
util.CommonError
|
||||||
|
Data struct {
|
||||||
|
URL string `json:"url"`
|
||||||
|
} `json:"data"` // 唯一请求标识
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRedPacketCoverURL 获得指定用户可以领取的红包封面链接。获取参数ctoken参考微信红包封面开放平台
|
||||||
|
// 文档地址: https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/red-packet-cover/getRedPacketCoverUrl.html
|
||||||
|
func (cover *RedPacketCover) GetRedPacketCoverURL(coderParams GetRedPacketCoverRequest) (res GetRedPacketCoverResp, err error) {
|
||||||
|
accessToken, err := cover.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
uri := fmt.Sprintf(getRedPacketCoverURL, accessToken)
|
||||||
|
response, err := util.PostJSON(uri, coderParams)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用通用方法返回错误
|
||||||
|
err = util.DecodeWithError(response, &res, "GetRedPacketCoverURL")
|
||||||
|
return
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user