Roc 7 år sedan
förälder
incheckning
a20f13c39f

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

@@ -124,8 +124,12 @@ namespace Essensoft.AspNetCore.Payment.Alipay.Parser
 
         public T Parse(string body)
         {
-            T rsp = null;
+            if (string.IsNullOrEmpty(body))
+            {
+                throw new ArgumentNullException(nameof(body));
+            }
 
+            T rsp = null;
             IDictionary json = null;
 
             try

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

@@ -157,6 +157,11 @@ namespace Essensoft.AspNetCore.Payment.Alipay.Parser
 
         public T Parse(string body)
         {
+            if (string.IsNullOrEmpty(body))
+            {
+                throw new ArgumentNullException(nameof(body));
+            }
+
             T rsp = null;
 
             try

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

@@ -152,8 +152,6 @@ namespace Essensoft.AspNetCore.Payment.JDPay
                 var body = await client.DoPostAsync(request.GetRequestUrl(), content, "application/x-www-form-urlencoded");
                 _logger.Log(options.LogLevel, "Response:{content}", body);
 
-                var rsp = JsonConvert.DeserializeObject<T>(body);
-
                 // 验签
                 var dic = JsonConvert.DeserializeObject<JDPayDictionary>(body);
                 if (!JDPaySecurity.VerifySign(dic, options.SingKey))
@@ -161,6 +159,7 @@ namespace Essensoft.AspNetCore.Payment.JDPay
                     throw new Exception("sign check fail: check Sign and Data Fail!");
                 }
 
+                var rsp = JsonConvert.DeserializeObject<T>(body);
                 rsp.Body = body;
                 return rsp;
             }

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

@@ -8,6 +8,11 @@ namespace Essensoft.AspNetCore.Payment.JDPay.Parser
     {
         public T Parse(string body)
         {
+            if (string.IsNullOrEmpty(body))
+            {
+                throw new ArgumentNullException(nameof(body));
+            }
+
             T rsp = null;
 
             try

+ 18 - 11
src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayClient.cs

@@ -14,7 +14,6 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay
 {
     public class LianLianPayClient : ILianLianPayClient
     {
-        private const string VERSION = "version";
         private const string OID_PARTNER = "oid_partner";
         private const string SIGN_TYPE = "sign_type";
         private const string BUSI_PARTNER = "busi_partner";
@@ -77,6 +76,7 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay
             {
                 content = Serialize(txtParams);
             }
+
             _logger.Log(options.LogLevel, "Request:{content}", content);
 
             using (var client = _clientFactory.CreateClient())
@@ -99,7 +99,7 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay
                     excludePara.Add("agreement_list");
                 }
 
-                CheckNotifySign(rsp.Parameters, excludePara, options);
+                CheckNotifySign(rsp, excludePara, options);
                 return rsp;
             }
         }
@@ -113,20 +113,27 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay
             return JsonConvert.SerializeObject(value, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
         }
 
-        private void CheckNotifySign(LianLianPayDictionary parameters, List<string> excludePara, LianLianPayOptions options)
+        private void CheckNotifySign(LianLianPayResponse response, List<string> excludePara, LianLianPayOptions options)
         {
-            if (parameters.Count == 0)
+            if (string.IsNullOrEmpty(response.Body))
             {
-                throw new Exception("sign check fail: para is Empty!");
+                throw new Exception("sign check fail: Body is Empty!");
             }
 
-            if (parameters.TryGetValue("sign", out var sign))
+            if (response.Parameters.Count == 0)
             {
-                var prestr = LianLianPaySecurity.GetSignContent(parameters, excludePara);
-                if (!MD5WithRSA.VerifyData(prestr, sign, options.PublicKey))
-                {
-                    throw new Exception("sign check fail: check Sign and Data Fail JSON also");
-                }
+                throw new Exception("sign check fail: Parameters is Empty!");
+            }
+
+            if (!response.Parameters.TryGetValue("sign", out var sign))
+            {
+                throw new Exception("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");
             }
         }
 

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

@@ -13,6 +13,11 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay.Parser
 
         public T Parse(string body)
         {
+            if (string.IsNullOrEmpty(body))
+            {
+                throw new ArgumentNullException(nameof(body));
+            }
+
             T rsp = null;
             var parameters = new LianLianPayDictionary();
 

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

@@ -127,11 +127,16 @@ namespace Essensoft.AspNetCore.Payment.QPay
 
         private void CheckResponseSign(QPayResponse response, QPayOptions options)
         {
-            if (string.IsNullOrEmpty(response.Body) || response?.Parameters == null)
+            if (string.IsNullOrEmpty(response.Body))
             {
                 throw new Exception("sign check fail: Body is Empty!");
             }
 
+            if (response.Parameters.Count == 0)
+            {
+                throw new Exception("sign check fail: Parameters is Empty!");
+            }
+
             if (!response.Parameters.TryGetValue("sign", out var sign))
             {
                 throw new Exception("sign check fail: sign is Empty!");

+ 6 - 1
src/Essensoft.AspNetCore.Payment.QPay/QPayNotifyClient.cs

@@ -52,11 +52,16 @@ namespace Essensoft.AspNetCore.Payment.QPay
 
         private void CheckNotifySign(QPayNotifyResponse response, QPayOptions options)
         {
-            if (response?.Parameters?.Count == 0)
+            if (string.IsNullOrEmpty(response.Body))
             {
                 throw new Exception("sign check fail: Body is Empty!");
             }
 
+            if (response.Parameters.Count == 0)
+            {
+                throw new Exception("sign check fail: Parameters is Empty!");
+            }
+
             if (!response.Parameters.TryGetValue("sign", out var sign))
             {
                 throw new Exception("sign check fail: sign is Empty!");

+ 6 - 5
src/Essensoft.AspNetCore.Payment.UnionPay/UnionPayClient.cs

@@ -90,11 +90,6 @@ namespace Essensoft.AspNetCore.Payment.UnionPay
                 var body = await client.DoPostAsync(request.GetRequestUrl(options.TestMode), query);
                 _logger.Log(options.LogLevel, "Response:{content}", body);
 
-                if (string.IsNullOrEmpty(body))
-                {
-                    throw new Exception("sign check fail: Body is Empty!");
-                }
-
                 var dic = ParseQueryString(body);
 
                 var ifValidateCNName = !options.TestMode;
@@ -183,12 +178,18 @@ namespace Essensoft.AspNetCore.Payment.UnionPay
 
         private static Dictionary<string, string> ParseQueryString(string str)
         {
+            if (string.IsNullOrEmpty(str))
+            {
+                return null;
+            }
+
             var Dictionary = new Dictionary<string, string>();
             var key = string.Empty;
             var isKey = true;
             var isOpen = false; // 值里有嵌套
             var openName = '\0'; // 关闭符
             var sb = new StringBuilder();
+
             for (var i = 0; i < str.Length; i++) // 遍历整个带解析的字符串
             {
                 var curChar = str[i];// 取当前字符

+ 5 - 0
src/Essensoft.AspNetCore.Payment.UnionPay/Utility/UnionPaySignature.cs

@@ -44,6 +44,11 @@ namespace Essensoft.AspNetCore.Payment.UnionPay.Utility
 
         public static bool Validate(Dictionary<string, string> data, X509Certificate rootCert, X509Certificate middleCert, string secureKey, bool ifValidateCNName)
         {
+            if (data == null)
+            {
+                return false;
+            }
+
             if (!data.ContainsKey("signMethod") || !data.ContainsKey("signature") || !data.ContainsKey("version"))
             {
                 return false;

+ 5 - 1
src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayClient.cs

@@ -201,7 +201,6 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay
             using (var client = _clientFactory.CreateClient(certificateName))
             {
                 var body = await client.DoPostAsync(request.GetRequestUrl(), content);
-
                 _logger.Log(options.LogLevel, "Response:{body}", body);
 
                 var parser = new WeChatPayXmlParser<T>();
@@ -271,6 +270,11 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay
                 throw new Exception("sign check fail: Body is Empty!");
             }
 
+            if (response.Parameters.Count == 0)
+            {
+                throw new Exception("sign check fail: Parameters is Empty!");
+            }
+
             if (!response.Parameters.TryGetValue("sign", out var sign))
             {
                 throw new Exception("sign check fail: sign is Empty!");

+ 6 - 1
src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayNotifyClient.cs

@@ -64,11 +64,16 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay
 
         private void CheckNotifySign(WeChatPayNotifyResponse response, WeChatPayOptions options)
         {
-            if (response?.Parameters?.Count == 0)
+            if (string.IsNullOrEmpty(response.Body))
             {
                 throw new Exception("sign check fail: Body is Empty!");
             }
 
+            if (response.Parameters.Count == 0)
+            {
+                throw new Exception("sign check fail: Parameters is Empty!");
+            }
+
             if (!response.Parameters.TryGetValue("sign", out var sign))
             {
                 throw new Exception("sign check fail: sign is Empty!");