[PHP] 如何免费对接快递鸟物流查询API-PHP →→→→→进入此内容的聊天室

来自 , 2019-10-28, 写在 PHP, 查看 99 次.
URL http://www.code666.cn/view/2e2c080d
  1. <?php
  2. //电商ID
  3. defined('EBusinessID') or define('EBusinessID', 1237100);
  4. //电商加密私钥,快递鸟提供,注意保管,不要泄漏
  5. defined('AppKey') or define('AppKey', '518a73d8-1f7f-441a-b644-33e77b49d846');
  6. //请求url
  7. defined('ReqURL') or define('ReqURL', 'http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx');
  8.  
  9. /**
  10.  * Json方式 查询订单物流轨迹
  11.  */
  12. function getOrderTracesByJson(){
  13.         $requestData= "{'OrderCode':'','ShipperCode':'SF','LogisticCode':'589707398027'}";
  14.        
  15.         $datas = array(
  16.         'EBusinessID' => EBusinessID,
  17.         'RequestType' => '1002',
  18.         'RequestData' => urlencode($requestData) ,
  19.         'DataType' => '2',
  20.     );
  21.     $datas['DataSign'] = encrypt($requestData, AppKey);
  22.         $result=sendPost(ReqURL, $datas);      
  23.        
  24.         //根据公司业务处理返回的信息......
  25.        
  26.         return $result;
  27. }
  28.  
  29. /**
  30.  * XML方式 查询订单物流轨迹
  31.  */
  32. function getOrderTracesByXml(){
  33.         $requestData= "<?xml version=\"1.0\" encoding=\"utf-8\" ?>".
  34.                                                 "<Content>".
  35.                                                 "<OrderCode></OrderCode>".
  36.                                                 "<ShipperCode>SF</ShipperCode>".
  37.                                                 "<LogisticCode>589707398027</LogisticCode>".
  38.                                                 "</Content>";
  39.        
  40.         $datas = array(
  41.         'EBusinessID' => EBusinessID,
  42.         'RequestType' => '1002',
  43.         'RequestData' => urlencode($requestData) ,
  44.         'DataType' => '1',
  45.     );
  46.     $datas['DataSign'] = encrypt($requestData, AppKey);
  47.         $result=sendPost(ReqURL, $datas);      
  48.        
  49.         //根据公司业务处理返回的信息......
  50.        
  51.         return $result;
  52. }
  53.  
  54. /**
  55.  *  post提交数据
  56.  * @param  string $url 请求Url
  57.  * @param  array $datas 提交的数据
  58.  * @return url响应返回的html
  59.  */
  60. function sendPost($url, $datas) {
  61.     $temps = array();  
  62.     foreach ($datas as $key => $value) {
  63.         $temps[] = sprintf('%s=%s', $key, $value);             
  64.     }  
  65.     $post_data = implode('&', $temps);
  66.     $url_info = parse_url($url);
  67.         if($url_info['port']=='')
  68.         {
  69.                 $url_info['port']=80;  
  70.         }
  71.         echo $url_info['port'];
  72.     $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
  73.     $httpheader.= "Host:" . $url_info['host'] . "\r\n";
  74.     $httpheader.= "Content-Type:application/x-www-form-urlencoded\r\n";
  75.     $httpheader.= "Content-Length:" . strlen($post_data) . "\r\n";
  76.     $httpheader.= "Connection:close\r\n\r\n";
  77.     $httpheader.= $post_data;
  78.     $fd = fsockopen($url_info['host'], $url_info['port']);
  79.     fwrite($fd, $httpheader);
  80.     $gets = "";
  81.         $headerFlag = true;
  82.         while (!feof($fd)) {
  83.                 if (($header = @fgets($fd)) && ($header == "\r\n" || $header == "\n")) {
  84.                         break;
  85.                 }
  86.         }
  87.     while (!feof($fd)) {
  88.                 $gets.= fread($fd, 128);
  89.     }
  90.     fclose($fd);  
  91.    
  92.     return $gets;
  93. }
  94.  
  95. /**
  96.  * 电商Sign签名生成
  97.  * @param data 内容  
  98.  * @param appkey Appkey
  99.  * @return DataSign签名
  100.  */
  101. function encrypt($data, $appkey) {
  102.     return urlencode(base64_encode(md5($data.$appkey)));
  103. }
  104.  
  105. ?>

回复 "如何免费对接快递鸟物流查询API-PHP"

这儿你可以回复上面这条便签

captcha