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

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

Roc пре 6 година
родитељ
комит
1fbf1b54d8
22 измењених фајлова са 78 додато и 42 уклоњено
  1. 14 14
      src/Essensoft.AspNetCore.Payment.Alipay/AlipayClient.cs
  2. 1 1
      src/Essensoft.AspNetCore.Payment.Alipay/AlipayConstants.cs
  3. 14 0
      src/Essensoft.AspNetCore.Payment.Alipay/AlipayException.cs
  4. 9 0
      src/Essensoft.AspNetCore.Payment.Alipay/AlipayNotify.cs
  5. 8 5
      src/Essensoft.AspNetCore.Payment.Alipay/AlipayNotifyClient.cs
  6. 0 5
      src/Essensoft.AspNetCore.Payment.Alipay/AlipayNotifyResponse.cs
  7. 1 1
      src/Essensoft.AspNetCore.Payment.Alipay/AlipayNotifyResult.cs
  8. 3 2
      src/Essensoft.AspNetCore.Payment.Alipay/AlipayObject.cs
  9. 3 0
      src/Essensoft.AspNetCore.Payment.Alipay/AlipayOptions.cs
  10. 3 3
      src/Essensoft.AspNetCore.Payment.Alipay/IAlipayNotifyClient.cs
  11. 1 1
      src/Essensoft.AspNetCore.Payment.Alipay/Notify/AlipayTradeAppPayNotify.cs
  12. 1 1
      src/Essensoft.AspNetCore.Payment.Alipay/Notify/AlipayTradePagePayNotify.cs
  13. 1 1
      src/Essensoft.AspNetCore.Payment.Alipay/Notify/AlipayTradePagePayReturn.cs
  14. 1 1
      src/Essensoft.AspNetCore.Payment.Alipay/Notify/AlipayTradePrecreateNotify.cs
  15. 1 1
      src/Essensoft.AspNetCore.Payment.Alipay/Notify/AlipayTradeWapPayNotify.cs
  16. 1 1
      src/Essensoft.AspNetCore.Payment.Alipay/Notify/AlipayTradeWapPayReturn.cs
  17. 1 1
      src/Essensoft.AspNetCore.Payment.Alipay/Parser/AlipayJsonParser.cs
  18. 1 1
      src/Essensoft.AspNetCore.Payment.Alipay/Parser/AlipayXmlParser.cs
  19. 5 2
      src/Essensoft.AspNetCore.Payment.Alipay/ResponseParseItem.cs
  20. 5 0
      src/Essensoft.AspNetCore.Payment.Alipay/SignItem.cs
  21. 3 0
      src/Essensoft.AspNetCore.Payment.Alipay/Utility/AlipaySignature.cs
  22. 1 1
      src/Essensoft.AspNetCore.Payment.Alipay/Utility/AlipayUtility.cs

+ 14 - 14
src/Essensoft.AspNetCore.Payment.Alipay/AlipayClient.cs

@@ -14,7 +14,7 @@ using Newtonsoft.Json;
 namespace Essensoft.AspNetCore.Payment.Alipay
 {
     /// <summary>
-    /// Alipay客户端。
+    /// Alipay 客户端。
     /// </summary>
     public class AlipayClient : IAlipayClient
     {
@@ -214,17 +214,17 @@ namespace Essensoft.AspNetCore.Payment.Alipay
 
                 if (string.IsNullOrEmpty(txtParams[BIZ_CONTENT]))
                 {
-                    throw new Exception("api request Fail ! The reason: encrypt request is not supported!");
+                    throw new AlipayException("api request Fail ! The reason: encrypt request is not supported!");
                 }
 
                 if (string.IsNullOrEmpty(options.EncyptKey) || string.IsNullOrEmpty(options.EncyptType))
                 {
-                    throw new Exception("encryptType or encryptKey must not null!");
+                    throw new AlipayException("encryptType or encryptKey must not null!");
                 }
 
                 if (!"AES".Equals(options.EncyptType))
                 {
-                    throw new Exception("api only support Aes!");
+                    throw new AlipayException("api only support Aes!");
 
                 }
 
@@ -273,9 +273,9 @@ namespace Essensoft.AspNetCore.Payment.Alipay
             }
 
             var item = ParseRespItem(request, body, parser, options.EncyptKey, options.EncyptType);
-            rsp = parser.Parse(item.realContent);
+            rsp = parser.Parse(item.RealContent);
 
-            CheckResponseSign(request, item.respContent, rsp.IsError, parser, options.PublicRSAParameters, options.SignType);
+            CheckResponseSign(request, item.RespContent, rsp.IsError, parser, options.PublicRSAParameters, options.SignType);
 
             return rsp;
         }
@@ -295,8 +295,8 @@ namespace Essensoft.AspNetCore.Payment.Alipay
 
             var item = new ResponseParseItem
             {
-                realContent = realContent,
-                respContent = respBody
+                RealContent = realContent,
+                RespContent = respBody
             };
             return item;
 
@@ -307,7 +307,7 @@ namespace Essensoft.AspNetCore.Payment.Alipay
             var signItem = parser.GetSignItem(request, responseBody);
             if (signItem == null)
             {
-                throw new Exception("sign check fail: Body is Empty!");
+                throw new AlipayException("sign check fail: Body is Empty!");
             }
 
             if (!isError || isError && !string.IsNullOrEmpty(signItem.Sign))
@@ -321,12 +321,12 @@ namespace Essensoft.AspNetCore.Payment.Alipay
                         var jsonCheck = AlipaySignature.RSACheckContent(srouceData, signItem.Sign, parameters, signType);
                         if (!jsonCheck)
                         {
-                            throw new Exception("sign check fail: check Sign and Data Fail JSON also");
+                            throw new AlipayException("sign check fail: check Sign and Data Fail JSON also");
                         }
                     }
                     else
                     {
-                        throw new Exception("sign check fail: check Sign and Data Fail!");
+                        throw new AlipayException("sign check fail: check Sign and Data Fail!");
                     }
                 }
 
@@ -385,17 +385,17 @@ namespace Essensoft.AspNetCore.Payment.Alipay
             {
                 if (string.IsNullOrEmpty(result[BIZ_CONTENT]))
                 {
-                    throw new Exception("api request Fail ! The reason: encrypt request is not supported!");
+                    throw new AlipayException("api request Fail ! The reason: encrypt request is not supported!");
                 }
 
                 if (string.IsNullOrEmpty(options.EncyptKey) || string.IsNullOrEmpty(options.EncyptType))
                 {
-                    throw new Exception("encryptType or encryptKey must not null!");
+                    throw new AlipayException("encryptType or encryptKey must not null!");
                 }
 
                 if (!"AES".Equals(options.EncyptType))
                 {
-                    throw new Exception("api only support Aes!");
+                    throw new AlipayException("api only support Aes!");
                 }
 
                 var encryptContent = AES.Encrypt(result[BIZ_CONTENT], options.EncyptKey, AlipaySignature.AES_IV, AESCipherMode.CBC, AESPaddingMode.PKCS7);

+ 1 - 1
src/Essensoft.AspNetCore.Payment.Alipay/AlipayConstants.cs

@@ -1,6 +1,6 @@
 namespace Essensoft.AspNetCore.Payment.Alipay
 {
-    public class AlipayConstants
+    internal class AlipayConstants
     {
         public const string RESPONSE_SUFFIX = "_response";
         public const string ERROR_RESPONSE = "error_response";

+ 14 - 0
src/Essensoft.AspNetCore.Payment.Alipay/AlipayException.cs

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

+ 9 - 0
src/Essensoft.AspNetCore.Payment.Alipay/AlipayNotify.cs

@@ -0,0 +1,9 @@
+namespace Essensoft.AspNetCore.Payment.Alipay
+{
+    /// <summary>
+    /// Alipay 通知
+    /// </summary>
+    public abstract class AlipayNotify : AlipayObject
+    {
+    }
+}

+ 8 - 5
src/Essensoft.AspNetCore.Payment.Alipay/AlipayNotifyClient.cs

@@ -11,6 +11,9 @@ using Microsoft.Extensions.Options;
 
 namespace Essensoft.AspNetCore.Payment.Alipay
 {
+    /// <summary>
+    /// Alipay 通知解析客户端。
+    /// </summary>
     public class AlipayNotifyClient : IAlipayNotifyClient
     {
         private readonly ILogger _logger;
@@ -30,12 +33,12 @@ namespace Essensoft.AspNetCore.Payment.Alipay
 
         #region IAlipayNotifyClient Members
 
-        public async Task<T> ExecuteAsync<T>(HttpRequest request) where T : AlipayNotifyResponse
+        public async Task<T> ExecuteAsync<T>(HttpRequest request) where T : AlipayNotify
         {
             return await ExecuteAsync<T>(request, null);
         }
 
-        public async Task<T> ExecuteAsync<T>(HttpRequest request, string optionsName) where T : AlipayNotifyResponse
+        public async Task<T> ExecuteAsync<T>(HttpRequest request, string optionsName) where T : AlipayNotify
         {
             var options = _optionsSnapshotAccessor.Get(optionsName);
             var parameters = await GetParametersAsync(request);
@@ -77,18 +80,18 @@ namespace Essensoft.AspNetCore.Payment.Alipay
         {
             if (parameters == null || parameters.Count == 0)
             {
-                throw new Exception("sign check fail: content is Empty!");
+                throw new AlipayException("sign check fail: content is Empty!");
             }
 
             if (!parameters.TryGetValue("sign", out var sign))
             {
-                throw new Exception("sign check fail: sign is Empty!");
+                throw new AlipayException("sign check fail: sign is Empty!");
             }
 
             var prestr = GetSignContent(parameters);
             if (!AlipaySignature.RSACheckContent(prestr, sign, publicRSAParameters, signType))
             {
-                throw new Exception("sign check fail: check Sign Data Fail!");
+                throw new AlipayException("sign check fail: check Sign Data Fail!");
             }
         }
 

+ 0 - 5
src/Essensoft.AspNetCore.Payment.Alipay/AlipayNotifyResponse.cs

@@ -1,5 +0,0 @@
-namespace Essensoft.AspNetCore.Payment.Alipay
-{
-    public abstract class AlipayNotifyResponse : AlipayObject
-    {}
-}

+ 1 - 1
src/Essensoft.AspNetCore.Payment.Alipay/AlipayNotifyResult.cs

@@ -3,7 +3,7 @@
 namespace Essensoft.AspNetCore.Payment.Alipay
 {
     /// <summary>
-    /// 支付宝 - 通知应答
+    /// Alipay 通知应答
     /// </summary>
     public class AlipayNotifyResult
     {

+ 3 - 2
src/Essensoft.AspNetCore.Payment.Alipay/AlipayObject.cs

@@ -3,9 +3,10 @@
 namespace Essensoft.AspNetCore.Payment.Alipay
 {
     /// <summary>
-    /// 基础对象。
+    /// Alipay 基础对象。
     /// </summary>
     [Serializable]
     public abstract class AlipayObject
-    {}
+    {
+    }
 }

+ 3 - 0
src/Essensoft.AspNetCore.Payment.Alipay/AlipayOptions.cs

@@ -4,6 +4,9 @@ using Microsoft.Extensions.Logging;
 
 namespace Essensoft.AspNetCore.Payment.Alipay
 {
+    /// <summary>
+    /// Alipay 选项。
+    /// </summary>
     public class AlipayOptions
     {
         internal RSAParameters PrivateRSAParameters;

+ 3 - 3
src/Essensoft.AspNetCore.Payment.Alipay/IAlipayNotifyClient.cs

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

+ 1 - 1
src/Essensoft.AspNetCore.Payment.Alipay/Notify/AlipayTradeAppPayNotifyResponse.cs → src/Essensoft.AspNetCore.Payment.Alipay/Notify/AlipayTradeAppPayNotify.cs

@@ -6,7 +6,7 @@ namespace Essensoft.AspNetCore.Payment.Alipay.Notify
     /// App支付异步通知
     /// 更新时间:2017-09-13
     /// </summary>
-    public class AlipayTradeAppPayNotifyResponse : AlipayNotifyResponse
+    public class AlipayTradeAppPayNotify : AlipayNotify
     {
         /// <summary>
         /// 通知时间

+ 1 - 1
src/Essensoft.AspNetCore.Payment.Alipay/Notify/AlipayTradePagePayNotifyResponse.cs → src/Essensoft.AspNetCore.Payment.Alipay/Notify/AlipayTradePagePayNotify.cs

@@ -6,7 +6,7 @@ namespace Essensoft.AspNetCore.Payment.Alipay.Notify
     /// 电脑网站支付结果异步通知
     /// 更新时间:2017/10/27
     /// </summary>
-    public class AlipayTradePagePayNotifyResponse : AlipayNotifyResponse
+    public class AlipayTradePagePayNotify : AlipayNotify
     {
         // 公共参数
 

+ 1 - 1
src/Essensoft.AspNetCore.Payment.Alipay/Notify/AlipayTradePagePayReturnResponse.cs → src/Essensoft.AspNetCore.Payment.Alipay/Notify/AlipayTradePagePayReturn.cs

@@ -6,7 +6,7 @@ namespace Essensoft.AspNetCore.Payment.Alipay.Notify
     /// 电脑网站支付页面回跳参数
     /// 更新时间:2017-11-02
     /// </summary>
-    public class AlipayTradePagePayReturnResponse : AlipayNotifyResponse
+    public class AlipayTradePagePayReturn : AlipayNotify
     {
         // 公共参数
 

+ 1 - 1
src/Essensoft.AspNetCore.Payment.Alipay/Notify/AlipayTradePrecreateNotifyResponse.cs → src/Essensoft.AspNetCore.Payment.Alipay/Notify/AlipayTradePrecreateNotify.cs

@@ -6,7 +6,7 @@ namespace Essensoft.AspNetCore.Payment.Alipay.Notify
     /// 当面付异步通知-仅用于扫码支付
     /// 更新时间:2017/08/24 
     /// </summary>
-    public class AlipayTradePrecreateNotifyResponse : AlipayNotifyResponse
+    public class AlipayTradePrecreateNotify : AlipayNotify
     {
         // 公共参数
 

+ 1 - 1
src/Essensoft.AspNetCore.Payment.Alipay/Notify/AlipayTradeWapPayNotifyResponse.cs → src/Essensoft.AspNetCore.Payment.Alipay/Notify/AlipayTradeWapPayNotify.cs

@@ -6,7 +6,7 @@ namespace Essensoft.AspNetCore.Payment.Alipay.Notify
     /// 手机网站支付结果异步通知
     /// 更新时间:2017-07-21
     /// </summary>
-    public class AlipayTradeWapPayNotifyResponse : AlipayNotifyResponse
+    public class AlipayTradeWapPayNotify : AlipayNotify
     {
         /// <summary>
         /// 通知时间

+ 1 - 1
src/Essensoft.AspNetCore.Payment.Alipay/Notify/AlipayTradeWapPayReturnResponse.cs → src/Essensoft.AspNetCore.Payment.Alipay/Notify/AlipayTradeWapPayReturn.cs

@@ -6,7 +6,7 @@ namespace Essensoft.AspNetCore.Payment.Alipay.Notify
     /// 手机网站支付页面回跳参数
     /// 更新时间:2018-01-18
     /// </summary>
-    public class AlipayTradeWapPayReturnResponse : AlipayNotifyResponse
+    public class AlipayTradeWapPayReturn : AlipayNotify
     {
         // 公共参数
 

+ 1 - 1
src/Essensoft.AspNetCore.Payment.Alipay/Parser/AlipayJsonParser.cs

@@ -15,7 +15,7 @@ namespace Essensoft.AspNetCore.Payment.Alipay.Parser
         {
             if (!"AES".Equals(encryptType))
             {
-                throw new Exception("API only support AES!");
+                throw new AlipayException("API only support AES!");
             }
 
             var item = ParseEncryptData(request, body);

+ 1 - 1
src/Essensoft.AspNetCore.Payment.Alipay/Parser/AlipayXmlParser.cs

@@ -39,7 +39,7 @@ namespace Essensoft.AspNetCore.Payment.Alipay.Parser
                 return match.Groups[1].ToString();
             }
 
-            throw new Exception("Invalid XML response format!");
+            throw new AlipayException("Invalid XML response format!");
         }
 
         private static string GetSign(string body)

+ 5 - 2
src/Essensoft.AspNetCore.Payment.Alipay/ResponseParseItem.cs

@@ -1,9 +1,12 @@
 namespace Essensoft.AspNetCore.Payment.Alipay
 {
+    /// <summary>
+    /// 应答解析项目
+    /// </summary>
     internal class ResponseParseItem
     {
-        public string realContent;
+        public string RealContent { get; set; }
 
-        public string respContent;
+        public string RespContent { get; set; }
     }
 }

+ 5 - 0
src/Essensoft.AspNetCore.Payment.Alipay/SignItem.cs

@@ -1,9 +1,14 @@
 namespace Essensoft.AspNetCore.Payment.Alipay
 {
+    /// <summary>
+    /// 签名项目
+    /// </summary>
     public class SignItem
     {
         public string SignSourceDate { get; set; }
+
         public string Sign { get; set; }
+
         public override string ToString()
         {
             return "{" + "Sign:" + Sign + ",SignSourceDate:" + SignSourceDate + "}";

+ 3 - 0
src/Essensoft.AspNetCore.Payment.Alipay/Utility/AlipaySignature.cs

@@ -5,6 +5,9 @@ using System.Text;
 
 namespace Essensoft.AspNetCore.Payment.Alipay.Utility
 {
+    /// <summary>
+    /// Alipay Ç©ÃûÀà¡£
+    /// </summary>
     public class AlipaySignature
     {
         public static readonly byte[] AES_IV = InitIv(16);

+ 1 - 1
src/Essensoft.AspNetCore.Payment.Alipay/Utility/AlipayUtility.cs

@@ -6,7 +6,7 @@ using System.Text;
 namespace Essensoft.AspNetCore.Payment.Alipay.Utility
 {
     /// <summary>
-    /// Alipay系统工具类。
+    /// Alipay 工具类。
     /// </summary>
     public static class AlipayUtility
     {