refactor(wxapi): 优化待验签字段字典排序方式

This commit is contained in:
Fu Diwei 2023-02-28 19:42:24 +08:00
parent 6d47aa5450
commit f059387edc
2 changed files with 8 additions and 10 deletions

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Xml.Linq;
@ -260,8 +260,10 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (callbackNonce == null) throw new ArgumentNullException(nameof(callbackNonce));
if (callbackSignature == null) throw new ArgumentNullException(nameof(callbackSignature));
ISet<string> set = new SortedSet<string>(StringComparer.Ordinal) { client.Credentials.PushToken!, callbackTimestamp, callbackNonce };
string sign = Utilities.SHA1Utility.Hash(string.Concat(set));
List<string> lstParams = new List<string>() { client.Credentials.PushToken!, callbackTimestamp, callbackNonce };
lstParams.Sort(StringComparer.Ordinal);
string sign = Utilities.SHA1Utility.Hash(string.Concat(lstParams));
return string.Equals(sign, callbackSignature, StringComparison.OrdinalIgnoreCase);
}

View File

@ -54,13 +54,9 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
string nonce = Guid.NewGuid().ToString("N");
string cardType = "INVOICE";
ISet<string> sortedParams = new SortedSet<string>(StringComparer.Ordinal);
sortedParams.Add(cardType);
sortedParams.Add(timestamp);
sortedParams.Add(client.Credentials.AppId);
sortedParams.Add(nonce);
sortedParams.Add(wxcardTicket);
string cardSign = Utilities.SHA1Utility.Hash(string.Join(string.Empty, sortedParams)).ToLower();
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();
return new ReadOnlyDictionary<string, string>(new Dictionary<string, string>()
{