快递鸟android_YII2 使用快递鸟api跟踪物流查询(示例代码)
namespacecommonutils;classKdniao
{//填寫你自己申請的快遞鳥的配置
private $EBusinessID = ‘000000‘;private $AppKey = ‘xxxxxxxxxxxxxx‘;private $ReqURL = ‘http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx‘;//nums 物流單號//code 快遞公司編號 如 SF
publicfunction deliver_search($nums,$code)
{
$requestData=array(‘ShipperCode‘ =>$code,‘LogisticCode‘ =>$nums,‘PayType‘ => ‘1‘,‘ExpType‘ => ‘1‘,‘IsNotice‘ => ‘0‘);
$params =json_encode($requestData);
$datas=array(‘EBusinessID‘ => $this->EBusinessID,‘RequestType‘ => ‘1002‘,‘RequestData‘ => urlencode($params) ,‘DataType‘ => ‘2‘,
);
$datas[‘DataSign‘] = $this->encrypt($params, $this->AppKey);
$result= $this->sendPost($this->ReqURL, $datas);return json_decode($result,1);
}/**
* post提交數據
* @param string $url 請求Url
* @param array $datas 提交的數據
* @return url響應返回的html*/
privatefunction sendPost($url, $datas) {
$temps=array();foreach ($datas as $key =>$value) {
$temps[]= sprintf(‘%s=%s‘, $key, $value);
}
$post_data= implode(‘&‘, $temps);
$url_info=parse_url($url);if(empty($url_info[‘port‘]))
{
$url_info[‘port‘]=80;
}
$httpheader= "POST" . $url_info[‘path‘] . "HTTP/1.0";
$httpheader.= "Host:" . $url_info[‘host‘] . "";
$httpheader.= "Content-Type:application/x-www-form-urlencoded";
$httpheader.= "Content-Length:" . strlen($post_data) . "";
$httpheader.= "Connection:close";
$httpheader.=$post_data;
$fd= fsockopen($url_info[‘host‘], $url_info[‘port‘]);
fwrite($fd, $httpheader);
$gets= "";
$headerFlag= true;while (!feof($fd)) {if (($header = @fgets($fd)) && ($header == "" || $header == "")) {break;
}
}while (!feof($fd)) {
$gets.= fread($fd, 128);
}
fclose($fd);return$gets;
}/**
* 電商Sign簽名生成
* @param data 內容
* @param appkey Appkey
* @return DataSign簽名*/
privatefunction encrypt($data, $appkey)
{returnurlencode(base64_encode(md5($data.$appkey)));
}
}
總結
以上是生活随笔為你收集整理的快递鸟android_YII2 使用快递鸟api跟踪物流查询(示例代码)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【笔试面试】携程笔试面试注意事项
- 下一篇: 怎么彻底删除users下的文件夹_use