diff --git a/app/mix/controller/alipay_callback.go b/app/mix/controller/alipay_callback.go index 08afbe5d..00a63c91 100644 --- a/app/mix/controller/alipay_callback.go +++ b/app/mix/controller/alipay_callback.go @@ -19,7 +19,7 @@ func AlipayCallback(ctx *gin.Context) { } 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"), OutOrderId: bm.GetString("trade_no"), CallbackPayType: vasproto.CallBackPayTypeAlipay, diff --git a/app/mix/controller/wxpay_callback.go b/app/mix/controller/wxpay_callback.go index 4e6fca8c..884b6d52 100644 --- a/app/mix/controller/wxpay_callback.go +++ b/app/mix/controller/wxpay_callback.go @@ -23,7 +23,7 @@ func WxpayCallback(ctx *gin.Context) { logger.Info("WxpayCallback, notify: %v", util.ToJson(notify)) if notify.TradeState == wxpay.TradeStateSuccess { - service.DefaultService.PayCallback(ctx, &vasproto.PayCallbackParamIn{ + _ = service.DefaultService.PayCallback(ctx, &vasproto.PayCallbackParamIn{ OrderId: notify.OutTradeNo, OutOrderId: notify.TransactionId, CallbackPayType: vasproto.CallBackPayTypeWxpay, @@ -34,7 +34,7 @@ func WxpayCallback(ctx *gin.Context) { func WxpayCallbackManual(ctx *gin.Context) { req := ctx.MustGet("client_req").(*vasproto.WxpayCallbackManualParam) - service.DefaultService.PayCallback(ctx, &vasproto.PayCallbackParamIn{ + _ = service.DefaultService.PayCallback(ctx, &vasproto.PayCallbackParamIn{ OrderId: req.OrderId, OutOrderId: req.OutOrderId, CallbackPayType: vasproto.CallBackPayTypeWxpay, diff --git a/app/mix/controller/yeepay_callback.go b/app/mix/controller/yeepay_callback.go index c3453af7..52b5324a 100644 --- a/app/mix/controller/yeepay_callback.go +++ b/app/mix/controller/yeepay_callback.go @@ -2,19 +2,33 @@ package controller import ( "github.com/gin-gonic/gin" + vasproto "service/api/proto/vas/proto" + "service/app/mix/service" "service/bizcommon/util" "service/library/logger" "service/library/payclients/yeepaycli" ) func YeepayCallback(ctx *gin.Context) { - //req, _ := ctx.GetRawData() - //logger.Info("_AlipayCallback req: %v", string(req)) - err := yeepaycli.GetDefaultYeepayClient().ParseNotify(ctx.Request) + notify, err := yeepaycli.GetDefaultYeepayClient().ParseNotify(ctx.Request) 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 } + 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") } diff --git a/app/mix/service/logic/vas.go b/app/mix/service/logic/vas.go index 697b44ae..3b55d2fe 100644 --- a/app/mix/service/logic/vas.go +++ b/app/mix/service/logic/vas.go @@ -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 ( orderId = p.OrderId 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) if err != nil { logger.Error("GetOrderById fail, p: %v, err: %v", util.ToJson(p), err) - return + return err } if checkOrder == nil { logger.Warn("GetOrderById nil, p: %v", util.ToJson(p)) - return + return err } // 是否已处理过的订单 if checkOrder.GetOrderStatus() != dbstruct.VasOrderStatusInit { logger.Error("repeat deal, p: %v", util.ToJson(p)) - return + return err } // out_order_id检查 @@ -1227,29 +1227,29 @@ func (v *Vas) PayCallback(ctx *gin.Context, p *vasproto.PayCallbackParamIn) { } if err != nil { logger.Error("GetOrderByOutOrderId fail, p: %v, err: %v", util.ToJson(p), err) - return + return err } if outOrder != nil { logger.Error("out order exists, p: %v", util.ToJson(p)) - return + return err } // 获取商品 product, err := v.store.GetProductById(ctx, checkOrder.GetProductId()) if err != nil { logger.Error("GetProductById fail, id: %v, err: %v", checkOrder.GetProductId(), err) - return + return err } if product == nil { logger.Error("GetProductById nil, id: %v", checkOrder.GetProductId()) - return + return err } // 钱包 _, hasWallet := v.CheckWalletExist(ctx, nil, checkOrder.GetMid()) if !hasWallet { 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) if !hasZoneUnlock { 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) if err != nil { logger.Error("vas begin fail, err: %v", err) - return + return err } defer func() { _ = v.AddOplogOrder( @@ -1314,7 +1314,7 @@ func (v *Vas) PayCallback(ctx *gin.Context, p *vasproto.PayCallbackParamIn) { order, err := v.store.GetOrderByIdForUpdate(ctx, tx, orderId) if err != nil { 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) if err != nil { 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) if err != nil { logger.Error("UpdateOrderStatus fail, p: %v", util.ToJson(p)) - return + return err } 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) if err != nil { 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()) if err != nil { 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) if err != nil { logger.Error("UpdateOrderStatus fail, order: %v, err: %v", util.ToJson(order), err) - return + return err } afterStatus = dbstruct.VasOrderStatusFinish 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()) if err != nil { logger.Error("IncCoins fail, order: %v, err: %v", util.ToJson(order), err) - return + return err } case product.Id == dbstruct.ProductIdMembership: // 解锁会员资格 _, err = v.UnlockMembership(ctx, tx, util.DerefInt64(order.Mid), product, order, wallet) if err != nil { logger.Error("UnlockMembership fail, order: %v, err: %v", util.ToJson(order), err) - return + return err } case product.Id == dbstruct.ProductIdH5ZoneMoment: err = v.UnlockZoneMoment(ctx, tx, order) if err != nil { logger.Error("UnlockZoneMoment fail, order: %v, err: %v", util.ToJson(order), err) - return + return err } case product.Id == dbstruct.ProductIdH5ZoneAdmission: err = v.UnlockZoneAdmission(ctx, tx, order, dbstruct.ZoneUnlockTypePay) if err != nil { logger.Error("UnlockZoneAdmission fail, order: %v, err: %v", util.ToJson(order), err) - return + return err } case product.Id == dbstruct.ProductIdH5ZoneSuperfanship: err = v.UnlockZoneSuperfanship(ctx, tx, order, dbstruct.ZoneUnlockTypePay) if err != nil { 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()) if _err != nil { 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) { diff --git a/app/mix/service/vasservice.go b/app/mix/service/vasservice.go index 32c9c4bf..2fffa548 100644 --- a/app/mix/service/vasservice.go +++ b/app/mix/service/vasservice.go @@ -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) { - _DefaultVas.PayCallback(ctx, req) - return +func (s *Service) PayCallback(ctx *gin.Context, req *vasproto.PayCallbackParamIn) error { + return _DefaultVas.PayCallback(ctx, req) } // 提现页面 diff --git a/library/payclients/yeepaycli/client.go b/library/payclients/yeepaycli/client.go index 00f11f8f..92635ba7 100644 --- a/library/payclients/yeepaycli/client.go +++ b/library/payclients/yeepaycli/client.go @@ -77,10 +77,10 @@ type YeepayNotify struct { 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 { logger.Error("Yeepay ParseForm fail, err: %v", err) - return err + return nil, err } var ( 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) if err != nil { 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)) - return nil + notify := new(YeepayNotify) + 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("payWay", param.PayWay) req.AddParam("channel", param.PayChannel) - req.AddParam("scene", "ONLINE") + req.AddParam("scene", "OFFLINE") req.AddParam("userIp", param.Ip) respMeta, err := c.client.Request(req)