function alikuaidi(){
$no = $this->request->get('kuaidi','','serach_in');
if(!$no) $this->error('参数错误');
try{
$host = "https://kdwlcxf.market.alicloudapi.com";
$path = "/kdwlcx";
$method = "GET";
$appcode = "93f9a1db2e64c4acdfea3f7b1e36aaa";
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
$querys = "no=".$no;
$url = $host . $path . "?" . $querys;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
if (1 == strpos("$" . $host, "https://")) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
$out_put = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
list($header, $body) = explode("\r\n\r\n", $out_put, 2);
if ($httpCode == 200) {
$body = json_decode($body,true);
$this->view->assign('info',$body);
return $this->display('alikuaidi');
} else {
if ($httpCode == 400 && strpos($header, "Invalid Param Location") !== false) {
$this->error('参数错误!');
} elseif ($httpCode == 400 && strpos($header, "Invalid AppCode") !== false) {
$this->error('AppCode错误!');
} elseif ($httpCode == 400 && strpos($header, "Invalid Url") !== false) {
$this->error('环境错误!');
} elseif ($httpCode == 403 && strpos($header, "Unauthorized") !== false) {
$this->error('服务未被授权!');
} elseif ($httpCode == 403 && strpos($header, "Quota Exhausted") !== false) {
$this->error('套餐包次数用完!');
} elseif ($httpCode == 500) {
$this->error('API网关错误!');
} elseif ($httpCode == 0) {
$this->error('URL错误!');
} else {
$this->error('其它参数错误!');
}
}
} catch (\Exception $e){
$this->error($e->getMessage());
}
}
物流查询接口很多服务商都有提供,但基本都是付费调用,价格也都差不是很多,也可以自己找单接口集成,比较费事而已,推荐找一家相对便宜的大服务商接入。上面案例来自阿里云某个商家,提供的一元测试。
|