PHP implements express bird instant query interface

Instant query interface

1. View the API interface documentation of the instant query interface
Insert picture description here

2. Refer to the PHP document demo
http://www.kdniao.com/file/KdApiSearchDemo(PHP).rar
3. Register an account, fill in the basic information of the company and upload the business license information.
4. Prepare the logistics company code and courier number, For details, check the courier company code in the interface document

4. Thinkphp6 implementation method
1) Constant define defines e-commerce ID and e-commerce encryption private key
2) E-commerce Sign signature generation
3) Send post request

<?php
namespace app\index\controller;

use think\Controller;


class Test extends  Base
{
    public function index()
    {
        //电商ID
        defined('EBusinessID') or define('EBusinessID', 'xxxxxx');//请到快递鸟官网申请http://kdniao.com/reg
//电商加密私钥,快递鸟提供,注意保管,不要泄漏
        defined('AppKey') or define('AppKey', '8f30e2c3-b4c4-423a-sssssss');//请到快递鸟官网申请http://kdniao.com/reg
//请求url
        defined('ReqURL') or define('ReqURL', 'https://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx');

        $requestData= "{'OrderCode':'','ShipperCode':'STO','LogisticCode':'773079102643511'}";

        $datas = array(
            'EBusinessID' => EBusinessID,
            'RequestType' => '1002',
            'RequestData' => urlencode($requestData) ,
            'DataType' => '2',
        );
        $datas['DataSign'] = $this->encrypt($requestData, AppKey);
        $result=$this->sendPost(ReqURL, $datas);

        //根据公司业务处理返回的信息......
        halt($result);
        //return $result;
    }

    /**
     *  post提交数据
     * @param  string $url 请求Url
     * @param  array $datas 提交的数据
     * @return url响应返回的html
     */
   public function sendPost($url, $datas) {
        $postdata = http_build_query($datas);
        $options = array(
            'http' => array(
                'method' => 'POST',
                'header' => 'Content-type:application/x-www-form-urlencoded',
                'content' => $postdata,
                'timeout' => 15 * 60 // 超时时间(单位:s)
            )
        );
        $context = stream_context_create($options);
        $result = file_get_contents($url, false, $context);
        return $result;
    }

    /**
     * 电商Sign签名生成
     * @param data 内容
     * @param appkey Appkey
     * @return DataSign签名
     */
    public function encrypt($data, $appkey) {
        return urlencode(base64_encode(md5($data.$appkey)));
    }

}

Guess you like

Origin blog.csdn.net/weixin_39218464/article/details/114268169