项目需求,在unity中内置查询物流信息的功能
需要用到查询物流 的API
在这选择的是快递100的API
首先需要申请快递100的API,官方会给你一个KEY,使用该KEY,就可以进行物流查询了
using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using System.Text; using System.Net; using System.IO; public class Http { public static string get(string url) { string result = null; Stream stream; StreamReader reader = null; WebClient clinet = new WebClient(); try { stream = clinet.OpenRead(url); reader = new StreamReader(stream, Encoding.Default); result = reader.ReadToEnd(); } catch { } finally { try { reader.Close(); } catch { } } return result; } }
using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using System.Linq; using System.Text; using Newtonsoft.Json; public class JsonParser { public int stattus; public int errCode; public string message; public string html; public int mailto; public string tel; public string expTextName; public List<Data> data; } public class Data { public string time; public string context; }
using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Text; using UnityEngine.UI; using Newtonsoft.Json; public class LookTest : MonoBehaviour { public InputField input; public Dropdown dropdown; public Text text; Hashtable table; string url = "http://api.ickd.cn/?id=key";//id就是你申请的KEY StringBuilder sb; // Use this for initialization void Start() { Load(); } // Update is called once per frame void Update() { } public void Load() { table = new Hashtable(); sb = new StringBuilder(); //88个快递公司 table.Add("0", "aae");//AAE快递 table.Add("1", "anjie");//安捷快递 table.Add("2", "anxinda");//安信达快递 table.Add("3", "aramex");//Aramex国际快递 table.Add("4", "cces");//CCES快递 table.Add("5", "changtong");//长通物流 table.Add("6", "chengguang");//程光快递 table.Add("7", "chuanxi");//传喜快递 table.Add("8", "chuanzhi");//传志快递 table.Add("9", "citylink");//CityLinkExpress table.Add("10", "coe");//东方快递 table.Add("11", "cszx");//城市之星 table.Add("12", "datian");//大田物流 table.Add("13", "debang");//德邦物流 table.Add("14", "dhl");//DHL快递 table.Add("15", "disifang");//递四方速递 table.Add("16", "dpex");//DPEX快递 table.Add("17", "dsu");//D速快递 table.Add("18", "ees");//百福东方物流 table.Add("19", "fedex");//国际Fedex table.Add("20", "fedexcn");//Fedex国内 table.Add("21", "feibang");//飞邦物流 table.Add("22", "feibao");//飞豹快递 table.Add("23", "feihang");//原飞航物流 table.Add("24", "feiyuan");//飞远物流 table.Add("25", "fengda");//丰达快递 table.Add("26", "fkd");//飞康达快递 table.Add("27", "fkdex");//飞快达快递 table.Add("28", "gdyz");//广东邮政物流 table.Add("29", "gongsuda");//共速达物流|快递 table.Add("30", "guotong");//国通快递 table.Add("31", "huayu");//天地华宇物流 table.Add("32", "huitong");//汇通快递 table.Add("33", "jiaji");//佳吉快运 table.Add("34", "jiayi");//佳怡物流 table.Add("35", "jiayunmei");//加运美快递 table.Add("36", "jingguang");//京广快递 table.Add("37", "jinyue");//晋越快递 table.Add("38", "jldt");//嘉里大通物流 table.Add("39", "kuaijie");//快捷快递 table.Add("40", "lanbiao");//蓝镖快递 table.Add("41", "lejiedi");//乐捷递快递 table.Add("42", "lianhaotong");//联昊通快递 table.Add("43", "longbang");//龙邦快递 table.Add("44", "minhang");//民航快递 table.Add("45", "nengda");//港中能达快递 table.Add("46", "ocs");//OCS快递 table.Add("47", "pinganda");//平安达 table.Add("48", "quanchen");//全晨快递 table.Add("49", "quanfeng");//全峰快递 table.Add("50", "quanjitong");//全际通快递 table.Add("51", "quanritong");//全日通快递 table.Add("52", "quanyi");//全一快递 table.Add("53", "rpx");//RPX保时达 table.Add("54", "rufeng");//如风达快递 table.Add("55", "santai");//三态速递 table.Add("56", "scs");//伟邦(SCS)快递 table.Add("57", "shengfeng");//盛丰物流 table.Add("58", "shenghui");//盛辉物流 table.Add("59", "shentong");//申通快递 table.Add("60", "sure");//速尔快递 table.Add("61", "tiantian");//天天快递 table.Add("62", "tnt");//TNT快递 table.Add("63", "tongcheng");//通成物流 table.Add("64", "ups");//UPS table.Add("65", "usps");//USPS快递 table.Add("66", "wanjia");//万家物流 table.Add("67", "xinbang");//新邦物流 table.Add("68", "xinfeng");//信丰快递 table.Add("69", "yad");//源安达快递 table.Add("70", "yafeng");//亚风快递 table.Add("71", "yibang");//一邦快递 table.Add("72", "yinjie");//银捷快递 table.Add("73", "yousu");//优速快递 table.Add("74", "ytfh");//北京一统飞鸿快递 table.Add("75", "yuancheng");//远成物流 table.Add("76", "yuantong");//圆通快递 table.Add("77", "yuanzhi");//元智捷诚 table.Add("78", "yuefeng");//越丰快递 table.Add("79", "yunda");//韵达快递 table.Add("80", "yuntong");//运通中港快递 table.Add("81", "ywfex");//源伟丰 table.Add("82", "zhaijisong");//宅急送快递 table.Add("83", "zhongtie");//中铁快运 table.Add("84", "zhongtong");//中通快递 table.Add("85", "zhongxinda");//忠信达快递 table.Add("86", "zhongyou");//中邮物流 table.Add("87", "ems");//EMS快递 table.Add("88", "shunfeng");//顺丰快递 } public void Click() { if (input.text != "") { string result = Http.get(url + "&nu=" + input.text + "&com=" + table[dropdown.value.ToString()].ToString()); if (result == null) { Debug.Log("网络异常"); return; } JsonParser jp = (JsonParser)JsonConvert.DeserializeObject<JsonParser>(result); List<Data> list = jp.data; list = jp.data; sb.Remove(0, sb.Length); if (jp.message != "") { Debug.Log("提示"); return; } foreach (Data data in list) { sb.Append(data.time + " "); sb.Append(data.context + " "); } Debug.Log(sb.ToString()); text.text = sb.ToString(); } else { Debug.Log("快递单号和快递公司都不能为空"); text.text = "快递单号和快递公司都不能为空"; } } }
提供了80多家快递公司,国内外常用的都涵盖了
写出来一是和大家分享,二是方便自己查询使用