Browse Source

1. QPay***NotifyResponse=> QPay***Notify 2. 添加部分助手 3. 优化

Roc 6 năm trước cách đây
mục cha
commit
12afd41bf7
22 tập tin đã thay đổi với 104 bổ sung51 xóa
  1. 2 2
      samples/WebApplicationSample/Controllers/NotifyController.cs
  2. 4 0
      src/Essensoft.AspNetCore.Payment.QPay/IQPayCertificateRequest.cs
  3. 1 1
      src/Essensoft.AspNetCore.Payment.QPay/IQPayClient.cs
  4. 3 3
      src/Essensoft.AspNetCore.Payment.QPay/IQPayNotifyClient.cs
  5. 4 0
      src/Essensoft.AspNetCore.Payment.QPay/IQPayRequest.cs
  6. 1 1
      src/Essensoft.AspNetCore.Payment.QPay/Notify/QPayMicroPayNotify.cs
  7. 1 1
      src/Essensoft.AspNetCore.Payment.QPay/Notify/QPayUnifiedOrderNotify.cs
  8. 1 1
      src/Essensoft.AspNetCore.Payment.QPay/Parser/IQPayParser.cs
  9. 3 0
      src/Essensoft.AspNetCore.Payment.QPay/Parser/QPayListPropertyParser.cs
  10. 5 1
      src/Essensoft.AspNetCore.Payment.QPay/Parser/QPayXmlParser.cs
  11. 7 6
      src/Essensoft.AspNetCore.Payment.QPay/QPayClient.cs
  12. 3 0
      src/Essensoft.AspNetCore.Payment.QPay/QPayDictionary.cs
  13. 14 0
      src/Essensoft.AspNetCore.Payment.QPay/QPayException.cs
  14. 9 0
      src/Essensoft.AspNetCore.Payment.QPay/QPayNotify.cs
  15. 10 7
      src/Essensoft.AspNetCore.Payment.QPay/QPayNotifyClient.cs
  16. 0 5
      src/Essensoft.AspNetCore.Payment.QPay/QPayNotifyResponse.cs
  17. 1 1
      src/Essensoft.AspNetCore.Payment.QPay/QPayNotifyResult.cs
  18. 22 3
      src/Essensoft.AspNetCore.Payment.QPay/QPayObject.cs
  19. 3 0
      src/Essensoft.AspNetCore.Payment.QPay/QPayOptions.cs
  20. 4 19
      src/Essensoft.AspNetCore.Payment.QPay/QPayResponse.cs
  21. 3 0
      src/Essensoft.AspNetCore.Payment.QPay/Utility/QPaySignature.cs
  22. 3 0
      src/Essensoft.AspNetCore.Payment.QPay/Utility/QPayUtility.cs

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

@@ -224,7 +224,7 @@ namespace WebApplicationSample.Controllers
         {
         {
             try
             try
             {
             {
-                var notify = await _client.ExecuteAsync<QPayUnifiedOrderNotifyResponse>(Request);
+                var notify = await _client.ExecuteAsync<QPayUnifiedOrderNotify>(Request);
                 if ("SUCCESS" == notify.TradeState)
                 if ("SUCCESS" == notify.TradeState)
                 {
                 {
                     Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
                     Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
@@ -248,7 +248,7 @@ namespace WebApplicationSample.Controllers
         {
         {
             try
             try
             {
             {
-                var notify = await _client.ExecuteAsync<QPayMicroPayNotifyResponse>(Request);
+                var notify = await _client.ExecuteAsync<QPayMicroPayNotify>(Request);
                 if ("SUCCESS" == notify.TradeState)
                 if ("SUCCESS" == notify.TradeState)
                 {
                 {
                     Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
                     Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);

+ 4 - 0
src/Essensoft.AspNetCore.Payment.QPay/IQPayCertificateRequest.cs

@@ -2,6 +2,10 @@
 
 
 namespace Essensoft.AspNetCore.Payment.QPay
 namespace Essensoft.AspNetCore.Payment.QPay
 {
 {
+    /// <summary>
+    /// QPay 证书请求接口。
+    /// </summary>
+    /// <typeparam name="T"></typeparam>
     public interface IQPayCertificateRequest<T> where T : QPayResponse
     public interface IQPayCertificateRequest<T> where T : QPayResponse
     {
     {
         /// <summary>
         /// <summary>

+ 1 - 1
src/Essensoft.AspNetCore.Payment.QPay/IQPayClient.cs

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

+ 3 - 3
src/Essensoft.AspNetCore.Payment.QPay/IQPayNotifyClient.cs

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

+ 4 - 0
src/Essensoft.AspNetCore.Payment.QPay/IQPayRequest.cs

@@ -2,6 +2,10 @@
 
 
 namespace Essensoft.AspNetCore.Payment.QPay
 namespace Essensoft.AspNetCore.Payment.QPay
 {
 {
+    /// <summary>
+    /// QPay 请求接口。
+    /// </summary>
+    /// <typeparam name="T"></typeparam>
     public interface IQPayRequest<T> where T : QPayResponse
     public interface IQPayRequest<T> where T : QPayResponse
     {
     {
         /// <summary>
         /// <summary>

+ 1 - 1
src/Essensoft.AspNetCore.Payment.QPay/Notify/QPayMicroPayNotifyResponse.cs → src/Essensoft.AspNetCore.Payment.QPay/Notify/QPayMicroPayNotify.cs

@@ -6,7 +6,7 @@ namespace Essensoft.AspNetCore.Payment.QPay.Notify
     /// 提交付款码支付 - 支付结果通知
     /// 提交付款码支付 - 支付结果通知
     /// </summary>
     /// </summary>
     [XmlRoot("xml")]
     [XmlRoot("xml")]
-    public class QPayMicroPayNotifyResponse : QPayNotifyResponse
+    public class QPayMicroPayNotify : QPayNotify
     {
     {
         /// <summary>
         /// <summary>
         /// 应用ID
         /// 应用ID

+ 1 - 1
src/Essensoft.AspNetCore.Payment.QPay/Notify/QPayUnifiedOrderNotifyResponse.cs → src/Essensoft.AspNetCore.Payment.QPay/Notify/QPayUnifiedOrderNotify.cs

@@ -6,7 +6,7 @@ namespace Essensoft.AspNetCore.Payment.QPay.Notify
     /// 统一下单 - 支付结果通知
     /// 统一下单 - 支付结果通知
     /// </summary>
     /// </summary>
     [XmlRoot("xml")]
     [XmlRoot("xml")]
-    public class QPayUnifiedOrderNotifyResponse : QPayNotifyResponse
+    public class QPayUnifiedOrderNotify : QPayNotify
     {
     {
         /// <summary>
         /// <summary>
         /// 应用ID
         /// 应用ID

+ 1 - 1
src/Essensoft.AspNetCore.Payment.QPay/Parser/IQPayParser.cs

@@ -1,7 +1,7 @@
 namespace Essensoft.AspNetCore.Payment.QPay.Parser
 namespace Essensoft.AspNetCore.Payment.QPay.Parser
 {
 {
     /// <summary>
     /// <summary>
-    /// QQ钱包结果解析
+    /// QPay 解析器。
     /// </summary>
     /// </summary>
     public interface IQPayParser<T> where T : QPayObject
     public interface IQPayParser<T> where T : QPayObject
     {
     {

+ 3 - 0
src/Essensoft.AspNetCore.Payment.QPay/Parser/QPayListPropertyParser.cs

@@ -4,6 +4,9 @@ using System.Xml.Serialization;
 
 
 namespace Essensoft.AspNetCore.Payment.QPay.Parser
 namespace Essensoft.AspNetCore.Payment.QPay.Parser
 {
 {
+    /// <summary>
+    /// QPay ListProperty 解析器。
+    /// </summary>
     public class QPayListPropertyParser
     public class QPayListPropertyParser
     {
     {
         public List<T> Parse<T, TChildren>(QPayDictionary dic, int index = -1)
         public List<T> Parse<T, TChildren>(QPayDictionary dic, int index = -1)

+ 5 - 1
src/Essensoft.AspNetCore.Payment.QPay/Parser/QPayXmlParser.cs

@@ -5,7 +5,11 @@ using System.Xml.Serialization;
 
 
 namespace Essensoft.AspNetCore.Payment.QPay.Parser
 namespace Essensoft.AspNetCore.Payment.QPay.Parser
 {
 {
-    public class QPayXmlParser<T> : IQPayParser<T> where T : QPayResponse
+    /// <summary>
+    /// QPay XML 解析器。
+    /// </summary>
+    /// <typeparam name="T"></typeparam>
+    public class QPayXmlParser<T> : IQPayParser<T> where T : QPayObject
     {
     {
         public T Parse(string body)
         public T Parse(string body)
         {
         {

+ 7 - 6
src/Essensoft.AspNetCore.Payment.QPay/QPayClient.cs

@@ -8,6 +8,9 @@ using Microsoft.Extensions.Options;
 
 
 namespace Essensoft.AspNetCore.Payment.QPay
 namespace Essensoft.AspNetCore.Payment.QPay
 {
 {
+    /// <summary>
+    /// QPay 客户端。
+    /// </summary>
     public class QPayClient : IQPayClient
     public class QPayClient : IQPayClient
     {
     {
         private const string APPID = "appid";
         private const string APPID = "appid";
@@ -43,7 +46,6 @@ namespace Essensoft.AspNetCore.Payment.QPay
         public async Task<T> ExecuteAsync<T>(IQPayRequest<T> request, string optionsName) where T : QPayResponse
         public async Task<T> ExecuteAsync<T>(IQPayRequest<T> request, string optionsName) where T : QPayResponse
         {
         {
             var options = string.IsNullOrEmpty(optionsName) ? _optionsSnapshotAccessor.Value : _optionsSnapshotAccessor.Get(optionsName);
             var options = string.IsNullOrEmpty(optionsName) ? _optionsSnapshotAccessor.Value : _optionsSnapshotAccessor.Get(optionsName);
-            // 字典排序
             var sortedTxtParams = new QPayDictionary(request.GetParameters())
             var sortedTxtParams = new QPayDictionary(request.GetParameters())
             {
             {
                 { MCHID, options.MchId },
                 { MCHID, options.MchId },
@@ -89,7 +91,6 @@ namespace Essensoft.AspNetCore.Payment.QPay
         public async Task<T> ExecuteAsync<T>(IQPayCertificateRequest<T> request, string optionsName, string certificateName) where T : QPayResponse
         public async Task<T> ExecuteAsync<T>(IQPayCertificateRequest<T> request, string optionsName, string certificateName) where T : QPayResponse
         {
         {
             var options = string.IsNullOrEmpty(optionsName) ? _optionsSnapshotAccessor.Value : _optionsSnapshotAccessor.Get(optionsName);
             var options = string.IsNullOrEmpty(optionsName) ? _optionsSnapshotAccessor.Value : _optionsSnapshotAccessor.Get(optionsName);
-            // 字典排序
             var sortedTxtParams = new QPayDictionary(request.GetParameters())
             var sortedTxtParams = new QPayDictionary(request.GetParameters())
             {
             {
                 { MCHID, options.MchId },
                 { MCHID, options.MchId },
@@ -129,17 +130,17 @@ namespace Essensoft.AspNetCore.Payment.QPay
         {
         {
             if (string.IsNullOrEmpty(response.Body))
             if (string.IsNullOrEmpty(response.Body))
             {
             {
-                throw new Exception("sign check fail: Body is Empty!");
+                throw new QPayException("sign check fail: Body is Empty!");
             }
             }
 
 
             if (response.Parameters.Count == 0)
             if (response.Parameters.Count == 0)
             {
             {
-                throw new Exception("sign check fail: Parameters is Empty!");
+                throw new QPayException("sign check fail: Parameters is Empty!");
             }
             }
 
 
             if (!response.Parameters.TryGetValue("sign", out var sign))
             if (!response.Parameters.TryGetValue("sign", out var sign))
             {
             {
-                throw new Exception("sign check fail: sign is Empty!");
+                throw new QPayException("sign check fail: sign is Empty!");
             }
             }
 
 
             if (response.Parameters["return_code"] == "SUCCESS" && !string.IsNullOrEmpty(sign))
             if (response.Parameters["return_code"] == "SUCCESS" && !string.IsNullOrEmpty(sign))
@@ -147,7 +148,7 @@ namespace Essensoft.AspNetCore.Payment.QPay
                 var cal_sign = QPaySignature.SignWithKey(response.Parameters, options.Key);
                 var cal_sign = QPaySignature.SignWithKey(response.Parameters, options.Key);
                 if (cal_sign != sign)
                 if (cal_sign != sign)
                 {
                 {
-                    throw new Exception("sign check fail: check Sign and Data Fail!");
+                    throw new QPayException("sign check fail: check Sign and Data Fail!");
                 }
                 }
             }
             }
         }
         }

+ 3 - 0
src/Essensoft.AspNetCore.Payment.QPay/QPayDictionary.cs

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

+ 14 - 0
src/Essensoft.AspNetCore.Payment.QPay/QPayException.cs

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

+ 9 - 0
src/Essensoft.AspNetCore.Payment.QPay/QPayNotify.cs

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

+ 10 - 7
src/Essensoft.AspNetCore.Payment.QPay/QPayNotifyClient.cs

@@ -10,6 +10,9 @@ using Microsoft.Extensions.Options;
 
 
 namespace Essensoft.AspNetCore.Payment.QPay
 namespace Essensoft.AspNetCore.Payment.QPay
 {
 {
+    /// <summary>
+    /// QPay 通知解析客户端。
+    /// </summary>
     public class QPayNotifyClient : IQPayNotifyClient
     public class QPayNotifyClient : IQPayNotifyClient
     {
     {
         private readonly ILogger _logger;
         private readonly ILogger _logger;
@@ -29,12 +32,12 @@ namespace Essensoft.AspNetCore.Payment.QPay
 
 
         #region IQPayNotifyClient Members
         #region IQPayNotifyClient Members
 
 
-        public async Task<T> ExecuteAsync<T>(HttpRequest request) where T : QPayNotifyResponse
+        public async Task<T> ExecuteAsync<T>(HttpRequest request) where T : QPayNotify
         {
         {
             return await ExecuteAsync<T>(request, null);
             return await ExecuteAsync<T>(request, null);
         }
         }
 
 
-        public async Task<T> ExecuteAsync<T>(HttpRequest request, string optionsName) where T : QPayNotifyResponse
+        public async Task<T> ExecuteAsync<T>(HttpRequest request, string optionsName) where T : QPayNotify
         {
         {
             var options = string.IsNullOrEmpty(optionsName) ? _optionsSnapshotAccessor.Value : _optionsSnapshotAccessor.Get(optionsName);
             var options = string.IsNullOrEmpty(optionsName) ? _optionsSnapshotAccessor.Value : _optionsSnapshotAccessor.Get(optionsName);
             var body = await new StreamReader(request.Body, Encoding.UTF8).ReadToEndAsync();
             var body = await new StreamReader(request.Body, Encoding.UTF8).ReadToEndAsync();
@@ -50,27 +53,27 @@ namespace Essensoft.AspNetCore.Payment.QPay
 
 
         #region Common Method
         #region Common Method
 
 
-        private void CheckNotifySign(QPayNotifyResponse response, QPayOptions options)
+        private void CheckNotifySign(QPayNotify response, QPayOptions options)
         {
         {
             if (string.IsNullOrEmpty(response.Body))
             if (string.IsNullOrEmpty(response.Body))
             {
             {
-                throw new Exception("sign check fail: Body is Empty!");
+                throw new QPayException("sign check fail: Body is Empty!");
             }
             }
 
 
             if (response.Parameters.Count == 0)
             if (response.Parameters.Count == 0)
             {
             {
-                throw new Exception("sign check fail: Parameters is Empty!");
+                throw new QPayException("sign check fail: Parameters is Empty!");
             }
             }
 
 
             if (!response.Parameters.TryGetValue("sign", out var sign))
             if (!response.Parameters.TryGetValue("sign", out var sign))
             {
             {
-                throw new Exception("sign check fail: sign is Empty!");
+                throw new QPayException("sign check fail: sign is Empty!");
             }
             }
 
 
             var cal_sign = QPaySignature.SignWithKey(response.Parameters, options.Key);
             var cal_sign = QPaySignature.SignWithKey(response.Parameters, options.Key);
             if (cal_sign != sign)
             if (cal_sign != sign)
             {
             {
-                throw new Exception("sign check fail: check Sign and Data Fail!");
+                throw new QPayException("sign check fail: check Sign and Data Fail!");
             }
             }
         }
         }
 
 

+ 0 - 5
src/Essensoft.AspNetCore.Payment.QPay/QPayNotifyResponse.cs

@@ -1,5 +0,0 @@
-namespace Essensoft.AspNetCore.Payment.QPay
-{
-    public abstract class QPayNotifyResponse : QPayResponse
-    {}
-}

+ 1 - 1
src/Essensoft.AspNetCore.Payment.QPay/QPayNotifyResult.cs

@@ -3,7 +3,7 @@
 namespace Essensoft.AspNetCore.Payment.QPay
 namespace Essensoft.AspNetCore.Payment.QPay
 {
 {
     /// <summary>
     /// <summary>
-    /// QQ钱包 - 通知应答
+    /// QPay 通知响应。
     /// </summary>
     /// </summary>
     public class QPayNotifyResult
     public class QPayNotifyResult
     {
     {

+ 22 - 3
src/Essensoft.AspNetCore.Payment.QPay/QPayObject.cs

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

+ 3 - 0
src/Essensoft.AspNetCore.Payment.QPay/QPayOptions.cs

@@ -2,6 +2,9 @@
 
 
 namespace Essensoft.AspNetCore.Payment.QPay
 namespace Essensoft.AspNetCore.Payment.QPay
 {
 {
+    /// <summary>
+    /// QPay 选项。
+    /// </summary>
     public class QPayOptions
     public class QPayOptions
     {
     {
         /// <summary>
         /// <summary>

+ 4 - 19
src/Essensoft.AspNetCore.Payment.QPay/QPayResponse.cs

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

+ 3 - 0
src/Essensoft.AspNetCore.Payment.QPay/Utility/QPaySignature.cs

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

+ 3 - 0
src/Essensoft.AspNetCore.Payment.QPay/Utility/QPayUtility.cs

@@ -3,6 +3,9 @@ using System.Text;
 
 
 namespace Essensoft.AspNetCore.Payment.QPay.Utility
 namespace Essensoft.AspNetCore.Payment.QPay.Utility
 {
 {
+    /// <summary>
+    /// QPay 工具类。
+    /// </summary>
     public static class QPayUtility
     public static class QPayUtility
     {
     {
         /// <summary>
         /// <summary>