public static bool CheckSign(Dictionary <string, string> dic, string sign) { string signdata = TdsPayUtil.GetSignData(dic); string _sign = TdsPayUtil.GetShaSign(signdata + signkey); if (_sign == sign) { return(true); } return(false); }
public static string GetSignData(Dictionary <string, string> dic) { string resStr = ""; List <KeyValuePair <string, string> > kvs = dic.ToList(); kvs.Sort(delegate(KeyValuePair <string, string> pair1, KeyValuePair <string, string> pair2) { return(pair1.Key.CompareTo(pair2.Key)); }); foreach (var kv in kvs) { if (!string.IsNullOrEmpty(kv.Value)) { resStr = resStr + TdsPayUtil.UrlEncode(kv.Value); } } //// 第二步:把所有参数名和参数值串在一起 //StringBuilder query = new StringBuilder(""); //签名字符串 //StringBuilder queryStr = new StringBuilder(""); //url参数 //if (parames == null || parames.Count == 0) // return ""; //while (kvs.MoveNext()) //{ // string key = dem.Current.Key; // string value = dem.Current.Value; // if (!string.IsNullOrEmpty(key)) // { // queryStr.Append("&").Append(key).Append("=").Append(value); // } //} return(resStr); }
public T DoPost <T>(IMinShunPayApiPostRequest <T> request) where T : MinShunPayApiBaseResult { string realServerUrl = GetServerUrl(this._serverUrl, request.ApiName); WebUtils webUtils = new WebUtils(); string signdata = TdsPayUtil.GetSignData(request.UrlParameters); string sign = TdsPayUtil.GetShaSign(signdata + _signkey); request.UrlParameters.Add("sign", sign); string postData = null; string body = webUtils.DoPost(realServerUrl, request.UrlParameters, postData, null); T rsp = JsonConvert.DeserializeObject <T>(body); return(rsp); }