/// <summary> /// 微信支付MD5簽名算法,ASCII碼字典序排序0,A,B,a,b /// </summary> /// <param name="InDict">待簽名名鍵值對</param> /// <param name="TenPayV3_Key">用於簽名的Key</param> /// <returns>MD5簽名字符串</returns> public static string WePaySign(IDictionary<string, string> InDict, string TenPayV3_Key) { string[] arrKeys = InDict.Keys.ToArray(); Array.Sort(arrKeys, string.CompareOrdinal); //參數名ASCII碼從小到大排序;0,A,B,a,b; var StrA = new StringBuilder(); foreach (var key in arrKeys) { string value = InDict[key]; if (!String.IsNullOrEmpty(value)) //空值不參與簽名 { StrA.Append(key + "=") .Append(value + "&"); } } //foreach (var item in InDict.OrderBy(x => x.Key))//參數名字典序;0,A,a,B,b; //{ // if(!String.IsNullOrEmpty(item.Value)) //空值不參與簽名 // { // StrA.Append(item.Key + "=") // .Append(item.Value + "&"); // } //} StrA.Append("key=" + TenPayV3_Key); //注:key爲商戶平臺設置的密鑰key return StrFormat.GetMd5Hash(StrA.ToString()).ToUpper(); }