KuaiDi100.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Net;
  9. using System.Net.Http;
  10. using System.Security.Cryptography;
  11. using System.Text;
  12. namespace PublicLibrary
  13. {
  14. public static class KuaiDi100
  15. {
  16. //http://www.kuaidi100.com/query?type=shentong&postid=3397565624265
  17. //http://www.kuaidi100.com/autonumber/auto?num=3397565624265&key=kPxmJCvS5025
  18. public static KuaiDiRoot Query(string kdcode)
  19. {
  20. HttpClient httpClient = new HttpClient();
  21. var httpResponseMessage = httpClient.GetAsync($"http://www.kuaidi100.com/autonumber/auto?num={kdcode}&key=kPxmJCvS5025").Result;
  22. var result = httpResponseMessage.Content.ReadAsStringAsync().Result;
  23. if (!string.IsNullOrEmpty(result) && result != "[]")
  24. {
  25. var list = JsonConvert.DeserializeObject<List<AutoNumber>>(result);
  26. var comCode = list.First().comCode;
  27. var str = $"http://www.kuaidi100.com/query?type={comCode}&postid={kdcode}";
  28. var web = WebRequest.Create(str);
  29. web.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0");
  30. var stream = web.GetResponse().GetResponseStream();
  31. StreamReader sr = new StreamReader(stream);
  32. string result2 = sr.ReadToEnd();
  33. var root = JsonConvert.DeserializeObject<KuaiDiRoot>(result2);
  34. return root;
  35. }
  36. return null;
  37. }
  38. class AutoNumber
  39. {
  40. public string comCode { get; set; }
  41. public string id { get; set; }
  42. public string noCount { get; set; }
  43. public string noPre { get; set; }
  44. public string startTime { get; set; }
  45. }
  46. public class KuaiDiData
  47. {
  48. public DateTime time { get; set; }
  49. public DateTime ftime { get; set; }
  50. public string context { get; set; }
  51. public string location { get; set; }
  52. }
  53. public class KuaiDiRoot
  54. {
  55. public string message { get; set; }
  56. public string nu { get; set; }
  57. public string ischeck { get; set; }
  58. public string condition { get; set; }
  59. public string com { get; set; }
  60. public string status { get; set; }
  61. public string state { get; set; }
  62. public List<KuaiDiData> data { get; set; }
  63. }
  64. }
  65. enum KuaiDiCode
  66. {
  67. [Description("aae全球专递")]
  68. aae,
  69. [Description("安捷快递")]
  70. anjie,
  71. [Description("安信达快递")]
  72. anxindakuaixi,
  73. [Description("彪记快递")]
  74. biaojikuaidi,
  75. [Description("bht")]
  76. bht,
  77. [Description("百福东方国际物流")]
  78. baifudongfang,
  79. [Description("中国东方(COE)")]
  80. coe,
  81. [Description("长宇物流")]
  82. changyuwuliu,
  83. [Description("大田物流")]
  84. datianwuliu,
  85. [Description("德邦物流")]
  86. debangwuliu,
  87. [Description("dhl")]
  88. dhl,
  89. [Description("dpex")]
  90. dpex,
  91. [Description("d速快递")]
  92. dsukuaidi,
  93. [Description("递四方")]
  94. disifang,
  95. [Description("ems快递")]
  96. ems,
  97. [Description("fedex(国外)")]
  98. fedex,
  99. [Description("飞康达物流")]
  100. feikangda,
  101. [Description("凤凰快递")]
  102. fenghuangkuaidi,
  103. [Description("飞快达")]
  104. feikuaida,
  105. [Description("国通快递")]
  106. guotongkuaidi,
  107. [Description("港中能达物流")]
  108. ganzhongnengda,
  109. [Description("广东邮政物流")]
  110. guangdongyouzhengwuliu,
  111. [Description("共速达")]
  112. gongsuda,
  113. [Description("汇通快运")]
  114. huitongkuaidi,
  115. [Description("恒路物流")]
  116. hengluwuliu,
  117. [Description("华夏龙物流")]
  118. huaxialongwuliu,
  119. [Description("海红")]
  120. haihongwangsong,
  121. [Description("海外环球")]
  122. haiwaihuanqiu,
  123. [Description("佳怡物流")]
  124. jiayiwuliu,
  125. [Description("京广速递")]
  126. jinguangsudikuaijian,
  127. [Description("急先达")]
  128. jixianda,
  129. [Description("佳吉物流")]
  130. jjwl,
  131. [Description("加运美物流")]
  132. jymwl,
  133. [Description("金大物流")]
  134. jindawuliu,
  135. [Description("嘉里大通")]
  136. jialidatong,
  137. [Description("晋越快递")]
  138. jykd,
  139. [Description("快捷速递")]
  140. kuaijiesudi,
  141. [Description("联邦快递(国内)")]
  142. lianb,
  143. [Description("联昊通物流")]
  144. lianhaowuliu,
  145. [Description("龙邦物流")]
  146. longbanwuliu,
  147. [Description("立即送")]
  148. lijisong,
  149. [Description("乐捷递")]
  150. lejiedi,
  151. [Description("民航快递")]
  152. minghangkuaidi,
  153. [Description("美国快递")]
  154. meiguokuaidi,
  155. [Description("门对门")]
  156. menduimen,
  157. [Description("OCS")]
  158. ocs,
  159. [Description("配思货运")]
  160. peisihuoyunkuaidi,
  161. [Description("全晨快递")]
  162. quanchenkuaidi,
  163. [Description("全峰快递")]
  164. quanfengkuaidi,
  165. [Description("全际通物流")]
  166. quanjitong,
  167. [Description("全日通快递")]
  168. quanritongkuaidi,
  169. [Description("全一快递")]
  170. quanyikuaidi,
  171. [Description("如风达")]
  172. rufengda,
  173. [Description("三态速递")]
  174. santaisudi,
  175. [Description("盛辉物流")]
  176. shenghuiwuliu,
  177. [Description("申通")]
  178. shentong,
  179. [Description("顺丰")]
  180. shunfeng,
  181. [Description("速尔物流")]
  182. sue,
  183. [Description("盛丰物流")]
  184. shengfeng,
  185. [Description("赛澳递")]
  186. saiaodi,
  187. [Description("天地华宇")]
  188. tiandihuayu,
  189. [Description("天天快递")]
  190. tiantian,
  191. [Description("tnt")]
  192. tnt,
  193. [Description("ups")]
  194. ups,
  195. [Description("万家物流")]
  196. wanjiawuliu,
  197. [Description("文捷航空速递")]
  198. wenjiesudi,
  199. [Description("伍圆")]
  200. wuyuan,
  201. [Description("万象物流")]
  202. wxwl,
  203. [Description("新邦物流")]
  204. xinbangwuliu,
  205. [Description("信丰物流")]
  206. xinfengwuliu,
  207. [Description("亚风速递")]
  208. yafengsudi,
  209. [Description("一邦速递")]
  210. yibangwuliu,
  211. [Description("优速物流")]
  212. youshuwuliu,
  213. [Description("邮政包裹挂号信")]
  214. youzhengguonei,
  215. [Description("邮政国际包裹挂号信")]
  216. youzhengguoji,
  217. [Description("远成物流")]
  218. yuanchengwuliu,
  219. [Description("圆通速递")]
  220. yuantong,
  221. [Description("源伟丰快递")]
  222. yuanweifeng,
  223. [Description("元智捷诚快递")]
  224. yuanzhijiecheng,
  225. [Description("韵达快运")]
  226. yunda,
  227. [Description("运通快递")]
  228. yuntongkuaidi,
  229. [Description("越丰物流")]
  230. yuefengwuliu,
  231. [Description("源安达")]
  232. yad,
  233. [Description("银捷速递")]
  234. yinjiesudi,
  235. [Description("宅急送")]
  236. zhaijisong,
  237. [Description("中铁快运")]
  238. zhongtiekuaiyun,
  239. [Description("中通速递")]
  240. zhongtong,
  241. [Description("中邮物流")]
  242. zhongyouwuliu,
  243. [Description("忠信达")]
  244. zhongxinda,
  245. [Description("芝麻开门")]
  246. zhimakaimen
  247. }
  248. }