Express.class.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Express.class.php 快递查询类 v1.0
  4. *
  5. * @copyright 福星高照
  6. * @license http://www.25531.com
  7. * @lastmodify 2014-08-22
  8. */
  9. class Express
  10. {
  11. /*
  12. * 网页内容获取方法
  13. */
  14. private function getcontent($url)
  15. {
  16. if (function_exists("file_get_contents")) {
  17. $file_contents = file_get_contents($url);
  18. } else {
  19. $ch = curl_init();
  20. $timeout = 5;
  21. curl_setopt($ch, CURLOPT_URL, $url);
  22. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  23. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  24. $file_contents = curl_exec($ch);
  25. curl_close($ch);
  26. }
  27. return $file_contents;
  28. }
  29. /*
  30. * 获取对应名称和对应传值的方法
  31. */
  32. private function expressname($order)
  33. {
  34. $name = json_decode($this->getcontent("http://www.kuaidi100.com/autonumber/auto?num={$order}"), true);
  35. $result = $name[0]['comCode'];
  36. if (empty($result)) {
  37. return false;
  38. } else {
  39. return $result;
  40. }
  41. }
  42. /*
  43. * 返回$data array 快递数组查询失败返回false
  44. * @param $order 快递的单号
  45. * $data['ischeck'] ==1 已经签收
  46. * $data['data'] 快递实时查询的状态 array
  47. */
  48. public function getorder($order)
  49. {
  50. $keywords = $this->expressname($order);
  51. if (!$keywords) {
  52. return false;
  53. } else {
  54. $result = $this->getcontent("http://www.kuaidi100.com/query?type={$keywords}&postid={$order}");
  55. $data = json_decode($result, true);
  56. return $data;
  57. }
  58. }
  59. }
  60. ?>