This commit is contained in:
李子铭 2025-03-06 10:42:47 +08:00
parent 5d639570a2
commit 87acc327b8
7 changed files with 62 additions and 34 deletions

View File

@ -1,13 +1,15 @@
package bo package bo
import "voucher/internal/biz/vo"
type CmbRequestBo struct { type CmbRequestBo struct {
FuncName string FuncName vo.CmbFuncName
BizContent string BizContent string
} }
type CmbResponseBo struct { type CmbResponseBo struct {
RespCode string RespCode string
RespMsg string RespMsg string
FuncName string FuncName vo.CmbFuncName
BizContent string BizContent string
} }

View File

@ -108,7 +108,7 @@ func (v *Cmb) NotifyConsume(ctx context.Context, order *bo.OrderBo, orderOutRequ
} }
request, err := v.CmbMixRepo.GetRequest(ctx, &bo.CmbRequestBo{ request, err := v.CmbMixRepo.GetRequest(ctx, &bo.CmbRequestBo{
FuncName: "updateCodeStatus.json", FuncName: vo.CmbNotifyFuncName,
BizContent: string(bizJsonBytes), BizContent: string(bizJsonBytes),
}) })
if err != nil { if err != nil {

View File

@ -4,11 +4,12 @@ import (
"context" "context"
v1 "voucher/api/v1" v1 "voucher/api/v1"
"voucher/internal/biz/bo" "voucher/internal/biz/bo"
"voucher/internal/biz/vo"
) )
type CmbMixRepo interface { type CmbMixRepo interface {
OrderVerify(ctx context.Context, req *v1.CmbRequest, funcName string) (*v1.CmbOrderRequest, error) OrderVerify(ctx context.Context, req *v1.CmbRequest, funcName vo.CmbFuncName) (*v1.CmbOrderRequest, error)
ProductQueryVerify(ctx context.Context, req *v1.CmbRequest, funcName string) (*v1.CmbQueryProductRequest, error) ProductQueryVerify(ctx context.Context, req *v1.CmbRequest, funcName vo.CmbFuncName) (*v1.CmbQueryProductRequest, error)
GetRequest(ctx context.Context, reqBo *bo.CmbRequestBo) (*v1.CmbRequest, error) GetRequest(ctx 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)
} }

35
internal/biz/vo/cmb.go Normal file
View File

@ -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)
}

View File

@ -1,8 +0,0 @@
package vo
type CmbStatus string
const (
CmbStatusSuccess CmbStatus = "0"
CmbStatusUse CmbStatus = "1"
)

View File

@ -8,6 +8,7 @@ import (
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/biz/vo"
"voucher/internal/conf" "voucher/internal/conf"
"voucher/internal/pkg/cmb" "voucher/internal/pkg/cmb"
) )
@ -20,7 +21,7 @@ func NewCmbMixRepoImpl(bc *conf.Bootstrap) mixrepos.CmbMixRepo {
return &CmbMixRepoImpl{bc: bc} 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) bizStr, err := s.Verify(ctx, req, funcName)
if err != nil { if err != nil {
return nil, err return nil, err
@ -34,7 +35,7 @@ func (s *CmbMixRepoImpl) OrderVerify(ctx context.Context, req *v1.CmbRequest, fu
return resp, nil 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) bizStr, err := s.Verify(ctx, req, funcName)
if err != nil { if err != nil {
return nil, err return nil, err
@ -48,8 +49,8 @@ func (s *CmbMixRepoImpl) ProductQueryVerify(ctx context.Context, req *v1.CmbRequ
return resp, nil return resp, nil
} }
func (s *CmbMixRepoImpl) Verify(_ context.Context, req *v1.CmbRequest, funcName string) (string, error) { func (s *CmbMixRepoImpl) Verify(_ context.Context, req *v1.CmbRequest, funcName vo.CmbFuncName) (string, error) {
str := cmb.SortStructStr(req, funcName) str := cmb.SortStructStr(req, funcName.GetValue())
b, err := cmb.Verify(s.bc.Cmb.CmbSm2Puk, str, req.Sign) b, err := cmb.Verify(s.bc.Cmb.CmbSm2Puk, str, req.Sign)
if err != nil { if err != nil {
@ -88,7 +89,7 @@ func (s *CmbMixRepoImpl) GetRequest(_ context.Context, reqBo *bo.CmbRequestBo) (
Sign: "", Sign: "",
} }
str := cmb.SortStructStr(req, reqBo.FuncName) str := cmb.SortStructStr(req, reqBo.FuncName.GetValue())
sing, err := cmb.Sign(s.bc.Cmb.CmbSm2Pik, str) sing, err := cmb.Sign(s.bc.Cmb.CmbSm2Pik, str)
if err != nil { if err != nil {
@ -121,7 +122,7 @@ func (s *CmbMixRepoImpl) GetResponse(_ context.Context, reqBo *bo.CmbResponseBo)
reply.EncryptBody = encryptBody 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) sign, err := cmb.Sign(s.bc.Cmb.CmbSm2Pik, str)
if err != nil { if err != nil {

View File

@ -8,31 +8,27 @@ import (
"voucher/internal/biz/vo" "voucher/internal/biz/vo"
) )
const (
cmbOrderFuncName = "/voucher/cmb/v1/order"
cmbProductQueryFuncName = "/voucher/cmb/v1/product/query"
)
func (s *VoucherService) CmbOrder(ctx http.Context) error { func (s *VoucherService) CmbOrder(ctx http.Context) error {
var ( var (
reply *v1.CmbReply reply *v1.CmbReply
err error err error
) )
bizReply, err := s.cmbOrder(ctx) bizReply, err := s.cmbOrder(ctx)
if err != nil { if err != nil {
reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{ reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{
RespCode: "1001", RespCode: vo.CmbResponseStatusFail.GetValue(),
RespMsg: err.Error(), RespMsg: err.Error(),
FuncName: cmbOrderFuncName, FuncName: vo.CmbOrderFuncName,
BizContent: "", BizContent: "",
}) })
} else { } else {
replyBizContent, _ := json.Marshal(bizReply) replyBizContent, _ := json.Marshal(bizReply)
reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{ reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{
RespCode: "1000", RespCode: vo.CmbResponseStatusSuccess.GetValue(),
RespMsg: "成功", RespMsg: "成功",
FuncName: cmbOrderFuncName, FuncName: vo.CmbOrderFuncName,
BizContent: string(replyBizContent), BizContent: string(replyBizContent),
}) })
} }
@ -51,7 +47,7 @@ func (s *VoucherService) cmbOrder(ctx http.Context) (*v1.CmbOrderReply, error) {
return nil, err return nil, err
} }
bizContent, err := s.CmbMixRepo.OrderVerify(ctx, req, cmbOrderFuncName) bizContent, err := s.CmbMixRepo.OrderVerify(ctx, req, vo.CmbOrderFuncName)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -78,20 +74,21 @@ func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
reply *v1.CmbReply reply *v1.CmbReply
err error err error
) )
bizReply, err := s.cmbProductQuery(ctx) bizReply, err := s.cmbProductQuery(ctx)
if err != nil { if err != nil {
reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{ reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{
RespCode: "1001", RespCode: vo.CmbResponseStatusFail.GetValue(),
RespMsg: err.Error(), RespMsg: err.Error(),
FuncName: cmbOrderFuncName, FuncName: vo.CmbOrderFuncName,
BizContent: "", BizContent: "",
}) })
} else { } else {
replyBizContent, _ := json.Marshal(bizReply) replyBizContent, _ := json.Marshal(bizReply)
reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{ reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{
RespCode: "1000", RespCode: vo.CmbResponseStatusSuccess.GetValue(),
RespMsg: "成功", RespMsg: "成功",
FuncName: cmbOrderFuncName, FuncName: vo.CmbOrderFuncName,
BizContent: string(replyBizContent), BizContent: string(replyBizContent),
}) })
} }
@ -109,7 +106,7 @@ func (s *VoucherService) cmbProductQuery(ctx http.Context) (*v1.CmbQueryProductR
return nil, err return nil, err
} }
bizContent, err := s.CmbMixRepo.ProductQueryVerify(ctx, req, cmbProductQueryFuncName) bizContent, err := s.CmbMixRepo.ProductQueryVerify(ctx, req, vo.CmbProductQueryFuncName)
if err != nil { if err != nil {
return nil, err return nil, err
} }