HttpServer.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Cryptography;
  5. using System.Text;
  6. using Newtonsoft.Json;
  7. using Newtonsoft.Json.Linq;
  8. using UAS_MES_NEW.DataOperate;
  9. namespace UAS_MES_NEW.PublicMethod
  10. {
  11. public class BindItem
  12. {
  13. [JsonProperty("bindKey")]
  14. public string BindKey { get; set; }
  15. [JsonProperty("bindValue")]
  16. public string BindValue { get; set; }
  17. [JsonProperty("keyType")]
  18. public string KeyType { get; set; }
  19. [JsonProperty("keyValue")]
  20. public string KeyValue { get; set; }
  21. [JsonProperty("hashType")]
  22. public string HashType { get; set; }
  23. [JsonProperty("hashKey")]
  24. public string HashKey { get; set; }
  25. }
  26. public class RootObject
  27. {
  28. [JsonProperty("productModuleType")]
  29. public string ProductModuleType { get; set; }
  30. [JsonProperty("productMainClass")]
  31. public string ProductMainClass { get; set; }
  32. [JsonProperty("productMediumClass")]
  33. public string ProductMediumClass { get; set; }
  34. [JsonProperty("productSubClass")]
  35. public string ProductSubClass { get; set; }
  36. [JsonProperty("task")]
  37. public string Task { get; set; }
  38. [JsonProperty("processType")]
  39. public string ProcessType { get; set; }
  40. [JsonProperty("userId")]
  41. public string UserId { get; set; }
  42. [JsonProperty("bindList")]
  43. public List<BindItem> BindList { get; set; }
  44. }
  45. class HttpServer
  46. {
  47. static DataHelper dh = new DataHelper();
  48. static string ComputeSha256Hash(string input)
  49. {
  50. using (SHA256 sha256 = SHA256.Create())
  51. {
  52. byte[] bytes = Encoding.UTF8.GetBytes(input);
  53. byte[] hashBytes = sha256.ComputeHash(bytes);
  54. StringBuilder builder = new StringBuilder();
  55. for (int i = 0; i < hashBytes.Length; i++)
  56. {
  57. builder.Append(hashBytes[i].ToString("x2"));
  58. }
  59. return builder.ToString().ToUpper();
  60. }
  61. }
  62. public static void SendBoxData(string iBox)
  63. {
  64. string sn = dh.getFieldDataByCondition("", "", "").ToString();
  65. var root = new RootObject
  66. {
  67. ProductModuleType = "整机",
  68. ProductMainClass = "固网_CPE",
  69. ProductMediumClass = "CPE",
  70. ProductSubClass = "ZXSLC SC50L",
  71. Task = "2025070006",
  72. ProcessType = "生产过程",
  73. UserId = "邓帝森",
  74. BindList = new List<BindItem>()
  75. };
  76. root.BindList.Add(new BindItem
  77. {
  78. BindKey = "cartonSn",
  79. BindValue = "4Y12R93C0001",
  80. KeyType = "macbox",
  81. KeyValue = sn,
  82. HashType = "SHA256",
  83. HashKey = ComputeSha256Hash(sn)
  84. }); ;
  85. string json = JsonConvert.SerializeObject(root, Formatting.Indented);
  86. }
  87. }
  88. }