安装PHP Wrapper for KuaiDi100.
github

composer require xu42/kuaidi100

使用

<?php
namespace app\index\controller;

use think\Controller;
use Xu42\KuaiDi100\KuaiDi100;

class TrackCode extends controller
{

    public function index2()
    {
        // 获取快递公司类型
        $logistics = KuaiDi100::getCode('634246542022');
        // 查询结果
        $data      = KuaiDi100::track($logistics, '634246542022');
        return json($data);
    }
}

注意
* 如果查询时间很长:

// 修改/src/Utils.php/curlRequest
// 原
private static function curlRequest($url)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_REFERER, $url);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0');
        $response = curl_exec($ch);
        curl_close($ch);
        return $response;
    }
//改为
private static function curlRequest($url)
    {
        $response = file_get_contents($url);
        return $response;
    }
Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐