From 222522dc7660a846bb12614ed27be7d4721b6e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BF=8A=E5=AE=8F?= <389838709@qq.com> Date: Thu, 8 Aug 2024 14:59:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=AE=B0=E5=BD=95third=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/third/paymentService/ali_service.go | 4 ++-- app/third/paymentService/payment_service.go | 17 +++++++++-------- app/third/paymentService/wechat_service.go | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/third/paymentService/ali_service.go b/app/third/paymentService/ali_service.go index 8829dcb..d0ed0b0 100644 --- a/app/third/paymentService/ali_service.go +++ b/app/third/paymentService/ali_service.go @@ -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 { diff --git a/app/third/paymentService/payment_service.go b/app/third/paymentService/payment_service.go index 2ba409a..ba850b1 100644 --- a/app/third/paymentService/payment_service.go +++ b/app/third/paymentService/payment_service.go @@ -8,6 +8,7 @@ import ( "PaymentCenter/app/third/paymentService/payCommon" "context" "encoding/json" + "fmt" "github.com/qit-team/snow-core/log/logger" "strconv" ) @@ -85,10 +86,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 } @@ -151,7 +152,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 } @@ -215,7 +216,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 @@ -267,7 +268,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 @@ -323,14 +324,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, diff --git a/app/third/paymentService/wechat_service.go b/app/third/paymentService/wechat_service.go index 2b4479e..6da53c2 100644 --- a/app/third/paymentService/wechat_service.go +++ b/app/third/paymentService/wechat_service.go @@ -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 { From 39e64c8a220949531eb843f2c3abd97462f2a120 Mon Sep 17 00:00:00 2001 From: wolter Date: Thu, 8 Aug 2024 15:44:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=90=8E=E5=8F=B0=EF=BC=8Crsa=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=AF=86=E9=92=A5=E8=B0=83=E6=95=B4,=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E8=AE=A2=E5=8D=95fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/console/command.go | 7 +++---- app/utils/encrypt/rsa/rsa.go | 7 ++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/console/command.go b/app/console/command.go index 67596a3..4ba35b5 100644 --- a/app/console/command.go +++ b/app/console/command.go @@ -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() diff --git a/app/utils/encrypt/rsa/rsa.go b/app/utils/encrypt/rsa/rsa.go index f93101e..4ce9ff9 100644 --- a/app/utils/encrypt/rsa/rsa.go +++ b/app/utils/encrypt/rsa/rsa.go @@ -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 }