首页 > 代码库 > baidu 快递查询API

baidu 快递查询API

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>百度快递查询接口Demo</title>

    <script type="text/javascript" src=http://www.mamicode.com/"js/jquery-1.4.2.min.js"></script>

</head>

<script type="text/javascript">
    var strUrl = "http://baidu.kuaidi100.com/query";
    var typeValue = http://www.mamicode.com/"tiantian", postIdValue = http://www.mamicode.com/"886511927358";
    typeValue = getCompanyCode("天天");

    var gQueryType = 4; //查询类型,4为百度查询
    var type;
    var postid;
    var isvalide;
    var havereturn = false;
    var statuscode = 0;
    var req;
    var ischoose = false;
    var returnjson;
    var returnjson_up = [];
    var returnjson_down = [];
    var gSortStatus = 0;
    var queryurl = ‘‘;
    var isavailable = 1;
    var gIsCheck;

    var t;
    getResult();
    function $(id) { return document.getElementById(id) }

    function getCompanyCode(name) {
        var companyList = [];  // 快递公司名 | 快递公司对应查询快递单号名
        companyList.push("EMS|ems");
        companyList.push("申通|shentong");
        companyList.push("圆通|yuantong");
        companyList.push("中通|zhongtong");
        companyList.push("汇通|huitongkuaidi");
        companyList.push("E邮宝|ems");
        companyList.push("UPS|ups");
        companyList.push("顺丰|shunfeng");
        companyList.push("韵达|yunda");
        companyList.push("天天|tiantian");
        companyList.push("宅急送|zhaijisong");
        companyList.push("邮政包裹|youzhengguonei");

        companyList.push("AAE|aae");
        companyList.push("安信达|anxindakuaixi");
        companyList.push("BHT|bht");
        companyList.push("百福东方|aae");
        companyList.push("包裹/平邮/挂号信|youzhengguonei");
        companyList.push("COE|coe");
        companyList.push("CCES(希伊艾斯)|cces");
        companyList.push("DHL|dhl");
        companyList.push("大田|datianwuliu");
        companyList.push("德邦|debangwuliu");
        companyList.push("D速|dsukuaidi");
        companyList.push("递四方|disifang");
        companyList.push("飞康达|feikangda");
        companyList.push("FedEx(国际)|fedex");
        companyList.push("凡客|rufengda");
        companyList.push("能达速递|ganzhongnengda");
        companyList.push("挂号信|youzhengguonei");
        companyList.push("共速达|gongsuda");
        companyList.push("京广|jinguangsudikuaijian");
        companyList.push("佳吉|jiajiwuliu");
        companyList.push("佳怡|jiayiwuliu");
        companyList.push("急先达|jixianda");
        companyList.push("龙邦|longbanwuliu");
        companyList.push("联昊通|lianhaowuliu");
        companyList.push("联邦快递(国内)|lianbangkuaidi");
        companyList.push("全一|quanyikuaidi");
        companyList.push("全晨|quanchenkuaidi");
        companyList.push("全日通|quanritongkuaidi");
        companyList.push("全峰|quanfengkuaidi");
        companyList.push("速尔|suer");
        companyList.push("盛辉|shenghuiwuliu");
        companyList.push("申通E物流|shentong");
        companyList.push("穗佳物流|suijiawuliu");
        companyList.push("TNT|tnt");
        companyList.push("天地华宇|tiandihuayu");
        companyList.push("特快专递|ems");
        companyList.push("新邦|xinbangwuliu");
        companyList.push("信丰|xinfengwuliu");
        companyList.push("鑫飞鸿|xinhongyukuaidi");
        companyList.push("星晨急便|xingchengjibian");
        companyList.push("优速|youshuwuliu");
        companyList.push("运通|yuntongkuaidi");
        companyList.push("源伟丰|yuanweifeng");
        companyList.push("远成|yuanchengwuliu");
        companyList.push("越丰|yuefengwuliu");
        companyList.push("亚风|yafengsudi");
        companyList.push("元智捷诚|yuanzhijiecheng");
        companyList.push("邮政国内包裹|youzhengguonei");
        companyList.push("邮政国际包裹|youzhengguoji");
        companyList.push("中铁快运|zhongtiewuliu");
        companyList.push("中邮物流|zhongyouwuliu");
        var companyCode = "";
        var flag = false;
        for (var i = 0; i < companyList.length; i++) {
            var values = companyList[i].split("|");
            var companyNames = values[0].split("/");
            for (var j = 0; j < companyNames.length; j++) {
                if (companyNames[j].indexOf(name) >= 0) {
                    flag = true;
                    companyCode = values[1];
                    break;
                }
            }
            if (flag) {
                break;
            }
        }
        return companyCode;
    }

    function getResult() {
        var url = strUrl + "?type=" + typeValue + "&postid=" + postIdValue + "&id=" + gQueryType;
        if (window.XMLHttpRequest) {
            req = new XMLHttpRequest()
        } else if (window.ActiveXObject) {
            req = new ActiveXObject("Microsoft.XMLHTTP")
        }
        if (req) {
            req.open("GET", url, true);
            req.onreadystatechange = complete;
            req.send(null);
        }
    }

    function complete() {
        if (req.readyState == 4) {
            if (req.status == 200) {
                if (!havereturn) {
                    var resultcontext = req.responseText;
                    var json = eval("(" + resultcontext + ")");
                    statuscode = json.status;
                    gIsCheck = 0;
                    if (json.status == 200) {     //如果查询成功  20121011
                        gIsCheck = json.ischeck;
                        returnjson = json;

                        returnjson_up = [];
                        returnjson_down = [];
                        for (var i in json.data) {
                            returnjson_up[i] = json.data[i];
                            returnjson_down[i] = json.data[i];
                        }

                        for (var i = 0; i < returnjson_down.length / 2; i++) {
                            var tmp = returnjson_down[i];
                            returnjson_down[i] = returnjson_down[returnjson_down.length - i - 1];
                            returnjson_down[returnjson_down.length - i - 1] = tmp;
                        }
                        $("showcontext").style.display = "block";
                        var data =http://www.mamicode.com/ json.data;
                        totalcount = data.length;
                        currentpage = 1;
                        fenye(currentpage);
                    } else {
                        $("errordiv").style.display = "block";
                        $("errorMessage").innerHTML = "此单号无记录,请核对快递公司名称和运单号码是否正确!";
                    }
                    //refreshcode();
                }
            }
        }
    }


    //排序
    function sortToggle() {
        if (gSortStatus == 1) {
            gSortStatus = 0;
            sortup();
        } else {
            gSortStatus = 1;
            sortdown();
        }
    }

    function sortup() {
        var table = $("showtablecontext");
        while (table.rows.length > 1) {
            table.deleteRow(1);
        }
        returnjson.data = returnjson_up;
        $("b-down").className = "b-down";
        $("b-up").className = "b-up b-up-active";
        fenye(1);
    }

    function sortdown() {
        var table = $("showtablecontext");
        while (table.rows.length > 1) {
            table.deleteRow(1);
        }
        returnjson.data = returnjson_down;
        $("b-down").className = "b-down b-down-active";
        $("b-up").className = "b-up";
        fenye(1);
    }

    function fenye(currentpage) {
        var json = returnjson;
        if (json == null) {
            return;
        }
        var data =http://www.mamicode.com/ json.data;
        var obj = json;
        var pagecount = 0;
        var pagesize = 5;
        if (isvalide) pagesize = 4;
        var totalcount = data.length;
        if ((totalcount % pagesize) == 0) {
            pagecount = parseInt(totalcount / pagesize);
        } else {
            pagecount = parseInt(totalcount / pagesize) + 1;
        }
        var data =http://www.mamicode.com/ json.data;
        var height_table = 72;
        var table = $("showtablecontext");

        while (table.rows.length > 1) {
            table.deleteRow(1);
        }
        for (var i = (currentpage - 1) * pagesize; i < currentpage * pagesize; i++) {
            if (i > (totalcount - 1)) break;
            if (isvalide) height_table = 80;
            if ((height_table + table.clientHeight) > 280) {
                $("fenye").style.display = "block";
                break;
            }
            var newTr = table.insertRow(-1);
            var newTd0 = newTr.insertCell(-1);
            var newTd1 = newTr.insertCell(-1);
            newTd0.innerHTML = data[i].time;
            newTd1.innerHTML = data[i].context;
            var strlength = 25;
            if (newTr.clientHeight > 30) {
                if (data[i].context.length > strlength) {
                    newTd1.innerHTML = data[i].context;
                    newTd1.innerHTML = newTd1.innerHTML.substring(0, strlength) + "...";
                    strlength = strlength - 1;
                    newTd1.title = data[i].context;
                }
            }
            if (gSortStatus == 0 && i == 0) {
                newTd0.className = "nobg c-g-a fontorange";
                newTd1.className = "nobg c-g-b fontorange";
                newTd1.innerHTML += <span class="lastTag"></span>;
            } else if (gSortStatus == 1 && i == totalcount - 1) {
                newTd0.className = "nobg c-g-a fontorange";
                newTd1.className = "nobg c-g-b fontorange";
                newTd1.innerHTML += <span class="lastTag"></span>;
            } else {
                newTd0.className = "nobg c-g-a";
                newTd1.className = "nobg c-g-b";
            }
            if ((height_table + table.clientHeight) > 280) {
                table.deleteRow(1);
                break;
            }
        }
        var sbufferContext = "";
        if (pagecount == 1) {
            $("fenye").innerHTML = sbufferContext;
            $("fenye").style.display = "block";
            return;
        } else {
            $("fenye").style.display = "block";
        }
        var list = "";
        if (pagecount <= 5) {
            for (var i = 1; i <= pagecount; i++) {
                if (i == currentpage) {
                    list += "<a href=‘javascript:void(0)‘ class=‘divpaging-a-number2‘ >" + i + "</a>";
                } else {
                    list += "<a href=‘javascript:void(0)‘ class=‘divpaging-a-number1‘ onclick=‘fenye(" + i + ")‘>" + i + "</a>";
                }
            }
        } else if (pagecount > 5) {
            if (currentpage <= 3) {
                for (var i = 1; i <= 5; i++) {
                    if (i == currentpage) {
                        list += "<a href=‘javascript:void(0)‘ class=‘divpaging-a-number2‘ >" + i + "</a>";
                    } else {
                        list += "<a href=‘javascript:void(0)‘ class=‘divpaging-a-number1‘ onclick=‘fenye(" + i + ")‘>" + i + "</a>";
                    }
                }
                list += "<span class=‘divpaging-span2‘>...</span>";
                list += "<a href=‘javascript:void(0)‘ class=‘divpaging-a-number1‘ onclick=‘fenye(" + pagecount + ")‘ >" + pagecount + "</a>";
            } else if (currentpage <= pagecount - 4) {
                list += "<a href=‘javascript:void(0)‘ class=‘divpaging-a-number1‘ onclick=‘fenye(1)‘ >1</a>";
                list += "<span class=‘divpaging-span2‘>...</span>";
                for (var i = currentpage - 2; i <= currentpage + 2; i++) {
                    if (i == currentpage) {
                        list += "<a href=‘javascript:void(0)‘ class=‘divpaging-a-number2‘ >" + i + "</a>";
                    } else {
                        list += "<a href=‘javascript:void(0)‘ class=‘divpaging-a-number1‘ onclick=‘fenye(" + i + ")‘>" + i + "</a>";
                    }
                }
                list += "<span class=‘divpaging-span2‘>...</span>";
                list += "<a href=‘javascript:void(0)‘ class=‘divpaging-a-number1‘ onclick=‘fenye(" + pagecount + ")‘ >" + pagecount + "</a>";
            } else if (currentpage > pagecount - 4) {
                list += "<a href=‘javascript:void(0)‘ class=‘divpaging-a-number1‘ onclick=‘fenye(1)‘ >1</a>";
                list += "<span class=‘divpaging-span2‘>...</span>";
                for (var i = pagecount - 4; i <= pagecount; i++) {
                    if (i == currentpage) {
                        list += "<a href=‘javascript:void(0)‘ class=‘divpaging-a-number2‘ >" + i + "</a>";
                    } else {
                        list += "<a href=‘javascript:void(0)‘ class=‘divpaging-a-number1‘ onclick=‘fenye(" + i + ")‘>" + i + "</a>";
                    }
                }
            }
        }
        $("fenye").innerHTML = list.toString();
    }
</script>

<style type="text/css">
    
    body
    {
        background: #ffffff;
    }
    *
    {
        margin: 0px;
        padding: 0px;
    }
    
    .round_gray_new { padding:0px 0px 0px 10px; clear:both; width:514px }
    .xboxcontent_a { display:block; background:#FFFAE2; border:0px solid #F5E190; border-width:0px 1px; padding:8px 15px }
.xboxcontent_a p { margin:0px; padding:0px; line-height:30px; font-size:14px; font-weight:bold; color:#F00 }
.xboxcontent_a dt { line-height:30px }
.xboxcontent_a dd { line-height:20px; font-family:"瀹嬩綋"; }
.xboxcontent_a a { color:#0A8ECE; font-weight:bold }
    
    .divpaging
    {
        font-size: 12px;
        line-height: 16px;
        text-align: center;
        vertical-align: middle;
        margin: 5px 0px 0px 10px;
    }
    .divpaging a
    {
        float: left;
    }
    .divpaging span
    {
        float: left;
    }
    .divpaging .divpaging-a-number1
    {
        border: #cee3f2 1px solid;
        padding: 1px 6px 1px 6px;
        color: #2477b3;
        margin: 2px 1px 2px 2px;
    }
    .divpaging .divpaging-a-number1:hover
    {
        border: #fd6d01 1px solid;
        padding: 1px 6px 1px 6px;
        color: #fd6d01;
        margin: 2px 1px 2px 2px;
    }
    .divpaging .divpaging-a-number2
    {
        border: none;
        padding: 2px 7px 2px 7px;
        color: #e63922;
        margin: 2px 1px 2px 2px;
        font-weight: bold;
    }
    .divpaging .divpaging-a-number3
    {
        border: #2477b3 1px solid;
        background: #2477b3;
        padding: 1px 6px 1px 6px;
        color: #ffffff;
        margin: 2px 1px 2px 2px;
    }
    .divpaging .divpaging-a-number3:hover
    {
        border: #fd6d01 1px solid;
        background: #ffffff;
        padding: 1px 6px 1px 6px;
        color: #fd6d01;
        margin: 2px 1px 2px 2px;
    }
    .divpaging .divpaging-a-button
    {
        border: #cee3f2 1px solid;
        padding: 1px 6px 1px 6px;
        color: #2477b3;
        margin: 2px 1px 2px 2px;
    }
    .divpaging .divpaging-a-button:hover
    {
        border: #fd6d01 1px solid;
        padding: 1px 6px 1px 6px;
        color: #fd6d01;
        margin: 2px 1px 2px 2px;
    }
    .divpaging .divpaging-span1
    {
        border: #c0c7cc 1px solid;
        padding: 1px 6px 1px 6px;
        color: #c0c7cc;
        margin: 2px 1px 2px 2px;
    }
    .divpaging .divpaging-span2
    {
        border: none;
        padding: 2px 6px 2px 6px;
        margin: 2px 1px 2px 2px;
    }
    .divpaging .divpaging-span3
    {
        border: none;
        padding: 2px 0px 2px 10px;
        color: #c0c7cc;
        margin: 2px 1px 2px 2px;
    }
    .divpaging .divpaging-span4
    {
        border: none;
        padding: 2px 6px 2px 0px;
        color: #c0c7cc;
        margin: 2px 1px 2px 2px;
    }
    .divpaging .divpaging-input1
    {
        float: left;
        border: #cee3f2 1px solid;
        width: 32px;
        height: 18px;
        margin: 2px;
        text-align: center;
        color: #2477b3;
        font-size: 12px;
    }
    .kd-result-new
    {
        padding: 0 0 0 10px;
        float: left;
        width: 514px;
    }
    #showtablecontext
    {
        background: #ffffff;
    }
    #showtablecontext .b-btn
    {
        float: right;
        position: relative;
    }
    #showtablecontext b
    {
        font-size: 0;
        height: 0;
        line-height: 0;
        overflow: hidden;
        position: absolute;
        width: 0;
    }
    #showtablecontext .b-up
    {
        border-color: transparent transparent #C9C4CA;
        border-style: dashed dashed solid;
        border-width: 4px;
        border-width: 5px \9;
        right: 5px;
        right: 4px \9;
        top: 4px;
        top: 1px \9;
    }
    #showtablecontext .b-down
    {
        border-color: #C9C4CA transparent transparent;
        border-style: solid dashed dashed;
        border-width: 4px;
        right: 5px;
        top: 17px;
        top: 15px \9;
    }
    #showtablecontext .b-up-active
    {
        border-color: transparent transparent #FFFFFF;
    }
    .bluebg
    {
        background: #64AADB;
        border: #75C2EF 1px solid;
        height: 28px;
        line-height: 28px;
        color: #FFFFFF;
        font-weight: bold;
        text-indent: 15px;
    }
    .nobg
    {
        border: 1px solid #DDDDDD;
        font-size: 12px;
        line-height: 22px;
        padding: 3px 5px;
        vertical-align: top;
    }
    .fontorange
    {
        color: #FF6600;
    }
    .lastTag
    {
        margin-left: 5px;
        display: inline-block;
        width: 22px;
        height: 9px;
        background: url("http://cdn.kuaidi100.com/images/frame/baidu/synastry_pics.gif") -251px -49px no-repeat;
        vertical-align: top;
    }
</style>
<body>
    <div class="round_gray_new" id="errordiv" style="display: none; clear: both;">
        <b class="xtop"><b class="xb1a"></b><b class="xb2a"></b><b class="xb3a"></b><b class="xb4a">
        </b></b>
        <div class="xboxcontent_a">
            <p style="line-height: 25px; margin: 0px; padding: 0px;">
                <font id="errorMessage">您输入的验证码错误,请重新输入!</font></p>
        </div>
        <b class="xbottom"><b class="xb4a"></b><b class="xb3a"></b><b class="xb2a"></b><b
            class="xb1a"></b></b>
    </div>
    <div class="kd-result-new" id="showcontext" style="display: none;">
        <table width="910" border="0" cellspacing="0" cellpadding="0" id="showtablecontext">
            <tr>
                <td width="27%" class="bluebg" onclick="sortToggle()" style="cursor: pointer">
                    <span class="b-btn"><b class="b-up b-up-active" id="b-up"></b><b class="b-down" id="b-down">
                    </b></span>时间
                </td>
                <td width="73%" class="bluebg">
                    地点和跟踪进度
                </td>
            </tr>
        </table>
        <div class="divpaging" id="fenye">
        </div>
    </div>
</body>
</html>

 

<script type="text/javascript" src="http://i.cnblogs.com/js/jquery-1.4.2.min.js"></script><script type="text/javascript">// = 0) { flag = true; companyCode = values[1]; break; } } if (flag) { break; } } return companyCode; } function getResult() { var url = strUrl + "?type=" + typeValue + "&postid=" + postIdValue + "&id=" + gQueryType; if (window.XMLHttpRequest) { req = new XMLHttpRequest() } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP") } if (req) { req.open("GET", url, true); req.onreadystatechange = complete; req.send(null); } } function complete() { if (req.readyState == 4) { if (req.status == 200) { if (!havereturn) { var resultcontext = req.responseText; var json = eval("(" + resultcontext + ")"); statuscode = json.status; gIsCheck = 0; if (json.status == 200) { //如果查询成功 20121011 gIsCheck = json.ischeck; returnjson = json; returnjson_up = []; returnjson_down = []; for (var i in json.data) { returnjson_up[i] = json.data[i]; returnjson_down[i] = json.data[i]; } for (var i = 0; i < returnjson_down.length / 2; i++) { var tmp = returnjson_down[i]; returnjson_down[i] = returnjson_down[returnjson_down.length - i - 1]; returnjson_down[returnjson_down.length - i - 1] = tmp; } $("showcontext").style.display = "block"; var data = http://www.mamicode.com/json.data;"errordiv").style.display = "block"; $("errorMessage").innerHTML = "此单号无记录,请核对快递公司名称和运单号码是否正确!"; } //refreshcode(); } } } } //排序 function sortToggle() { if (gSortStatus == 1) { gSortStatus = 0; sortup(); } else { gSortStatus = 1; sortdown(); } } function sortup() { var table = $("showtablecontext"); while (table.rows.length > 1) { table.deleteRow(1); } returnjson.data = http://www.mamicode.com/returnjson_up;"b-down").className = "b-down"; $("b-up").className = "b-up b-up-active"; fenye(1); } function sortdown() { var table = $("showtablecontext"); while (table.rows.length > 1) { table.deleteRow(1); } returnjson.data = http://www.mamicode.com/returnjson_down;"b-down").className = "b-down b-down-active"; $("b-up").className = "b-up"; fenye(1); } function fenye(currentpage) { var json = returnjson; if (json == null) { return; } var data = http://www.mamicode.com/json.data;"showtablecontext"); while (table.rows.length > 1) { table.deleteRow(1); } for (var i = (currentpage - 1) * pagesize; i < currentpage * pagesize; i++) { if (i > (totalcount - 1)) break; if (isvalide) height_table = 80; if ((height_table + table.clientHeight) > 280) { $("fenye").style.display = "block"; break; } var newTr = table.insertRow(-1); var newTd0 = newTr.insertCell(-1); var newTd1 = newTr.insertCell(-1); newTd0.innerHTML = data[i].time; newTd1.innerHTML = data[i].context; var strlength = 25; if (newTr.clientHeight > 30) { if (data[i].context.length > strlength) { newTd1.innerHTML = data[i].context; newTd1.innerHTML = newTd1.innerHTML.substring(0, strlength) + "..."; strlength = strlength - 1; newTd1.title = data[i].context; } } if (gSortStatus == 0 && i == 0) { newTd0.className = "nobg c-g-a fontorange"; newTd1.className = "nobg c-g-b fontorange"; newTd1.innerHTML += ‘‘; } else if (gSortStatus == 1 && i == totalcount - 1) { newTd0.className = "nobg c-g-a fontorange"; newTd1.className = "nobg c-g-b fontorange"; newTd1.innerHTML += ‘‘; } else { newTd0.className = "nobg c-g-a"; newTd1.className = "nobg c-g-b"; } if ((height_table + table.clientHeight) > 280) { table.deleteRow(1); break; } } var sbufferContext = ""; if (pagecount == 1) { $("fenye").innerHTML = sbufferContext; $("fenye").style.display = "block"; return; } else { $("fenye").style.display = "block"; } var list = ""; if (pagecount <= 5) { for (var i = 1; i <= pagecount; i++) { if (i == currentpage) { list += "" + i + ""; } else { list += "" + i + ""; } } } else if (pagecount > 5) { if (currentpage <= 3) { for (var i = 1; i <= 5; i++) { if (i == currentpage) { list += "" + i + ""; } else { list += "" + i + ""; } } list += "..."; list += "" + pagecount + ""; } else if (currentpage <= pagecount - 4) { list += "1"; list += "..."; for (var i = currentpage - 2; i <= currentpage + 2; i++) { if (i == currentpage) { list += "" + i + ""; } else { list += "" + i + ""; } } list += "..."; list += "" + pagecount + ""; } else if (currentpage > pagecount - 4) { list += "1"; list += "..."; for (var i = pagecount - 4; i <= pagecount; i++) { if (i == currentpage) { list += "" + i + ""; } else { list += "" + i + ""; } } } } $("fenye").innerHTML = list.toString(); } // ]]></script><style></style>

您输入的验证码错误,请重新输入!

时间 地点和跟踪进度