This commit is contained in:
Fu Diwei
2023-06-19 19:48:19 +08:00
parent 818e437a04
commit 008062c983
7 changed files with 21 additions and 33 deletions

View File

@@ -260,10 +260,10 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (callbackNonce == null) throw new ArgumentNullException(nameof(callbackNonce));
if (callbackSignature == null) throw new ArgumentNullException(nameof(callbackSignature));
List<string> lstParams = new List<string>() { client.Credentials.PushToken!, callbackTimestamp, callbackNonce };
lstParams.Sort(StringComparer.Ordinal);
List<string> tmp = new List<string>(capacity: 3) { client.Credentials.PushToken!, callbackTimestamp, callbackNonce };
tmp.Sort(StringComparer.Ordinal);
string sign = Utilities.SHA1Utility.Hash(string.Concat(lstParams));
string sign = Utilities.SHA1Utility.Hash(string.Concat(tmp));
return string.Equals(sign, callbackSignature, StringComparison.OrdinalIgnoreCase);
}

View File

@@ -54,9 +54,9 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
string nonce = Guid.NewGuid().ToString("N");
string cardType = "INVOICE";
List<string> lstParams = new List<string>() { cardType, timestamp, client.Credentials.AppId, nonce, wxcardTicket };
lstParams.Sort(StringComparer.Ordinal);
string cardSign = Utilities.SHA1Utility.Hash(string.Join(string.Empty, lstParams)).ToLower();
List<string> tmp = new List<string>(capacity: 5) { cardType, timestamp, client.Credentials.AppId, nonce, wxcardTicket };
tmp.Sort(StringComparer.Ordinal);
string cardSign = Utilities.SHA1Utility.Hash(string.Concat(tmp)).ToLower();
return new ReadOnlyDictionary<string, string>(new Dictionary<string, string>()
{

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Security;
using System.Security.Cryptography;
@@ -230,14 +229,11 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.Utilities
if (sNonce == null) throw new ArgumentNullException(nameof(sNonce));
if (sMsgEncrypt == null) throw new ArgumentNullException(nameof(sMsgEncrypt));
ISet<string> set = new SortedSet<string>(StringComparer.Ordinal);
set.Add(sToken);
set.Add(sTimestamp);
set.Add(sNonce);
set.Add(sMsgEncrypt);
List<string> tmp = new List<string>(capacity: 4) { sToken, sTimestamp, sNonce, sMsgEncrypt };
tmp.Sort(StringComparer.Ordinal);
string rawText = string.Join(string.Empty, set.ToArray());
string signText = Utilities.SHA1Utility.Hash(rawText);
string rawText = string.Join(string.Empty, tmp);
string signText = SHA1Utility.Hash(rawText);
return signText.ToLower();
}

View File

@@ -11,7 +11,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI
where TEvent : WechatOpenAIEvent
{
if (client == null) throw new ArgumentNullException(nameof(client));
if (string.IsNullOrEmpty(callbackXml)) throw new ArgumentNullException(callbackXml);
if (callbackXml == null) throw new ArgumentNullException(callbackXml);
try
{

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Security;
using System.Security.Cryptography;
@@ -230,14 +229,11 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Utilities
if (sNonce == null) throw new ArgumentNullException(nameof(sNonce));
if (sMsgEncrypt == null) throw new ArgumentNullException(nameof(sMsgEncrypt));
ISet<string> set = new SortedSet<string>(StringComparer.Ordinal);
set.Add(sToken);
set.Add(sTimestamp);
set.Add(sNonce);
set.Add(sMsgEncrypt);
List<string> tmp = new List<string>(capacity: 4) { sToken, sTimestamp, sNonce, sMsgEncrypt };
tmp.Sort(StringComparer.Ordinal);
string rawText = string.Join(string.Empty, set.ToArray());
string signText = Utilities.SHA1Utility.Hash(rawText);
string rawText = string.Join(string.Empty, tmp);
string signText = SHA1Utility.Hash(rawText);
return signText.ToLower();
}

View File

@@ -32,7 +32,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
where TEvent : WechatWorkEvent
{
if (client == null) throw new ArgumentNullException(nameof(client));
if (string.IsNullOrEmpty(callbackJson)) throw new ArgumentNullException(callbackJson);
if (callbackJson == null) throw new ArgumentNullException(callbackJson);
try
{
@@ -58,7 +58,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
where TEvent : WechatWorkEvent
{
if (client == null) throw new ArgumentNullException(nameof(client));
if (string.IsNullOrEmpty(callbackXml)) throw new ArgumentNullException(callbackXml);
if (callbackXml == null) throw new ArgumentNullException(callbackXml);
try
{

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Security;
using System.Security.Cryptography;
@@ -230,14 +229,11 @@ namespace SKIT.FlurlHttpClient.Wechat.Work.Utilities
if (sNonce == null) throw new ArgumentNullException(nameof(sNonce));
if (sMsgEncrypt == null) throw new ArgumentNullException(nameof(sMsgEncrypt));
ISet<string> set = new SortedSet<string>(StringComparer.Ordinal);
set.Add(sToken);
set.Add(sTimestamp);
set.Add(sNonce);
set.Add(sMsgEncrypt);
List<string> tmp = new List<string>(capacity: 4) { sToken, sTimestamp, sNonce, sMsgEncrypt };
tmp.Sort(StringComparer.Ordinal);
string rawText = string.Join(string.Empty, set.ToArray());
string signText = Utilities.SHA1Utility.Hash(rawText);
string rawText = string.Join(string.Empty, tmp);
string signText = SHA1Utility.Hash(rawText);
return signText.ToLower();
}