人人商城

express.php 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. $matchs = array();
  3. $ret = preg_match('/^(?P<express>申通|圆通|中通|汇通|韵达|顺丰|ems|天天|宅急送|邮政|德邦|全峰) *(?P<sn>[a-z\d]{1,})$/i', $this->message['content'], $matchs);
  4. if(!$ret) {
  5. return $this->respText('请输入合适的格式, 快递公司+空格+单号(当前仅支持申通,圆通,中通,汇通,韵达,顺丰,EMS,天天,宅急送,邮政,德邦,全峰), 例如: 申通 2309381801');
  6. }
  7. $express = $matchs['express'];
  8. $sn = $matchs['sn'];
  9. $mappings = array(
  10. '申通' => 'shentong',
  11. '圆通' => 'yuantong',
  12. '中通' => 'zhongtong',
  13. '汇通' => 'huitongkuaidi',
  14. '韵达' => 'yunda',
  15. '顺丰' => 'shunfeng',
  16. 'ems' => 'ems',
  17. '天天' => 'tiantian',
  18. '宅急送' => 'zhaijisong',
  19. '邮政' => 'youzhengguonei',
  20. '德邦' => 'debangwuliu',
  21. '全峰' => 'quanfengkuaidi'
  22. );
  23. $images = array(
  24. 'shentong' => 'http://cdn.kuaidi100.com/images/all/st_logo.gif',
  25. 'yuantong' => 'http://cdn.kuaidi100.com/images/all/yt_logo.gif',
  26. 'zhongtong' => 'http://cdn.kuaidi100.com/images/all/zt_logo.gif',
  27. 'huitongkuaidi' => 'http://cdn.kuaidi100.com/images/all/htky_logo.gif',
  28. 'yunda' => 'http://cdn.kuaidi100.com/images/all/yd_logo.gif',
  29. 'shunfeng' => 'http://cdn.kuaidi100.com/images/all/sf_logo.gif',
  30. 'ems' => 'http://cdn.kuaidi100.com/images/all/ems_logo.gif',
  31. 'tiantian' => 'http://cdn.kuaidi100.com/images/all/tt_logo.gif',
  32. 'zhaijisong' => 'http://cdn.kuaidi100.com/images/all/zjs_logo.gif',
  33. 'youzhengguonei' => 'http://cdn.kuaidi100.com/images/all/yzgn_logo.gif',
  34. 'debangwuliu' => 'http://cdn.kuaidi100.com/images/all/dbwl_logo.gif',
  35. 'quanfengkuaidi' => 'http://cdn.kuaidi100.com/images/all/qfkd_logo.gif'
  36. ) ;
  37. $code = $mappings[$express];
  38. $rand = rand();
  39. $url = "http://wap.kuaidi100.com/wap_result.jsp?rand={$rand}&id={$code}&fromWeb=null&&postid={$sn}";
  40. $dat = ihttp_get($url);
  41. $msg = '';
  42. if(!empty($dat) && !empty($dat['content'])) {
  43. $reply = $dat['content'];
  44. preg_match ('/查询结果如下所示.+/', $reply, $matchs);
  45. $reply = $matchs[0];
  46. preg_match_all('/&middot;(.*?)<br \/>(.*?)<\/p>/', $reply, $matchs);
  47. $traces = '';
  48. for ($i = 0; $i < count($matchs[0]); $i++ ) {
  49. $traces .= $matchs[1][$i]. '-'. $matchs[2][$i]. PHP_EOL;
  50. }
  51. $replys = array();
  52. $replys[] = array(
  53. 'title' => '已经为你查到相关快递记录:',
  54. 'picurl' => $images[$code],
  55. 'description' => $traces,
  56. 'url' => 'http://m.kuaidi100.com/index_all.html?type='.$code.'&postid='.$sn,
  57. );
  58. return $this->respNews ($replys);
  59. }
  60. return $this->respText ('没有查找到相关的数据' . $msg . '. 请重新发送或检查您的输入格式, 正确格式为: 快递公司+空格+单号, 例如: 申通 2309381801');