Exemplo n.º 1
0
        private void btnSrch_Click(object sender, EventArgs e)
        {
            if (comKd.SelectedIndex < 0)
            {
                MessageBox.Show("请选择快递公司!");
                return;
            }
            if (edtKdh.Text == "")
            {
                MessageBox.Show("请输入快递单号!");
                return;
            }
            ComboxItem item   = comKd.SelectedItem as ComboxItem;
            ApiUtils   apiGet = new ApiUtils();
            object     obj    = null;

            if (apiGet.ApiData_Get(PubApi.ApiTypeEnum.ApiExpressInfo, out obj, item.Value, edtKdh.Text))
            {
                if (obj != null)
                {
                    apiDataObject.ExpressInfoObj dataInfo = obj as apiDataObject.ExpressInfoObj;
                    if (dataInfo.status != "200")
                    {
                        MessageBox.Show("查询失败!");
                        return;
                    }
                    else
                    {
                        string sNr = string.Empty;
                        for (int i = 0; i < dataInfo.data.Count; i++)
                        {
                            sNr += dataInfo.data[i].time + "\r\n";
                            sNr += dataInfo.data[i].context + "\r\n";
                            sNr += "------------------------------------------------------------------------\r\n";
                        }
                        memoNr.Text = sNr;
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 快递查询接口
        /// </summary>
        /// <param name="expressType">快递公司代号</param>
        /// <param name="expressNo">快递单号</param>
        /// <param name="ObjInfo">返回数据</param>
        /// <returns></returns>
        public bool ApiData_GetExpressInfo(string expressType, string expressNo, out object ObjInfo)
        {
            ObjInfo = null;
            try
            {
                string    url      = "http://www.kuaidi100.com/query?type=" + expressType + "&postid=" + expressNo;
                WebClient client   = new WebClient();
                var       buffer   = client.DownloadData(url);
                string    jsonText = Encoding.UTF8.GetString(buffer);

                string str = string.Empty;
                apiDataObject.ExpressInfoObj expressInfos = JsonConvert.DeserializeObject <apiDataObject.ExpressInfoObj>(jsonText);
                if (expressInfos != null)
                {
                    ObjInfo = expressInfos;
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                return(false);
            }
            return(true);
        }