PHP—— 商品物流实时查询接口 (快递100API对接)

2021-01-22 21:12

阅读:685

标签:info   api接口   amp   div   手机   客户   style   system   foreach   

PHP后台  与前端   对接商品物流信息的接口

运用的 快递100的API接口

public function getExpress() { 
        $user_id = input(post.user_id);
        if(null===$user_id){
            $this->json_error(请传过来用户编号);
        }

        $com = input(post.expresscom);
        $num = input(post.expresssn);
        // $com = ‘zhongtong‘;
        // $num = ‘73124309026125‘;
        $key = Config::get(kuaidi)[key];                      //客户授权key
        $customer = Config::get(kuaidi)[cus];                 //查询公司编号
        $param = array (
            com => $com,           //快递公司编码
            num => $num,   //快递单号
            phone => ‘‘,              //手机号
            from => ‘‘,               //出发地城市
            to => ‘‘,                 //目的地城市
            resultv2 => 1           //开启行政区域解析
        );
    
        //请求参数
        $post_data = array();
        $post_data["customer"] = $customer;
        $post_data["param"] = json_encode($param);
        $sign = md5($post_data["param"].$key.$post_data["customer"]);
        $post_data["sign"] = strtoupper($sign);
        
        $url = http://poll.kuaidi100.com/poll/query.do;   //实时查询请求地址
        
        $params = "";
        foreach ($post_data as $k=>$v) {
            $params .= "$k=".urlencode($v)."&";     //默认UTF-8编码格式
        }
        $post_data = substr($params, 0, -1);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $result = curl_exec($ch);
        $data = str_replace("\"", ", $result );
       
        // $data[‘name‘] = config(‘system.express_company‘)[$com][‘statusname‘];
        $data = json_decode($data,true);
        $data[name] = config(system.express_company)[$com][statusname];
        
        $data = json_encode($data);
        $data = json_decode($data);
          $this->json_success($data);
    }

如下图所示

技术图片

PHP—— 商品物流实时查询接口 (快递100API对接)

标签:info   api接口   amp   div   手机   客户   style   system   foreach   

原文地址:https://www.cnblogs.com/renluyang/p/12076238.html


评论


亲,登录后才可以留言!