diff --git a/internal/biz/mixrepos/cmb.go b/internal/biz/mixrepos/cmb.go index 330d444..934f220 100644 --- a/internal/biz/mixrepos/cmb.go +++ b/internal/biz/mixrepos/cmb.go @@ -6,5 +6,5 @@ import ( ) type CmbMixRepo interface { - BuildRequest(ctx context.Context, bizJsonStr string) (*v1.CmbRequest, error) + BuildRequest(ctx context.Context, funcName, bizJsonStr string) (*v1.CmbRequest, error) } diff --git a/internal/data/mixrepoimpl/cmb.go b/internal/data/mixrepoimpl/cmb.go index 52d15a7..e8bc3ea 100644 --- a/internal/data/mixrepoimpl/cmb.go +++ b/internal/data/mixrepoimpl/cmb.go @@ -20,7 +20,7 @@ func NewCmbMixRepoImpl(bc *conf.Bootstrap) mixrepos.CmbMixRepo { 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 公钥加密 // 请求到我们这边 使用 我们的私钥解密 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)) } - 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) if err != nil { diff --git a/internal/server/http.go b/internal/server/http.go index 4940964..8125102 100644 --- a/internal/server/http.go +++ b/internal/server/http.go @@ -40,8 +40,8 @@ func NewHTTPServer( cmb.POST("/v1/orderMock", voucherService.CmbOrderMock) cmb.POST("/v1/order", voucherService.CmbOrder) - cmb.POST("/v1/product_query_mock", voucherService.CmbProductQueryMock) - cmb.POST("/v1/product_query", voucherService.CmbProductQuery) + cmb.POST("/v1/productQueryMock", voucherService.CmbProductQueryMock) + cmb.POST("/v1/productQuery", voucherService.CmbProductQuery) return srv } diff --git a/internal/service/cmb_mock.go b/internal/service/cmb_mock.go index a9a589f..d5082e1 100644 --- a/internal/service/cmb_mock.go +++ b/internal/service/cmb_mock.go @@ -20,7 +20,7 @@ func (s *VoucherService) CmbOrderMock(ctx http.Context) error { bizJsonStr := string(bizJsonBytes) - reply, err := s.CmbMixRepo.BuildRequest(ctx, bizJsonStr) + reply, err := s.CmbMixRepo.BuildRequest(ctx, "/voucher/cmb/v1/order", bizJsonStr) if err != nil { return err } @@ -30,16 +30,22 @@ func (s *VoucherService) CmbOrderMock(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 { return err } - if err := req.Validate(); err != nil { + bizJsonBytes, err := json.Marshal(req) + if err != nil { 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) }