/// <summary> /// 取Sign /// </summary> /// <param name="obj"></param> /// <returns></returns> protected SignParams GetSign(string token, object obj, string action) { long timestamp = ToolsCommon.GetTimestamp(); JObject jObj = JObject.FromObject(obj); jObj.Add("app_key", EleConfig.APP_KEY); jObj.Add("timestamp", timestamp); string sortJson = JsonSort.SortJson(jObj, null); ////替换掉属性排序关键字 //Regex reg = new Regex("[a-z]__"); //sortJson = reg.Replace(sortJson, ""); jObj = JObject.Parse(sortJson); List <JProperty> listProperty = jObj.Properties().ToList(); StringBuilder buff = new StringBuilder(); foreach (JProperty attr in listProperty) { string pKey = attr.Name; string pValue = attr.Value.ToString(Newtonsoft.Json.Formatting.None); if (attr.Value.Type == JTokenType.String) { pValue = "\"" + attr.Value.ToString() + "\""; } else if (attr.Value.Type == JTokenType.Float) { pValue = float.Parse(pValue).ToString(); } else if (attr.Value.Type == JTokenType.Object) { } buff.Append(pKey + "=" + pValue); } //完整拼接字符串 string fullParams = action + token + buff.ToString() + EleConfig.APP_SECRET; string sign = ToolsCommon.GetMD5(fullParams).ToUpper(); SignParams pSignParams = new SignParams(); pSignParams.sign = sign; pSignParams.timestamp = timestamp; pSignParams.token = token; pSignParams.action = action; return(pSignParams); }