快递接口api数据整理

2019年10月26日 40
<?php
header('Access-Control-Allow-Origin:*');
header('Content-type: application/json');
error_reporting(0);
function myCurl($url, $ip){
    $ch = curl_init();     // Curl 初始化
    $ua='Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36';    // 伪造抓取 UA
    curl_setopt($ch, CURLOPT_URL, $url);              // 设置 Curl 目标
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);      // Curl 请求有返回的值
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);     // 设置抓取超时时间
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);        // 跟踪重定向
    curl_setopt($ch, CURLOPT_ENCODING, "");    // 设置编码
    curl_setopt($ch, CURLOPT_REFERER, $url);   // 伪造来源网址
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:'.$ip, 'CLIENT-IP:'.$ip));  //伪造IP
    curl_setopt($ch, CURLOPT_USERAGENT, $ua);   // 伪造ua
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip'); // 取消gzip压缩
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    $content = curl_exec($ch);
    curl_close($ch);    // 结束 Curl
    return $content;    // 函数返回内容
}
function GetClientIP(){
    $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
    if($ip != ""){
        $arr = explode(",",$ip);
        return $arr[0];
    }else{
        return $_SERVER["REMOTE_ADDR"];
    }
}
!empty($_GET['num'])  ? $_GET['num'] :exit(json_encode([
    "code"=>-1,
    "msg"=>"请输入订单号!"
],JSON_UNESCAPED_UNICODE));
$json = json_decode(myCurl("https://hdgateway.zto.com/WayBill_GetDetail?billCode=".$_GET['num'],GetClientIP()));
if ($json->message!=="快递信息查询成功" || $json->result==null){
    $output = [
        "code"=>-1,
        "msg"=>"查询失败"
    ];
} else {
    $arr = $json->result->logisticsRecord;
    foreach ($arr as $k=>$v){
        foreach ($v as $value){
            $arrl[]=array(
                "time"=>$value->scanDate,
                "signMan"=>$value->signMan,
                "operateUserPhone"=>$value->operateUserPhone,
                "date"=>$value->date,
                "operateUser"=>$value->operateUser,
                "scanType"=>$value->scanType,
                "stateDescription"=>$value->stateDescription
            );
        }
    }
    $output = [
        "code"=>1,
        "msg"=>"查询成功!",
        "logisticsRecord"=>$arrl,
        "billPrescription"=>$json->result->billPrescription,
        "billCode"=>$json->result->billCode,
        "author"=>"老巫"
    ];
}
exit(json_encode($output,JSON_UNESCAPED_UNICODE));
1:如非特殊说明,本站对提供的源码不拥有任何权利,其版权归原著者拥有。请在下载后24小时之内自觉删除。
2:该资源只为研究、学习所提供,任何涉及商业盈利目的均不得使用,若需要,请购买正版,否则产生的一切后果将由您自己承担,与本站无关!
3:本网站所有资源均为作者提供和网友推荐收集整理而来,不保证其完整性以及安全性。如有侵犯你版权的,请来信(邮箱:lwvip_com@qq.com)指出,本站将立即改正。
本文地址:老巫源码 » 快递接口api数据整理

全屏

切换