add wechat auth code

This commit is contained in:
lwl0608 2024-02-20 23:13:17 +08:00
parent 201e1f4c5c
commit 98ea808079
2 changed files with 20 additions and 13 deletions

View File

@ -137,9 +137,10 @@ type QueryWechatData struct {
// h5直接解锁微信
type H5DirectUnlockWechatReq struct {
base.BaseRequest
Uid int64 `json:"uid"` // 主播id
PayType string `json:"pay_type"` // 支付类型
InviterMid int64
Uid int64 `json:"uid"` // 主播id
PayType string `json:"pay_type"` // 支付类型
WechatAuthCode string `json:"wechat_auth_code"` // 微信auth_code
InviterMid int64
}
type H5DirectUnlockWechatData struct {

View File

@ -215,6 +215,11 @@ func (v *Vas) CreateOrder(ctx *gin.Context, req *vasproto.CreateOrderReq) (data
}
req.Oid3 = wxpayCli.AppId
case vasproto.PayTypeWxpayJsapi:
if len(req.WechatAuthCode) <= 0 {
err = errors.New("invalid WechatAuthCode")
return
}
wxpayCli := wxpaycli.GetDefaultWxpayClient()
var openid string
openid, err = wxpayCli.GetOpenIdByAuthCode(ctx, req.WechatAuthCode)
@ -1527,16 +1532,17 @@ func (v *Vas) H5DirectUnlockWechat(ctx *gin.Context, req *vasproto.H5DirectUnloc
// 创建订单
cData, err := v.CreateOrder(ctx, &vasproto.CreateOrderReq{
BaseRequest: req.BaseRequest,
Ip: ctx.ClientIP(),
ProductId: dbstruct.ProductIdH5ContactWechat,
PayType: req.PayType,
From: dbstruct.VasCoinOrderFromH5,
CustomCoins: uVas.GetH5WechatCoinPrice(),
CalcPrice: uVas.GetH5WechatCoinPrice() * 10,
Uid: uid,
Oid1: fmt.Sprintf("%d", uid),
ReturnUrl: "https://tiefen.fun/purchased",
BaseRequest: req.BaseRequest,
Ip: ctx.ClientIP(),
ProductId: dbstruct.ProductIdH5ContactWechat,
PayType: req.PayType,
From: dbstruct.VasCoinOrderFromH5,
CustomCoins: uVas.GetH5WechatCoinPrice(),
WechatAuthCode: req.WechatAuthCode,
CalcPrice: uVas.GetH5WechatCoinPrice() * 10,
Uid: uid,
Oid1: fmt.Sprintf("%d", uid),
ReturnUrl: "https://tiefen.fun/purchased",
})
if err != nil {
logger.Error("CreateOrder fail, req: %v, err: %v", util.ToJson(req), err)