StringUtils.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace AnHuiMI.Common
  9. {
  10. class StringUtils
  11. {
  12. // Token: 0x06000098 RID: 152 RVA: 0x00008CE8 File Offset: 0x00006EE8
  13. public static long CurrentTimeStamp(bool isMinseconds = false)
  14. {
  15. TimeSpan timeSpan = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  16. return Convert.ToInt64(isMinseconds ? timeSpan.TotalMilliseconds : timeSpan.TotalSeconds);
  17. }
  18. // Token: 0x06000099 RID: 153 RVA: 0x00008D28 File Offset: 0x00006F28
  19. public static string SortJson(string json)
  20. {
  21. var dic = JsonConvert.DeserializeObject<SortedDictionary<string, object>>(json);
  22. SortedDictionary<string, object> keyValues = new SortedDictionary<string, object>(dic);
  23. keyValues.OrderBy(m => m.Key);//升序 把Key换成Value 就是对Value进行排序
  24. //keyValues.OrderByDescending(m => m.Key);//降序
  25. SortedDictionary<string, object> tempKeyValues = new SortedDictionary<string, object>(keyValues);
  26. foreach (KeyValuePair<string, object> kv in tempKeyValues)
  27. {
  28. // 判断value是不是JObject类型
  29. Type t0 = typeof(JObject);
  30. Type t1 = kv.Value.GetType();
  31. if (t0 == t1)
  32. {
  33. // value是JObject类型
  34. string jsonItem = JsonConvert.SerializeObject(kv.Value);
  35. jsonItem = SortJson(jsonItem);
  36. keyValues[kv.Key] = JsonConvert.DeserializeObject<JObject>(jsonItem);
  37. }
  38. }
  39. return JsonConvert.SerializeObject(keyValues);
  40. }
  41. // Token: 0x0600009B RID: 155 RVA: 0x00009080 File Offset: 0x00007280
  42. public static string Json2sign(string json)
  43. {
  44. Dictionary<string, object> dictionary = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
  45. string text = "";
  46. foreach (KeyValuePair<string, object> keyValuePair in dictionary)
  47. {
  48. text = string.Concat(new object[]
  49. {
  50. text,
  51. keyValuePair.Key,
  52. "=",
  53. keyValuePair.Value,
  54. "&"
  55. });
  56. }
  57. return text.Substring(0, text.Length - 1);
  58. }
  59. }
  60. }