zoukankan      html  css  js  c++  java
  • PHP—— 商品物流实时查询接口 (快递100API对接)

    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);
        }

    如下图所示

  • 相关阅读:
    关于栈部分知识点
    面向对象--四则运算
    转型第一步
    输入输出文件版本——计算题
    作业二
    2017《面向对象程序设计》课程作业一
    第四次作业
    light oj 1079
    Light oj 1080
    Codeforces 486B OR in Matrix【水题】
  • 原文地址:https://www.cnblogs.com/renluyang/p/12076238.html
Copyright © 2011-2022 走看看