Form1.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. using NPOI.SS.Formula.Functions;
  2. using NPOI.SS.UserModel;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Net;
  7. using System.Security.Cryptography;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
  11. namespace FileAnalysis
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19. private void Analysis_Click(object sender, EventArgs e)
  20. {
  21. string url = "https://openapi.seewo.com/seewo-study-machine/device-manager/check-activate";
  22. HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
  23. webrequest.Method = "POST";
  24. webrequest.Timeout = 1000;
  25. webrequest.ContentType = "application/x-www-form-urlencoded";
  26. string secret = "QmxcghPaupQjjSOTV3NJLkPeyycEBuYk";
  27. System.Collections.Hashtable pars = new System.Collections.Hashtable();
  28. string sign = "x-sw-app-id3a1252d81dff4fd3b1ece153b3a9cb71x-sw-req-path/seewo-study-machine/device-manager/check-activatex-sw-version2";
  29. webrequest.Headers.Add("x-sw-app-id", "3a1252d81dff4fd3b1ece153b3a9cb71"); //必填
  30. webrequest.Headers.Add("x-sw-sign", GETMD5(secret + sign + secret));//必填
  31. webrequest.Headers.Add("x-sw-req-path", "/seewo-study-machine/device-manager/check-activate");//必填
  32. webrequest.Headers.Add("x-sw-version", "2");//必填
  33. //webrequest.Headers.Add("x-sw-sign-type", "");
  34. //webrequest.Headers.Add("x-sw-sign-headers", "");
  35. //webrequest.Headers.Add("x-sw-timestamp", "");
  36. //webrequest.Headers.Add("x-sw-content-md5", "");c
  37. pars.Add("sn", "{sn:123}");
  38. string buffer = "";
  39. //发送POST数据
  40. if (!(pars == null || pars.Count == 0))
  41. {
  42. foreach (string key in pars.Keys)
  43. {
  44. buffer = buffer + "&" + key + "=" + pars[key].ToString();
  45. }
  46. byte[] data = Encoding.UTF8.GetBytes(buffer);
  47. using (Stream stream = webrequest.GetRequestStream())
  48. {
  49. stream.Write(data, 0, data.Length);
  50. }
  51. }
  52. string[] values = webrequest.Headers.GetValues("Content-Type");
  53. WebResponse myResponse = webrequest.GetResponse();
  54. using (Stream resStream = myResponse.GetResponseStream())//得到回写的流
  55. {
  56. StreamReader newReader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
  57. string Content = newReader.ReadToEnd();
  58. ReturnData.Text = Content;
  59. Dictionary<string, object> dic = new Dictionary<string, object>();
  60. //dic = BaseUtil.ToDictionary(Content);
  61. //if (!dic.ContainsKey("erpaccount"))
  62. //{
  63. // oMsg = dic["reason"].ToString();
  64. // return false;
  65. //}
  66. newReader.Close();
  67. }
  68. }
  69. private string GETMD5(string password)
  70. {
  71. //初始化MD5对象
  72. MD5 md5 = MD5.Create();
  73. //将源字符串转化为byte数组
  74. Byte[] soucebyte = Encoding.Default.GetBytes(password);
  75. //soucebyte转化为mf5的byte数组
  76. Byte[] md5bytes = md5.ComputeHash(soucebyte);
  77. //将md5的byte数组再转化为MD5数组
  78. StringBuilder sb = new StringBuilder();
  79. foreach (Byte b in md5bytes)
  80. {
  81. //x表示16进制,2表示2位
  82. sb.Append(b.ToString("x2"));
  83. }
  84. return sb.ToString();
  85. }
  86. public static int[] GetDecimalData(string HexStr, int[] DataSize, int[] NotShow)
  87. {
  88. List<int> ReturnData = new List<int>();
  89. try
  90. {
  91. //去除前面的指令字符和数据长度字符
  92. HexStr = HexStr.Replace(":", "");
  93. if (HexStr != "")
  94. {
  95. int ValueDataSize = Convert.ToInt32("0x" + (HexStr.Substring(4, 2)), 16) * 2;
  96. string RealData = HexStr.Substring(6);
  97. RealData = RealData.Substring(0, ValueDataSize);
  98. int SubIndex = 0;
  99. for (int i = 0; i < DataSize.Length; i = i + 1)
  100. {
  101. if (SubIndex + DataSize[i] < RealData.Length)
  102. {
  103. bool notshow = false;
  104. for (int j = 0; j < NotShow.Length; j++)
  105. {
  106. if (i == NotShow[j])
  107. notshow = true;
  108. }
  109. if (notshow)
  110. {
  111. SubIndex += DataSize[i];
  112. continue;
  113. }
  114. if (DataSize[i] == 8)
  115. {
  116. Console.WriteLine("0x" + (RealData.Substring(SubIndex, DataSize[i]).Substring(4, 4)) + (RealData.Substring(SubIndex, DataSize[i]).Substring(0, 4)));
  117. ReturnData.Add(Convert.ToInt32("0x" + (RealData.Substring(SubIndex, DataSize[i]).Substring(4, 4)) + (RealData.Substring(SubIndex, DataSize[i]).Substring(0, 4)), 16));
  118. }
  119. else if (DataSize[i] == 4)
  120. {
  121. Console.WriteLine("0x" + (RealData.Substring(SubIndex, DataSize[i])));
  122. ReturnData.Add(Convert.ToInt32("0x" + (RealData.Substring(SubIndex, DataSize[i])), 16));
  123. }
  124. }
  125. SubIndex += DataSize[i];
  126. }
  127. }
  128. }
  129. catch (Exception ex)
  130. {
  131. Console.WriteLine(ex.Message);
  132. }
  133. return ReturnData.ToArray();
  134. }
  135. private void Form1_Load(object sender, EventArgs e)
  136. {
  137. }
  138. }
  139. }