cmb
This commit is contained in:
parent
9d22d81cce
commit
f04ad17edb
|
|
@ -10,6 +10,5 @@ type CmbRequestBo struct {
|
||||||
type CmbResponseBo struct {
|
type CmbResponseBo struct {
|
||||||
RespCode string
|
RespCode string
|
||||||
RespMsg string
|
RespMsg string
|
||||||
FuncName vo.CmbFuncName
|
|
||||||
BizContent string
|
BizContent string
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
v1 "voucher/api/v1"
|
v1 "voucher/api/v1"
|
||||||
"voucher/internal/biz/bo"
|
"voucher/internal/biz/bo"
|
||||||
|
|
@ -50,7 +51,7 @@ func (s *CmbMixRepoImpl) ProductQueryVerify(ctx context.Context, req *v1.CmbRequ
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *CmbMixRepoImpl) Verify(_ context.Context, req *v1.CmbRequest, funcName vo.CmbFuncName) (string, error) {
|
func (s *CmbMixRepoImpl) Verify(_ context.Context, req *v1.CmbRequest, funcName vo.CmbFuncName) (string, error) {
|
||||||
str := cmb.SortStructStr(req, funcName.GetValue())
|
str := cmb.SortStructStr(req)
|
||||||
|
|
||||||
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 {
|
||||||
|
|
@ -87,7 +88,11 @@ func (s *CmbMixRepoImpl) GetRequest(_ context.Context, reqBo *bo.CmbRequestBo) (
|
||||||
Sign: "",
|
Sign: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
str := cmb.SortStructStr(req, reqBo.FuncName.GetValue())
|
str := cmb.SortStructStr(req)
|
||||||
|
|
||||||
|
if len(reqBo.FuncName) > 0 {
|
||||||
|
str = fmt.Sprintf("%s?%s", reqBo.FuncName, str)
|
||||||
|
}
|
||||||
|
|
||||||
sing, err := cmb.Sign(s.bc.Cmb.CmbSm2Pik, str)
|
sing, err := cmb.Sign(s.bc.Cmb.CmbSm2Pik, str)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -119,7 +124,7 @@ func (s *CmbMixRepoImpl) GetResponse(_ context.Context, reqBo *bo.CmbResponseBo)
|
||||||
reply.EncryptBody = encryptBody
|
reply.EncryptBody = encryptBody
|
||||||
}
|
}
|
||||||
|
|
||||||
str := cmb.SortStructStr(reply, reqBo.FuncName.GetValue())
|
str := cmb.SortStructStr(reply)
|
||||||
|
|
||||||
sign, err := cmb.Sign(s.bc.Cmb.CmbSm2Pik, str)
|
sign, err := cmb.Sign(s.bc.Cmb.CmbSm2Pik, str)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ func AssemblingByteArray(key, iv []byte) []byte {
|
||||||
return os
|
return os
|
||||||
}
|
}
|
||||||
|
|
||||||
func SortStructStr(req interface{}, funcName string) string {
|
func SortStructStr(req interface{}) string {
|
||||||
kvRows := helper.SortStructFieldsByKey(req)
|
kvRows := helper.SortStructFieldsByKey(req)
|
||||||
|
|
||||||
var strToBeSigned strings.Builder
|
var strToBeSigned strings.Builder
|
||||||
|
|
@ -78,5 +78,5 @@ func SortStructStr(req interface{}, funcName string) string {
|
||||||
strToBeSigned.WriteString(fmt.Sprintf("%s=%s&", kv.Key, kv.Value))
|
strToBeSigned.WriteString(fmt.Sprintf("%s=%s&", kv.Key, kv.Value))
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%s?%s", funcName, strings.TrimRight(strToBeSigned.String(), "&"))
|
return strings.TrimRight(strToBeSigned.String(), "&")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,12 @@ func NewHTTPServer(
|
||||||
//构建 server
|
//构建 server
|
||||||
srv := buildHTTPServer(c, accessLogger, log)
|
srv := buildHTTPServer(c, accessLogger, log)
|
||||||
|
|
||||||
srv.Route("/").GET("/ping", func(ctx http.Context) error {
|
r := srv.Route("/voucher")
|
||||||
|
|
||||||
|
r.GET("/ping", func(ctx http.Context) error {
|
||||||
return ctx.String(http2.StatusOK, "pong")
|
return ctx.String(http2.StatusOK, "pong")
|
||||||
})
|
})
|
||||||
|
|
||||||
r := srv.Route("/voucher")
|
|
||||||
r.POST("/v1/wechat/notify", voucherService.WechatNotify)
|
r.POST("/v1/wechat/notify", voucherService.WechatNotify)
|
||||||
|
|
||||||
cmb := r.Group("/cmb")
|
cmb := r.Group("/cmb")
|
||||||
|
|
|
||||||
|
|
@ -17,20 +17,24 @@ func (s *VoucherService) CmbOrder(ctx http.Context) 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(
|
||||||
RespCode: vo.CmbResponseStatusFail.GetValue(),
|
ctx,
|
||||||
RespMsg: err.Error(),
|
&bo.CmbResponseBo{
|
||||||
FuncName: vo.CmbOrderFuncName,
|
RespCode: vo.CmbResponseStatusFail.GetValue(),
|
||||||
BizContent: "",
|
RespMsg: err.Error(),
|
||||||
})
|
BizContent: "",
|
||||||
|
},
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
replyBizContent, _ := json.Marshal(bizReply)
|
replyBizContent, _ := json.Marshal(bizReply)
|
||||||
reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{
|
reply, err = s.CmbMixRepo.GetResponse(
|
||||||
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
ctx,
|
||||||
RespMsg: "成功",
|
&bo.CmbResponseBo{
|
||||||
FuncName: vo.CmbOrderFuncName,
|
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
||||||
BizContent: string(replyBizContent),
|
RespMsg: "成功",
|
||||||
})
|
BizContent: string(replyBizContent),
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.JSON(200, reply)
|
return ctx.JSON(200, reply)
|
||||||
|
|
@ -79,20 +83,23 @@ func (s *VoucherService) CmbProductQuery(ctx http.Context) 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(
|
||||||
RespCode: vo.CmbResponseStatusFail.GetValue(),
|
ctx,
|
||||||
RespMsg: err.Error(),
|
&bo.CmbResponseBo{
|
||||||
FuncName: vo.CmbOrderFuncName,
|
RespCode: vo.CmbResponseStatusFail.GetValue(),
|
||||||
BizContent: "",
|
RespMsg: err.Error(),
|
||||||
})
|
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,
|
||||||
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
&bo.CmbResponseBo{
|
||||||
RespMsg: "成功",
|
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
||||||
FuncName: vo.CmbOrderFuncName,
|
RespMsg: "成功",
|
||||||
BizContent: string(replyBizContent),
|
BizContent: string(replyBizContent),
|
||||||
})
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.JSON(200, reply)
|
return ctx.JSON(200, reply)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue