qyhack 发表于 2015-11-9 09:24:38

利用kuaidi100实现快递查询源码

本帖最后由 qyhack 于 2015-11-9 09:26 编辑

利用kuaidi100实现快递查询源码

感谢佐佑 大神提供的协议包
http://bbs.msdn5.com/thread-384-1-1.html

代码写得比较渣,望各位同仁指正



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

namespace ExpressCheck
{
    public partial class Form1 : Form
    {
      private SynchronizationContext Context;
      public Form1()
      {
            InitializeComponent();
            Context = SynchronizationContext.Current;

      }

      private void button1_Click(object sender, EventArgs e)
      {
            new System.Threading.Thread(QueryExpress).Start(textBox1.Text);
      }

      private void QueryExpress(object obj)
      {
            try
            {
                HttpCodeLib.Wininet w = new HttpCodeLib.Wininet();
                string retCode = w.GetData(string.Format("http://www.kuaidi100.com/autonumber/auto?num={0}", obj));
                List<ExpressType> typeList = JsonConvert.DeserializeObject<List<ExpressType>>(retCode);
                ExpressInfo info;
                foreach (ExpressType item in typeList)
                {
                  retCode = w.GetUtf8(string.Format("http://www.kuaidi100.com/query?type={0}&postid={1}", item.ComCode, obj));
                  info = JsonConvert.DeserializeObject<ExpressInfo>(retCode);
                  if (info != null && info.Status == "200")
                  {
                        OnLog("当前订单查询成功:");
                        foreach (Datum tmp in info.Data)
                        {
                            OnLog("【" + tmp.Time + "】 " + tmp.Context);
                        }
                        break;
                  }
                }
            }
            catch (Exception ex)
            {
                OnLog(ex.Message);
            }
      }

      private void OnLog(string log)
      {
            Context.Send(o =>
            {
                textBox2.Text += log + "\r\n";
            }, null);
      }
    }

    public class ExpressType
    {
      
      public string ComCode { get; set; }

      
      public string Id { get; set; }

      
      public int NoCount { get; set; }

      
      public string NoPre { get; set; }

      
      public string StartTime { get; set; }
    }

    public class ExpressInfo
    {
      
      public string Nu { get; set; }

      
      public string Message { get; set; }

      
      public string Ischeck { get; set; }

      
      public string Com { get; set; }

      
      public string Updatetime { get; set; }

      
      public string Status { get; set; }

      
      public string Condition { get; set; }

      
      public Datum[] Data { get; set; }

      
      public string State { get; set; }
    }

    public class Datum
    {
      
      public string Time { get; set; }

      
      public string Context { get; set; }

      
      public string Ftime { get; set; }
    }
}




milest 发表于 2015-11-9 09:54:11

支持开源,谢谢分享!!!

somk 发表于 2015-11-9 13:24:10

支持你的新作!!

whoamixx 发表于 2015-11-9 15:35:31

感谢分享

SmartN2015 发表于 2015-11-10 15:00:18

不错 学习一下

jgsh 发表于 2015-11-10 16:48:44

好东西~~~~~

954624 发表于 2015-11-10 19:46:18

支持开源,谢谢分享!!!

独来读网 发表于 2015-11-11 09:56:25

不错,学习一下。

ppszxc 发表于 2015-11-15 16:46:23

来下载看看效果

fendou 发表于 2015-11-15 23:19:16

太感谢了
页: [1] 2 3 4 5
查看完整版本: 利用kuaidi100实现快递查询源码