微信物流查询

来源:互联网 发布:pkpm绿色建筑设计软件 编辑:程序博客网 时间:2024/05/17 06:28

获取物流公司传过来的JASON信息并解析

前台代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Expresscheck.aspx.cs" Inherits="WebApplication4.express.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head"  runat="server">
<title>订单跟踪系统</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<%--<Link href='../css/form.css' type=text/css rel=stylesheet>--%>
<Link href='../css/newform.css?v=201606131150' type=text/css rel=stylesheet>
<%--<Link href='../css/STYLE2017.css?v=201606131149' type=text/css rel=stylesheet>--%>
<%--<LINK href="../css/button.css" type=text/css rel=stylesheet>--%>
<LINK href="../css/bottom.css" type=text/css rel=stylesheet>
<meta name="viewport" content="width=device-width">
<meta name="viewport" content="target- densitydpi =device-dpi, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">


 <style>
   body{font-size: 15px;}
   ul li{list-style: none;}
   .track-rcol{width: 900px; border: 1px solid #eee;}
   .track-list{margin: 20px; padding-left: 5px; position: relative;}
   .track-list li{position: relative; padding: 9px 0 0 25px; line-height: 18px; border-left: 1px solid #d9d9d9; color: #999;}
   .track-list li.first{color: red; padding-top: 0; border-left-color: #fff;}
   .track-list li .node-icon{position: absolute; left: -6px; top: 50%; width: 11px; height: 11px; background: url(../images/order-icons.png)  -21px -72px no-repeat;}
   .track-list li.first .node-icon{background-position:0 -72px;}
   .track-list li .time{margin-right: 15px; position: relative; top: 4px; display: inline-block; vertical-align: middle;}
   .track-list li .txt{max-width: 600px; position: relative; top: 4px; display: inline-block; vertical-align: middle;}
   .track-list li.first .time{margin-right: 20px; }
   .track-list li.first .txt{max-width: 600px; }

  </style>
 </head>
 <body>

  <%-- <table width="100%" height="52" background="../images/126.gif" >
 <tr>
   <td width="160" height="52" valign="middle"><div>
       <img src="../images/mcquay-logo-b.png" width="100" height="30"></div></td>
    <td>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">   
          <tr>
    <td width="60%" height="25" align="left" valign="top" ><b style="font-size: medium">订单跟踪系统</b></td>
          </tr>  
  </table>
       </td>
    </table>  --%>
     <table border="0" cellpadding="0" cellspacing="0" style="width: 100%; " align="center">
     <tr><td align="center" class="title" colspan="2"  style=" font-size:20px" >物流查询</td></tr>
     </table>
    
       
   <%--<div id="wrapper">
     <div class="content">
     <table border="0" cellpadding="0" cellspacing="0"
             style="width: 100%; " align="center">
     <tr><td align="center" class="titleCN" colspan="2" style="color: White" >订单物流查询</td></tr>
     <<%--tr Height="40px">
      <td align="center" style="border:none"  Width="25%" Height="40px" >
        <asp:ImageButton ID="singer" runat="server" Height="40px"  Width="40px"  
              ToolTip="singer"  ImageUrl="../images/A2.png" 
              onclick="ButtonExpress_Click" BorderStyle="None" /></td>
      <td align="center" style="border:none"   Width="25%" Height="40px">
        <asp:ImageButton ID="double" runat="server" Height="40px"  Width="40px"  
              ToolTip="double"  ImageUrl="../images/A2.png" 
              onclick="ButtonExpress_Click" BorderStyle="None" /></td>
     </tr> 
    <tr  Height="8px" style="padding-top:0px">
      <td align="center" style="border:none; font-size:8px; color:White" Width="25%">单个查询</td>
      <td align="center" style="border:none; font-size:8px; color:White" Width="25%">批量查询</td>
    </tr>-
     </table>
    </DIV>
     </DIV>--%>
     <form id="form" runat="server"> 
     <div>
    <table border=0 align="center" width="350px">
       <tr align="center" style="border:0px"; >     
       <td height="40px" width="260px" style="padding-left:20px">
        <asp:TextBox ID="ExpressNo" runat="server"   value="输入发货单号"  style="Font-Size:15px; color:#AAAAAA"
        OnClick="this.value= '';this.style.color='#000000'" Width="260px" Height="29px"/></td>
       <%-- <td align="center" class="BUTTON" style="width: 50px;border-top:0px; border-right:0px; border-bottom:0px;;border-left:0px"> --%>
        <%--<asp:Button ID="ButtonExpress" runat="server"  Font-Size="Medium"  Text="搜索" Height="30px" Width="60px"  BorderStyle="None"    CssClass="BUTTON" onclick="ButtonExpress_Click" ></asp:Button>--%>
        <td align="center" style="border:none"  Width="40px" >
        <asp:ImageButton ID="ButtonExpress" runat="server" Height="40px"  Width="40px"  
                ToolTip="搜索"  ImageUrl="../images/serchbig_001.png" 
                onclick="ButtonExpress_Click" BorderStyle="None" /></td>
        </tr>      
      </table>
      <br />
     </div>
 <%if (num != 0){ %>
     <div class="track-rcol">
   <div class="track-list">
    <ul>
     <li class="first">
                     <i class="node-icon"></i>
         <span class="txt"><%=strmeno[0]%></span>                      
                   </li>
                   <li class="first">
                     <i></i>              
                     <span class="time"><%=strtime[0]%></span>
                   </li>
                   <% for (int i = 1; i < num; i++) {   %>                 
     <li>
      <i class="node-icon"></i>
      <span class="txt"><%=strmeno[i]%></span>
     </li>
                    <li>
      <i ></i>  
                        <span class="time"><%=strtime[i]%></span>
     </li>
                  <%} %> 
     
    
    </ul>
   </div>
  </div>
    <%} %> 
     <%-- <table border=0 align="center" width="100%">
   <tr>
   <td align="left" class="title_home"> <asp:Button ID="ButtonExpress" runat="server"   CssClass="serch"
             onclick="ButtonExpress_Click"  Text="查询"  ></asp:Button></td>
   </tr>
  </table>   --%>
  
     </form>
        <div class="nav">
            <ul>
                <li>
                    <a  href="../home.aspx"><span></span><span style="font-size:18px">首页</span></a>
                </li>
                <li style="position:relative;">
                  <%--  <a href="../QRcode/QR.aspx"><span></span><span style="font-size:18px">二维码扫一扫</span></a>--%>
                  <a href="#"><span></span><span style="font-size:18px">关于我们</span></a>

                </li>
                <li>             
                    <a href="../QRcode/zchabom.aspx?_r="><span></span><span style="font-size:18px">上一页</span></a>
                </li>
              
            </ul>
        </div>
     </body>
</html>

后台代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
//using System.Web.Script.Serialization;    //导入解析Json的类 
using System.Collections;
using System.Data.SqlClient;
using System.Data;

namespace WebApplication4.express
{
    public partial class WebForm1 : System.Web.UI.Page
    {
   
        public string[] strtime = null;//存放时间
        public string[] strmeno = null;//存放轨迹
        public int num = 0;//存放数量

        protected void Page_Load(object sender, EventArgs e)
        {
           // branch = Session["branch"].ToString();
            num = 0;
        }

        protected void ButtonExpress_Click(object sender, ImageClickEventArgs e)
        {

       

            string ordernum = ExpressNo.Text.ToString();//发货单号
        //    string pars = "param={" + "\"cust_code\"" + ":" + "服务部\"" + "," + "\"pk_corp\"" + ":" + "\"WHCD\"" + "," + "\"cust_orderno\"" + ":" + "\"" + ordernum + "\"" + "}";        
        //    byte[] data = System.Text.Encoding.UTF8.GetBytes(pars);
        //    string getdata = System.Text.Encoding.UTF8.GetString(data);
        //    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://xxxxx8091/tms-webapp/public/httpEdi/weChat/searchOrders.json?uid=public&pwd=YcmysX23eieEG77qv/kjRIsP" + "&" + getdata);
        //    request.Method = "GET";
        //    request.ContentType = "text/html;charset=UTF-8";
        //    HttpWebResponse myResponse = (HttpWebResponse)request.GetResponse();
        //    Stream myResponseStream = myResponse.GetResponseStream();
        //    StreamReader reader = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
        //    string content = reader.ReadToEnd();
        //    reader.Close();
        //    myResponseStream.Close();
        //    //Response.Write(content);
        //    string JSON = content;
        //    JavaScriptSerializer serializer = new JavaScriptSerializer();
        //    Dictionary<string, object> json = (Dictionary<string, object>)serializer.DeserializeObject(JSON);
        //    object[] info = (object[])json["datas"];
        //    Dictionary<string, object> val1;
        //    Dictionary<int, string> Objs = null;
        //    Dictionary<int, string> fileOldName = null;
        //    Session["bigfile_datas"] = null;
        //    Session["file_name"] = null;

           ArrayList time_list = new ArrayList(); //add by wendy
           ArrayList meno_list = new ArrayList(); //add by wendy
        //    for (int i = 0; i < info.Length; i++)
        //    {

        //        val1 = (Dictionary<string, object>)info[i];

        //        foreach (KeyValuePair<string, object> str in val1)
        //        {
        //            //保存信息到 session 

        //            if (Session["bigfile_datas"] == null)
        //            {
        //                Objs = new Dictionary<int, string>();
        //                Session["bigfile_datas"] = Objs;  //地点
        //            }

        //            if (Session["file_name"] == null)
        //            {
        //                fileOldName = new Dictionary<int, string>();
        //                Session["file_name"] = fileOldName; //时间
        //            }


        //            if (str.Key.Equals("tracking_memo"))
        //            {

        //                Objs[i + 1] = str.Value.ToString();//地点

        //            }

        //            if (str.Key.Equals("tracking_time"))
        //            {

        //                fileOldName[i + 1] = str.Value.ToString();//时间

        //            }

        //        }

        //    }
        //    Session["bigfile_datas"] = Objs;
        //    Session["file_name"] = fileOldName;

        //    if (Session["bigfile_datas"] != null)
        //    {
        //        Objs = (Dictionary<int, string>)Session["bigfile_datas"];
        //        foreach (int i in Objs.Keys)
        //        {
                        
        //            meno_list.Add(Objs[i].ToString());
        //            strmeno = (string[])meno_list.ToArray(typeof(string));
        //        }
        //    }
        //    if (Session["file_name"] != null)
        //    {
        //        Objs = (Dictionary<int, string>)Session["file_name"];
             
        //        foreach (int i in fileOldName.Keys)
        //        {
                
        //            time_list.Add(fileOldName[i].ToString());
        //            strtime = (string[])time_list.ToArray(typeof(string));
                 
        //        }
        //        num = time_list.Count;
        //    }

            SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
            string strSQL = "";
            strSQL = "select*  from EXPRESS where cust_orderno  = '" + ordernum + "' order by tracking_time desc";
            SqlDataAdapter myCommand = new SqlDataAdapter(strSQL, conn);
            DataSet ds = new DataSet();
            myCommand.Fill(ds);
            DataTable dt = ds.Tables[0];
            for (int k= 0; k < dt.Rows.Count; k++)
            {

                time_list.Add(dt.Rows[k][3].ToString());
                strtime = (string[])time_list.ToArray(typeof(string));
                meno_list.Add(dt.Rows[k][4].ToString());
                strmeno = (string[])meno_list.ToArray(typeof(string));

            }
            num = time_list.Count;
        }


    }
}