mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
返回sign处理
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using SDKCSharp.Request;
|
||||
|
||||
namespace SDKCSharp.Utility
|
||||
{
|
||||
@@ -36,6 +37,7 @@ namespace SDKCSharp.Utility
|
||||
return JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 对象转换成json字符串
|
||||
/// </summary>
|
||||
|
@@ -2,13 +2,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SDKCSharp.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// 签名工具类
|
||||
/// </summary>
|
||||
public class SignUtil
|
||||
public static class SignUtil
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
@@ -26,6 +27,13 @@ namespace SDKCSharp.Utility
|
||||
return rsa.Sign(content);
|
||||
}
|
||||
|
||||
public static bool RsaCheck(string content, string sign, string publicKeyPlatform, Encoding charset,
|
||||
SignType signType)
|
||||
{
|
||||
RSAHelper rsa = new RSAHelper(signType, charset, null, publicKeyPlatform);
|
||||
return rsa.Verify(content, sign);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构建签名内容
|
||||
/// </summary>
|
||||
@@ -53,5 +61,33 @@ namespace SDKCSharp.Utility
|
||||
return content;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构建签名内容
|
||||
/// </summary>
|
||||
/// <returns>The sign content.</returns>
|
||||
/// <param name="parameters">Parameters.</param>
|
||||
public static string GetSignContentObject(IDictionary<string, object> parameters)
|
||||
{
|
||||
// 第一步:把字典按Key的字母顺序排序
|
||||
IDictionary<string, object> sortedParams = new SortedDictionary<string, object>(parameters);
|
||||
IEnumerator<KeyValuePair<string, object>> dem = sortedParams.GetEnumerator();
|
||||
|
||||
// 第二步:把所有参数名和参数值串在一起
|
||||
StringBuilder query = new StringBuilder("");
|
||||
while (dem.MoveNext())
|
||||
{
|
||||
string key = dem.Current.Key;
|
||||
string value = Convert.ToString(dem.Current.Value);
|
||||
value = Regex.Replace(value, @"\s", "");
|
||||
if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
|
||||
{
|
||||
query.Append(key).Append("=").Append(value).Append("&");
|
||||
}
|
||||
}
|
||||
string content = query.ToString().Substring(0, query.Length - 1);
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user