PHP对接阿里云物流信息接口

public function  logistics($no,$type){
$host = "https://wuliu.market.alicloudapi.com"; $path = "/kdi"; $method = "GET"; $appcode = "XXXXXXX"; $headers = array(); array_push($headers, "Authorization:APPCODE " . $appcode); $querys = "no=$no&type=$type"; //参数写在这里 $no要查询的快递单号,$type 那家的快递编码 阿里云的编码 自己对照 可不写 $bodys = ""; $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, false); if (1 == strpos("$".$host, "https://")){ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys); $res=curl_exec($curl); $data=json_decode($res); if($data->status==0){ $wuliu=$data->result->list; return ['code'=>2000,'msg'=>'成功','data'=>$wuliu]; }else{ return ['code'=>4000,'msg'=>'暂无物流信息']; }
}
原文地址:https://www.cnblogs.com/cyk2/p/15337238.html