From 16f2f8981192fbee068bd55bcfaf2922b6b9008b Mon Sep 17 00:00:00 2001 From: Jerry <85411418@qq.com> Date: Thu, 15 Aug 2024 11:22:48 +0800 Subject: [PATCH] v1.5.104 --- release_note.txt | 8 +++++--- wechat/v3/encrypt_decrypt.go | 14 ++++++++++++++ wechat/v3/notify.go | 28 +++++++++++++++------------- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/release_note.txt b/release_note.txt index 83e59605..9ad55773 100644 --- a/release_note.txt +++ b/release_note.txt @@ -1,9 +1,11 @@ 版本号:Release 1.5.104 修改记录: - (1) gopay:golang.org/x/crypto v0.24.0 版本升级到 v0.25.0。 + (1) gopay:golang.org/x/crypto v0.24.0 版本升级到 v0.26.0。 (2) 支付宝:client.TradeOrderSettle(),response 完善字段。 - (3) 微信V3:新增client.V3QQTransactionH5(), QQ小程序H5下单。 - (4) 微信V3:新增client.V3CombineQQTransactionH5(), 合单QQ小程序下单-H5。 + (3) 微信V3:新增 client.V3QQTransactionH5(),QQ小程序H5下单。 + (4) 微信V3:新增 client.V3CombineQQTransactionH5(),合单QQ小程序下单-H5。 + (5) 微信V3:新增 wechat.V3DecryptViolationNotifyCipherText(),解密 服务商子商户处置记录 回调中的加密信息。#412 + (6) 微信V3:新增 V3NotifyReq method req.DecryptViolationCipherText(),解密 服务商子商户处置记录 回调中的加密信息。 版本号:Release 1.5.103 修改记录: diff --git a/wechat/v3/encrypt_decrypt.go b/wechat/v3/encrypt_decrypt.go index 29c82137..e9b3544c 100644 --- a/wechat/v3/encrypt_decrypt.go +++ b/wechat/v3/encrypt_decrypt.go @@ -293,3 +293,17 @@ func V3DecryptInvoiceNotifyCipherText(ciphertext, nonce, additional, apiV3Key st } return result, nil } + +// 解密 服务商子商户处置记录 回调中的加密信息 +func V3DecryptViolationNotifyCipherText(ciphertext, nonce, additional, apiV3Key string) (result *V3DecryptViolationResult, err error) { + cipherBytes, _ := base64.StdEncoding.DecodeString(ciphertext) + decrypt, err := aes.GCMDecrypt(cipherBytes, []byte(nonce), []byte(additional), []byte(apiV3Key)) + if err != nil { + return nil, fmt.Errorf("aes.GCMDecrypt, err:%w", err) + } + result = &V3DecryptViolationResult{} + if err = json.Unmarshal(decrypt, result); err != nil { + return nil, fmt.Errorf("json.Unmarshal(%s), err:%w", string(decrypt), err) + } + return result, nil +} diff --git a/wechat/v3/notify.go b/wechat/v3/notify.go index f35548e6..c14988ef 100644 --- a/wechat/v3/notify.go +++ b/wechat/v3/notify.go @@ -57,8 +57,8 @@ type V3DecryptPartnerPayResult struct { PromotionDetail []*PromotionDetail `json:"promotion_detail"` } -// V3DecryptViolationNotificationResult 服务商子商户处置记录回调通知 -type V3DecryptViolationNotificationResult struct { +// 服务商子商户处置记录回调通知 +type V3DecryptViolationResult struct { SubMchid string `json:"sub_mchid" dc:"子商户商户ID"` CompanyName string `json:"company_name" dc:"子商户主体名称"` RecordId string `json:"record_id" dc:"通知ID,可用于去重"` @@ -69,17 +69,6 @@ type V3DecryptViolationNotificationResult struct { RiskDescription string `json:"risk_description" dc:"风险描述"` } -// V3DecryptViolationNotification 服务商子商户处置记录回调解密 -func V3DecryptViolationNotification(req *http.Request, apiV3Key string) (res *V3DecryptViolationNotificationResult, err error) { - notifyResult, err := V3ParseNotify(req) - if err != nil { - return - } - var result *V3DecryptViolationNotificationResult - err = notifyResult.DecryptCipherTextToStruct(apiV3Key, &result) - return result, err -} - // 退款通知 解密结果 type V3DecryptRefundResult struct { Mchid string `json:"mchid"` @@ -548,6 +537,19 @@ func (v *V3NotifyReq) DecryptInvoiceCipherText(apiV3Key string) (result *V3Decry return nil, errors.New("notify data Resource is nil") } +// 解密 服务商子商户处置记录 回调中的加密信息 +func (v *V3NotifyReq) DecryptViolationCipherText(apiV3Key string) (result *V3DecryptViolationResult, err error) { + if v.Resource != nil { + result, err = V3DecryptViolationNotifyCipherText(v.Resource.Ciphertext, v.Resource.Nonce, v.Resource.AssociatedData, apiV3Key) + if err != nil { + bytes, _ := json.Marshal(v) + return nil, fmt.Errorf("V3NotifyReq(%s) decrypt cipher text error(%w)", string(bytes), err) + } + return result, nil + } + return nil, errors.New("notify data Resource is nil") +} + // Deprecated // 暂时不推荐此方法,请使用 wechat.V3ParseNotify() // 解析微信回调请求的参数到 gopay.BodyMap