fix yeepay callback

This commit is contained in:
lwl0608 2024-05-27 19:23:05 +08:00
parent 72d858539f
commit 49561af1de
6 changed files with 60 additions and 40 deletions

View File

@ -19,7 +19,7 @@ func AlipayCallback(ctx *gin.Context) {
} }
if bm.GetString("trade_status") == "TRADE_SUCCESS" { if bm.GetString("trade_status") == "TRADE_SUCCESS" {
service.DefaultService.PayCallback(ctx, &vasproto.PayCallbackParamIn{ _ = service.DefaultService.PayCallback(ctx, &vasproto.PayCallbackParamIn{
OrderId: bm.GetString("out_trade_no"), OrderId: bm.GetString("out_trade_no"),
OutOrderId: bm.GetString("trade_no"), OutOrderId: bm.GetString("trade_no"),
CallbackPayType: vasproto.CallBackPayTypeAlipay, CallbackPayType: vasproto.CallBackPayTypeAlipay,

View File

@ -23,7 +23,7 @@ func WxpayCallback(ctx *gin.Context) {
logger.Info("WxpayCallback, notify: %v", util.ToJson(notify)) logger.Info("WxpayCallback, notify: %v", util.ToJson(notify))
if notify.TradeState == wxpay.TradeStateSuccess { if notify.TradeState == wxpay.TradeStateSuccess {
service.DefaultService.PayCallback(ctx, &vasproto.PayCallbackParamIn{ _ = service.DefaultService.PayCallback(ctx, &vasproto.PayCallbackParamIn{
OrderId: notify.OutTradeNo, OrderId: notify.OutTradeNo,
OutOrderId: notify.TransactionId, OutOrderId: notify.TransactionId,
CallbackPayType: vasproto.CallBackPayTypeWxpay, CallbackPayType: vasproto.CallBackPayTypeWxpay,
@ -34,7 +34,7 @@ func WxpayCallback(ctx *gin.Context) {
func WxpayCallbackManual(ctx *gin.Context) { func WxpayCallbackManual(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*vasproto.WxpayCallbackManualParam) req := ctx.MustGet("client_req").(*vasproto.WxpayCallbackManualParam)
service.DefaultService.PayCallback(ctx, &vasproto.PayCallbackParamIn{ _ = service.DefaultService.PayCallback(ctx, &vasproto.PayCallbackParamIn{
OrderId: req.OrderId, OrderId: req.OrderId,
OutOrderId: req.OutOrderId, OutOrderId: req.OutOrderId,
CallbackPayType: vasproto.CallBackPayTypeWxpay, CallbackPayType: vasproto.CallBackPayTypeWxpay,

View File

@ -2,19 +2,33 @@ package controller
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
vasproto "service/api/proto/vas/proto"
"service/app/mix/service"
"service/bizcommon/util" "service/bizcommon/util"
"service/library/logger" "service/library/logger"
"service/library/payclients/yeepaycli" "service/library/payclients/yeepaycli"
) )
func YeepayCallback(ctx *gin.Context) { func YeepayCallback(ctx *gin.Context) {
//req, _ := ctx.GetRawData() notify, err := yeepaycli.GetDefaultYeepayClient().ParseNotify(ctx.Request)
//logger.Info("_AlipayCallback req: %v", string(req))
err := yeepaycli.GetDefaultYeepayClient().ParseNotify(ctx.Request)
if err != nil { if err != nil {
logger.Error("ParseNotify fail, req: %v, err: %v", util.ToJson(""), err) logger.Error("ParseNotify fail, req: %v, err: %v", util.ToJson(notify), err)
return return
} }
logger.Info("YeepayCallback, notify: %v", util.ToJson(notify))
//ctx.String(200, "success") if notify.Status != "SUCCESS" {
logger.Error("YeepayCallback invalid, notify: %v", util.ToJson(notify))
return
}
err = service.DefaultService.PayCallback(ctx, &vasproto.PayCallbackParamIn{
OrderId: notify.OrderId,
OutOrderId: notify.UniqueOrderNo,
CallbackPayType: vasproto.CallBackPayTypeWxpay,
})
if err != nil {
logger.Error("YeepayCallback fail, notify: %v, err: %v", util.ToJson(notify), err)
return
}
ctx.String(200, "SUCCESS")
} }

View File

@ -1195,7 +1195,7 @@ func (v *Vas) GetUserWechatUnlock(ctx *gin.Context, mid, uid int64) (uu *dbstruc
} }
// 【支付】回调 // 【支付】回调
func (v *Vas) PayCallback(ctx *gin.Context, p *vasproto.PayCallbackParamIn) { func (v *Vas) PayCallback(ctx *gin.Context, p *vasproto.PayCallbackParamIn) error {
var ( var (
orderId = p.OrderId orderId = p.OrderId
outOrderId = p.OutOrderId outOrderId = p.OutOrderId
@ -1207,16 +1207,16 @@ func (v *Vas) PayCallback(ctx *gin.Context, p *vasproto.PayCallbackParamIn) {
checkOrder, err := v.store.GetOrderById(ctx, nil, orderId) checkOrder, err := v.store.GetOrderById(ctx, nil, orderId)
if err != nil { if err != nil {
logger.Error("GetOrderById fail, p: %v, err: %v", util.ToJson(p), err) logger.Error("GetOrderById fail, p: %v, err: %v", util.ToJson(p), err)
return return err
} }
if checkOrder == nil { if checkOrder == nil {
logger.Warn("GetOrderById nil, p: %v", util.ToJson(p)) logger.Warn("GetOrderById nil, p: %v", util.ToJson(p))
return return err
} }
// 是否已处理过的订单 // 是否已处理过的订单
if checkOrder.GetOrderStatus() != dbstruct.VasOrderStatusInit { if checkOrder.GetOrderStatus() != dbstruct.VasOrderStatusInit {
logger.Error("repeat deal, p: %v", util.ToJson(p)) logger.Error("repeat deal, p: %v", util.ToJson(p))
return return err
} }
// out_order_id检查 // out_order_id检查
@ -1227,29 +1227,29 @@ func (v *Vas) PayCallback(ctx *gin.Context, p *vasproto.PayCallbackParamIn) {
} }
if err != nil { if err != nil {
logger.Error("GetOrderByOutOrderId fail, p: %v, err: %v", util.ToJson(p), err) logger.Error("GetOrderByOutOrderId fail, p: %v, err: %v", util.ToJson(p), err)
return return err
} }
if outOrder != nil { if outOrder != nil {
logger.Error("out order exists, p: %v", util.ToJson(p)) logger.Error("out order exists, p: %v", util.ToJson(p))
return return err
} }
// 获取商品 // 获取商品
product, err := v.store.GetProductById(ctx, checkOrder.GetProductId()) product, err := v.store.GetProductById(ctx, checkOrder.GetProductId())
if err != nil { if err != nil {
logger.Error("GetProductById fail, id: %v, err: %v", checkOrder.GetProductId(), err) logger.Error("GetProductById fail, id: %v, err: %v", checkOrder.GetProductId(), err)
return return err
} }
if product == nil { if product == nil {
logger.Error("GetProductById nil, id: %v", checkOrder.GetProductId()) logger.Error("GetProductById nil, id: %v", checkOrder.GetProductId())
return return err
} }
// 钱包 // 钱包
_, hasWallet := v.CheckWalletExist(ctx, nil, checkOrder.GetMid()) _, hasWallet := v.CheckWalletExist(ctx, nil, checkOrder.GetMid())
if !hasWallet { if !hasWallet {
logger.Error("CheckWalletExist fail, mid: %v", checkOrder.GetMid()) logger.Error("CheckWalletExist fail, mid: %v", checkOrder.GetMid())
return return err
} }
// 解锁信息 // 解锁信息
@ -1259,7 +1259,7 @@ func (v *Vas) PayCallback(ctx *gin.Context, p *vasproto.PayCallbackParamIn) {
_, hasZoneUnlock := v.CheckZoneUnlockExist(ctx, nil, mid, zid) _, hasZoneUnlock := v.CheckZoneUnlockExist(ctx, nil, mid, zid)
if !hasZoneUnlock { if !hasZoneUnlock {
logger.Error("CheckZoneUnlockExist fail, mid: %v, zid: %v", mid, zid) logger.Error("CheckZoneUnlockExist fail, mid: %v, zid: %v", mid, zid)
return return err
} }
} }
@ -1267,7 +1267,7 @@ func (v *Vas) PayCallback(ctx *gin.Context, p *vasproto.PayCallbackParamIn) {
tx, err := v.store.VasBegin(ctx) tx, err := v.store.VasBegin(ctx)
if err != nil { if err != nil {
logger.Error("vas begin fail, err: %v", err) logger.Error("vas begin fail, err: %v", err)
return return err
} }
defer func() { defer func() {
_ = v.AddOplogOrder( _ = v.AddOplogOrder(
@ -1314,7 +1314,7 @@ func (v *Vas) PayCallback(ctx *gin.Context, p *vasproto.PayCallbackParamIn) {
order, err := v.store.GetOrderByIdForUpdate(ctx, tx, orderId) order, err := v.store.GetOrderByIdForUpdate(ctx, tx, orderId)
if err != nil { if err != nil {
logger.Error("GetOrderByIdForUpdate fail, p: %v", util.ToJson(p)) logger.Error("GetOrderByIdForUpdate fail, p: %v", util.ToJson(p))
return return err
} }
// 锁住钱包 // 锁住钱包
@ -1349,14 +1349,14 @@ func (v *Vas) PayCallback(ctx *gin.Context, p *vasproto.PayCallbackParamIn) {
err = v.store.CreateConsumeHistory(ctx, tx, ch) err = v.store.CreateConsumeHistory(ctx, tx, ch)
if err != nil { if err != nil {
logger.Error("CreateConsumeHistory fail, ch: %v, err: %v", util.ToJson(ch), err) logger.Error("CreateConsumeHistory fail, ch: %v, err: %v", util.ToJson(ch), err)
return return err
} }
// 更新状态 // 更新状态
err = v.store.UpdateOrderStatus(ctx, tx, orderId, dbstruct.VasOrderStatusInit, dbstruct.VasOrderStatusPaySuccess) err = v.store.UpdateOrderStatus(ctx, tx, orderId, dbstruct.VasOrderStatusInit, dbstruct.VasOrderStatusPaySuccess)
if err != nil { if err != nil {
logger.Error("UpdateOrderStatus fail, p: %v", util.ToJson(p)) logger.Error("UpdateOrderStatus fail, p: %v", util.ToJson(p))
return return err
} }
afterStatus = dbstruct.VasOrderStatusPaySuccess afterStatus = dbstruct.VasOrderStatusPaySuccess
@ -1364,7 +1364,7 @@ func (v *Vas) PayCallback(ctx *gin.Context, p *vasproto.PayCallbackParamIn) {
err = v.store.UpdateOutOrderId(ctx, tx, orderId, outOrderId) err = v.store.UpdateOutOrderId(ctx, tx, orderId, outOrderId)
if err != nil { if err != nil {
logger.Error("UpdateOutOrderId fail, p: %v", util.ToJson(p)) logger.Error("UpdateOutOrderId fail, p: %v", util.ToJson(p))
return return err
} }
// 商品判断 // 商品判断
@ -1374,12 +1374,12 @@ func (v *Vas) PayCallback(ctx *gin.Context, p *vasproto.PayCallbackParamIn) {
err = v.store.IncCoins(ctx, tx, order.GetMid(), order.GetCoins()) err = v.store.IncCoins(ctx, tx, order.GetMid(), order.GetCoins())
if err != nil { if err != nil {
logger.Error("IncCoins fail, order: %v, err: %v", util.ToJson(order), err) logger.Error("IncCoins fail, order: %v, err: %v", util.ToJson(order), err)
return return err
} }
err = v.store.UpdateOrderStatus(ctx, tx, orderId, dbstruct.VasOrderStatusPaySuccess, dbstruct.VasOrderStatusFinish) err = v.store.UpdateOrderStatus(ctx, tx, orderId, dbstruct.VasOrderStatusPaySuccess, dbstruct.VasOrderStatusFinish)
if err != nil { if err != nil {
logger.Error("UpdateOrderStatus fail, order: %v, err: %v", util.ToJson(order), err) logger.Error("UpdateOrderStatus fail, order: %v, err: %v", util.ToJson(order), err)
return return err
} }
afterStatus = dbstruct.VasOrderStatusFinish afterStatus = dbstruct.VasOrderStatusFinish
case product.Id == dbstruct.ProductIdH5ContactWechat: case product.Id == dbstruct.ProductIdH5ContactWechat:
@ -1387,32 +1387,32 @@ func (v *Vas) PayCallback(ctx *gin.Context, p *vasproto.PayCallbackParamIn) {
err = v.store.IncCoins(ctx, tx, order.GetMid(), order.GetCoins()) err = v.store.IncCoins(ctx, tx, order.GetMid(), order.GetCoins())
if err != nil { if err != nil {
logger.Error("IncCoins fail, order: %v, err: %v", util.ToJson(order), err) logger.Error("IncCoins fail, order: %v, err: %v", util.ToJson(order), err)
return return err
} }
case product.Id == dbstruct.ProductIdMembership: case product.Id == dbstruct.ProductIdMembership:
// 解锁会员资格 // 解锁会员资格
_, err = v.UnlockMembership(ctx, tx, util.DerefInt64(order.Mid), product, order, wallet) _, err = v.UnlockMembership(ctx, tx, util.DerefInt64(order.Mid), product, order, wallet)
if err != nil { if err != nil {
logger.Error("UnlockMembership fail, order: %v, err: %v", util.ToJson(order), err) logger.Error("UnlockMembership fail, order: %v, err: %v", util.ToJson(order), err)
return return err
} }
case product.Id == dbstruct.ProductIdH5ZoneMoment: case product.Id == dbstruct.ProductIdH5ZoneMoment:
err = v.UnlockZoneMoment(ctx, tx, order) err = v.UnlockZoneMoment(ctx, tx, order)
if err != nil { if err != nil {
logger.Error("UnlockZoneMoment fail, order: %v, err: %v", util.ToJson(order), err) logger.Error("UnlockZoneMoment fail, order: %v, err: %v", util.ToJson(order), err)
return return err
} }
case product.Id == dbstruct.ProductIdH5ZoneAdmission: case product.Id == dbstruct.ProductIdH5ZoneAdmission:
err = v.UnlockZoneAdmission(ctx, tx, order, dbstruct.ZoneUnlockTypePay) err = v.UnlockZoneAdmission(ctx, tx, order, dbstruct.ZoneUnlockTypePay)
if err != nil { if err != nil {
logger.Error("UnlockZoneAdmission fail, order: %v, err: %v", util.ToJson(order), err) logger.Error("UnlockZoneAdmission fail, order: %v, err: %v", util.ToJson(order), err)
return return err
} }
case product.Id == dbstruct.ProductIdH5ZoneSuperfanship: case product.Id == dbstruct.ProductIdH5ZoneSuperfanship:
err = v.UnlockZoneSuperfanship(ctx, tx, order, dbstruct.ZoneUnlockTypePay) err = v.UnlockZoneSuperfanship(ctx, tx, order, dbstruct.ZoneUnlockTypePay)
if err != nil { if err != nil {
logger.Error("UnlockZoneSuperfanship fail, order: %v, err: %v", util.ToJson(order), err) logger.Error("UnlockZoneSuperfanship fail, order: %v, err: %v", util.ToJson(order), err)
return return err
} }
} }
@ -1420,8 +1420,9 @@ func (v *Vas) PayCallback(ctx *gin.Context, p *vasproto.PayCallbackParamIn) {
_err := v.UnlockZoneIronfanshipReachConsume(ctx, tx, order.GetMid(), order.GetZid(), order.GetUid()) _err := v.UnlockZoneIronfanshipReachConsume(ctx, tx, order.GetMid(), order.GetZid(), order.GetUid())
if _err != nil { if _err != nil {
logger.Error("UnlockZoneIronfanshipReachConsume fail, order: %v, err: %v", util.ToJson(order), _err) logger.Error("UnlockZoneIronfanshipReachConsume fail, order: %v, err: %v", util.ToJson(order), _err)
return return nil
} }
return nil
} }
func (v *Vas) GetCoinOrderById(ctx *gin.Context, id string) (*dbstruct.CoinOrder, error) { func (v *Vas) GetCoinOrderById(ctx *gin.Context, id string) (*dbstruct.CoinOrder, error) {

View File

@ -498,9 +498,8 @@ func (s *Service) H5DirectUnlockWechat(ctx *gin.Context, req *vasproto.H5DirectU
} }
// 支付回调 // 支付回调
func (s *Service) PayCallback(ctx *gin.Context, req *vasproto.PayCallbackParamIn) (data *vasproto.H5DirectUnlockWechatData, ec errcode.ErrCode) { func (s *Service) PayCallback(ctx *gin.Context, req *vasproto.PayCallbackParamIn) error {
_DefaultVas.PayCallback(ctx, req) return _DefaultVas.PayCallback(ctx, req)
return
} }
// 提现页面 // 提现页面

View File

@ -77,10 +77,10 @@ type YeepayNotify struct {
Status string `json:"status"` Status string `json:"status"`
} }
func (c *YeepayClient) ParseNotify(req *http.Request) error { func (c *YeepayClient) ParseNotify(req *http.Request) (*YeepayNotify, error) {
if err := req.ParseForm(); err != nil { if err := req.ParseForm(); err != nil {
logger.Error("Yeepay ParseForm fail, err: %v", err) logger.Error("Yeepay ParseForm fail, err: %v", err)
return err return nil, err
} }
var ( var (
response = req.Form.Get("response") response = req.Form.Get("response")
@ -90,10 +90,16 @@ func (c *YeepayClient) ParseNotify(req *http.Request) error {
content, err := yoputils.DecryptCallback(request.YOP_PLATFORM_PUBLIC_KEY, c.PrivateKey, response) content, err := yoputils.DecryptCallback(request.YOP_PLATFORM_PUBLIC_KEY, c.PrivateKey, response)
if err != nil { if err != nil {
logger.Error("Yeepay DecryptCallback fail, form: %v, err: %v", req.Form.Encode(), err) logger.Error("Yeepay DecryptCallback fail, form: %v, err: %v", req.Form.Encode(), err)
return err return nil, err
} }
logger.Info("Yeepay ParseNotify, %v", util.ToJson(content)) notify := new(YeepayNotify)
return nil err = json.Unmarshal([]byte(util.ToJson(content)), notify)
if err != nil {
logger.Error("Yeepay unmarshal fail, form: %v, content: %v, err: %v", req.Form.Encode(), util.ToJson(content), err)
return nil, err
}
logger.Info("Yeepay ParseNotify, %v", util.ToJson(notify))
return notify, nil
} }
// 易宝支付 聚合支付 // 易宝支付 聚合支付
@ -129,7 +135,7 @@ func (c *YeepayClient) AggPay(ctx context.Context, param *AggPayParam) (resp *Ag
req.AddParam("notifyUrl", c.NotifyUrl) req.AddParam("notifyUrl", c.NotifyUrl)
req.AddParam("payWay", param.PayWay) req.AddParam("payWay", param.PayWay)
req.AddParam("channel", param.PayChannel) req.AddParam("channel", param.PayChannel)
req.AddParam("scene", "ONLINE") req.AddParam("scene", "OFFLINE")
req.AddParam("userIp", param.Ip) req.AddParam("userIp", param.Ip)
respMeta, err := c.client.Request(req) respMeta, err := c.client.Request(req)