快递物流查询接口(阿里云市场接口),调用示例

//获取阿里云市场,快递物流记录 https://market.aliyun.com/products/56928004/cmapi022273.html?spm=5176.2020520132.101.26.61f97218v18GBF#sku=yuncode1627300000

//get_express_log(self::$config['web']['aliyun_AppCode']阿里云市场 AppCode,缓存秒数如 300秒,'快递公司代码,如:STO',快递单号,如:3398499691970);
//self::$config['web']是梦行框架的配置变量
function get_express_log($appcode,$show_express_cache,$type,$code){ $cache_path='./express_cache/'.md5($type.$code).'.express'; $cache_file_time=@filemtime($cache_path)+$show_express_cache*60; if(time()<$cache_file_time){return file_get_contents($cache_path);} $host = "https://kdwlcxf.market.alicloudapi.com"; $path = "/kdwlcx"; $method = "GET"; //$appcode = "a9e85f0ded814bc7a97a9f3ad5ccab01"; $headers = array(); array_push($headers, "Authorization:APPCODE " . $appcode); $querys = "no=".$code."&type=".$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); //curl_setopt($curl, CURLOPT_HEADER, true); 如不输出json, 请打开这行代码,打印调试头部状态码。 //状态码: 200 正常;400 URL无效;401 appCode错误; 403 次数用完; 500 API网管错误 if (1 == strpos("$".$host, "https://")) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } $out_put = curl_exec($curl); file_put_contents($cache_path,$out_put); return $out_put; }

猜你喜欢

转载自www.cnblogs.com/monxin/p/10415128.html