cmb
This commit is contained in:
parent
e9e86d3fc5
commit
6fbd79f3a1
|
|
@ -6,5 +6,5 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type CmbMixRepo interface {
|
type CmbMixRepo interface {
|
||||||
BuildRequest(ctx context.Context, bizJsonStr string) (*v1.CmbRequest, error)
|
BuildRequest(ctx context.Context, funcName, bizJsonStr string) (*v1.CmbRequest, error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ func NewCmbMixRepoImpl(bc *conf.Bootstrap) mixrepos.CmbMixRepo {
|
||||||
return &CmbMixRepoImpl{bc: bc}
|
return &CmbMixRepoImpl{bc: bc}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *CmbMixRepoImpl) BuildRequest(_ context.Context, bizJsonStr string) (*v1.CmbRequest, error) {
|
func (s *CmbMixRepoImpl) BuildRequest(_ context.Context, funcName, bizJsonStr string) (*v1.CmbRequest, error) {
|
||||||
// 我们的sm2 公钥加密
|
// 我们的sm2 公钥加密
|
||||||
// 请求到我们这边 使用 我们的私钥解密
|
// 请求到我们这边 使用 我们的私钥解密
|
||||||
encryptBody, err := cmb.Encrypt(s.bc.Cmb.Sm2Puk, bizJsonStr)
|
encryptBody, err := cmb.Encrypt(s.bc.Cmb.Sm2Puk, bizJsonStr)
|
||||||
|
|
@ -54,7 +54,7 @@ func (s *CmbMixRepoImpl) BuildRequest(_ context.Context, bizJsonStr string) (*v1
|
||||||
strToBeSigned.WriteString(fmt.Sprintf("%s=%s&", kv.Key, kv.Value))
|
strToBeSigned.WriteString(fmt.Sprintf("%s=%s&", kv.Key, kv.Value))
|
||||||
}
|
}
|
||||||
|
|
||||||
str := fmt.Sprintf("/voucher/cmb/v1/order?%s", strings.TrimRight(strToBeSigned.String(), "&"))
|
str := fmt.Sprintf("%s?%s", funcName, strings.TrimRight(strToBeSigned.String(), "&"))
|
||||||
|
|
||||||
sing, err := cmb.Sign(s.bc.Cmb.CmbSm2Pik, str)
|
sing, err := cmb.Sign(s.bc.Cmb.CmbSm2Pik, str)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,8 @@ func NewHTTPServer(
|
||||||
cmb.POST("/v1/orderMock", voucherService.CmbOrderMock)
|
cmb.POST("/v1/orderMock", voucherService.CmbOrderMock)
|
||||||
cmb.POST("/v1/order", voucherService.CmbOrder)
|
cmb.POST("/v1/order", voucherService.CmbOrder)
|
||||||
|
|
||||||
cmb.POST("/v1/product_query_mock", voucherService.CmbProductQueryMock)
|
cmb.POST("/v1/productQueryMock", voucherService.CmbProductQueryMock)
|
||||||
cmb.POST("/v1/product_query", voucherService.CmbProductQuery)
|
cmb.POST("/v1/productQuery", voucherService.CmbProductQuery)
|
||||||
|
|
||||||
return srv
|
return srv
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ func (s *VoucherService) CmbOrderMock(ctx http.Context) error {
|
||||||
|
|
||||||
bizJsonStr := string(bizJsonBytes)
|
bizJsonStr := string(bizJsonBytes)
|
||||||
|
|
||||||
reply, err := s.CmbMixRepo.BuildRequest(ctx, bizJsonStr)
|
reply, err := s.CmbMixRepo.BuildRequest(ctx, "/voucher/cmb/v1/order", bizJsonStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -30,16 +30,22 @@ func (s *VoucherService) CmbOrderMock(ctx http.Context) error {
|
||||||
|
|
||||||
func (s *VoucherService) CmbProductQueryMock(ctx http.Context) error {
|
func (s *VoucherService) CmbProductQueryMock(ctx http.Context) error {
|
||||||
|
|
||||||
var req v1.CmbQueryProductRequest
|
var req *v1.CmbQueryProductRequest
|
||||||
if err := ctx.BindForm(&req); err != nil {
|
if err := ctx.BindForm(&req); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := req.Validate(); err != nil {
|
bizJsonBytes, err := json.Marshal(req)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
reply := &v1.CmbRequest{}
|
bizJsonStr := string(bizJsonBytes)
|
||||||
|
|
||||||
|
reply, err := s.CmbMixRepo.BuildRequest(ctx, "/voucher/cmb/v1/productQuery", bizJsonStr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return ctx.JSON(200, reply)
|
return ctx.JSON(200, reply)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue