C#第三者全国速達物流インタフェース

4372 ワード

私はアリ雲の物流のインターフェースを使って、無料のインターフェースを申請することができます【全国の速達の物流】
製品を購入するとAppcodeでデバッグできます
//using System.IO;
//using System.Text;
//using System.Net;
//using System.Net.Security;
//using System.Security.Cryptography.X509Certificates;

        private const String host = "https://wuliu.market.alicloudapi.com";
        private const String path = "/kdi";
        private const String method = "GET";
        private const String appcode = "    AppCode";

        static void Main(string[] args)
        {
            String querys = "no=780098068058&type=zto";
            String bodys = "";
            String url = host + path;
            HttpWebRequest httpRequest = null;
            HttpWebResponse httpResponse = null;

            if (0 < querys.Length)
            {
                url = url + "?" + querys;
            }

            if (host.Contains("https://"))
            {
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
            }
            else
            {
                httpRequest = (HttpWebRequest)WebRequest.Create(url);
            }
            httpRequest.Method = method;
            httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
            if (0 < bodys.Length)
            {
                byte[] data = Encoding.UTF8.GetBytes(bodys);
                using (Stream stream = httpRequest.GetRequestStream())
                {
                    stream.Write(data, 0, data.Length);
                }
            }
            try
            {
                httpResponse = (HttpWebResponse)httpRequest.GetResponse();
            }
            catch (WebException ex)
            {
                httpResponse = (HttpWebResponse)ex.Response;
            }

            Console.WriteLine(httpResponse.StatusCode);
            Console.WriteLine(httpResponse.Method);
            Console.WriteLine(httpResponse.Headers);
            Stream st = httpResponse.GetResponseStream();
            StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
            Console.WriteLine(reader.ReadToEnd());
            Console.WriteLine("
"); } public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { return true; }

 
通常の戻り値の例
{
	"status": "0",
	"msg": "ok",
	"result": {
		"number": "780098068058",
		"type": "zto",
		"list": [{
			"time": "2018-03-09 11:59:26",
			"status": "【    】      【    】   ,   :   ,         ,        !"
		}, {
			"time": "2018-03-09 09:03:10",
			"status": "【    】       【    】(0311-85344265),       (13081105270)    1   ,        ,     "
		}, {
			"time": "2018-03-08 23:43:44",
			"status": "【    】      【   】    【    】"
		}, {
			"time": "2018-03-08 21:00:44",
			"status": "【    】      【   】"
		}, {
			"time": "2018-03-07 01:38:45",
			"status": "【   】      【    】    【   】"
		}, {
			"time": "2018-03-07 01:36:53",
			"status": "【   】      【    】"
		}, {
			"time": "2018-03-07 00:40:57",
			"status": "【   】      【    】    【     】"
		}, {
			"time": "2018-03-07 00:01:55",
			"status": "【   】 【    】(020-37738523)      (18998345739)    "
		}],
		"deliverystatus": "3",         /*  1.    2.     3.    4.      */
		"issign": "1",                  /*  1.      */
		"expName": "    ",
		"expSite": "www.zto.com",
		"expPhone": "95311"
	}
}

失敗した戻り例
{
	"status": "205",   /* status         */
	"msg": "    ",
	"result": ""
}

注意:C#では、クラスを追加して呼び出し、必要なものを返すことができます.
過去の宅配会社はその略記コードで、直接「韻達速達」のように行うと、失敗の例に戻りますので、注意してください.