package transfer import ( "context" "encoding/json" "rs/rpc/transfer" "rs/untils/rsa" "github.com/jinzhu/copier" "github.com/zeromicro/go-zero/core/logx" "rs/cmd/api/internal/svc" "rs/cmd/api/internal/types" ) type MarketLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } // 荣数立减金发放 func NewMarketLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MarketLogic { return &MarketLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *MarketLogic) Market(req *types.Req) (resp *types.Resp, err error) { var ( reqData transfer.RsCouponGrantReq res types.Resp ) DecryptData, _ := l.Decrypt(req.VendorNo, req.Data) _ = copier.Copy(&reqData, &req) tagLen := len(DecryptData.VoucherTag) if tagLen > 6 { //如果没有解析出来,直接投递给荣数,让荣数自行处理转发 result, _err := l.svcCtx.TransferRpc.RsCouponGrant(l.ctx, &reqData) if _err != nil { return nil, err } _ = copier.Copy(&res, &result) } else { prefix := DecryptData.VoucherTag[0:6] prefixData, err := l.svcCtx.ProductRedirectConf.FindOneByProductNoPrefix(l.ctx, prefix) if err != nil { return nil, err } if prefixData == nil { result, _err := l.svcCtx.TransferRpc.RsCouponGrant(l.ctx, &reqData) if _err != nil { return nil, _err } _ = copier.Copy(&res, &result) } else { result, _err := l.svcCtx.TransferRpc.ZltxRsMiXue(l.ctx, &reqData) if _err != nil { return nil, _err } _ = copier.Copy(&res, &result) } } return &res, nil } func (l *MarketLogic) Decrypt(vendorNo string, encryptData string) (types.DecryptReqData, error) { var ( decryptData types.DecryptReqData deCrypt []byte ) merchantInfo, err := l.svcCtx.Merchant.FindOneByMerchantId(l.ctx, vendorNo) if err != nil { return decryptData, err } // 修改请求体 switch merchantInfo.SignatureMethod { default: privateKeyPEM := `-----BEGIN RSA PRIVATE KEY----- ` + merchantInfo.RsaPrivateKey.String + ` -----END RSA PRIVATE KEY-----` deCrypt, err = rsa.Decrypt(privateKeyPEM, encryptData) if err != nil { return decryptData, err } } _ = json.Unmarshal(deCrypt, &decryptData) return decryptData, nil }