Kuaidiniao.class.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace Lib;
  3. class Kuaidiniao {
  4. private $ebusinessid = '';
  5. private $appkey = '';
  6. private $requrl = 'http://api.kdniao.cc/api/dist';
  7. public function __construct() {
  8. $ebuss_info = M('config')->where( array('name' => 'EXPRESS_EBUSS_ID') )->find();
  9. $exappkey = M('config')->where( array('name' => 'EXPRESS_APPKEY') )->find();
  10. $this->ebusinessid = $ebuss_info['value'];
  11. $this->appkey = $exappkey['value'];
  12. }
  13. public function subscribe($order_id){
  14. //百世快递
  15. //70988266665060
  16. $order_info = M('order')->where( array('order_id' => $order_id) )->find();
  17. //shipping_method
  18. //shipping_no
  19. $seller_express = M('seller_express')->where( array('id' =>$order_info['shipping_method'] ) )->find();
  20. if(!empty($seller_express['jianma']))
  21. {
  22. $requestData_arr = array('ShipperCode' => $seller_express['jianma'],'OrderCode' => $order_id,'LogisticCode' => $order_info['shipping_no']);
  23. $requestData = json_encode($requestData_arr);
  24. $datas = array(
  25. 'EBusinessID' => $this->ebusinessid,
  26. 'RequestType' => '1008',
  27. 'RequestData' => urlencode($requestData) ,
  28. 'DataType' => '2',
  29. );
  30. $datas['DataSign'] = $this->encrypt($requestData, $this->appkey);
  31. $result=$this->sendPost($this->requrl, $datas);
  32. //根据公司业务处理返回的信息......
  33. return $result;
  34. }
  35. }
  36. //调用获取物流轨迹
  37. //-------------------------------------------------------------
  38. //-------------------------------------------------------------
  39. /**
  40. * Json方式 物流信息订阅
  41. */
  42. function orderTracesSubByJson(){
  43. }
  44. /**
  45. * post提交数据
  46. * @param string $url 请求Url
  47. * @param array $datas 提交的数据
  48. * @return url响应返回的html
  49. */
  50. function sendPost($url, $datas) {
  51. $temps = array();
  52. foreach ($datas as $key => $value) {
  53. $temps[] = sprintf('%s=%s', $key, $value);
  54. }
  55. $post_data = implode('&', $temps);
  56. $url_info = parse_url($url);
  57. if(empty($url_info['port']))
  58. {
  59. $url_info['port']=80;
  60. }
  61. $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
  62. $httpheader.= "Host:" . $url_info['host'] . "\r\n";
  63. $httpheader.= "Content-Type:application/x-www-form-urlencoded\r\n";
  64. $httpheader.= "Content-Length:" . strlen($post_data) . "\r\n";
  65. $httpheader.= "Connection:close\r\n\r\n";
  66. $httpheader.= $post_data;
  67. $fd = fsockopen($url_info['host'], $url_info['port']);
  68. fwrite($fd, $httpheader);
  69. $gets = "";
  70. $headerFlag = true;
  71. while (!feof($fd)) {
  72. if (($header = @fgets($fd)) && ($header == "\r\n" || $header == "\n")) {
  73. break;
  74. }
  75. }
  76. while (!feof($fd)) {
  77. $gets.= fread($fd, 128);
  78. }
  79. fclose($fd);
  80. return $gets;
  81. }
  82. /**
  83. * 电商Sign签名生成
  84. * @param data 内容
  85. * @param appkey Appkey
  86. * @return DataSign签名
  87. */
  88. function encrypt($data, $appkey) {
  89. return urlencode(base64_encode(md5($data.$appkey)));
  90. }
  91. }
  92. ?>