diff --git a/internal/biz/cmb/notify.go b/internal/biz/cmb/notify.go index 4d729b3..0688a46 100644 --- a/internal/biz/cmb/notify.go +++ b/internal/biz/cmb/notify.go @@ -31,27 +31,22 @@ func (v *Cmb) Notify(ctx context.Context, order *bo.OrderBo) (*bo.OrderNotifyBo, return nil, err } - x, err := v.CmbMixRepo.Request(ctx, request, order.NotifyUrl) + rep, err := v.CmbMixRepo.Request(ctx, request, order.NotifyUrl) if err != nil { return orderNotify, v.notifyFail(ctx, orderNotify.ID, err.Error()) } - bizStr, err := v.CmbMixRepo.VerifyResponse(ctx, x) + _, err = v.CmbMixRepo.VerifyResponse(ctx, rep) if err != nil { - log.Errorf("Notify CmbMixRepo.VerifyResponse error:%s", err.Error()) + log.Errorf("回调通知招行返回验证结果发生错误,rep:%+v error:%s", rep, err.Error()) return orderNotify, v.notifyFail(ctx, orderNotify.ID, err.Error()) } - var reply *v1.CmbNotifyReply - if err = json.Unmarshal([]byte(bizStr), &reply); err != nil { - return orderNotify, v.notifyFail(ctx, orderNotify.ID, err.Error()) + if rep.RespCode == vo.CmbResponseStatusSuccess.GetValue() { + return orderNotify, v.notifySuccess(ctx, orderNotify.ID, "{}") } - if reply.RespCode != vo.CmbResponseStatusSuccess.GetValue() { - return orderNotify, v.notifyFail(ctx, orderNotify.ID, reply.RespMsg) - } - - return orderNotify, v.notifySuccess(ctx, orderNotify.ID, bizStr) + return orderNotify, v.notifyFail(ctx, orderNotify.ID, "{}") } func (v *Cmb) bizContent(_ context.Context, order *bo.OrderBo, orderNotify *bo.OrderNotifyBo) (string, error) { diff --git a/internal/biz/wechat_notify_consume.go b/internal/biz/wechat_notify_consume.go index ee8e797..a558366 100644 --- a/internal/biz/wechat_notify_consume.go +++ b/internal/biz/wechat_notify_consume.go @@ -12,10 +12,6 @@ import ( func (v *VoucherBiz) WechatNotifyConsumer(ctx context.Context, tag string, req *bo.WechatVoucherNotifyBo) error { - //req.PlainText.StockCreatorMchid = "1676203838" - //req.PlainText.StockID = "20215869" - //req.PlainText.CouponID = "96059179220" - c := vo.WechatNotifyConsumeLockKey.BuildCache([]string{tag, req.PlainText.StockID, req.PlainText.CouponID}) return lock.NewMutex(v.rdb.Rdb, c.TTL).Lock(ctx, c.Key, func(ctx context.Context) error { diff --git a/internal/data/mixrepoimpl/cmb.go b/internal/data/mixrepoimpl/cmb.go index cb59647..6974d10 100644 --- a/internal/data/mixrepoimpl/cmb.go +++ b/internal/data/mixrepoimpl/cmb.go @@ -167,12 +167,17 @@ func (s *CmbMixRepoImpl) VerifyResponse(_ context.Context, req *v1.CmbReply) (st return "", errors.New("签名验证失败") } - bizStr, err := cmb.Decrypt(s.bc.Cmb.Sm2Prk, req.EncryptBody) - if err != nil { - return "", err + if len(req.EncryptBody) > 0 { + + bizStr, err := cmb.Decrypt(s.bc.Cmb.Sm2Prk, req.EncryptBody) + if err != nil { + return "", err + } + + return bizStr, nil } - return bizStr, nil + return "", nil } func (s *CmbMixRepoImpl) GetResponse(_ context.Context, reqBo *bo.CmbResponseBo) (*v1.CmbReply, error) { diff --git a/internal/pkg/mq_http/mq_http_test.go b/internal/pkg/mq_http/mq_http_test.go index d2d2c13..f658f4d 100644 --- a/internal/pkg/mq_http/mq_http_test.go +++ b/internal/pkg/mq_http/mq_http_test.go @@ -10,7 +10,24 @@ func Test_WechatNotifyProducer(t *testing.T) { tag := "voucher_notify_dev" - bodyStr := `{"id":"5465699d-de6a-5414-a8df-283167b577ca","create_time":"2025-03-07T15:57:24+08:00","resource_type":"encrypt-resource","event_type":"COUPON.USE","summary":"代金券核销通知","original_type":"coupon","associated_data":"coupon","plain_text":{"stock_creator_mchid":"1605446142","stock_id":"19990623","coupon_id":"95952277058","coupon_name":"萧山农商新客激活礼","description":"","status":"USED","create_time":"2025-03-07T15:49:31+08:00","coupon_type":"NORMAL","no_cash":false,"singleitem":false,"consume_information":{"consume_time":"2025-03-07T15:57:24+08:00","consume_mchid":"1800002761","transaction_id":"4200002544202503077103159055"}}}` + bodyStr := `{"id":"5465699d-de6a-5414-a8df-283167b577ca", +"create_time":"2025-03-07T15:57:24+08:00", +"resource_type":"encrypt-resource", +"event_type":"COUPON.USE", +"summary":"代金券核销通知", +"original_type":"coupon", +"associated_data":"coupon", +"plain_text":{ +"stock_creator_mchid":"1676203838", +"stock_id":"20215869", +"coupon_id":"754343650536853505", +"coupon_name":"萧山农商新客激活礼", +"description":"","status":"USED", +"create_time":"2025-03-07T15:49:31+08:00", +"coupon_type":"NORMAL", +"no_cash":false, +"singleitem":false, +"consume_information":{"consume_time":"2025-03-07T15:57:24+08:00","consume_mchid":"1800002761","transaction_id":"4200002544202503077103159055"}}}` if err := wechatNotifyProducer(tag, bodyStr); err != nil { t.Errorf("入队失败 error = %v", err) @@ -20,7 +37,25 @@ func Test_WechatNotifyProducer(t *testing.T) { func Test_WechatVoucherNotifyData(t *testing.T) { - bodyStr := `{"id":"5465699d-de6a-5414-a8df-283167b577ca","create_time":"2025-03-07T15:57:24+08:00","resource_type":"encrypt-resource","event_type":"COUPON.USE","summary":"代金券核销通知","original_type":"coupon","associated_data":"coupon","plain_text":{"stock_creator_mchid":"1605446142","stock_id":"19990623","coupon_id":"95952277058","coupon_name":"萧山农商新客激活礼","description":"","status":"USED","create_time":"2025-03-07T15:49:31+08:00","coupon_type":"NORMAL","no_cash":false,"singleitem":false,"consume_information":{"consume_time":"2025-03-07T15:57:24+08:00","consume_mchid":"1800002761","transaction_id":"4200002544202503077103159055"}}}` + bodyStr := `{"id":"5465699d-de6a-5414-a8df-283167b577ca", +"create_time":"2025-03-07T15:57:24+08:00", +"resource_type":"encrypt-resource", +"event_type":"COUPON.USE", +"summary":"代金券核销通知", +"original_type":"coupon", +"associated_data":"coupon", +"plain_text":{ +"stock_creator_mchid":"1605446142", +"stock_id":"19990623", +"coupon_id":"95952277058", +"coupon_name":"萧山农商新客激活礼", +"description":"","status":"USED", +"create_time":"2025-03-07T15:49:31+08:00", +"coupon_type":"NORMAL", +"no_cash":false, +"singleitem":false, +"consume_information":{"consume_time":"2025-03-07T15:57:24+08:00","consume_mchid":"1800002761","transaction_id":"4200002544202503077103159055"}}}` + //bodyStr := `{"id":"5465699d-de6a-5414-a8df-283167b577ca","create_time":"2025-03-07T15:57:24+08:00","resource_type":"encrypt-resource","event_type":"COUPON.USE","summary":"代金券核销通知","original_type":"coupon","associated_data":"coupon","plain_text":{"stock_creator_mchid":"1605446142","stock_id":"19990623","coupon_id":"95952277058","coupon_name":"萧山农商新客激活礼","description":"","status":"USED","create_time":"2025-03-07T15:49:31+08:00","coupon_type":"NORMAL","no_cash":false,"singleitem":false,"consume_information":{"consume_time":"2025-03-07T15:57:24+08:00","consume_mchid":"1800002761","transaction_id":"4200002544202503077103159055"}}}` var x *bo.WechatVoucherNotifyBo