快递查询接口
中通快递查询接口
<?php header("Content-type: text/html; charset=utf-8"); $url = \'http://japi.zto.cn/traceInterfaceNewTraces\'; $company_id = \'xxxx\'; $key = \'xxxx\'; // 注意这里的 $data 里必须都是字符串,如果有array的话要先json_encode $data = array(\'data\' => \'["xx快递单号xxx"]\', \'company_id\' => $company_id, \'msg_type\'=>\'NEW_TRACES\'); $str_to_digest = ""; foreach ($data as $k=>$v) { $str_to_digest =$str_to_digest.$k."=".$v."&"; } $str_to_digest = substr($str_to_digest, 0, -1).$key; $data_digest = base64_encode(md5($str_to_digest,TRUE)); $options = array( \'http\' => array( \'header\' => "Content-type: application/x-www-form-urlencoded; charset=utf-8\r\n". "x-companyid: ".$company_id."\r\n". "x-datadigest: ".$data_digest."\r\n", \'method\' => \'POST\', \'content\' => http_build_query($data) ) ); $context = stream_context_create($options); // file_get_contents性能不好,请自行优化 $result = file_get_contents($url, false, $context); echo $result;
开发平台的接口需要开通,否则提示没有权限
https://github.com/ZTO-Express/zopsdk-php(sdk版)
https://zop.zto.com/zopdoc/index.html
快递100 查询接口
$url = \'https://www.kuaidi100.com/query?type=\' . $express . \'&postid=\' . $expresssn . \'&id=1&valicode=&temp=\'; $response = ihttp_request($url); $content = $response[\'content\']; $info = json_decode($content, true); $useapi = false;
免费的经常不稳定,企业版的才行
if ($express_set[\'isopen\'] == 1) { $url = \'http://api.kuaidi100.com/api?id=\' . $express_set[\'apikey\'] . \'&com=\' . $express . \'&nu=\' . $expresssn; $params = array(); } else { $url = \'http://poll.kuaidi100.com/poll/query.do\'; $params = array(\'customer\' => $express_set[\'customer\'], \'param\' => json_encode(array(\'com\' => $express, \'num\' => $expresssn))); $params[\'sign\'] = md5($params[\'param\'] . $express_set[\'apikey\'] . $params[\'customer\']); $params[\'sign\'] = strtoupper($params[\'sign\']); } $response = ihttp_post($url, $params); $content = $response[\'content\']; $info = json_decode($content, true);
版权声明:本文为lemonphp原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。