/// <summary> /// 获取微信签名 /// </summary> /// <param name="sParams"></param> /// <param name="key">自己设置的证书密钥</param> /// <returns></returns> public static string GetSign(SortedDictionary <string, string> sParams, string key) { string sign = string.Empty; StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <string, string> temp in sParams) { if (temp.Value == "" || temp.Value == null || temp.Key.ToLower() == "sign") { continue; } sb.Append(temp.Key.Trim() + "=" + temp.Value.Trim() + "&"); } sb.Append("key=" + key.Trim()); string signkey = sb.ToString(); sign = WXPayTool.GetMD5(signkey, "utf-8"); return(sign); }
/// <summary> /// 随机串 /// </summary> public static string getNoncestr() { Random random = new Random(); return(WXPayTool.GetMD5(random.Next(1000).ToString(), "UTF-8").ToLower().Replace("s", "S")); }