From 56210b1a603c42131cfc7a35b65bb775e5725268 Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Mon, 3 Apr 2023 21:52:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(tenpayv2):=20=E5=A2=9E=E5=8A=A0=E5=8F=8D?= =?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8C=96=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=E9=80=9A=E7=9F=A5=E4=BA=8B=E4=BB=B6=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E7=9A=84=E6=89=A9=E5=B1=95=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...hatTenpayClientEventDecryptionExtensions.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/SKIT.FlurlHttpClient.Wechat.TenpayV2/Extensions/WechatTenpayClientEventDecryptionExtensions.cs b/src/SKIT.FlurlHttpClient.Wechat.TenpayV2/Extensions/WechatTenpayClientEventDecryptionExtensions.cs index 0d509316..b3a80b18 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.TenpayV2/Extensions/WechatTenpayClientEventDecryptionExtensions.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.TenpayV2/Extensions/WechatTenpayClientEventDecryptionExtensions.cs @@ -23,6 +23,22 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV2 return client.JsonSerializer.Deserialize(callbackJson); } + /// + /// 反序列化得到微信支付回调通知事件模型对象。 + /// + /// + /// + /// + public static TEvent DeserializeEvent(this WechatTenpayClient client, string callbackXml) + where TEvent : WechatTenpayEvent, new() + { + if (client == null) throw new ArgumentNullException(nameof(client)); + if (callbackXml == null) throw new ArgumentNullException(callbackXml); + + string callbackJson = Utilities.XmlUtility.ConvertToJson(callbackXml); + return client.JsonSerializer.Deserialize(callbackJson); + } + /// /// 返回序列化并解密事件数据中被加密的信息。 /// @@ -36,11 +52,11 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV2 if (client == null) throw new ArgumentNullException(nameof(client)); if (callback == null) throw new ArgumentNullException(nameof(callback)); - string key = Utilities.MD5Utility.Hash(client.Credentials.MerchantSecret).ToLower(); string plainJson; try { + string key = Utilities.MD5Utility.Hash(client.Credentials.MerchantSecret).ToLower(); string plainXml = Utilities.AESUtility.DecryptWithECB( encodingKey: Convert.ToBase64String(Encoding.UTF8.GetBytes(key)), encodingCipherText: callback.EncryptedRequestInfo!