接口调整
This commit is contained in:
parent
084635fa6a
commit
05b23b3cde
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -167,6 +167,8 @@ func (s *CmbMixRepoImpl) VerifyResponse(_ context.Context, req *v1.CmbReply) (st
|
|||
return "", errors.New("签名验证失败")
|
||||
}
|
||||
|
||||
if len(req.EncryptBody) > 0 {
|
||||
|
||||
bizStr, err := cmb.Decrypt(s.bc.Cmb.Sm2Prk, req.EncryptBody)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
@ -175,6 +177,9 @@ func (s *CmbMixRepoImpl) VerifyResponse(_ context.Context, req *v1.CmbReply) (st
|
|||
return bizStr, nil
|
||||
}
|
||||
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (s *CmbMixRepoImpl) GetResponse(_ context.Context, reqBo *bo.CmbResponseBo) (*v1.CmbReply, error) {
|
||||
|
||||
reply := &v1.CmbReply{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue