cmb
This commit is contained in:
parent
5d639570a2
commit
87acc327b8
|
|
@ -1,13 +1,15 @@
|
|||
package bo
|
||||
|
||||
import "voucher/internal/biz/vo"
|
||||
|
||||
type CmbRequestBo struct {
|
||||
FuncName string
|
||||
FuncName vo.CmbFuncName
|
||||
BizContent string
|
||||
}
|
||||
|
||||
type CmbResponseBo struct {
|
||||
RespCode string
|
||||
RespMsg string
|
||||
FuncName string
|
||||
FuncName vo.CmbFuncName
|
||||
BizContent string
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ func (v *Cmb) NotifyConsume(ctx context.Context, order *bo.OrderBo, orderOutRequ
|
|||
}
|
||||
|
||||
request, err := v.CmbMixRepo.GetRequest(ctx, &bo.CmbRequestBo{
|
||||
FuncName: "updateCodeStatus.json",
|
||||
FuncName: vo.CmbNotifyFuncName,
|
||||
BizContent: string(bizJsonBytes),
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -4,11 +4,12 @@ import (
|
|||
"context"
|
||||
v1 "voucher/api/v1"
|
||||
"voucher/internal/biz/bo"
|
||||
"voucher/internal/biz/vo"
|
||||
)
|
||||
|
||||
type CmbMixRepo interface {
|
||||
OrderVerify(ctx context.Context, req *v1.CmbRequest, funcName string) (*v1.CmbOrderRequest, error)
|
||||
ProductQueryVerify(ctx context.Context, req *v1.CmbRequest, funcName string) (*v1.CmbQueryProductRequest, error)
|
||||
OrderVerify(ctx context.Context, req *v1.CmbRequest, funcName vo.CmbFuncName) (*v1.CmbOrderRequest, error)
|
||||
ProductQueryVerify(ctx context.Context, req *v1.CmbRequest, funcName vo.CmbFuncName) (*v1.CmbQueryProductRequest, error)
|
||||
GetRequest(ctx context.Context, reqBo *bo.CmbRequestBo) (*v1.CmbRequest, error)
|
||||
GetResponse(ctx context.Context, reqBo *bo.CmbResponseBo) (*v1.CmbReply, error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
package vo
|
||||
|
||||
type CmbFuncName string
|
||||
|
||||
const (
|
||||
CmbOrderFuncName CmbFuncName = "/voucher/cmb/v1/order"
|
||||
CmbProductQueryFuncName CmbFuncName = "/voucher/cmb/v1/product/query"
|
||||
CmbNotifyFuncName CmbFuncName = "updateCodeStatus.json"
|
||||
)
|
||||
|
||||
func (s CmbFuncName) GetValue() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
type CmbStatus string
|
||||
|
||||
const (
|
||||
CmbStatusSuccess CmbStatus = "0"
|
||||
CmbStatusUse CmbStatus = "1"
|
||||
)
|
||||
|
||||
func (s CmbStatus) GetValue() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
type CmbResponseStatus string
|
||||
|
||||
const (
|
||||
CmbResponseStatusSuccess CmbResponseStatus = "1000"
|
||||
CmbResponseStatusFail CmbResponseStatus = "1001"
|
||||
)
|
||||
|
||||
func (s CmbResponseStatus) GetValue() string {
|
||||
return string(s)
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
package vo
|
||||
|
||||
type CmbStatus string
|
||||
|
||||
const (
|
||||
CmbStatusSuccess CmbStatus = "0"
|
||||
CmbStatusUse CmbStatus = "1"
|
||||
)
|
||||
|
|
@ -8,6 +8,7 @@ import (
|
|||
v1 "voucher/api/v1"
|
||||
"voucher/internal/biz/bo"
|
||||
"voucher/internal/biz/mixrepos"
|
||||
"voucher/internal/biz/vo"
|
||||
"voucher/internal/conf"
|
||||
"voucher/internal/pkg/cmb"
|
||||
)
|
||||
|
|
@ -20,7 +21,7 @@ func NewCmbMixRepoImpl(bc *conf.Bootstrap) mixrepos.CmbMixRepo {
|
|||
return &CmbMixRepoImpl{bc: bc}
|
||||
}
|
||||
|
||||
func (s *CmbMixRepoImpl) OrderVerify(ctx context.Context, req *v1.CmbRequest, funcName string) (*v1.CmbOrderRequest, error) {
|
||||
func (s *CmbMixRepoImpl) OrderVerify(ctx context.Context, req *v1.CmbRequest, funcName vo.CmbFuncName) (*v1.CmbOrderRequest, error) {
|
||||
bizStr, err := s.Verify(ctx, req, funcName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -34,7 +35,7 @@ func (s *CmbMixRepoImpl) OrderVerify(ctx context.Context, req *v1.CmbRequest, fu
|
|||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *CmbMixRepoImpl) ProductQueryVerify(ctx context.Context, req *v1.CmbRequest, funcName string) (*v1.CmbQueryProductRequest, error) {
|
||||
func (s *CmbMixRepoImpl) ProductQueryVerify(ctx context.Context, req *v1.CmbRequest, funcName vo.CmbFuncName) (*v1.CmbQueryProductRequest, error) {
|
||||
bizStr, err := s.Verify(ctx, req, funcName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -48,8 +49,8 @@ func (s *CmbMixRepoImpl) ProductQueryVerify(ctx context.Context, req *v1.CmbRequ
|
|||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *CmbMixRepoImpl) Verify(_ context.Context, req *v1.CmbRequest, funcName string) (string, error) {
|
||||
str := cmb.SortStructStr(req, funcName)
|
||||
func (s *CmbMixRepoImpl) Verify(_ context.Context, req *v1.CmbRequest, funcName vo.CmbFuncName) (string, error) {
|
||||
str := cmb.SortStructStr(req, funcName.GetValue())
|
||||
|
||||
b, err := cmb.Verify(s.bc.Cmb.CmbSm2Puk, str, req.Sign)
|
||||
if err != nil {
|
||||
|
|
@ -88,7 +89,7 @@ func (s *CmbMixRepoImpl) GetRequest(_ context.Context, reqBo *bo.CmbRequestBo) (
|
|||
Sign: "",
|
||||
}
|
||||
|
||||
str := cmb.SortStructStr(req, reqBo.FuncName)
|
||||
str := cmb.SortStructStr(req, reqBo.FuncName.GetValue())
|
||||
|
||||
sing, err := cmb.Sign(s.bc.Cmb.CmbSm2Pik, str)
|
||||
if err != nil {
|
||||
|
|
@ -121,7 +122,7 @@ func (s *CmbMixRepoImpl) GetResponse(_ context.Context, reqBo *bo.CmbResponseBo)
|
|||
reply.EncryptBody = encryptBody
|
||||
}
|
||||
|
||||
str := cmb.SortStructStr(reply, reqBo.FuncName)
|
||||
str := cmb.SortStructStr(reply, reqBo.FuncName.GetValue())
|
||||
|
||||
sign, err := cmb.Sign(s.bc.Cmb.CmbSm2Pik, str)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -8,31 +8,27 @@ import (
|
|||
"voucher/internal/biz/vo"
|
||||
)
|
||||
|
||||
const (
|
||||
cmbOrderFuncName = "/voucher/cmb/v1/order"
|
||||
cmbProductQueryFuncName = "/voucher/cmb/v1/product/query"
|
||||
)
|
||||
|
||||
func (s *VoucherService) CmbOrder(ctx http.Context) error {
|
||||
|
||||
var (
|
||||
reply *v1.CmbReply
|
||||
err error
|
||||
)
|
||||
|
||||
bizReply, err := s.cmbOrder(ctx)
|
||||
if err != nil {
|
||||
reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{
|
||||
RespCode: "1001",
|
||||
RespCode: vo.CmbResponseStatusFail.GetValue(),
|
||||
RespMsg: err.Error(),
|
||||
FuncName: cmbOrderFuncName,
|
||||
FuncName: vo.CmbOrderFuncName,
|
||||
BizContent: "",
|
||||
})
|
||||
} else {
|
||||
replyBizContent, _ := json.Marshal(bizReply)
|
||||
reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{
|
||||
RespCode: "1000",
|
||||
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
||||
RespMsg: "成功",
|
||||
FuncName: cmbOrderFuncName,
|
||||
FuncName: vo.CmbOrderFuncName,
|
||||
BizContent: string(replyBizContent),
|
||||
})
|
||||
}
|
||||
|
|
@ -51,7 +47,7 @@ func (s *VoucherService) cmbOrder(ctx http.Context) (*v1.CmbOrderReply, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
bizContent, err := s.CmbMixRepo.OrderVerify(ctx, req, cmbOrderFuncName)
|
||||
bizContent, err := s.CmbMixRepo.OrderVerify(ctx, req, vo.CmbOrderFuncName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -78,20 +74,21 @@ func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
|
|||
reply *v1.CmbReply
|
||||
err error
|
||||
)
|
||||
|
||||
bizReply, err := s.cmbProductQuery(ctx)
|
||||
if err != nil {
|
||||
reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{
|
||||
RespCode: "1001",
|
||||
RespCode: vo.CmbResponseStatusFail.GetValue(),
|
||||
RespMsg: err.Error(),
|
||||
FuncName: cmbOrderFuncName,
|
||||
FuncName: vo.CmbOrderFuncName,
|
||||
BizContent: "",
|
||||
})
|
||||
} else {
|
||||
replyBizContent, _ := json.Marshal(bizReply)
|
||||
reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{
|
||||
RespCode: "1000",
|
||||
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
||||
RespMsg: "成功",
|
||||
FuncName: cmbOrderFuncName,
|
||||
FuncName: vo.CmbOrderFuncName,
|
||||
BizContent: string(replyBizContent),
|
||||
})
|
||||
}
|
||||
|
|
@ -109,7 +106,7 @@ func (s *VoucherService) cmbProductQuery(ctx http.Context) (*v1.CmbQueryProductR
|
|||
return nil, err
|
||||
}
|
||||
|
||||
bizContent, err := s.CmbMixRepo.ProductQueryVerify(ctx, req, cmbProductQueryFuncName)
|
||||
bizContent, err := s.CmbMixRepo.ProductQueryVerify(ctx, req, vo.CmbProductQueryFuncName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue