Преглед изворни кода

1.LianLianPay***ReturnResponse=>LianLianPay***Return 2.LianLianPay***NotifyResponse=>LianLianPay***Notify 3.添加注释 4.优化

Roc пре 6 година
родитељ
комит
804af370ee
25 измењених фајлова са 95 додато и 53 уклоњено
  1. 2 2
      samples/WebApplicationSample/Controllers/NotifyController.cs
  2. 1 1
      src/Essensoft.AspNetCore.Payment.LianLianPay/ILianLianPayClient.cs
  3. 3 3
      src/Essensoft.AspNetCore.Payment.LianLianPay/ILianLianPayNotifyClient.cs
  4. 1 1
      src/Essensoft.AspNetCore.Payment.LianLianPay/ILianLianPayRequest.cs
  5. 7 5
      src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayClient.cs
  6. 3 0
      src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayDictionary.cs
  7. 14 0
      src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayException.cs
  8. 9 0
      src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayNotify.cs
  9. 9 6
      src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayNotifyClient.cs
  10. 0 5
      src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayNotifyResponse.cs
  11. 1 1
      src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayNotifyResult.cs
  12. 19 2
      src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayObject.cs
  13. 3 0
      src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayOptions.cs
  14. 4 13
      src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayResponse.cs
  15. 1 1
      src/Essensoft.AspNetCore.Payment.LianLianPay/Notify/LianLianPayCardBindNotify.cs
  16. 1 1
      src/Essensoft.AspNetCore.Payment.LianLianPay/Notify/LianLianPayCardBindReturn.cs
  17. 1 1
      src/Essensoft.AspNetCore.Payment.LianLianPay/Notify/LianLianPayReceiveMoneyNotify.cs
  18. 1 1
      src/Essensoft.AspNetCore.Payment.LianLianPay/Notify/LianLianPayReceiveMoneyReturn.cs
  19. 1 1
      src/Essensoft.AspNetCore.Payment.LianLianPay/Notify/LianLianPayRefundNotify.cs
  20. 1 1
      src/Essensoft.AspNetCore.Payment.LianLianPay/Notify/LianLianPaySendMoneyNotify.cs
  21. 1 1
      src/Essensoft.AspNetCore.Payment.LianLianPay/Parser/ILianLianPayParser.cs
  22. 5 1
      src/Essensoft.AspNetCore.Payment.LianLianPay/Parser/LianLianPayDictionaryParser.cs
  23. 1 6
      src/Essensoft.AspNetCore.Payment.LianLianPay/Parser/LianLianPayJsonParser.cs
  24. 3 0
      src/Essensoft.AspNetCore.Payment.LianLianPay/Utility/LianLianPaySecurity.cs
  25. 3 0
      src/Essensoft.AspNetCore.Payment.LianLianPay/Utility/LianLianPayUtility.cs

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

@@ -330,7 +330,7 @@ namespace WebApplicationSample.Controllers
         {
             try
             {
-                var notify = await _client.ExecuteAsync<LianLianPayReceiveMoneyNotifyResponse>(Request);
+                var notify = await _client.ExecuteAsync<LianLianPayReceiveMoneyNotify>(Request);
                 Console.WriteLine("NoOrder: " + notify.NoOrder);
                 return LianLianPayNotifyResult.Success;
             }
@@ -346,7 +346,7 @@ namespace WebApplicationSample.Controllers
         {
             try
             {
-                var notify = await _client.ExecuteAsync<LianLianPayRefundNotifyResponse>(Request);
+                var notify = await _client.ExecuteAsync<LianLianPayRefundNotify>(Request);
                 Console.WriteLine("NoRefund: " + notify.NoRefund);
                 return LianLianPayNotifyResult.Success;
             }

+ 1 - 1
src/Essensoft.AspNetCore.Payment.LianLianPay/ILianLianPayClient.cs

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

+ 3 - 3
src/Essensoft.AspNetCore.Payment.LianLianPay/ILianLianPayNotifyClient.cs

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

+ 1 - 1
src/Essensoft.AspNetCore.Payment.LianLianPay/ILianLianPayRequest.cs

@@ -3,7 +3,7 @@
 namespace Essensoft.AspNetCore.Payment.LianLianPay
 {
     /// <summary>
-    /// 卡bin查询
+    /// LianLianPay 请求接口
     /// </summary>
     /// <typeparam name="T"></typeparam>
     public interface ILianLianPayRequest<T> where T : LianLianPayResponse

+ 7 - 5
src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayClient.cs

@@ -12,6 +12,9 @@ using Newtonsoft.Json;
 
 namespace Essensoft.AspNetCore.Payment.LianLianPay
 {
+    /// <summary>
+    /// LianLianPay 客户端。
+    /// </summary>
     public class LianLianPayClient : ILianLianPayClient
     {
         private const string OID_PARTNER = "oid_partner";
@@ -48,7 +51,6 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay
         public async Task<T> ExecuteAsync<T>(ILianLianPayRequest<T> request, string optionsName) where T : LianLianPayResponse
         {
             var options = string.IsNullOrEmpty(optionsName) ? _optionsSnapshotAccessor.Value : _optionsSnapshotAccessor.Get(optionsName);
-            // 字典排序
             var txtParams = new LianLianPayDictionary(request.GetParameters())
             {
                 { OID_PARTNER, options.OidPartner },
@@ -117,23 +119,23 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay
         {
             if (string.IsNullOrEmpty(response.Body))
             {
-                throw new Exception("sign check fail: Body is Empty!");
+                throw new LianLianPayException("sign check fail: Body is Empty!");
             }
 
             if (response.Parameters.Count == 0)
             {
-                throw new Exception("sign check fail: Parameters is Empty!");
+                throw new LianLianPayException("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 LianLianPayException("sign check fail: sign is Empty!");
             }
 
             var prestr = LianLianPaySecurity.GetSignContent(response.Parameters, excludePara);
             if (!MD5WithRSA.VerifyData(prestr, sign, options.PublicKey))
             {
-                throw new Exception("sign check fail: check Sign and Data Fail JSON also");
+                throw new LianLianPayException("sign check fail: check Sign and Data Fail JSON also");
             }
         }
 

+ 3 - 0
src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayDictionary.cs

@@ -3,6 +3,9 @@ using System.Collections.Generic;
 
 namespace Essensoft.AspNetCore.Payment.LianLianPay
 {
+    /// <summary>
+    /// LianLianPay 字典。
+    /// </summary>
     public class LianLianPayDictionary : SortedDictionary<string, string>
     {
         private const string DATE_TIME_FORMAT = "yyyyMMddHHmmss";

+ 14 - 0
src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayException.cs

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

+ 9 - 0
src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayNotify.cs

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

+ 9 - 6
src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayNotifyClient.cs

@@ -10,6 +10,9 @@ using Microsoft.Extensions.Options;
 
 namespace Essensoft.AspNetCore.Payment.LianLianPay
 {
+    /// <summary>
+    /// LianLianPay 通知解析客户端。
+    /// </summary>
     public class LianLianPayNotifyClient : ILianLianPayNotifyClient
     {
         private readonly ILogger _logger;
@@ -29,12 +32,12 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay
 
         #region ILianLianPayNotifyClient Members
 
-        public async Task<T> ExecuteAsync<T>(HttpRequest request) where T : LianLianPayNotifyResponse
+        public async Task<T> ExecuteAsync<T>(HttpRequest request) where T : LianLianPayNotify
         {
             return await ExecuteAsync<T>(request, null);
         }
 
-        public async Task<T> ExecuteAsync<T>(HttpRequest request, string optionsName) where T : LianLianPayNotifyResponse
+        public async Task<T> ExecuteAsync<T>(HttpRequest request, string optionsName) where T : LianLianPayNotify
         {
             var options = string.IsNullOrEmpty(optionsName) ? _optionsSnapshotAccessor.Value : _optionsSnapshotAccessor.Get(optionsName);
             if (request.HasFormContentType)
@@ -60,7 +63,7 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay
                 return rsp;
             }
 
-            throw new Exception("content type is not supported");
+            throw new LianLianPayException("content type is not supported");
         }
 
         #endregion
@@ -82,18 +85,18 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay
         {
             if (para.Count == 0)
             {
-                throw new Exception("sign check fail: para is Empty!");
+                throw new LianLianPayException("sign check fail: para is Empty!");
             }
 
             if (!para.TryGetValue("sign", out var sign))
             {
-                throw new Exception("sign check fail: sign is Empty!");
+                throw new LianLianPayException("sign check fail: sign is Empty!");
             }
 
             var prestr = LianLianPaySecurity.GetSignContent(para);
             if (!MD5WithRSA.VerifyData(prestr, sign, options.PublicKey))
             {
-                throw new Exception("sign check fail: check Sign and Data Fail JSON also");
+                throw new LianLianPayException("sign check fail: check Sign and Data Fail JSON also");
             }
         }
 

+ 0 - 5
src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayNotifyResponse.cs

@@ -1,5 +0,0 @@
-namespace Essensoft.AspNetCore.Payment.LianLianPay
-{
-    public abstract class LianLianPayNotifyResponse : LianLianPayResponse
-    {}
-}

+ 1 - 1
src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayNotifyResult.cs

@@ -3,7 +3,7 @@
 namespace Essensoft.AspNetCore.Payment.LianLianPay
 {
     /// <summary>
-    /// 连连支付 - 通知应答
+    /// LianLianPay 通知应答。
     /// </summary>
     public class LianLianPayNotifyResult
     {

+ 19 - 2
src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayObject.cs

@@ -1,5 +1,22 @@
-namespace Essensoft.AspNetCore.Payment.LianLianPay
+using Newtonsoft.Json;
+
+namespace Essensoft.AspNetCore.Payment.LianLianPay
 {
+    /// <summary>
+    /// LianLianPay 基础对象。
+    /// </summary>
     public abstract class LianLianPayObject
-    {}
+    {
+        /// <summary>
+        /// 响应原始内容
+        /// </summary>
+        [JsonIgnore]
+        public string Body { get; set; }
+
+        /// <summary>
+        /// 响应原始参数
+        /// </summary>
+        [JsonIgnore]
+        public LianLianPayDictionary Parameters { get; internal set; }
+    }
 }

+ 3 - 0
src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayOptions.cs

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

+ 4 - 13
src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayResponse.cs

@@ -1,19 +1,10 @@
-using Newtonsoft.Json;
-
-namespace Essensoft.AspNetCore.Payment.LianLianPay
+namespace Essensoft.AspNetCore.Payment.LianLianPay
 {
+    /// <summary>
+    /// LianLianPay 响应。
+    /// </summary>
     public abstract class LianLianPayResponse : LianLianPayObject
     {
-        /// <summary>
-        /// 响应原始内容
-        /// </summary>
-        [JsonIgnore]
-        public string Body { get; set; }
 
-        /// <summary>
-        /// 响应原始参数
-        /// </summary>
-        [JsonIgnore]
-        public LianLianPayDictionary Parameters { get; internal set; }
     }
 }

+ 1 - 1
src/Essensoft.AspNetCore.Payment.LianLianPay/Notify/LianLianPayCardBindNotifyResponse.cs → src/Essensoft.AspNetCore.Payment.LianLianPay/Notify/LianLianPayCardBindNotify.cs

@@ -5,7 +5,7 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay.Notify
     /// <summary>
     /// 签约类异步通知
     /// </summary>
-    public class LianLianPayCardBindNotifyResponse : LianLianPayNotifyResponse
+    public class LianLianPayCardBindNotify : LianLianPayNotify
     {
         /// <summary>
         /// 商户编号是商户在连连支付支付平台上开设的商户号码,为18位数字,如:201304121000001004。

+ 1 - 1
src/Essensoft.AspNetCore.Payment.LianLianPay/Notify/LianLianPayCardBindReturnResponse.cs → src/Essensoft.AspNetCore.Payment.LianLianPay/Notify/LianLianPayCardBindReturn.cs

@@ -5,7 +5,7 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay.Notify
     /// <summary>
     /// 签约类同步通知
     /// </summary>
-    public class LianLianPayCardBindReturnResponse : LianLianPayNotifyResponse
+    public class LianLianPayCardBindReturn : LianLianPayNotify
     {
         /// <summary>
         /// 交易结果代码。 

+ 1 - 1
src/Essensoft.AspNetCore.Payment.LianLianPay/Notify/LianLianPayReceiveMoneyNotifyResponse.cs → src/Essensoft.AspNetCore.Payment.LianLianPay/Notify/LianLianPayReceiveMoneyNotify.cs

@@ -5,7 +5,7 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay.Notify
     /// <summary>
     /// 收款类异步通知
     /// </summary>
-    public class LianLianPayReceiveMoneyNotifyResponse : LianLianPayNotifyResponse
+    public class LianLianPayReceiveMoneyNotify : LianLianPayNotify
     {
         /// <summary>
         /// 商户编号是商户在连连支付支付平台上开设的商户号码,为18位数字,如:201304121000001004。

+ 1 - 1
src/Essensoft.AspNetCore.Payment.LianLianPay/Notify/LianLianPayReceiveMoneyReturnResponse.cs → src/Essensoft.AspNetCore.Payment.LianLianPay/Notify/LianLianPayReceiveMoneyReturn.cs

@@ -5,7 +5,7 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay.Notify
     /// <summary>
     /// 收款类同步通知
     /// </summary>
-    public class LianLianPayReceiveMoneyReturnResponse : LianLianPayNotifyResponse
+    public class LianLianPayReceiveMoneyReturnResponse : LianLianPayNotify
     {
         /// <summary>
         /// 交易结果代码。

+ 1 - 1
src/Essensoft.AspNetCore.Payment.LianLianPay/Notify/LianLianPayRefundNotifyResponse.cs → src/Essensoft.AspNetCore.Payment.LianLianPay/Notify/LianLianPayRefundNotify.cs

@@ -5,7 +5,7 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay.Notify
     /// <summary>
     /// 退款类异步通知
     /// </summary>
-    public class LianLianPayRefundNotifyResponse : LianLianPayNotifyResponse
+    public class LianLianPayRefundNotify : LianLianPayNotify
     {
         /// <summary>
         /// 商户编号是商户在连连支付支付平台上开设的商户号码,为18位数字,如:201304121000001004。

+ 1 - 1
src/Essensoft.AspNetCore.Payment.LianLianPay/Notify/LianLianPaySendMoneyNotifyResponse.cs → src/Essensoft.AspNetCore.Payment.LianLianPay/Notify/LianLianPaySendMoneyNotify.cs

@@ -5,7 +5,7 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay.Notify
     /// <summary>
     /// 付款类异步通知
     /// </summary>
-    public class LianLianPaySendMoneyNotifyResponse : LianLianPayNotifyResponse
+    public class LianLianPaySendMoneyNotify : LianLianPayNotify
     {
         /// <summary>
         /// 商户编号是商户在连连支付支付平台上开设的商户号码,为18位数字,如:201304121000001004。

+ 1 - 1
src/Essensoft.AspNetCore.Payment.LianLianPay/Parser/ILianLianPayParser.cs

@@ -4,7 +4,7 @@
     /// LianLianPay API响应解释器接口。
     /// </summary>
     /// <typeparam name="T">领域对象</typeparam>
-    public interface ILianLianPayParser<T> where T : LianLianPayResponse
+    public interface ILianLianPayParser<T> where T : LianLianPayObject
     {
         /// <summary>
         /// 把响应字符串解释成相应的领域对象。

+ 5 - 1
src/Essensoft.AspNetCore.Payment.LianLianPay/Parser/LianLianPayDictionaryParser.cs

@@ -4,7 +4,11 @@ using Newtonsoft.Json;
 
 namespace Essensoft.AspNetCore.Payment.LianLianPay.Parser
 {
-    public class LianLianPayDictionaryParser<T> where T : LianLianPayResponse
+    /// <summary>
+    /// LianLianPay 字典解释器。
+    /// </summary>
+    /// <typeparam name="T"></typeparam>
+    public class LianLianPayDictionaryParser<T> where T : LianLianPayObject
     {
         public T Parse(IDictionary dic)
         {

+ 1 - 6
src/Essensoft.AspNetCore.Payment.LianLianPay/Parser/LianLianPayJsonParser.cs

@@ -7,17 +7,12 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay.Parser
     /// <summary>
     /// LianLianPay JSON响应通用解释器。
     /// </summary>
-    public class LianLianPayJsonParser<T> : ILianLianPayParser<T> where T : LianLianPayResponse
+    public class LianLianPayJsonParser<T> : ILianLianPayParser<T> where T : LianLianPayObject
     {
         #region ILianLianPayParser<T> Members
 
         public T Parse(string body)
         {
-            if (string.IsNullOrEmpty(body))
-            {
-                throw new ArgumentNullException(nameof(body));
-            }
-
             T rsp = null;
             var parameters = new LianLianPayDictionary();
 

+ 3 - 0
src/Essensoft.AspNetCore.Payment.LianLianPay/Utility/LianLianPaySecurity.cs

@@ -6,6 +6,9 @@ using Org.BouncyCastle.Crypto;
 
 namespace Essensoft.AspNetCore.Payment.LianLianPay.Utility
 {
+    /// <summary>
+    /// LianLianPay °²È«Àà¡£
+    /// </summary>
     public class LianLianPaySecurity
     {
         public static string GetSignContent(LianLianPayDictionary para, List<string> exclude = null)

+ 3 - 0
src/Essensoft.AspNetCore.Payment.LianLianPay/Utility/LianLianPayUtility.cs

@@ -7,6 +7,9 @@ using Microsoft.AspNetCore.Http;
 
 namespace Essensoft.AspNetCore.Payment.LianLianPay.Utility
 {
+    /// <summary>
+    /// LianLianPay 工具类。
+    /// </summary>
     public static class LianLianPayUtility
     {
         /// <summary>