如何在php项目中使用快递单号查询接口

发布时间:2021-03-09 16:13:16 作者:Leah
来源:亿速云 阅读:110

如何在php项目中使用快递单号查询接口?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

代码如下:


<?php
/**
 * 查询物流信息
 */
define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');

if ($id = intval($_REQUEST['id'])) {
    $sql_select = 'SELECT consignee,mobile,tel,tracking_sn,shipping_code,shipping_name FROM '.
        $GLOBALS['ecs']->table('order_info')." WHERE order_id=$id";
    $order_info = $GLOBALS['db']->getRow($sql_select);

    // 快递公司code映射
    $shipping_code = array (
        'ems'         => 'ems',
        'ems2'        => 'ems',
        'sto_express' => 'zjs',
        'sto_nopay'   => 'zjs',
        'zto'         => 'zhongtong',
        'sto'         => 'shentong',
        'yto'         => 'yuantong',
        'sf'          => 'shunfeng',
        'emssn'       => 'ems',
        'sf2'         => 'shunfeng',
        'yunda'       => 'yunda',
    );

    $logistics_code = $shipping_code[$order_info['shipping_code']] ? $shipping_code[$order_info['shipping_code']] : $order_info['shipping_code'];
    $aikuaidi_key = 'xxxxxxx';

    $logistics_url = "http://www.aikuaidi.cn/rest/?key=$aikuaidi_key&order={$order_info['tracking_sn']}&id=$logistics_code&ord=asc&show=html";

    $logistics_info = file_get_contents($logistics_url);
    //var_dump($logistics_info);

    //$logistics_info = iconv('gb2312', 'UTF-8', $logistics_info);

    echo <<<EOF
        <span>收货人:<strong>{$order_info['consignee']}</strong></span>
        <span>联系电话:<strong>{$order_info['mobile']} // {$order_info['tel']}</strong></span>
        <span>配送:<strong>{$order_info['shipping_name']}</strong></span>
        <span>运单号:<strong>{$order_info['tracking_sn']}</strong></span><br><br>
EOF;
    echo $logistics_info;

    echo "<br><br><a href='$logistics_url' target='_self'>点我点我</a>";
    //exit;
}

关于如何在php项目中使用快递单号查询接口问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。

推荐阅读:
  1. 常用物流快递单号查询接口种类及对接方法
  2. 中通快递物流单号查询API接口免费对接案例

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php

上一篇:MySQL数据库怎么使用altertable语句来修改表结构

下一篇:MySQL数据库mysqlcheck的使用方法

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》