cmb
This commit is contained in:
parent
549f24da52
commit
d382acfd2d
|
|
@ -7,21 +7,21 @@ import "validate/validate.proto";
|
||||||
message CmbRequest {
|
message CmbRequest {
|
||||||
// 请求公共参数
|
// 请求公共参数
|
||||||
// 合作方唯一ID,32位定长
|
// 合作方唯一ID,32位定长
|
||||||
string mid = 1 [json_name = "mid", (validate.rules).string = {min_len: 1,max_len: 32}];
|
string mid = 1 [json_name = "mid", (validate.rules).string = {min_len: 1,max_len: 100}];
|
||||||
// 应用唯一ID,32位定长
|
// 应用唯一ID,32位定长
|
||||||
string aid = 2 [json_name = "aid", (validate.rules).string = {min_len: 1,max_len: 32}];
|
string aid = 2 [json_name = "aid", (validate.rules).string = {min_len: 1,max_len: 100}];
|
||||||
// 时间戳 yyyyMMddHHmmss
|
// 时间戳 yyyyMMddHHmmss
|
||||||
string date = 3 [json_name = "date", (validate.rules).string = {min_len: 14}];
|
string date = 3 [json_name = "date", (validate.rules).string = {min_len: 14}];
|
||||||
// 随机字符串,保证签名不可预测,不长于32位
|
// 随机字符串,保证签名不可预测,不长于32位
|
||||||
string random = 4 [json_name = "random", (validate.rules).string = {min_len: 1,max_len: 32}];
|
string random = 4 [json_name = "random", (validate.rules).string = {min_len: 1,max_len: 50}];
|
||||||
// 合作方密钥对别名
|
// 合作方密钥对别名
|
||||||
string keyAlias = 5 [json_name = "keyAlias", (validate.rules).string = {min_len: 2}];
|
string keyAlias = 5 [json_name = "keyAlias", (validate.rules).string = {min_len: 2,max_len: 50}];
|
||||||
// 掌上生活密钥对别名
|
// 掌上生活密钥对别名
|
||||||
string cmbKeyAlias = 6 [json_name = "cmbKeyAlias", (validate.rules).string = {min_len: 2}];
|
string cmbKeyAlias = 6 [json_name = "cmbKeyAlias", (validate.rules).string = {min_len: 2,max_len: 50}];
|
||||||
// 加密报文,是否需要加密,请查看各API的说明文档
|
// 加密报文,是否需要加密,请查看各API的说明文档
|
||||||
string encryptBody = 7 [json_name = "encryptBody", (validate.rules).string = {min_len: 10}];
|
string encryptBody = 7 [json_name = "encryptBody", (validate.rules).string = {min_len: 10,max_len: 20000}];
|
||||||
// 签名,具体详见签名规范
|
// 签名,具体详见签名规范
|
||||||
string sign = 8 [json_name = "sign", (validate.rules).string = {min_len: 10}];
|
string sign = 8 [json_name = "sign", (validate.rules).string = {min_len: 10,max_len: 5000}];
|
||||||
}
|
}
|
||||||
|
|
||||||
message CmbReply {
|
message CmbReply {
|
||||||
|
|
@ -50,13 +50,13 @@ message CmbOrderRequest {
|
||||||
// 外部合作方权益批次号
|
// 外部合作方权益批次号
|
||||||
string activityId = 10 [json_name = "activityId", (validate.rules).string = {min_len: 1,max_len: 32}];
|
string activityId = 10 [json_name = "activityId", (validate.rules).string = {min_len: 1,max_len: 32}];
|
||||||
// 招商银行用户号 用户标识,比如手机号、支付宝openId
|
// 招商银行用户号 用户标识,比如手机号、支付宝openId
|
||||||
string cmbUid = 11 [json_name = "cmbUid", (validate.rules).string = {min_len: 1,max_len: 100}];
|
string cmbUid = 11 [json_name = "cmbUid", (validate.rules).string = {min_len: 1,max_len: 50}];
|
||||||
// 应用id
|
// 应用id
|
||||||
string appId = 14 [json_name = "appId", (validate.rules).string = {min_len: 1,max_len: 50}];
|
string appId = 14 [json_name = "appId", (validate.rules).string = {min_len: 1,max_len: 20}];
|
||||||
// 用户标识类型,0-手机号,1-支付宝openId
|
// 用户标识类型,0-手机号,1-支付宝openId
|
||||||
string cmbUidType = 12 [json_name = "cmbUidType", (validate.rules).string = {min_len: 1,max_len: 10}];
|
string cmbUidType = 12 [json_name = "cmbUidType", (validate.rules).string = {min_len: 1,max_len: 10}];
|
||||||
// 时间戳,长度为13位,精度为毫秒
|
// 时间戳,长度为13位,精度为毫秒
|
||||||
string timestamp = 13 [json_name = "timestamp", (validate.rules).string = {min_len: 1,max_len: 20}];
|
string timestamp = 13 [json_name = "timestamp", (validate.rules).string = {min_len: 1,max_len: 14}];
|
||||||
}
|
}
|
||||||
message CmbOrderReply {
|
message CmbOrderReply {
|
||||||
// 接口调用返回码,1000 成功,1001 失败
|
// 接口调用返回码,1000 成功,1001 失败
|
||||||
|
|
@ -129,4 +129,12 @@ message CmbNotifyReply {
|
||||||
string respCode = 1 [json_name = "respCode"];
|
string respCode = 1 [json_name = "respCode"];
|
||||||
// 返回信息,失败信息落此字段
|
// 返回信息,失败信息落此字段
|
||||||
string respMsg = 2 [json_name = "respMsg"];
|
string respMsg = 2 [json_name = "respMsg"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
message EncryptBody {
|
||||||
|
string encryptBody = 1 [json_name = "encryptBody"];
|
||||||
|
}
|
||||||
|
message DecryptBody {
|
||||||
|
string decryptBody = 1 [json_name = "decryptBody"];
|
||||||
}
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ server:
|
||||||
data:
|
data:
|
||||||
db:
|
db:
|
||||||
driver: mysql
|
driver: mysql
|
||||||
source: root:lansexiongdi6,@tcp(47.97.27.195:3306)/merketing?parseTime=True&loc=Local
|
source: root:lansexiongdi6,@tcp(47.97.27.195:3306)/voucher?parseTime=True&loc=Local
|
||||||
maxIdle: 5 #最大的空闲连接数
|
maxIdle: 5 #最大的空闲连接数
|
||||||
maxOpen: 100 #最大连接数,0表示不受限制
|
maxOpen: 100 #最大连接数,0表示不受限制
|
||||||
maxLifetime: 5s #连接复用的最大生命周期
|
maxLifetime: 5s #连接复用的最大生命周期
|
||||||
|
|
|
||||||
|
|
@ -15,4 +15,5 @@ type CmbMixRepo interface {
|
||||||
GetRequest(_ context.Context, reqBo *bo.CmbRequestBo) (*v1.CmbRequest, error)
|
GetRequest(_ 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)
|
||||||
Request(ctx context.Context, req *v1.CmbRequest, uri string) (*v1.CmbReply, error)
|
Request(ctx context.Context, req *v1.CmbRequest, uri string) (*v1.CmbReply, error)
|
||||||
|
Decrypt(_ context.Context, encryptBody string) (string, error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -221,3 +221,13 @@ func (s *CmbMixRepoImpl) Request(ctx context.Context, req *v1.CmbRequest, uri st
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *CmbMixRepoImpl) Decrypt(_ context.Context, encryptBody string) (string, error) {
|
||||||
|
|
||||||
|
encryptBody, err := cmb.Decrypt(s.bc.Cmb.Sm2Prk, encryptBody)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return encryptBody, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ type OrderRepoImpl struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOrderRepoImpl .
|
// NewOrderRepoImpl .
|
||||||
func NewOrderRepoImpl() repo.OrderRepo {
|
func NewOrderRepoImpl(db *data.Db) repo.OrderRepo {
|
||||||
return &OrderRepoImpl{}
|
return &OrderRepoImpl{db: db}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *OrderRepoImpl) DB(ctx context.Context) *gorm.DB {
|
func (p *OrderRepoImpl) DB(ctx context.Context) *gorm.DB {
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@ type OrderNotifyRepoImpl struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOrderNotifyRepoImpl .
|
// NewOrderNotifyRepoImpl .
|
||||||
func NewOrderNotifyRepoImpl() repo.OrderNotifyRepo {
|
func NewOrderNotifyRepoImpl(db *data.Db) repo.OrderNotifyRepo {
|
||||||
return &OrderNotifyRepoImpl{}
|
return &OrderNotifyRepoImpl{db: db}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *OrderNotifyRepoImpl) DB(ctx context.Context) *gorm.DB {
|
func (p *OrderNotifyRepoImpl) DB(ctx context.Context) *gorm.DB {
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@ type OrderWechatRepoImpl struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOrderWechatRepoImpl .
|
// NewOrderWechatRepoImpl .
|
||||||
func NewOrderWechatRepoImpl() repo.OrderWechatRepo {
|
func NewOrderWechatRepoImpl(db *data.Db) repo.OrderWechatRepo {
|
||||||
return &OrderWechatRepoImpl{}
|
return &OrderWechatRepoImpl{db: db}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *OrderWechatRepoImpl) DB(ctx context.Context) *gorm.DB {
|
func (p *OrderWechatRepoImpl) DB(ctx context.Context) *gorm.DB {
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ type ProductRepoImpl struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewProductRepoImpl .
|
// NewProductRepoImpl .
|
||||||
func NewProductRepoImpl() repo.ProductRepo {
|
func NewProductRepoImpl(db *data.Db) repo.ProductRepo {
|
||||||
return &ProductRepoImpl{}
|
return &ProductRepoImpl{db: db}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProductRepoImpl) DB(ctx context.Context) *gorm.DB {
|
func (p *ProductRepoImpl) DB(ctx context.Context) *gorm.DB {
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@ type WechatNotifyRegisterTagRepoImpl struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWechatNotifyRegisterTagRepoImpl .
|
// NewWechatNotifyRegisterTagRepoImpl .
|
||||||
func NewWechatNotifyRegisterTagRepoImpl() repo.WechatNotifyRegisterTagRepo {
|
func NewWechatNotifyRegisterTagRepoImpl(db *data.Db) repo.WechatNotifyRegisterTagRepo {
|
||||||
return &WechatNotifyRegisterTagRepoImpl{}
|
return &WechatNotifyRegisterTagRepoImpl{db: db}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *WechatNotifyRegisterTagRepoImpl) DB(ctx context.Context) *gorm.DB {
|
func (p *WechatNotifyRegisterTagRepoImpl) DB(ctx context.Context) *gorm.DB {
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,8 @@ func NewHTTPServer(
|
||||||
cmb.POST("/v1/product/QueryMock", voucherService.CmbProductQueryMock)
|
cmb.POST("/v1/product/QueryMock", voucherService.CmbProductQueryMock)
|
||||||
cmb.POST("/v1/product/query", voucherService.CmbProductQuery)
|
cmb.POST("/v1/product/query", voucherService.CmbProductQuery)
|
||||||
|
|
||||||
|
cmb.POST("/v1/decryptBody", voucherService.DecryptBody)
|
||||||
|
|
||||||
return srv
|
return srv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/go-kratos/kratos/v2/log"
|
"github.com/go-kratos/kratos/v2/log"
|
||||||
"github.com/go-kratos/kratos/v2/transport/http"
|
"github.com/go-kratos/kratos/v2/transport/http"
|
||||||
|
"io"
|
||||||
v1 "voucher/api/v1"
|
v1 "voucher/api/v1"
|
||||||
"voucher/internal/biz/bo"
|
"voucher/internal/biz/bo"
|
||||||
"voucher/internal/biz/vo"
|
"voucher/internal/biz/vo"
|
||||||
|
|
@ -20,10 +21,11 @@ func (s *VoucherService) CmbOrder(ctx http.Context) error {
|
||||||
orderNo, err := s.cmbOrder(ctx)
|
orderNo, err := s.cmbOrder(ctx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Errorf("cmbOrder error: %v", err)
|
||||||
bizReply = &v1.CmbOrderReply{
|
bizReply = &v1.CmbOrderReply{
|
||||||
RespCode: vo.CmbResponseStatusFail.GetValue(),
|
RespCode: vo.CmbResponseStatusFail.GetValue(),
|
||||||
RespMsg: err.Error(),
|
RespMsg: err.Error(),
|
||||||
CodeNo: orderNo,
|
CodeNo: "",
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bizReply = &v1.CmbOrderReply{
|
bizReply = &v1.CmbOrderReply{
|
||||||
|
|
@ -36,13 +38,14 @@ func (s *VoucherService) CmbOrder(ctx http.Context) error {
|
||||||
replyBizContent, _ := json.Marshal(bizReply)
|
replyBizContent, _ := json.Marshal(bizReply)
|
||||||
xx := &bo.CmbResponseBo{
|
xx := &bo.CmbResponseBo{
|
||||||
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
||||||
RespMsg: err.Error(),
|
RespMsg: "成功",
|
||||||
BizContent: string(replyBizContent),
|
BizContent: string(replyBizContent),
|
||||||
}
|
}
|
||||||
|
|
||||||
reply, err = s.CmbMixRepo.GetResponse(ctx, xx)
|
reply, err = s.CmbMixRepo.GetResponse(ctx, xx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("cmbOrder CmbMixRepo GetResponse error: %v", err)
|
log.Errorf("cmbOrder CmbMixRepo GetResponse error: %v", err)
|
||||||
|
return ctx.JSON(400, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.JSON(200, reply)
|
return ctx.JSON(200, reply)
|
||||||
|
|
@ -51,11 +54,17 @@ func (s *VoucherService) CmbOrder(ctx http.Context) error {
|
||||||
func (s *VoucherService) cmbOrder(ctx http.Context) (string, error) {
|
func (s *VoucherService) cmbOrder(ctx http.Context) (string, error) {
|
||||||
|
|
||||||
var req *v1.CmbRequest
|
var req *v1.CmbRequest
|
||||||
if err := ctx.BindForm(&req); err != nil {
|
|
||||||
|
bodyBytes, err := io.ReadAll(ctx.Request().Body)
|
||||||
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := req.Validate(); err != nil {
|
if err = json.Unmarshal(bodyBytes, &req); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = req.Validate(); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,6 +112,7 @@ func (s *VoucherService) CmbQuery(ctx http.Context) error {
|
||||||
reply, err = s.CmbMixRepo.GetResponse(ctx, xx)
|
reply, err = s.CmbMixRepo.GetResponse(ctx, xx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("cmbProductQuery CmbMixRepo GetResponse error: %v", err)
|
log.Errorf("cmbProductQuery CmbMixRepo GetResponse error: %v", err)
|
||||||
|
return ctx.JSON(400, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.JSON(200, reply)
|
return ctx.JSON(200, reply)
|
||||||
|
|
@ -110,12 +120,17 @@ func (s *VoucherService) CmbQuery(ctx http.Context) error {
|
||||||
|
|
||||||
func (s *VoucherService) cmbQuery(ctx http.Context) (*v1.CmbQueryReply, error) {
|
func (s *VoucherService) cmbQuery(ctx http.Context) (*v1.CmbQueryReply, error) {
|
||||||
|
|
||||||
var req *v1.CmbRequest
|
bodyBytes, err := io.ReadAll(ctx.Request().Body)
|
||||||
if err := ctx.BindForm(&req); err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := req.Validate(); err != nil {
|
var req *v1.CmbRequest
|
||||||
|
if err = json.Unmarshal(bodyBytes, &req); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = req.Validate(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -137,6 +152,7 @@ func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
|
||||||
|
|
||||||
bizReply, err := s.cmbProductQuery(ctx)
|
bizReply, err := s.cmbProductQuery(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Errorf("cmbProductQuery error: %v", err)
|
||||||
bizReply = &v1.CmbQueryProductReply{
|
bizReply = &v1.CmbQueryProductReply{
|
||||||
RespCode: vo.CmbResponseStatusFail.GetValue(),
|
RespCode: vo.CmbResponseStatusFail.GetValue(),
|
||||||
RespMsg: err.Error(),
|
RespMsg: err.Error(),
|
||||||
|
|
@ -153,6 +169,7 @@ func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
|
||||||
reply, err = s.CmbMixRepo.GetResponse(ctx, xx)
|
reply, err = s.CmbMixRepo.GetResponse(ctx, xx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("cmbProductQuery CmbMixRepo GetResponse error: %v", err)
|
log.Errorf("cmbProductQuery CmbMixRepo GetResponse error: %v", err)
|
||||||
|
return ctx.JSON(400, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.JSON(200, reply)
|
return ctx.JSON(200, reply)
|
||||||
|
|
@ -160,12 +177,17 @@ func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
|
||||||
|
|
||||||
func (s *VoucherService) cmbProductQuery(ctx http.Context) (*v1.CmbQueryProductReply, error) {
|
func (s *VoucherService) cmbProductQuery(ctx http.Context) (*v1.CmbQueryProductReply, error) {
|
||||||
|
|
||||||
var req *v1.CmbRequest
|
bodyBytes, err := io.ReadAll(ctx.Request().Body)
|
||||||
if err := ctx.BindForm(&req); err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := req.Validate(); err != nil {
|
var req *v1.CmbRequest
|
||||||
|
if err = json.Unmarshal(bodyBytes, &req); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = req.Validate(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -176,3 +198,25 @@ func (s *VoucherService) cmbProductQuery(ctx http.Context) (*v1.CmbQueryProductR
|
||||||
|
|
||||||
return s.VoucherBiz.CmbProductQuery(ctx, bizContent.ActivityId)
|
return s.VoucherBiz.CmbProductQuery(ctx, bizContent.ActivityId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *VoucherService) DecryptBody(ctx http.Context) error {
|
||||||
|
|
||||||
|
bodyBytes, err := io.ReadAll(ctx.Request().Body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var req *v1.EncryptBody
|
||||||
|
if err = json.Unmarshal(bodyBytes, &req); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
decryptBody, err := s.CmbMixRepo.Decrypt(ctx, req.EncryptBody)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.JSON(200, &v1.DecryptBody{
|
||||||
|
DecryptBody: decryptBody,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue