From cf9ecc4486757041f54e69c17034c4217aa41792 Mon Sep 17 00:00:00 2001 From: ziming Date: Thu, 26 Mar 2026 10:14:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=87=E6=8D=A2=E4=B8=BB=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/wechat_notify.go | 7 +++++++ internal/service/notify.go | 2 ++ test/coupon.go | 11 ++++++----- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/internal/biz/wechat_notify.go b/internal/biz/wechat_notify.go index ac73bc1..18c0f8f 100644 --- a/internal/biz/wechat_notify.go +++ b/internal/biz/wechat_notify.go @@ -21,6 +21,9 @@ func (this *VoucherBiz) WechatNotifyConsumer(ctx context.Context, ip string, req } if order.ActivityId != "" { + if err = req.Validate(); err != nil { + return fmt.Errorf("multi validate req error: %v", err) + } return this.MultiBiz.Run(ctx, ip, req.PlainText.StockCreatorMchid, req, order) } @@ -43,6 +46,10 @@ func (this *VoucherBiz) WechatNotifyConsumer(ctx context.Context, ip string, req func (this *VoucherBiz) getOrder(ctx context.Context, req *bo.WechatVoucherNotifyBo) (*bo.OrderBo, error) { + if req.PlainText.StockCreatorMchid == "" || req.PlainText.StockID == "" || req.PlainText.CouponID == "" { + return nil, fmt.Errorf("订单查询参数错误") + } + order, err := this.OrderRepo.GetByCouponId(ctx, req.PlainText.StockCreatorMchid, req.PlainText.StockID, req.PlainText.CouponID) if err != nil { diff --git a/internal/service/notify.go b/internal/service/notify.go index 01dfb5b..9c35c63 100644 --- a/internal/service/notify.go +++ b/internal/service/notify.go @@ -66,6 +66,8 @@ func (srv *NotifyService) Notify(ctx http.Context) error { ip := helper.GetClientIP(ctx) + log.Warnf("微信回调通知[%s],解析数据,response:%+v", mchId, response) + if err = srv.VoucherBiz.WechatNotifyConsumer(ctx, ip, response); err != nil { log.Errorf("微信回调通知[%s],处理失败,headers:%+v,body:%s,err:%s", mchId, headers, string(bodyBytes), err.Error()) diff --git a/test/coupon.go b/test/coupon.go index a2ca471..8cccda8 100644 --- a/test/coupon.go +++ b/test/coupon.go @@ -24,8 +24,8 @@ var bc = &conf.Bootstrap{ }, } -// bc2 Callback{NotifyUrl:https://nsall.86698.cn/wechatPay/coupon_notify/fjxingwang, Mchid:1652465541} -var bc2 = &conf.Bootstrap{ +// bcFJXW Callback{NotifyUrl:https://nsall.86698.cn/wechatPay/coupon_notify/fjxingwang, Mchid:1652465541} +var bcFJXW = &conf.Bootstrap{ Wechat: &conf.Wechat{ MchID: "1652465541", // notifyUrl https://nsall.86698.cn/wechatPay/coupon_notify/fjxingwang MchCertificateSerialNumber: "1E3F2CE013203BA9C3DEFC5782FCD3329C3DAC1C", @@ -169,8 +169,8 @@ func QueryProduct() { } req := cashcoupons.QueryStockRequest{ - StockId: core.String("21502886"), - StockCreatorMchid: core.String("1652465541"), + StockId: core.String("21923564"), + StockCreatorMchid: core.String("1100040695"), } svc := cashcoupons.StockApiService{Client: client} @@ -195,7 +195,8 @@ func QueryProduct() { fmt.Printf("\n剩余库存:%d", availableStock) fmt.Printf("\n剩余预算:%d", availableStock*couponAmount) - fmt.Printf("\nWxResp:%+v", WxResp(resp)) + str, _ := json.Marshal(WxResp(resp)) + fmt.Printf("\nWxResp:%+v", string(str)) return }