StringUtils.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 SortedDictionary<string, object> KeySort(JObject obj)
  20. {
  21. var dic = new SortedDictionary<string, object>();
  22. foreach (var x in obj)
  23. {
  24. if (x.Value is JValue) dic.Add(x.Key, x.Value);
  25. else if (x.Value is JObject) dic.Add(x.Key, KeySort((JObject)x.Value));
  26. else if (x.Value is JArray)
  27. {
  28. var tmp = new SortedDictionary<string, object>[x.Value.Count()];
  29. for (var i = 0; i < x.Value.Count(); i++)
  30. {
  31. tmp[i] = KeySort((JObject)x.Value[i]);
  32. }
  33. dic.Add(x.Key, tmp);
  34. }
  35. }
  36. return dic;
  37. }
  38. public static string SortJson(string json)
  39. {
  40. SortedDictionary<string, object> keyValues = KeySort(JObject.Parse(json));
  41. keyValues.OrderBy(m => m.Key);
  42. return JsonConvert.SerializeObject(keyValues);
  43. }
  44. // Token: 0x0600009B RID: 155 RVA: 0x00009080 File Offset: 0x00007280
  45. public static string Json2sign(string json)
  46. {
  47. Dictionary<string, object> dictionary = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
  48. string text = "";
  49. foreach (KeyValuePair<string, object> keyValuePair in dictionary)
  50. {
  51. // 值为空不参与签名
  52. //if (!string.IsNullOrEmpty(keyValuePair.Value + ""))
  53. //{
  54. text = string.Concat(new object[]
  55. {
  56. text,
  57. keyValuePair.Key,
  58. "=",
  59. keyValuePair.Value,
  60. "&"
  61. });
  62. //}
  63. }
  64. return text.Substring(0, text.Length - 1);
  65. }
  66. }
  67. }