免费物流轨迹查询 对接接口

物流轨迹查询 对接接口

功能说明
物流轨迹查询-使用的物流单号和快递单号即可实现查询物流信息。
接口规则
(1)、查询接口支持按照运单号查询(单个查询,并发不超过10个/S)。
(2)、指定的物流运单号选择相应的快递公司编码,格式不对或则编码错误都会返失败的信息。如EMS物流单号应选择快递公司编码(EMS)
(3)、返回的物流跟踪信息按照发生的时间升序排列。
(4)、接口指令1002。
(5)、请求地址:http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx
(6)、接口秘钥申请:快递鸟官网

  **这是一个winfrom查询物流轨迹的demo**

免费物流轨迹查询 对接接口_第1张图片
免费物流轨迹查询 对接接口_第2张图片

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using Newtonsoft.Json;
using System.Threading;
using KdGoldAPI;

namespace 快递查询
{
    public partial class Form1 : Form
    {
        Hashtable table;      
        StringBuilder sb;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //KdApiSearchDemo demo = new KdApiSearchDemo();
            //demo.getOrderTracesByJson();
            table = new Hashtable();
            sb = new StringBuilder();
                 
            table.Add("顺丰速运", "SF");
            table.Add("百世快递", "HTKY");
            table.Add("中通快递", "ZTO");
            table.Add("申通快递", "STO");
            table.Add("圆通速递", "YTO");
            table.Add("韵达速递", "YD");
            table.Add("邮政快递包裹", "YZPY");
            table.Add("EMS", "EMS");
            table.Add("天天快递", "HHTT");
            table.Add("京东快递", "JD");
            table.Add("优速快递", "UC");
            table.Add("德邦快递", "DBL");
            table.Add("宅急送", "ZJS");

        }     
        private void button1_Click(object sender, EventArgs e)
        {
            KdApiSearchDemo demo = new KdApiSearchDemo();
            Dictionary<string, string> keyValuePairs = demo.getOrderTracesByJson(table[comboBox1.Text].ToString(), textBox1.Text);
            
            if (textBox1.Text != "" && comboBox1.Text != "") {
                string temp = this.Text;
                 this.Text = "查询中...";
                string result = Http.get("http://sandboxapi.kdniao.com:8080/kdniaosandbox/gateway/exterfaceInvoke.json?RequestData=" + keyValuePairs["RequestData"] + "&EBusinessID="+ keyValuePairs["EBusinessID"] + "&RequestType=1002&DataSign="+ keyValuePairs["DataSign"] + "&DataType=2");
                //result == null 代表网络异常
             
                if (result == null) {
                    MessageBox.Show("网络异常", "提示");
                    this.Text = temp;
                    return;
                }
                //将Json数据反序列化
                JsonParser jp = (JsonParser)JsonConvert.DeserializeObject<JsonParser>(result);
                List<Traces> list = jp.Traces;
                list = jp.Traces;
                sb.Remove(0,sb.Length);
                //jp.message != ""代表查询失败
                if (jp.Reason != ""&& jp.Reason!=null)
                {
                    MessageBox.Show(jp.Reason, "提示");
                    this.Text = temp;
                    return;
                }
                foreach(Traces data in list){
                    sb.Append(data.AcceptTime + "\t");
                    sb.Append(data.AcceptStation + "\r\n\r\n");
                }
                textBox2.Text = sb.ToString();
                this.Text = temp ;
            }else{
                MessageBox.Show("快递单号和快递公司都不能为空", "提示");
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
namespace 快递查询
{
    class Http
    {
        public static string get(string url)
        {
            string result=null;
            Stream stream;
            StreamReader reader=null;
            WebClient clinet = new WebClient();
            try
            {
                //Encoding enc = Encoding.GetEncoding("UTF-8");
                //Byte[] pageData = clinet.DownloadData(url);
                //result = enc.GetString(pageData);

                stream = clinet.OpenRead(url);
                reader = new StreamReader(stream, Encoding.UTF8);
                result = reader.ReadToEnd();
            }
             catch(Exception ex)
            {
                
            }
            finally {
                try
                {
                    reader.Close();
                }
                catch { }
            }
            return result;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json; 

namespace 快递查询
{
   public class JsonParser
    {
       public int State;
        //public int errCode;
        //public string message;
        //public string html;
        //public int mailTo;
        //public string tel;
        //public string expTextName;
        //public List data;
        public string EBusinessID;
        public string ShipperCode;
        public string LogisticCode;
        public string Reason;
        public List<Traces> Traces;
    }
    public class Traces
    {
       public string AcceptTime;
       public string AcceptStation;
       public string Remark;
    }
}

KdApiSearchDemo可以去官网下载

你可能感兴趣的:(对接接口)