[C#] 快递鸟物流单号自动查询接口-C# →→→→→进入此内容的聊天室

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

回复 "快递鸟物流单号自动查询接口-C#"

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

captcha