cmb
This commit is contained in:
parent
159fece2dd
commit
73ce021b25
|
|
@ -56,7 +56,7 @@ cmb:
|
||||||
keyAlias: "CO_PUB_KEY_SM2"
|
keyAlias: "CO_PUB_KEY_SM2"
|
||||||
cmbKeyAlias: "SM2_CMBLIFE"
|
cmbKeyAlias: "SM2_CMBLIFE"
|
||||||
orgNo: "orgNo" # 发码机构号,固定值,掌上生活优惠券系统提供
|
orgNo: "orgNo" # 发码机构号,固定值,掌上生活优惠券系统提供
|
||||||
notifyUrl: "https://gateway.dev.cdlsxd.cn/ymt/jd/v1/notify"
|
notifyUrl: "https://sandbox.cdcc.cmbchina.com/AccessGateway/transIn/updateCodeStatus.json" # 招行测试回调地址
|
||||||
|
|
||||||
#配置日志
|
#配置日志
|
||||||
logs:
|
logs:
|
||||||
|
|
|
||||||
|
|
@ -143,16 +143,11 @@ func (v *Cmb) NotifyConsume(ctx context.Context, order *bo.OrderBo, orderOutRequ
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo 发起请求
|
x, err := v.CmbMixRepo.Request(ctx, request, v.bc.Cmb.NotifyUrl)
|
||||||
fmt.Print(orderNotify)
|
if err != nil {
|
||||||
|
return v.OrderNotifyRepo.Fail(ctx, orderNotify.ID, err.Error())
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
responses, _ := json.Marshal(x)
|
||||||
|
|
||||||
func (v *Cmb) notifySuccess(ctx context.Context, id uint64) error {
|
return v.OrderNotifyRepo.Success(ctx, orderNotify.ID, string(responses))
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,4 +12,5 @@ type CmbMixRepo interface {
|
||||||
GetMockRequest(ctx context.Context, bizContent string) (*v1.CmbRequest, error)
|
GetMockRequest(ctx context.Context, bizContent string) (*v1.CmbRequest, error)
|
||||||
GetRequest(_ context.Context, reqBo *bo.CmbRequestBo) (*v1.CmbRequest, error)
|
GetRequest(_ context.Context, reqBo *bo.CmbRequestBo) (*v1.CmbRequest, error)
|
||||||
GetResponse(ctx context.Context, reqBo *bo.CmbResponseBo) (*v1.CmbReply, 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"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
v1 "voucher/api/v1"
|
v1 "voucher/api/v1"
|
||||||
"voucher/internal/biz/bo"
|
"voucher/internal/biz/bo"
|
||||||
"voucher/internal/biz/mixrepos"
|
"voucher/internal/biz/mixrepos"
|
||||||
"voucher/internal/conf"
|
"voucher/internal/conf"
|
||||||
"voucher/internal/pkg/cmb"
|
"voucher/internal/pkg/cmb"
|
||||||
|
"voucher/internal/pkg/helper"
|
||||||
|
"voucher/internal/pkg/request"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CmbMixRepoImpl struct {
|
type CmbMixRepoImpl struct {
|
||||||
|
|
@ -117,9 +121,7 @@ func (s *CmbMixRepoImpl) GetMockRequest(_ context.Context, bizContent string) (*
|
||||||
Sign: "",
|
Sign: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
str := cmb.SortStructStr(req)
|
sign, err := cmb.Sign(s.bc.Cmb.CmbSm2Pik, cmb.SortStructStr(req))
|
||||||
|
|
||||||
sign, err := cmb.Sign(s.bc.Cmb.CmbSm2Pik, str)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -149,9 +151,7 @@ func (s *CmbMixRepoImpl) GetResponse(_ context.Context, reqBo *bo.CmbResponseBo)
|
||||||
reply.EncryptBody = encryptBody
|
reply.EncryptBody = encryptBody
|
||||||
}
|
}
|
||||||
|
|
||||||
str := cmb.SortStructStr(reply)
|
sign, err := cmb.Sign(s.bc.Cmb.CmbSm2Pik, cmb.SortStructStr(reply))
|
||||||
|
|
||||||
sign, err := cmb.Sign(s.bc.Cmb.CmbSm2Pik, str)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -160,3 +160,30 @@ func (s *CmbMixRepoImpl) GetResponse(_ context.Context, reqBo *bo.CmbResponseBo)
|
||||||
|
|
||||||
return reply, nil
|
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