Selaa lähdekoodia

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

Roc 6 vuotta sitten
vanhempi
sitoutus
c1f32e94c0
24 muutettua tiedostoa jossa 108 lisäystä ja 50 poistoa
  1. 1 1
      samples/WebApplicationSample/Controllers/JDPayController.cs
  2. 2 2
      samples/WebApplicationSample/Controllers/NotifyController.cs
  3. 1 1
      src/Essensoft.AspNetCore.Payment.JDPay/IJDPayClient.cs
  4. 4 0
      src/Essensoft.AspNetCore.Payment.JDPay/IJDPayNPP10Request.cs
  5. 3 3
      src/Essensoft.AspNetCore.Payment.JDPay/IJDPayNotifyClient.cs
  6. 4 0
      src/Essensoft.AspNetCore.Payment.JDPay/IJDPayRequest.cs
  7. 5 2
      src/Essensoft.AspNetCore.Payment.JDPay/JDPayClient.cs
  8. 3 0
      src/Essensoft.AspNetCore.Payment.JDPay/JDPayDictionary.cs
  9. 14 0
      src/Essensoft.AspNetCore.Payment.JDPay/JDPayException.cs
  10. 4 1
      src/Essensoft.AspNetCore.Payment.JDPay/JDPayNotify.cs
  11. 16 13
      src/Essensoft.AspNetCore.Payment.JDPay/JDPayNotifyClient.cs
  12. 1 1
      src/Essensoft.AspNetCore.Payment.JDPay/JDPayNotifyResult.cs
  13. 19 2
      src/Essensoft.AspNetCore.Payment.JDPay/JDPayObject.cs
  14. 3 0
      src/Essensoft.AspNetCore.Payment.JDPay/JDPayOptions.cs
  15. 4 14
      src/Essensoft.AspNetCore.Payment.JDPay/JDPayResponse.cs
  16. 1 1
      src/Essensoft.AspNetCore.Payment.JDPay/Notify/JDPayAsyncNotify.cs
  17. 1 1
      src/Essensoft.AspNetCore.Payment.JDPay/Notify/JDPayDefrayPayNotify.cs
  18. 1 1
      src/Essensoft.AspNetCore.Payment.JDPay/Notify/JDPaySyncReturn.cs
  19. 1 1
      src/Essensoft.AspNetCore.Payment.JDPay/Parser/IJDPayParser.cs
  20. 5 1
      src/Essensoft.AspNetCore.Payment.JDPay/Parser/JDPayDictionaryParser.cs
  21. 5 1
      src/Essensoft.AspNetCore.Payment.JDPay/Parser/JDPayXmlParser.cs
  22. 1 1
      src/Essensoft.AspNetCore.Payment.JDPay/Utility/JDPayContants.cs
  23. 6 3
      src/Essensoft.AspNetCore.Payment.JDPay/Utility/JDPaySecurity.cs
  24. 3 0
      src/Essensoft.AspNetCore.Payment.JDPay/Utility/JDPayUtility.cs

+ 1 - 1
samples/WebApplicationSample/Controllers/JDPayController.cs

@@ -324,7 +324,7 @@ namespace WebApplicationSample.Controllers
         {
             try
             {
-                var notify = await _notifyClient.ExecuteAsync<JDPaySyncReturnResponse>(Request);
+                var notify = await _notifyClient.ExecuteAsync<JDPaySyncReturn>(Request);
                 ViewData["response"] = "支付成功";
                 return View();
             }

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

@@ -283,7 +283,7 @@ namespace WebApplicationSample.Controllers
         {
             try
             {
-                var notify = await _client.ExecuteAsync<JDPayAsyncNotifyResponse>(Request);
+                var notify = await _client.ExecuteAsync<JDPayAsyncNotify>(Request);
                 Console.WriteLine("TradeNum: " + notify.TradeNum + " tradeType :" + notify.TradeType);// notify.TradeType 0-消费 1-退款
                 return JDPayNotifyResult.Success;
             }
@@ -299,7 +299,7 @@ namespace WebApplicationSample.Controllers
         {
             try
             {
-                var notify = await _client.ExecuteAsync<JDPayDefrayPayNotifyResponse>(Request);
+                var notify = await _client.ExecuteAsync<JDPayDefrayPayNotify>(Request);
                 Console.WriteLine("trade_no: " + notify.TradeNo + " trade_amount :" + notify.TradeAmount);
                 return JDPayNotifyResult.Success;
             }

+ 1 - 1
src/Essensoft.AspNetCore.Payment.JDPay/IJDPayClient.cs

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

+ 4 - 0
src/Essensoft.AspNetCore.Payment.JDPay/IJDPayNPP10Request.cs

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

+ 3 - 3
src/Essensoft.AspNetCore.Payment.JDPay/IJDPayNotifyClient.cs

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

+ 4 - 0
src/Essensoft.AspNetCore.Payment.JDPay/IJDPayRequest.cs

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

+ 5 - 2
src/Essensoft.AspNetCore.Payment.JDPay/JDPayClient.cs

@@ -14,6 +14,9 @@ using Newtonsoft.Json;
 
 namespace Essensoft.AspNetCore.Payment.JDPay
 {
+    /// <summary>
+    /// JDPay 客户端。
+    /// </summary>
     public class JDPayClient : IJDPayClient
     {
         private readonly ILogger _logger;
@@ -88,7 +91,7 @@ namespace Essensoft.AspNetCore.Payment.JDPay
                     }
                     else
                     {
-                        throw new Exception("sign check fail: check Sign and Data Fail!");
+                        throw new JDPayException("sign check fail: check Sign and Data Fail!");
                     }
                 }
                 return rsp;
@@ -156,7 +159,7 @@ namespace Essensoft.AspNetCore.Payment.JDPay
                 var dic = JsonConvert.DeserializeObject<JDPayDictionary>(body);
                 if (!JDPaySecurity.VerifySign(dic, options.SingKey))
                 {
-                    throw new Exception("sign check fail: check Sign and Data Fail!");
+                    throw new JDPayException("sign check fail: check Sign and Data Fail!");
                 }
 
                 var rsp = JsonConvert.DeserializeObject<T>(body);

+ 3 - 0
src/Essensoft.AspNetCore.Payment.JDPay/JDPayDictionary.cs

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

+ 14 - 0
src/Essensoft.AspNetCore.Payment.JDPay/JDPayException.cs

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

+ 4 - 1
src/Essensoft.AspNetCore.Payment.JDPay/JDPayNotifyResponse.cs → src/Essensoft.AspNetCore.Payment.JDPay/JDPayNotify.cs

@@ -2,7 +2,10 @@
 
 namespace Essensoft.AspNetCore.Payment.JDPay
 {
-    public abstract class JDPayNotifyResponse : JDPayResponse
+    /// <summary>
+    /// JDPay 通知。
+    /// </summary>
+    public abstract class JDPayNotify : JDPayObject
     {
         /// <summary>
         /// 原始参数

+ 16 - 13
src/Essensoft.AspNetCore.Payment.JDPay/JDPayNotifyClient.cs

@@ -13,6 +13,9 @@ using Microsoft.Extensions.Options;
 
 namespace Essensoft.AspNetCore.Payment.JDPay
 {
+    /// <summary>
+    /// JDPay 通知解析客户端。
+    /// </summary>
     public class JDPayNotifyClient : IJDPayNotifyClient
     {
         private readonly ILogger _logger;
@@ -32,19 +35,19 @@ namespace Essensoft.AspNetCore.Payment.JDPay
 
         #region IJDPayNotifyClient Members
 
-        public async Task<T> ExecuteAsync<T>(HttpRequest request) where T : JDPayNotifyResponse
+        public async Task<T> ExecuteAsync<T>(HttpRequest request) where T : JDPayNotify
         {
             return await ExecuteAsync<T>(request, null);
         }
 
-        public async Task<T> ExecuteAsync<T>(HttpRequest request, string optionsName) where T : JDPayNotifyResponse
+        public async Task<T> ExecuteAsync<T>(HttpRequest request, string optionsName) where T : JDPayNotify
         {
             var options = string.IsNullOrEmpty(optionsName) ? _optionsSnapshotAccessor.Value : _optionsSnapshotAccessor.Get(optionsName);
             if (request.HasFormContentType || request.Method == "GET")
             {
                 var rspInstance = Activator.CreateInstance<T>();
 
-                var parameters = GetParameters(request, options, !(rspInstance is JDPayDefrayPayNotifyResponse));
+                var parameters = GetParameters(request, options, !(rspInstance is JDPayDefrayPayNotify));
 
                 var query = JDPayUtility.BuildQuery(parameters);
                 _logger.Log(options.LogLevel, "Request:{query}", query);
@@ -52,7 +55,7 @@ namespace Essensoft.AspNetCore.Payment.JDPay
                 var parser = new JDPayDictionaryParser<T>();
                 var rsp = parser.Parse(parameters);
 
-                if (rsp is JDPayDefrayPayNotifyResponse)
+                if (rsp is JDPayDefrayPayNotify)
                 {
                     CheckNotifyDefrayPaySign(rsp.Parameters, options);
                 }
@@ -102,13 +105,13 @@ namespace Essensoft.AspNetCore.Payment.JDPay
                         return rsp;
                     }
 
-                    throw new Exception("sign check fail: check Sign and Data Fail!");
+                    throw new JDPayException("sign check fail: check Sign and Data Fail!");
                 }
 
-                throw new Exception("encrypt is Empty!");
+                throw new JDPayException("encrypt is Empty!");
             }
 
-            throw new Exception("content type is not supported!");
+            throw new JDPayException("content type is not supported!");
         }
 
         #endregion
@@ -156,18 +159,18 @@ namespace Essensoft.AspNetCore.Payment.JDPay
         {
             if (parameters.Count == 0)
             {
-                throw new Exception("sign check fail: parameters is Empty!");
+                throw new JDPayException("sign check fail: parameters is Empty!");
             }
 
             if (!parameters.TryGetValue(JDPayContants.SIGN, out var sign))
             {
-                throw new Exception("sign check fail: sign is Empty!");
+                throw new JDPayException("sign check fail: sign is Empty!");
             }
 
             var signContent = JDPaySecurity.GetSignContent(parameters);
             if (!JDPaySecurity.RSACheckContent(signContent, sign, options.PublicKey))
             {
-                throw new Exception("sign check fail: check Sign and Data Fail");
+                throw new JDPayException("sign check fail: check Sign and Data Fail");
             }
         }
 
@@ -175,17 +178,17 @@ namespace Essensoft.AspNetCore.Payment.JDPay
         {
             if (parameters.Count == 0)
             {
-                throw new Exception("sign check fail: parameters is Empty!");
+                throw new JDPayException("sign check fail: parameters is Empty!");
             }
 
             if (!parameters.TryGetValue(JDPayContants.SIGN_DATA, out var sign_data))
             {
-                throw new Exception("sign check fail: sign is Empty!");
+                throw new JDPayException("sign check fail: sign is Empty!");
             }
 
             if (!JDPaySecurity.VerifySign(parameters, options.SingKey))
             {
-                throw new Exception("sign check fail: check Sign and Data Fail!");
+                throw new JDPayException("sign check fail: check Sign and Data Fail!");
             }
         }
 

+ 1 - 1
src/Essensoft.AspNetCore.Payment.JDPay/JDPayNotifyResult.cs

@@ -3,7 +3,7 @@
 namespace Essensoft.AspNetCore.Payment.JDPay
 {
     /// <summary>
-    /// 京东支付 - 通知应答
+    /// JDPay 通知应答。
     /// </summary>
     public class JDPayNotifyResult
     {

+ 19 - 2
src/Essensoft.AspNetCore.Payment.JDPay/JDPayObject.cs

@@ -1,5 +1,22 @@
-namespace Essensoft.AspNetCore.Payment.JDPay
+using System.Xml.Serialization;
+
+namespace Essensoft.AspNetCore.Payment.JDPay
 {
+    /// <summary>
+    /// JDPay 基础对象。
+    /// </summary>
     public abstract class JDPayObject
-    {}
+    {
+        /// <summary>
+        /// 原始内容
+        /// </summary>
+        [XmlIgnore]
+        public string Body { get; set; }
+
+        /// <summary>
+        /// 加密报文
+        /// </summary>
+        [XmlElement("encrypt")]
+        public string Encrypt { get; set; }
+    }
 }

+ 3 - 0
src/Essensoft.AspNetCore.Payment.JDPay/JDPayOptions.cs

@@ -5,6 +5,9 @@ using Org.BouncyCastle.Crypto;
 
 namespace Essensoft.AspNetCore.Payment.JDPay
 {
+    /// <summary>
+    /// JDPay 选项。
+    /// </summary>
     public class JDPayOptions
     {
         internal byte[] DesKeyBase64;

+ 4 - 14
src/Essensoft.AspNetCore.Payment.JDPay/JDPayResponse.cs

@@ -1,19 +1,9 @@
-using System.Xml.Serialization;
-
-namespace Essensoft.AspNetCore.Payment.JDPay
+namespace Essensoft.AspNetCore.Payment.JDPay
 {
+    /// <summary>
+    /// JDPay 响应。
+    /// </summary>
     public abstract class JDPayResponse : JDPayObject
     {
-        /// <summary>
-        /// 原始内容
-        /// </summary>
-        [XmlIgnore]
-        public string Body { get; set; }
-
-        /// <summary>
-        /// 加密报文
-        /// </summary>
-        [XmlElement("encrypt")]
-        public string Encrypt { get; set; }
     }
 }

+ 1 - 1
src/Essensoft.AspNetCore.Payment.JDPay/Notify/JDPayAsyncNotifyResponse.cs → src/Essensoft.AspNetCore.Payment.JDPay/Notify/JDPayAsyncNotify.cs

@@ -8,7 +8,7 @@ namespace Essensoft.AspNetCore.Payment.JDPay.Notify
     /// 异步通知接口
     /// </summary>
     [XmlRoot("jdpay")]
-    public class JDPayAsyncNotifyResponse : JDPayNotifyResponse
+    public class JDPayAsyncNotify : JDPayNotify
     {
         /// <summary>
         /// 版本号

+ 1 - 1
src/Essensoft.AspNetCore.Payment.JDPay/Notify/JDPayDefrayPayNotifyResponse.cs → src/Essensoft.AspNetCore.Payment.JDPay/Notify/JDPayDefrayPayNotify.cs

@@ -5,7 +5,7 @@ namespace Essensoft.AspNetCore.Payment.JDPay.Notify
     /// <summary>
     /// 代付交易 - 异步通知接口
     /// </summary>
-    public class JDPayDefrayPayNotifyResponse : JDPayNotifyResponse
+    public class JDPayDefrayPayNotify : JDPayNotify
     {
         /// <summary>
         /// 提交者会员号

+ 1 - 1
src/Essensoft.AspNetCore.Payment.JDPay/Notify/JDPaySyncReturnResponse.cs → src/Essensoft.AspNetCore.Payment.JDPay/Notify/JDPaySyncReturn.cs

@@ -6,7 +6,7 @@ namespace Essensoft.AspNetCore.Payment.JDPay.Notify
     /// 支付成功页面跳转
     /// </summary>
     [XmlRoot("jdpay")]
-    public class JDPaySyncReturnResponse : JDPayNotifyResponse
+    public class JDPaySyncReturn : JDPayNotify
     {
         /// <summary>
         /// 交易流水号

+ 1 - 1
src/Essensoft.AspNetCore.Payment.JDPay/Parser/IJDPayParser.cs

@@ -3,7 +3,7 @@
     /// <summary>
     /// 京东支付结果解析
     /// </summary>
-    public interface IJDPayParser<T> where T : JDPayResponse
+    public interface IJDPayParser<T> where T : JDPayObject
     {
         T Parse(string body);
     }

+ 5 - 1
src/Essensoft.AspNetCore.Payment.JDPay/Parser/JDPayDictionaryParser.cs

@@ -7,7 +7,11 @@ using Essensoft.AspNetCore.Payment.JDPay.Utility;
 
 namespace Essensoft.AspNetCore.Payment.JDPay.Parser
 {
-    public class JDPayDictionaryParser<T> where T : JDPayNotifyResponse
+    /// <summary>
+    /// JDPay 字典解释器。
+    /// </summary>
+    /// <typeparam name="T"></typeparam>
+    public class JDPayDictionaryParser<T> where T : JDPayNotify
     {
         private static readonly Dictionary<Type, Dictionary<string, PropertyInfo>> DicProperties = new Dictionary<Type, Dictionary<string, PropertyInfo>>();
 

+ 5 - 1
src/Essensoft.AspNetCore.Payment.JDPay/Parser/JDPayXmlParser.cs

@@ -4,7 +4,11 @@ using System.Xml.Serialization;
 
 namespace Essensoft.AspNetCore.Payment.JDPay.Parser
 {
-    public class JDPayXmlParser<T> : IJDPayParser<T> where T : JDPayResponse
+    /// <summary>
+    /// JDPay XML 解释器。
+    /// </summary>
+    /// <typeparam name="T"></typeparam>
+    public class JDPayXmlParser<T> : IJDPayParser<T> where T : JDPayObject
     {
         public T Parse(string body)
         {

+ 1 - 1
src/Essensoft.AspNetCore.Payment.JDPay/Utility/JDPayContants.cs

@@ -1,6 +1,6 @@
 namespace Essensoft.AspNetCore.Payment.JDPay.Utility
 {
-    public class JDPayContants
+    internal class JDPayContants
     {
         public const string VERSION = "version";
         public const string MERCHANT = "merchant";

+ 6 - 3
src/Essensoft.AspNetCore.Payment.JDPay/Utility/JDPaySecurity.cs

@@ -14,6 +14,9 @@ using X509Certificate = Org.BouncyCastle.X509.X509Certificate;
 
 namespace Essensoft.AspNetCore.Payment.JDPay.Utility
 {
+    /// <summary>
+    /// JDPay 安全类。
+    /// </summary>
     public class JDPaySecurity
     {
         private const int MAX_MSG_LENGTH = 16 * 1024;
@@ -140,7 +143,7 @@ namespace Essensoft.AspNetCore.Payment.JDPay.Utility
             var dsb = ByteArrayToInt(dataSizeByte, 0);
             if (dsb > MAX_MSG_LENGTH)
             {
-                throw new Exception("msg over MAX_MSG_LENGTH or msg error");
+                throw new JDPayException("msg over MAX_MSG_LENGTH or msg error");
             }
             var tempData = new byte[dsb];
             for (var i = 0; i < dsb; i++)
@@ -180,7 +183,7 @@ namespace Essensoft.AspNetCore.Payment.JDPay.Utility
         {
             if (b.Length % 2 != 0)
             {
-                throw new Exception("长度不是偶数");
+                throw new JDPayException("长度不是偶数");
             }
             var b2 = new byte[b.Length / 2];
             for (var n = 0; n < b.Length; n += 2)
@@ -296,7 +299,7 @@ namespace Essensoft.AspNetCore.Payment.JDPay.Utility
                 }
                 else
                 {
-                    throw new Exception("不支持的加密方式");
+                    throw new JDPayException("不支持的加密方式");
                 }
             }
 

+ 3 - 0
src/Essensoft.AspNetCore.Payment.JDPay/Utility/JDPayUtility.cs

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