diff --git a/app/mix/controller/alipay_callback.go b/app/mix/controller/alipay_callback.go index 8da5b0f4..8eda9d93 100644 --- a/app/mix/controller/alipay_callback.go +++ b/app/mix/controller/alipay_callback.go @@ -18,9 +18,11 @@ func AlipayCallback(ctx *gin.Context) { return } - service.DefaultService.AlipayCallback(ctx, &vasproto.AlipayCallbackParamIn{ - OrderId: bm.GetString("out_trade_no"), - AlipayOrderId: bm.GetString("trade_no"), - }) + if bm.GetString("trade_status") == "TRADE_SUCCESS" { + service.DefaultService.AlipayCallback(ctx, &vasproto.AlipayCallbackParamIn{ + OrderId: bm.GetString("out_trade_no"), + AlipayOrderId: bm.GetString("trade_no"), + }) + } ctx.String(200, "success") } diff --git a/app/mix/dao/mysql.go b/app/mix/dao/mysql.go index d42ad4ce..5321967a 100644 --- a/app/mix/dao/mysql.go +++ b/app/mix/dao/mysql.go @@ -219,6 +219,23 @@ func (m *Mysql) UpdateOrderStatus(ctx *gin.Context, tx *sqlx.Tx, orderId string, return err } +// 更新订单out_order_id +func (m *Mysql) UpdateOutOrderId(ctx *gin.Context, tx *sqlx.Tx, orderId string, outOrderId string) error { + var err error + sqlStr := "update " + TableOrder + " set out_order_id=? where id=?" + if tx != nil { + _, err = tx.ExecContext(ctx, sqlStr, outOrderId, orderId) + } else { + db := m.getDBVas() + _, err = db.ExecContext(ctx, sqlStr, outOrderId, orderId) + } + if err != nil { + logger.Error("UpdateOutOrderId fail, orderId: %v, outOrderId: %v, err: %v", orderId, outOrderId, err) + return err + } + return err +} + // 获取钱包 for update func (m *Mysql) GetWalletForUpdate(ctx *gin.Context, tx *sqlx.Tx, mid int64) (wallet *dbstruct.Wallet, err error) { var tmpWallet dbstruct.Wallet diff --git a/app/mix/service/logic/vas.go b/app/mix/service/logic/vas.go index 8c22b0fe..80ff0b12 100644 --- a/app/mix/service/logic/vas.go +++ b/app/mix/service/logic/vas.go @@ -1650,6 +1650,13 @@ func (v *Vas) AlipayCallback(ctx *gin.Context, p *vasproto.AlipayCallbackParamIn } afterStatus = dbstruct.VasOrderStatusPaySuccess + // 更新支付宝订单 + err = v.store.UpdateOutOrderId(ctx, tx, orderId, alipayOrderId) + if err != nil { + logger.Error("UpdateOutOrderId fail, p: %v", util.ToJson(p)) + return + } + // 商品判断 switch { case product.Type == dbstruct.ProductTypeCoins: diff --git a/library/payclients/alipaycli/client.go b/library/payclients/alipaycli/client.go index 34eec5d7..e2270dbf 100644 --- a/library/payclients/alipaycli/client.go +++ b/library/payclients/alipaycli/client.go @@ -59,12 +59,8 @@ func (c *AlipayClient) ParseNotify(req *http.Request) (notify gopay.BodyMap, err return } logger.Info("Alipay ParseNotify, %v", util.ToJson(notifyTmp)) + // 验签 - //ok, err := alipay.VerifySign("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAl9Pj5j6cNRdaDyWTWWFkcBViDqw/py1bDrqe7VykND1JywgLsFogeKGG0YhJfTfEeExAlGlP2DUV7z0uc8QhCMF7N+qdfXNb/RemFIpSs71i9kkaFIJEl20JnWipps96LwZLDpNRck3Nho/Xnbs4wuft3sQtd7T0sB2zEYyl7OyuTqehcoz3uAQp0JOYBosVPpgofaD6BN2RSZQ33QvqS37w3xHLif8P7hfYXdeIe+JxeHmchzQK22dRzJinYfU+pKE5J2Wm+dq1l3/ls4w8Xc3RyqvvW2UMx2lOMtSg2WWXDDi1skmHn/l1BbBP/uogNq4Avf50eoZ1UE6JxPrZpQIDAQAB", notifyTmp) - //if err != nil { - // logger.Error("VerifySign fail, bm: %v, err: %v", util.ToJson(notifyTmp), err) - // return - //} ok, err := alipay.VerifySignWithCert("/app/wishpal-ironfan/etc/mix/alipaycert/alipayCertPublicKey_RSA2.crt", notifyTmp) if !ok { logger.Error("VerifySign fail, not ok, bm: %v", util.ToJson(notifyTmp))