cmb
This commit is contained in:
parent
159fece2dd
commit
73ce021b25
|
|
@ -56,7 +56,7 @@ cmb:
|
|||
keyAlias: "CO_PUB_KEY_SM2"
|
||||
cmbKeyAlias: "SM2_CMBLIFE"
|
||||
orgNo: "orgNo" # 发码机构号,固定值,掌上生活优惠券系统提供
|
||||
notifyUrl: "https://gateway.dev.cdlsxd.cn/ymt/jd/v1/notify"
|
||||
notifyUrl: "https://sandbox.cdcc.cmbchina.com/AccessGateway/transIn/updateCodeStatus.json" # 招行测试回调地址
|
||||
|
||||
#配置日志
|
||||
logs:
|
||||
|
|
|
|||
|
|
@ -143,16 +143,11 @@ func (v *Cmb) NotifyConsume(ctx context.Context, order *bo.OrderBo, orderOutRequ
|
|||
return err
|
||||
}
|
||||
|
||||
// todo 发起请求
|
||||
fmt.Print(orderNotify)
|
||||
|
||||
return nil
|
||||
x, err := v.CmbMixRepo.Request(ctx, request, v.bc.Cmb.NotifyUrl)
|
||||
if err != nil {
|
||||
return v.OrderNotifyRepo.Fail(ctx, orderNotify.ID, err.Error())
|
||||
}
|
||||
responses, _ := json.Marshal(x)
|
||||
|
||||
func (v *Cmb) notifySuccess(ctx context.Context, id uint64) error {
|
||||
return v.OrderNotifyRepo.Success(ctx, id, "")
|
||||
}
|
||||
|
||||
func (v *Cmb) notifyFail(ctx context.Context, id uint64, remark string) error {
|
||||
return v.OrderNotifyRepo.Fail(ctx, id, remark)
|
||||
return v.OrderNotifyRepo.Success(ctx, orderNotify.ID, string(responses))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,4 +12,5 @@ type CmbMixRepo interface {
|
|||
GetMockRequest(ctx context.Context, bizContent string) (*v1.CmbRequest, error)
|
||||
GetRequest(_ context.Context, reqBo *bo.CmbRequestBo) (*v1.CmbRequest, error)
|
||||
GetResponse(ctx context.Context, reqBo *bo.CmbResponseBo) (*v1.CmbReply, error)
|
||||
Request(ctx context.Context, req *v1.CmbRequest, uri string) (*v1.CmbReply, error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,12 +5,16 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
v1 "voucher/api/v1"
|
||||
"voucher/internal/biz/bo"
|
||||
"voucher/internal/biz/mixrepos"
|
||||
"voucher/internal/conf"
|
||||
"voucher/internal/pkg/cmb"
|
||||
"voucher/internal/pkg/helper"
|
||||
"voucher/internal/pkg/request"
|
||||
)
|
||||
|
||||
type CmbMixRepoImpl struct {
|
||||
|
|
@ -117,9 +121,7 @@ func (s *CmbMixRepoImpl) GetMockRequest(_ context.Context, bizContent string) (*
|
|||
Sign: "",
|
||||
}
|
||||
|
||||
str := cmb.SortStructStr(req)
|
||||
|
||||
sign, err := cmb.Sign(s.bc.Cmb.CmbSm2Pik, str)
|
||||
sign, err := cmb.Sign(s.bc.Cmb.CmbSm2Pik, cmb.SortStructStr(req))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -149,9 +151,7 @@ func (s *CmbMixRepoImpl) GetResponse(_ context.Context, reqBo *bo.CmbResponseBo)
|
|||
reply.EncryptBody = encryptBody
|
||||
}
|
||||
|
||||
str := cmb.SortStructStr(reply)
|
||||
|
||||
sign, err := cmb.Sign(s.bc.Cmb.CmbSm2Pik, str)
|
||||
sign, err := cmb.Sign(s.bc.Cmb.CmbSm2Pik, cmb.SortStructStr(reply))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -160,3 +160,30 @@ func (s *CmbMixRepoImpl) GetResponse(_ context.Context, reqBo *bo.CmbResponseBo)
|
|||
|
||||
return reply, nil
|
||||
}
|
||||
|
||||
func (s *CmbMixRepoImpl) Request(ctx context.Context, req *v1.CmbRequest, uri string) (*v1.CmbReply, error) {
|
||||
|
||||
kvRows := helper.SortStructFieldsByKey(req)
|
||||
|
||||
uv := url.Values{}
|
||||
|
||||
for _, kv := range kvRows {
|
||||
uv.Set(kv.Key, fmt.Sprintf("%v", kv.Value))
|
||||
}
|
||||
|
||||
h := http.Header{
|
||||
"Content-Type": []string{"application/x-www-form-urlencoded"},
|
||||
}
|
||||
|
||||
_, bodyBytes, err := request.Post(ctx, uri+"?"+uv.Encode(), nil, request.WithHeaders(h))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var response *v1.CmbReply
|
||||
if err = json.Unmarshal(bodyBytes, &response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue