Browse Source

1. WeChatPay***NotifyResponse => WeChatPay***Notify 2.添加部分注释 3.部分优化

Roc 7 years ago
parent
commit
3ff2f31e67
23 changed files with 144 additions and 117 deletions
  1. 2 2
      samples/WebApplicationSample/Controllers/NotifyController.cs
  2. 1 1
      src/Essensoft.AspNetCore.Payment.WeChatPay/IWeChatPayCallRequest.cs
  3. 1 1
      src/Essensoft.AspNetCore.Payment.WeChatPay/IWeChatPayCertificateRequest.cs
  4. 1 1
      src/Essensoft.AspNetCore.Payment.WeChatPay/IWeChatPayClient.cs
  5. 3 3
      src/Essensoft.AspNetCore.Payment.WeChatPay/IWeChatPayNotifyClient.cs
  6. 1 1
      src/Essensoft.AspNetCore.Payment.WeChatPay/IWeChatPayRequest.cs
  7. 1 1
      src/Essensoft.AspNetCore.Payment.WeChatPay/Notify/WeChatPayRefundNotify.cs
  8. 1 1
      src/Essensoft.AspNetCore.Payment.WeChatPay/Notify/WeChatPayUnifiedOrderNotify.cs
  9. 2 2
      src/Essensoft.AspNetCore.Payment.WeChatPay/Parser/IWeChatPayParser.cs
  10. 5 0
      src/Essensoft.AspNetCore.Payment.WeChatPay/Parser/WeChatPayListPropertyParser.cs
  11. 23 34
      src/Essensoft.AspNetCore.Payment.WeChatPay/Parser/WeChatPayXmlParser.cs
  12. 3 0
      src/Essensoft.AspNetCore.Payment.WeChatPay/Utility/WeChatPaySignature.cs
  13. 3 9
      src/Essensoft.AspNetCore.Payment.WeChatPay/Utility/WeChatPayUtility.cs
  14. 17 13
      src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayClient.cs
  15. 3 0
      src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayDictionary.cs
  16. 14 0
      src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayException.cs
  17. 9 0
      src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayNotify.cs
  18. 23 20
      src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayNotifyClient.cs
  19. 0 5
      src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayNotifyResponse.cs
  20. 1 1
      src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayNotifyResult.cs
  21. 23 3
      src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayObject.cs
  22. 3 0
      src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayOptions.cs
  23. 4 19
      src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayResponse.cs

+ 2 - 2
samples/WebApplicationSample/Controllers/NotifyController.cs

@@ -154,7 +154,7 @@ namespace WebApplicationSample.Controllers
         {
             try
             {
-                var notify = await _client.ExecuteAsync<WeChatPayUnifiedOrderNotifyResponse>(Request);
+                var notify = await _client.ExecuteAsync<WeChatPayUnifiedOrderNotify>(Request);
                 if (notify.ReturnCode == "SUCCESS")
                 {
                     if (notify.ResultCode == "SUCCESS")
@@ -182,7 +182,7 @@ namespace WebApplicationSample.Controllers
         {
             try
             {
-                var notify = await _client.ExecuteAsync<WeChatPayRefundNotifyResponse>(Request);
+                var notify = await _client.ExecuteAsync<WeChatPayRefundNotify>(Request);
                 if (notify.ReturnCode == "SUCCESS")
                 {
                     if (notify.RefundStatus == "SUCCESS")

+ 1 - 1
src/Essensoft.AspNetCore.Payment.WeChatPay/IWeChatPayCallRequest.cs

@@ -3,7 +3,7 @@
 namespace Essensoft.AspNetCore.Payment.WeChatPay
 {
     /// <summary>
-    /// WeChatPay API调起请求
+    /// WeChatPay 调起请求
     /// </summary>
     public interface IWeChatPayCallRequest
     {

+ 1 - 1
src/Essensoft.AspNetCore.Payment.WeChatPay/IWeChatPayCertificateRequest.cs

@@ -3,7 +3,7 @@
 namespace Essensoft.AspNetCore.Payment.WeChatPay
 {
     /// <summary>
-    /// WeChatPay API证书请求
+    /// WeChatPay 证书请求
     /// </summary>
     /// <typeparam name="T"></typeparam>
     public interface IWeChatPayCertificateRequest<T> where T : WeChatPayResponse

+ 1 - 1
src/Essensoft.AspNetCore.Payment.WeChatPay/IWeChatPayClient.cs

@@ -3,7 +3,7 @@
 namespace Essensoft.AspNetCore.Payment.WeChatPay
 {
     /// <summary>
-    /// WeChatPay客户端。
+    /// WeChatPay 客户端。
     /// </summary>
     public interface IWeChatPayClient
     {

+ 3 - 3
src/Essensoft.AspNetCore.Payment.WeChatPay/IWeChatPayNotifyClient.cs

@@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Http;
 namespace Essensoft.AspNetCore.Payment.WeChatPay
 {
     /// <summary>
-    /// WeChatPay通知解析客户端。
+    /// WeChatPay 通知解析客户端。
     /// </summary>
     public interface IWeChatPayNotifyClient
     {
@@ -14,7 +14,7 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay
         /// <typeparam name="T">领域对象</typeparam>
         /// <param name="request">控制器的请求</param>
         /// <returns>领域对象</returns>
-        Task<T> ExecuteAsync<T>(HttpRequest request) where T : WeChatPayNotifyResponse;
+        Task<T> ExecuteAsync<T>(HttpRequest request) where T : WeChatPayNotify;
 
         /// <summary>
         /// 执行WeChatPay通知请求解析。
@@ -23,6 +23,6 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay
         /// <param name="request">控制器的请求</param>
         /// <param name="optionsName">配置选项名称</param>
         /// <returns>领域对象</returns>
-        Task<T> ExecuteAsync<T>(HttpRequest request, string optionsName) where T : WeChatPayNotifyResponse;
+        Task<T> ExecuteAsync<T>(HttpRequest request, string optionsName) where T : WeChatPayNotify;
     }
 }

+ 1 - 1
src/Essensoft.AspNetCore.Payment.WeChatPay/IWeChatPayRequest.cs

@@ -3,7 +3,7 @@
 namespace Essensoft.AspNetCore.Payment.WeChatPay
 {
     /// <summary>
-    /// WeChatPay API请求
+    /// WeChatPay 请求
     /// </summary>
     /// <typeparam name="T"></typeparam>
     public interface IWeChatPayRequest<T> where T : WeChatPayResponse

+ 1 - 1
src/Essensoft.AspNetCore.Payment.WeChatPay/Notify/WeChatPayRefundNotifyResponse.cs → src/Essensoft.AspNetCore.Payment.WeChatPay/Notify/WeChatPayRefundNotify.cs

@@ -6,7 +6,7 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay.Notify
     /// 申请退款 - 退款结果通知
     /// </summary>
     [XmlRoot("xml")]
-    public class WeChatPayRefundNotifyResponse : WeChatPayNotifyResponse
+    public class WeChatPayRefundNotify : WeChatPayNotify
     {
         /// <summary>
         /// 返回状态码

+ 1 - 1
src/Essensoft.AspNetCore.Payment.WeChatPay/Notify/WeChatPayUnifiedOrderNotifyResponse.cs → src/Essensoft.AspNetCore.Payment.WeChatPay/Notify/WeChatPayUnifiedOrderNotify.cs

@@ -9,7 +9,7 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay.Notify
     /// 统一下单 - 支付结果通知
     /// </summary>
     [XmlRoot("xml")]
-    public class WeChatPayUnifiedOrderNotifyResponse : WeChatPayNotifyResponse
+    public class WeChatPayUnifiedOrderNotify : WeChatPayNotify
     {
         /// <summary>
         /// 返回状态码

+ 2 - 2
src/Essensoft.AspNetCore.Payment.WeChatPay/Parser/IWeChatPayParser.cs

@@ -1,9 +1,9 @@
 namespace Essensoft.AspNetCore.Payment.WeChatPay.Parser
 {
     /// <summary>
-    /// 微信支付结果解析
+    /// WeChatPay 解析。
     /// </summary>
-    public interface IWeChatPayParser<T> where T : WeChatPayResponse
+    public interface IWeChatPayParser<T> where T : WeChatPayObject
     {
         T Parse(string body);
 

+ 5 - 0
src/Essensoft.AspNetCore.Payment.WeChatPay/Parser/WeChatPayListPropertyParser.cs

@@ -4,6 +4,9 @@ using System.Xml.Serialization;
 
 namespace Essensoft.AspNetCore.Payment.WeChatPay.Parser
 {
+    /// <summary>
+    /// WeChatPay ListPropert解析。
+    /// </summary>
     public class WeChatPayListPropertyParser
     {
         public List<T> Parse<T, TChildren>(WeChatPayDictionary dic, int index = -1)
@@ -37,6 +40,7 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay.Parser
                         {
                             key += $"_{index}";
                         }
+
                         key += $"_{i}";
 
                         var value = dic.GetValue(key);
@@ -47,6 +51,7 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay.Parser
                                 flag = false;
                                 break;
                             }
+
                             continue;
                         }
 

+ 23 - 34
src/Essensoft.AspNetCore.Payment.WeChatPay/Parser/WeChatPayXmlParser.cs

@@ -6,16 +6,15 @@ using System.Xml.Serialization;
 
 namespace Essensoft.AspNetCore.Payment.WeChatPay.Parser
 {
-    public class WeChatPayXmlParser<T> : IWeChatPayParser<T> where T : WeChatPayResponse
+    /// <summary>
+    /// WeChatPay Xml解析。
+    /// </summary>
+    /// <typeparam name="T"></typeparam>
+    public class WeChatPayXmlParser<T> : IWeChatPayParser<T> where T : WeChatPayObject
     {
         public T Parse(string body)
         {
-            if (string.IsNullOrEmpty(body))
-            {
-                throw new ArgumentNullException(nameof(body));
-            }
-
-            T rsp = null;
+            T result = null;
             var parameters = new WeChatPayDictionary();
 
             try
@@ -23,7 +22,7 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay.Parser
                 using (var sr = new StringReader(body))
                 {
                     var xmldes = new XmlSerializer(typeof(T));
-                    rsp = (T)xmldes.Deserialize(sr);
+                    result = (T)xmldes.Deserialize(sr);
                 }
 
                 var bodyDoc = XDocument.Parse(body).Element("xml");
@@ -34,36 +33,26 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay.Parser
             }
             catch { }
 
-            if (rsp == null)
+            if (result == null)
             {
-                rsp = Activator.CreateInstance<T>();
+                result = Activator.CreateInstance<T>();
             }
 
-            if (rsp != null)
+            if (result != null)
             {
-                rsp.Body = body;
+                result.Body = body;
 
-                rsp.Parameters = parameters;
+                result.Parameters = parameters;
 
-                rsp.Execute();
+                result.Execute();
             }
 
-            return rsp;
+            return result;
         }
 
         public T Parse(string body, string data)
         {
-            if (string.IsNullOrEmpty(body))
-            {
-                throw new ArgumentNullException(nameof(body));
-            }
-
-            if (string.IsNullOrEmpty(data))
-            {
-                throw new ArgumentNullException(nameof(data));
-            }
-
-            T rsp = null;
+            T result = null;
             var parameters = new WeChatPayDictionary();
 
             try
@@ -81,7 +70,7 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay.Parser
                 using (var sr = new StringReader(sb.ToString()))
                 {
                     var xmldes = new XmlSerializer(typeof(T));
-                    rsp = (T)xmldes.Deserialize(sr);
+                    result = (T)xmldes.Deserialize(sr);
                 }
 
                 foreach (var xe in bodyDoc.Elements())
@@ -91,21 +80,21 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay.Parser
             }
             catch { }
 
-            if (rsp == null)
+            if (result == null)
             {
-                rsp = Activator.CreateInstance<T>();
+                result = Activator.CreateInstance<T>();
             }
 
-            if (rsp != null)
+            if (result != null)
             {
-                rsp.Body = data;
+                result.Body = data;
 
-                rsp.Parameters = parameters;
+                result.Parameters = parameters;
 
-                rsp.Execute();
+                result.Execute();
             }
 
-            return rsp;
+            return result;
         }
     }
 }

+ 3 - 0
src/Essensoft.AspNetCore.Payment.WeChatPay/Utility/WeChatPaySignature.cs

@@ -4,6 +4,9 @@ using Essensoft.AspNetCore.Payment.Security;
 
 namespace Essensoft.AspNetCore.Payment.WeChatPay.Utility
 {
+    /// <summary>
+    /// WeChatPay 签名类。
+    /// </summary>
     public class WeChatPaySignature
     {
         public static string SignWithKey(SortedDictionary<string, string> parameters, string key, bool signType = true, bool excludeSignType = true)

+ 3 - 9
src/Essensoft.AspNetCore.Payment.WeChatPay/Utility/WeChatPayUtility.cs

@@ -1,11 +1,12 @@
 using System;
 using System.Collections.Generic;
-using System.Net.Http.Headers;
 using System.Text;
-using Microsoft.AspNetCore.Http;
 
 namespace Essensoft.AspNetCore.Payment.WeChatPay.Utility
 {
+    /// <summary>
+    /// WeChatPay 工具类。
+    /// </summary>
     public static class WeChatPayUtility
     {
         /// <summary>
@@ -26,13 +27,6 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay.Utility
             return content.Append("</xml>").ToString();
         }
 
-        internal static bool HasTextJsonContentType(this HttpRequest request)
-        {
-            // Content-Type: text/json;charset=UTF-8
-            MediaTypeHeaderValue.TryParse(request.ContentType, out var contentType);
-            return contentType != null && contentType.MediaType.Equals("text/json", StringComparison.OrdinalIgnoreCase);
-        }
-
         public static string GetTimeStamp()
         {
             var ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);

+ 17 - 13
src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayClient.cs

@@ -10,6 +10,9 @@ using Microsoft.Extensions.Options;
 
 namespace Essensoft.AspNetCore.Payment.WeChatPay
 {
+    /// <summary>
+    /// WeChatPay 客户端。
+    /// </summary>
     public class WeChatPayClient : IWeChatPayClient
     {
         private const string appid = "appid";
@@ -59,7 +62,7 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay
         public async Task<T> ExecuteAsync<T>(IWeChatPayRequest<T> request, string optionsName) where T : WeChatPayResponse
         {
             var options = string.IsNullOrEmpty(optionsName) ? _optionsSnapshotAccessor.Value : _optionsSnapshotAccessor.Get(optionsName);
-            // 字典排序
+
             var sortedTxtParams = new WeChatPayDictionary(request.GetParameters())
             {
                 { mch_id, options.MchId },
@@ -81,14 +84,14 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay
                 _logger.Log(options.LogLevel, "Response:{body}", body);
 
                 var parser = new WeChatPayXmlParser<T>();
-                var rsp = parser.Parse(body);
+                var response = parser.Parse(body);
 
                 if (request.IsCheckResponseSign())
                 {
-                    CheckResponseSign(rsp, options);
+                    CheckResponseSign(response, options);
                 }
 
-                return rsp;
+                return response;
             }
         }
 
@@ -106,8 +109,8 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay
             var signType = true; // ture:MD5,false:HMAC-SHA256
             var excludeSignType = true;
             var options = string.IsNullOrEmpty(optionsName) ? _optionsSnapshotAccessor.Value : _optionsSnapshotAccessor.Get(optionsName);
-            // 字典排序
             var sortedTxtParams = new WeChatPayDictionary(request.GetParameters());
+
             if (request is WeChatPayTransfersRequest)
             {
                 if (string.IsNullOrEmpty(sortedTxtParams.GetValue(mch_appid)))
@@ -127,7 +130,7 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay
             {
                 if (options.PublicKey == null)
                 {
-                    throw new ArgumentNullException(nameof(options.RsaPublicKey));
+                    throw new WeChatPayException("WeChatPayPayBankRequest: PublicKey is null!");
                 }
 
                 var no = RSA_ECB_OAEPWithSHA1AndMGF1Padding.Encrypt(sortedTxtParams.GetValue(enc_bank_no), options.PublicKey);
@@ -204,14 +207,14 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay
                 _logger.Log(options.LogLevel, "Response:{body}", body);
 
                 var parser = new WeChatPayXmlParser<T>();
-                var rsp = parser.Parse(body);
+                var response = parser.Parse(body);
 
                 if (request.IsCheckResponseSign())
                 {
-                    CheckResponseSign(rsp, options, signType, excludeSignType);
+                    CheckResponseSign(response, options, signType, excludeSignType);
                 }
 
-                return rsp;
+                return response;
             }
         }
 
@@ -256,6 +259,7 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay
                 sortedTxtParams.Add(signType, "MD5");
                 sortedTxtParams.Add(paySign, WeChatPaySignature.SignWithKey(sortedTxtParams, options.Key));
             }
+
             return Task.FromResult(sortedTxtParams);
         }
 
@@ -267,17 +271,17 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay
         {
             if (string.IsNullOrEmpty(response.Body))
             {
-                throw new Exception("sign check fail: Body is Empty!");
+                throw new WeChatPayException("sign check fail: Body is Empty!");
             }
 
             if (response.Parameters.Count == 0)
             {
-                throw new Exception("sign check fail: Parameters is Empty!");
+                throw new WeChatPayException("sign check fail: Parameters is Empty!");
             }
 
             if (!response.Parameters.TryGetValue("sign", out var sign))
             {
-                throw new Exception("sign check fail: sign is Empty!");
+                throw new WeChatPayException("sign check fail: sign is Empty!");
             }
 
             if (response.Parameters["return_code"] == "SUCCESS" && !string.IsNullOrEmpty(sign))
@@ -285,7 +289,7 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay
                 var cal_sign = WeChatPaySignature.SignWithKey(response.Parameters, options.Key, useMD5, excludeSignType);
                 if (cal_sign != sign)
                 {
-                    throw new Exception("sign check fail: check Sign and Data Fail!");
+                    throw new WeChatPayException("sign check fail: check Sign and Data Fail!");
                 }
             }
         }

+ 3 - 0
src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayDictionary.cs

@@ -2,6 +2,9 @@
 
 namespace Essensoft.AspNetCore.Payment.WeChatPay
 {
+    /// <summary>
+    /// WeChatPay 字典。
+    /// </summary>
     public class WeChatPayDictionary : SortedDictionary<string, string>
     {
         public WeChatPayDictionary() { }

+ 14 - 0
src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayException.cs

@@ -0,0 +1,14 @@
+using System;
+
+namespace Essensoft.AspNetCore.Payment.WeChatPay
+{
+    /// <summary>
+    /// WeChatPay 异常。
+    /// </summary>
+    public class WeChatPayException : Exception
+    {
+        public WeChatPayException(string messages) : base(messages)
+        {
+        }
+    }
+}

+ 9 - 0
src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayNotify.cs

@@ -0,0 +1,9 @@
+namespace Essensoft.AspNetCore.Payment.WeChatPay
+{
+    /// <summary>
+    /// WeChatPay 通知。
+    /// </summary>
+    public abstract class WeChatPayNotify : WeChatPayObject
+    {
+    }
+}

+ 23 - 20
src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayNotifyClient.cs

@@ -1,5 +1,4 @@
-using System;
-using System.IO;
+using System.IO;
 using System.Text;
 using System.Threading.Tasks;
 using Essensoft.AspNetCore.Payment.Security;
@@ -12,6 +11,9 @@ using Microsoft.Extensions.Options;
 
 namespace Essensoft.AspNetCore.Payment.WeChatPay
 {
+    /// <summary>
+    /// WeChatPay 通知解析客户端。
+    /// </summary>
     public class WeChatPayNotifyClient : IWeChatPayNotifyClient
     {
         private readonly ILogger _logger;
@@ -31,58 +33,59 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay
 
         #region IWeChatPayNotifyClient Members
 
-        public async Task<T> ExecuteAsync<T>(HttpRequest request) where T : WeChatPayNotifyResponse
+        public async Task<T> ExecuteAsync<T>(HttpRequest request) where T : WeChatPayNotify
         {
             return await ExecuteAsync<T>(request, null);
         }
 
-        public async Task<T> ExecuteAsync<T>(HttpRequest request, string optionsName) where T : WeChatPayNotifyResponse
+        public async Task<T> ExecuteAsync<T>(HttpRequest request, string optionsName) where T : WeChatPayNotify
         {
             var options = string.IsNullOrEmpty(optionsName) ? _optionsSnapshotAccessor.Value : _optionsSnapshotAccessor.Get(optionsName);
             var body = await new StreamReader(request.Body, Encoding.UTF8).ReadToEndAsync();
             _logger.Log(options.LogLevel, "Request:{body}", body);
 
             var parser = new WeChatPayXmlParser<T>();
-            var rsp = parser.Parse(body);
-            if (rsp is WeChatPayRefundNotifyResponse)
+            var notify = parser.Parse(body);
+            if (notify is WeChatPayRefundNotify)
             {
                 var key = MD5.Compute(options.Key).ToLower();
-                var data = AES.Decrypt((rsp as WeChatPayRefundNotifyResponse).ReqInfo, key, AESCipherMode.ECB, AESPaddingMode.PKCS7);
-                _logger.Log(options.LogLevel, "Decrypt Content:{data}", data); // AES-256-ECB
-                rsp = parser.Parse(body, data);
+                var data = AES.Decrypt((notify as WeChatPayRefundNotify).ReqInfo, key, AESCipherMode.ECB, AESPaddingMode.PKCS7);
+                _logger.Log(options.LogLevel, "Decrypt Content:{data}", data); // AES-256-ECB 解密内容
+                notify = parser.Parse(body, data);
             }
             else
             {
-                CheckNotifySign(rsp, options);
+                CheckNotifySign(notify, options);
             }
-            return rsp;
+
+            return notify;
         }
 
         #endregion
 
         #region Common Method
 
-        private void CheckNotifySign(WeChatPayNotifyResponse response, WeChatPayOptions options)
+        private void CheckNotifySign(WeChatPayNotify notify, WeChatPayOptions options)
         {
-            if (string.IsNullOrEmpty(response.Body))
+            if (string.IsNullOrEmpty(notify.Body))
             {
-                throw new Exception("sign check fail: Body is Empty!");
+                throw new WeChatPayException("sign check fail: Body is Empty!");
             }
 
-            if (response.Parameters.Count == 0)
+            if (notify.Parameters.Count == 0)
             {
-                throw new Exception("sign check fail: Parameters is Empty!");
+                throw new WeChatPayException("sign check fail: Parameters is Empty!");
             }
 
-            if (!response.Parameters.TryGetValue("sign", out var sign))
+            if (!notify.Parameters.TryGetValue("sign", out var sign))
             {
-                throw new Exception("sign check fail: sign is Empty!");
+                throw new WeChatPayException("sign check fail: sign is Empty!");
             }
 
-            var cal_sign = WeChatPaySignature.SignWithKey(response.Parameters, options.Key);
+            var cal_sign = WeChatPaySignature.SignWithKey(notify.Parameters, options.Key);
             if (cal_sign != sign)
             {
-                throw new Exception("sign check fail: check Sign and Data Fail!");
+                throw new WeChatPayException("sign check fail: check Sign and Data Fail!");
             }
         }
 

+ 0 - 5
src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayNotifyResponse.cs

@@ -1,5 +0,0 @@
-namespace Essensoft.AspNetCore.Payment.WeChatPay
-{
-    public abstract class WeChatPayNotifyResponse : WeChatPayResponse
-    {}
-}

+ 1 - 1
src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayNotifyResult.cs

@@ -3,7 +3,7 @@
 namespace Essensoft.AspNetCore.Payment.WeChatPay
 {
     /// <summary>
-    /// 微信支付 - 通知应答
+    /// WeChatPay 通知应答。
     /// </summary>
     public class WeChatPayNotifyResult
     {

+ 23 - 3
src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayObject.cs

@@ -1,8 +1,28 @@
-namespace Essensoft.AspNetCore.Payment.WeChatPay
+using System.Xml.Serialization;
+
+namespace Essensoft.AspNetCore.Payment.WeChatPay
 {
     /// <summary>
-    /// 基础对象。
+    /// WeChatPay 基础对象。
     /// </summary>
     public abstract class WeChatPayObject
-    {}
+    {
+        /// <summary>
+        /// 原始内容
+        /// </summary>
+        [XmlIgnore]
+        public string Body { get; set; }
+
+        /// <summary>
+        /// 原始参数
+        /// </summary>
+        [XmlIgnore]
+        public WeChatPayDictionary Parameters { get; internal set; }
+
+
+        /// <summary>
+        /// 处理 _$n / _$n_$m
+        /// </summary>
+        internal virtual void Execute() { }
+    }
 }

+ 3 - 0
src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayOptions.cs

@@ -4,6 +4,9 @@ using Org.BouncyCastle.Crypto;
 
 namespace Essensoft.AspNetCore.Payment.WeChatPay
 {
+    /// <summary>
+    /// WeChatPay 选项。
+    /// </summary>
     public class WeChatPayOptions
     {
         internal ICipherParameters PublicKey;

+ 4 - 19
src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayResponse.cs

@@ -1,24 +1,9 @@
-using System.Xml.Serialization;
-
-namespace Essensoft.AspNetCore.Payment.WeChatPay
+namespace Essensoft.AspNetCore.Payment.WeChatPay
 {
+    /// <summary>
+    /// WeChatPay 应答。
+    /// </summary>
     public abstract class WeChatPayResponse : WeChatPayObject
     {
-        /// <summary>
-        /// 原始内容
-        /// </summary>
-        [XmlIgnore]
-        public string Body { get; set; }
-
-        /// <summary>
-        /// 原始参数
-        /// </summary>
-        [XmlIgnore]
-        public WeChatPayDictionary Parameters { get; internal set; }
-
-        /// <summary>
-        /// 处理 _$n / _$n_$m
-        /// </summary>
-        internal virtual void Execute() { }
     }
 }