接口调整

This commit is contained in:
李子铭 2025-03-12 18:50:31 +08:00
parent 084635fa6a
commit 05b23b3cde
4 changed files with 52 additions and 21 deletions

View File

@ -31,27 +31,22 @@ func (v *Cmb) Notify(ctx context.Context, order *bo.OrderBo) (*bo.OrderNotifyBo,
return nil, err return nil, err
} }
x, err := v.CmbMixRepo.Request(ctx, request, order.NotifyUrl) rep, err := v.CmbMixRepo.Request(ctx, request, order.NotifyUrl)
if err != nil { if err != nil {
return orderNotify, v.notifyFail(ctx, orderNotify.ID, err.Error()) 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 { 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()) return orderNotify, v.notifyFail(ctx, orderNotify.ID, err.Error())
} }
var reply *v1.CmbNotifyReply if rep.RespCode == vo.CmbResponseStatusSuccess.GetValue() {
if err = json.Unmarshal([]byte(bizStr), &reply); err != nil { return orderNotify, v.notifySuccess(ctx, orderNotify.ID, "{}")
return orderNotify, v.notifyFail(ctx, orderNotify.ID, err.Error())
} }
if reply.RespCode != vo.CmbResponseStatusSuccess.GetValue() { return orderNotify, v.notifyFail(ctx, orderNotify.ID, "{}")
return orderNotify, v.notifyFail(ctx, orderNotify.ID, reply.RespMsg)
}
return orderNotify, v.notifySuccess(ctx, orderNotify.ID, bizStr)
} }
func (v *Cmb) bizContent(_ context.Context, order *bo.OrderBo, orderNotify *bo.OrderNotifyBo) (string, error) { func (v *Cmb) bizContent(_ context.Context, order *bo.OrderBo, orderNotify *bo.OrderNotifyBo) (string, error) {

View File

@ -12,10 +12,6 @@ import (
func (v *VoucherBiz) WechatNotifyConsumer(ctx context.Context, tag string, req *bo.WechatVoucherNotifyBo) error { 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}) 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 { return lock.NewMutex(v.rdb.Rdb, c.TTL).Lock(ctx, c.Key, func(ctx context.Context) error {

View File

@ -167,12 +167,17 @@ func (s *CmbMixRepoImpl) VerifyResponse(_ context.Context, req *v1.CmbReply) (st
return "", errors.New("签名验证失败") return "", errors.New("签名验证失败")
} }
bizStr, err := cmb.Decrypt(s.bc.Cmb.Sm2Prk, req.EncryptBody) if len(req.EncryptBody) > 0 {
if err != nil {
return "", err 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) { func (s *CmbMixRepoImpl) GetResponse(_ context.Context, reqBo *bo.CmbResponseBo) (*v1.CmbReply, error) {

View File

@ -10,7 +10,24 @@ func Test_WechatNotifyProducer(t *testing.T) {
tag := "voucher_notify_dev" 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 { if err := wechatNotifyProducer(tag, bodyStr); err != nil {
t.Errorf("入队失败 error = %v", err) t.Errorf("入队失败 error = %v", err)
@ -20,7 +37,25 @@ func Test_WechatNotifyProducer(t *testing.T) {
func Test_WechatVoucherNotifyData(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 var x *bo.WechatVoucherNotifyBo