mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2026-03-10 00:13:36 +08:00
refactor
This commit is contained in:
@@ -260,10 +260,10 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
|||||||
if (callbackNonce == null) throw new ArgumentNullException(nameof(callbackNonce));
|
if (callbackNonce == null) throw new ArgumentNullException(nameof(callbackNonce));
|
||||||
if (callbackSignature == null) throw new ArgumentNullException(nameof(callbackSignature));
|
if (callbackSignature == null) throw new ArgumentNullException(nameof(callbackSignature));
|
||||||
|
|
||||||
List<string> lstParams = new List<string>() { client.Credentials.PushToken!, callbackTimestamp, callbackNonce };
|
List<string> tmp = new List<string>(capacity: 3) { client.Credentials.PushToken!, callbackTimestamp, callbackNonce };
|
||||||
lstParams.Sort(StringComparer.Ordinal);
|
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);
|
return string.Equals(sign, callbackSignature, StringComparison.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,9 +54,9 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
|||||||
string nonce = Guid.NewGuid().ToString("N");
|
string nonce = Guid.NewGuid().ToString("N");
|
||||||
string cardType = "INVOICE";
|
string cardType = "INVOICE";
|
||||||
|
|
||||||
List<string> lstParams = new List<string>() { cardType, timestamp, client.Credentials.AppId, nonce, wxcardTicket };
|
List<string> tmp = new List<string>(capacity: 5) { cardType, timestamp, client.Credentials.AppId, nonce, wxcardTicket };
|
||||||
lstParams.Sort(StringComparer.Ordinal);
|
tmp.Sort(StringComparer.Ordinal);
|
||||||
string cardSign = Utilities.SHA1Utility.Hash(string.Join(string.Empty, lstParams)).ToLower();
|
string cardSign = Utilities.SHA1Utility.Hash(string.Concat(tmp)).ToLower();
|
||||||
|
|
||||||
return new ReadOnlyDictionary<string, string>(new Dictionary<string, string>()
|
return new ReadOnlyDictionary<string, string>(new Dictionary<string, string>()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Security;
|
using System.Security;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
@@ -230,14 +229,11 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.Utilities
|
|||||||
if (sNonce == null) throw new ArgumentNullException(nameof(sNonce));
|
if (sNonce == null) throw new ArgumentNullException(nameof(sNonce));
|
||||||
if (sMsgEncrypt == null) throw new ArgumentNullException(nameof(sMsgEncrypt));
|
if (sMsgEncrypt == null) throw new ArgumentNullException(nameof(sMsgEncrypt));
|
||||||
|
|
||||||
ISet<string> set = new SortedSet<string>(StringComparer.Ordinal);
|
List<string> tmp = new List<string>(capacity: 4) { sToken, sTimestamp, sNonce, sMsgEncrypt };
|
||||||
set.Add(sToken);
|
tmp.Sort(StringComparer.Ordinal);
|
||||||
set.Add(sTimestamp);
|
|
||||||
set.Add(sNonce);
|
|
||||||
set.Add(sMsgEncrypt);
|
|
||||||
|
|
||||||
string rawText = string.Join(string.Empty, set.ToArray());
|
string rawText = string.Join(string.Empty, tmp);
|
||||||
string signText = Utilities.SHA1Utility.Hash(rawText);
|
string signText = SHA1Utility.Hash(rawText);
|
||||||
return signText.ToLower();
|
return signText.ToLower();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
|||||||
where TEvent : WechatOpenAIEvent
|
where TEvent : WechatOpenAIEvent
|
||||||
{
|
{
|
||||||
if (client == null) throw new ArgumentNullException(nameof(client));
|
if (client == null) throw new ArgumentNullException(nameof(client));
|
||||||
if (string.IsNullOrEmpty(callbackXml)) throw new ArgumentNullException(callbackXml);
|
if (callbackXml == null) throw new ArgumentNullException(callbackXml);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Security;
|
using System.Security;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
@@ -230,14 +229,11 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Utilities
|
|||||||
if (sNonce == null) throw new ArgumentNullException(nameof(sNonce));
|
if (sNonce == null) throw new ArgumentNullException(nameof(sNonce));
|
||||||
if (sMsgEncrypt == null) throw new ArgumentNullException(nameof(sMsgEncrypt));
|
if (sMsgEncrypt == null) throw new ArgumentNullException(nameof(sMsgEncrypt));
|
||||||
|
|
||||||
ISet<string> set = new SortedSet<string>(StringComparer.Ordinal);
|
List<string> tmp = new List<string>(capacity: 4) { sToken, sTimestamp, sNonce, sMsgEncrypt };
|
||||||
set.Add(sToken);
|
tmp.Sort(StringComparer.Ordinal);
|
||||||
set.Add(sTimestamp);
|
|
||||||
set.Add(sNonce);
|
|
||||||
set.Add(sMsgEncrypt);
|
|
||||||
|
|
||||||
string rawText = string.Join(string.Empty, set.ToArray());
|
string rawText = string.Join(string.Empty, tmp);
|
||||||
string signText = Utilities.SHA1Utility.Hash(rawText);
|
string signText = SHA1Utility.Hash(rawText);
|
||||||
return signText.ToLower();
|
return signText.ToLower();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
|||||||
where TEvent : WechatWorkEvent
|
where TEvent : WechatWorkEvent
|
||||||
{
|
{
|
||||||
if (client == null) throw new ArgumentNullException(nameof(client));
|
if (client == null) throw new ArgumentNullException(nameof(client));
|
||||||
if (string.IsNullOrEmpty(callbackJson)) throw new ArgumentNullException(callbackJson);
|
if (callbackJson == null) throw new ArgumentNullException(callbackJson);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -58,7 +58,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
|||||||
where TEvent : WechatWorkEvent
|
where TEvent : WechatWorkEvent
|
||||||
{
|
{
|
||||||
if (client == null) throw new ArgumentNullException(nameof(client));
|
if (client == null) throw new ArgumentNullException(nameof(client));
|
||||||
if (string.IsNullOrEmpty(callbackXml)) throw new ArgumentNullException(callbackXml);
|
if (callbackXml == null) throw new ArgumentNullException(callbackXml);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Security;
|
using System.Security;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
@@ -230,14 +229,11 @@ namespace SKIT.FlurlHttpClient.Wechat.Work.Utilities
|
|||||||
if (sNonce == null) throw new ArgumentNullException(nameof(sNonce));
|
if (sNonce == null) throw new ArgumentNullException(nameof(sNonce));
|
||||||
if (sMsgEncrypt == null) throw new ArgumentNullException(nameof(sMsgEncrypt));
|
if (sMsgEncrypt == null) throw new ArgumentNullException(nameof(sMsgEncrypt));
|
||||||
|
|
||||||
ISet<string> set = new SortedSet<string>(StringComparer.Ordinal);
|
List<string> tmp = new List<string>(capacity: 4) { sToken, sTimestamp, sNonce, sMsgEncrypt };
|
||||||
set.Add(sToken);
|
tmp.Sort(StringComparer.Ordinal);
|
||||||
set.Add(sTimestamp);
|
|
||||||
set.Add(sNonce);
|
|
||||||
set.Add(sMsgEncrypt);
|
|
||||||
|
|
||||||
string rawText = string.Join(string.Empty, set.ToArray());
|
string rawText = string.Join(string.Empty, tmp);
|
||||||
string signText = Utilities.SHA1Utility.Hash(rawText);
|
string signText = SHA1Utility.Hash(rawText);
|
||||||
return signText.ToLower();
|
return signText.ToLower();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user