<feat>增加解密失败报错

This commit is contained in:
Rzy 2024-08-08 15:46:54 +08:00
commit 7f20bf6925
9 changed files with 35 additions and 20 deletions

View File

@ -82,11 +82,10 @@ func closeOrder() {
// 发起关闭订单请求
response := paymentService.OrderClose(ctx, req)
// 成功
if response.Code == payCommon.PAY_SUCCESS_CODE {
orderIds = append(orderIds, orderInfo.Id)
} else {
utils.Log(nil, "关闭订单,上游失败", response)
if response.Code != payCommon.PAY_SUCCESS_CODE {
utils.Log(nil, "关闭订单,上游失败", response, orderInfo.Id)
}
orderIds = append(orderIds, orderInfo.Id)
}
// 修改订单状态为关闭
cond = builder.NewCond()

View File

@ -48,6 +48,7 @@ const (
AppSM4EncryptKeyNotFound = 1232
AppSM4EncryptFail = 1233
AppAesEncryptFail = 1234
AppDeEncryptFail = 1250
// 加密方式不存在
EncryptTypeNotFound = 1241
@ -121,6 +122,8 @@ var MsgZH = map[int]string{
EncryptTypeNotFound: "加密方式不存在",
AppDeEncryptFail: "未知原因导致解密失败请检查加密数据是和app加密配置",
PayChannelNotFound: "支付方式不存在",
PayChannelNotBuild: "支付方式尚未开通",
PayChannelExtJsonError: "支付方式扩展参数错误",

View File

@ -43,6 +43,9 @@ func DeCrypt(app *appmodel.App, data string, aesKey string) ([]byte, int) {
if errCode != apicrypt.CryptNotError {
return nil, errCode
}
if len(dataByte) == 0 {
return nil, errorcode.AppDeEncryptFail
}
//aesData, err := aes.Decrypt(dataByte, []byte(aesKey))
//if err != nil {
// return nil, errorcode.AppAesEncryptFail

View File

@ -131,8 +131,8 @@ func ALiCallBack(notifyReq gopay.BodyMap, aliConfig AliPay) error {
// 记录日志
go func() {
payCallback, _ := json.Marshal(notifyReq)
payParam := ""
saveLog(int64(orderId), common.THIRD_ORDER_TYPE_CALL_BACK, string(payCallback), payParam, string(merchantCallback))
payParam := "{}"
SaveLog(int64(orderId), common.THIRD_ORDER_TYPE_CALL_BACK, string(payCallback), payParam, string(merchantCallback))
}()
if res.ErrCode != errorcode.Success {

View File

@ -8,6 +8,7 @@ import (
"PaymentCenter/app/third/paymentService/payCommon"
"context"
"encoding/json"
"fmt"
"github.com/qit-team/snow-core/log/logger"
"strconv"
)
@ -77,10 +78,10 @@ func PaymentService(c context.Context, payOrderRequest PayOrderRequest) PayOrder
// 记录日志
go func() {
orderId := payOrderRequest.OrderId
payCallback := info
payCallback := fmt.Sprintf("{%s}", info)
payParam, _ := json.Marshal(payOrderRequest)
merchantCallback, _ := json.Marshal(payOrderResponse)
saveLog(orderId, common.THIRD_ORDER_TYPE_PAY, payCallback, string(payParam), string(merchantCallback))
SaveLog(orderId, common.THIRD_ORDER_TYPE_PAY, payCallback, string(payParam), string(merchantCallback))
}()
return payOrderResponse
}
@ -143,7 +144,7 @@ func PayOrderQuery(c context.Context, payOrderQueryRequest PayOrderQueryRequest)
payCallback, _ := json.Marshal(info)
payParam, _ := json.Marshal(payOrderQueryRequest)
merchantCallback, _ := json.Marshal(payOrderQueryResponse)
saveLog(orderId, common.THIRD_ORDER_TYPE_ORDER_QUERY, string(payCallback), string(payParam), string(merchantCallback))
SaveLog(orderId, common.THIRD_ORDER_TYPE_ORDER_QUERY, string(payCallback), string(payParam), string(merchantCallback))
}()
return payOrderQueryResponse
}
@ -207,7 +208,7 @@ func OrderRefund(c context.Context, orderRefundRequest OrderRefundRequest) Order
payCallback, _ := json.Marshal(info)
payParam, _ := json.Marshal(orderRefundRequest)
merchantCallback, _ := json.Marshal(orderRefundResponse)
saveLog(orderId, common.THIRD_ORDER_TYPE_REFUND, string(payCallback), string(payParam), string(merchantCallback))
SaveLog(orderId, common.THIRD_ORDER_TYPE_REFUND, string(payCallback), string(payParam), string(merchantCallback))
}()
return orderRefundResponse
@ -259,7 +260,7 @@ func OrderRefundQuery(c context.Context, orderRefundQueryRequest OrderRefundQuer
payCallback, _ := json.Marshal(info)
payParam, _ := json.Marshal(orderRefundQueryRequest)
merchantCallback, _ := json.Marshal(orderRefundQueryResponse)
saveLog(orderId, common.THIRD_ORDER_TYPE_REFUND_QUERY, string(payCallback), string(payParam), string(merchantCallback))
SaveLog(orderId, common.THIRD_ORDER_TYPE_REFUND_QUERY, string(payCallback), string(payParam), string(merchantCallback))
}()
return orderRefundQueryResponse
@ -315,14 +316,14 @@ func OrderClose(c context.Context, orderCloseRequest OrderCloseRequest) OrderClo
payCallback, _ := json.Marshal(info)
payParam, _ := json.Marshal(orderCloseRequest)
merchantCallback, _ := json.Marshal(orderCloseResponse)
saveLog(orderId, common.THIRD_ORDER_TYPE_CLOSE, string(payCallback), string(payParam), string(merchantCallback))
SaveLog(orderId, common.THIRD_ORDER_TYPE_CLOSE, string(payCallback), string(payParam), string(merchantCallback))
}()
return orderCloseResponse
}
// saveLog 记录操作日志
func saveLog(orderId int64, OType int, payCallback string, PayParam string, MerchantCallback string) {
// SaveLog 记录操作日志
func SaveLog(orderId int64, OType int, payCallback string, PayParam string, MerchantCallback string) {
thirdRepo := data.NewOrderThirdPayLogRepo(paychannelmodel.GetInstance().GetDb())
log := orderthirdpaylogmodel.OrderThirdPayLog{
OrderId: orderId,

View File

@ -165,8 +165,8 @@ func WxPayCallBack(notifyReq *wechat.V3NotifyReq, wxConfig WxPay) error {
// 记录日志
go func() {
payCallback, _ := json.Marshal(CallBackInfo)
payParam := ""
saveLog(int64(orderId), common.THIRD_ORDER_TYPE_CALL_BACK, string(payCallback), payParam, string(merchantCallback))
payParam := "{}"
SaveLog(int64(orderId), common.THIRD_ORDER_TYPE_CALL_BACK, string(payCallback), payParam, string(merchantCallback))
}()
if res.ErrCode != errorcode.Success {

View File

@ -8,6 +8,7 @@ import (
"encoding/base64"
"encoding/pem"
"fmt"
"strings"
)
// parseRSAPublicKeyFromPEM 解析PEM编码的RSA公钥
@ -136,5 +137,9 @@ func GenerateKey() (string, string, error) {
Bytes: derPkix,
}
pubPem := pem.EncodeToMemory(pubBlock)
return string(pubPem), string(privPem), nil
pri := strings.Replace(string(privPem), "-----BEGIN RSA PRIVATE KEY-----\n", "", -1)
pri = strings.Replace(pri, "\n-----END RSA PRIVATE KEY-----\n", "", -1)
pub := strings.Replace(string(pubPem), "-----BEGIN PUBLIC KEY-----\n", "", -1)
pub = strings.Replace(pub, "\n-----END PUBLIC KEY-----\n", "", -1)
return pub, pri, nil
}

View File

@ -8,7 +8,7 @@ import (
const (
SELF_PRI = "BD13D44C74422F80ADDF54AD2DE2888C4092AF6F61E41FABADA6C47F17574A41"
SELF_PUB = "04363DF574D4FE34EE58FB8A3F7CB08E6CA5EBB3B7335CBAE10A2900551F6450AB3AD25DBC0A76EFA9E6D44D2C51E3027483F7BFD09996457888BAFD1AF673817F"
SELF_PUB = "04F26C6CDA5E58153999FDF3023259F16EDE0A556C39FCF4BC97C04A10A8A6CF1D52297B53DB4DD72FEEF8221394C8478E6424F4E84E4A6E2784C1A4A1C99F2DC2"
)
func TestGenerateSM2KeyPair(t *testing.T) {

View File

@ -2,6 +2,7 @@ package sm4
import (
"fmt"
"strconv"
"testing"
)
@ -25,7 +26,10 @@ func TestSM4Encrypt(t *testing.T) {
}
func TestSM4Decrypt(t *testing.T) {
uid, en := encrypt()
//uid := "1729382256910270475"
//en := "{\"accessToken\":\"77F59F157466F309E703F43CFDCFFECF\",\"encryptKey\":\"04237241E4A465C18645985B3C1DAE987B5DDF1C077AA27D677C843C52E833A24711C63F2512D1A4C37E85A5C9CEAC94156C97460CB5E8966CAD2A0C2596A64ED69CF3306D031C4AADAA73D165FB7EEC34E5AAF532A301169847560329F7F1E40E9FD09EB191976BB49ABFE611E05158EF\",\"request\":\"mkuquQ1RB2AtZYzBtWtLPJ3MMULWj7I5RmK3dKENYVW8OgB//I/+MAD/XnjxYYJlRWM8uL/rWL9o\\r\\n0L7W9fSBvOXWwz8reiwcAF/JZ5dnacZtVe0NPujDfeVIJp+9ua7hxQcegcEsIRS9CQqtF/rJN7M9\\r\\nxxCLSzEiJY8bIdRLBsfmB0uVIE2144s2tH7Q8R2fSOVbiSTH1PW3Ye0kkyCcBw==\",\"signature\":\"ed99a2ce827a4d443e2639ccfb78865e913854e2d61d1746dafb640e19cbb4f8#3793b1cac082d9e1cdfc2b7b8387a8c29e44b2f3fb35b352d02f1b2c9321e0a7\"}"
decrypt, err := Sm4Decrypt(uid, SELF_PRI, PARTY_PUB, en, true)
if err != nil {
panic(err)
@ -34,8 +38,8 @@ func TestSM4Decrypt(t *testing.T) {
}
func encrypt() (string, string) {
uid := "1234567890"
data := "{\"name\":\"张三\",\"sex\":1,\"is_human\":true}"
uid := strconv.FormatInt(int64(5476377146882523149), 10)
data := "{\"pay_channel_id\":1729382256910270476,\"out_trade_no\":\"asdadasdas\",\"order_type\":1,\"amount\":1,\"desc\":\"abc\",\"ext_json\":\"\",\"app_id\":5476377146882523149,\"timestamp\":1723096731}"
en, err := Sm4Encrypt(uid, PARTY_PRI, SELF_PUB, data, "", true)
if err != nil {
panic(err)