php 阿里云调用快递接口

阿里云申请appcode地址:https://market.aliyun.com/products/57126001/cmapi021863.html?spm=5176.730005.productlist.d_cmapi021863.ebSZX2#sku=yuncode1586300000

由于是原生开发,所以我写在了一个控制器里面,框架开发提出来即可使用。

代码如下:

<?php
function Goculr($no,$type){
    //请求网址
    $host = "https://kuaidi101.market.alicloudapi.com";
    $path = "/getExpress"; //请求前缀
    $method = "GET"; //请求方式
    $appcode = ""; //阿里云 appcode
    $headers = array();
    array_push($headers, "Authorization:APPCODE " . $appcode);
    //$no 订单物流号 $type 快递公司 中通(zhongtong)
    $querys = "NO=$no&TYPE=$type";
    $url = $host . $path . "?" . $querys; //拼接地址
    //curl 请求
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_FAILONERROR, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HEADER, false);
    if (1 == strpos("$".$host, "https://")){
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    }
    //这里改成false 可以转成json格式
    curl_setopt($curl, CURLOPT_POSTFIELDS,false);
    return curl_exec($curl);
}

//接受物流订单
$no="";
//接受物流公司名称
$type="";
//返回结果
$res=Goculr($no,$type);
print_r($res);die();

  

posted @ 2021-10-15 17:11  锕果先生  阅读(125)  评论(0)    收藏  举报