public
static
string SignTopRequest(IDictionary<string, string> parameters,string signMethod, string appSecret)
{
IDictionary<string, string> sortedParams =
new
SortedDictionary<string, string>(parameters, StringComparer.Ordinal);
IEnumerator<KeyValuePair<string, string>> dem = sortedParams.GetEnumerator();
StringBuilder query =
new
StringBuilder();
while
(dem.MoveNext())
{
string key = dem.Current.Key;
string value = dem.Current.Value;
if
(!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
{
query.Append(key).Append(value);
}
}
query.Append(appSecret);
byte
[] bytes;
MD5 md5 = MD5.Create();
bytes = md5.ComputeHash(Encoding.UTF8.GetBytes(query.ToString()));
StringBuilder result =
new
StringBuilder();
for
(
int
i =
0
; i < bytes.Length; i++)
{
result.Append(bytes[i].ToString(
"X2"
));
}
return
result.ToString();
}