Экспресс 100 Логистический запрос

PHP

Запрос по коду курьерской компании и номеру логистического заказа

$encipher = 'shunfeng';//快递公司的编码
$order_number = '1234656545';//物流单号
$result = getLogisticsByKdhundred($encipher, order_number);$state = '暂无物流轨迹';
$traces = [];
if (array_key_exists('state', $result)) {    
    switch ($result['state']) {
        case 1: 
           $state = '揽收';
            break; 
       case 2:  
          $state = '疑难';
            break;
        case 3:
            $state = '签收';
            break;
        case 4: 
           $state = '退签';
            break;
        case 5:
            $state = '派件';
            break;
        case 6:
            $state = '退单';
            break;
        default:
            $state = '';
            break;
    } 
   $traces = $result['data'];
    foreach ($traces as $key => &$value) {
        $value['context'] = empty($value['context']) ? "" : $value['context'];
    }
    $traces = array_reverse($traces);
}


function getLogistics($com, $nu){
    $post_data = array();
    $post_data["customer"] = '22222';//快递100 分配的编号
    $key= '1231232'; //快递100 key
    $param = [
        'com'=> $com, //快递公司的编码
       'num' => $nu,//物流单号
    ];
    $post_data["param"] = json_encode($param);
    $url='http://poll.kuaidi100.com/poll/query.do';//查询接口url
    $post_data["sign"] = md5($post_data["param"].$key.$post_data["customer"]);
    $post_data["sign"] = strtoupper($post_data["sign"]);
    $o="";
    foreach ($post_data as $k=>$v) {
        $o.= "$k=".urlencode($v)."&";//默认UTF-8编码格式
    }
    $post_data=substr($o,0,-1);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
    curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $status = curl_exec($ch);
    curl_close($ch);
    $res = json_decode($status, true);
    return $res;
}