日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

怎樣用手機(jī)號(hào)查快遞信息 怎樣用手機(jī)號(hào)查快遞


怎樣用手機(jī)號(hào)查快遞信息 怎樣用手機(jī)號(hào)查快遞


【怎樣用手機(jī)號(hào)查快遞信息 怎樣用手機(jī)號(hào)查快遞】一、目的做這個(gè)項(xiàng)目的初衷是因?yàn)槲胰ツ暝谖⑿刨u老家水果 , 好多朋友下單后都問我快遞單號(hào),每天發(fā)貨后我都要挨個(gè)甄別這個(gè)人是哪個(gè)快遞信息,很麻煩一部小心就搞錯(cuò)了 ?;谶@件小事我有了自助快遞查詢的這個(gè)想法 。將發(fā)貨的快遞信息導(dǎo)入到我的系統(tǒng)里,用戶訪問我的系統(tǒng),通過輸入手機(jī)號(hào)就可以查看自己的快遞物流信息 。項(xiàng)目是去年8月寫的,一直擱淺在哪,最近無意間翻看我發(fā)的那篇文章自助快遞單號(hào)查詢閱讀量竟然都1.8w了,有圖有真相 。
怎樣用手機(jī)號(hào)查快遞信息 怎樣用手機(jī)號(hào)查快遞


這著實(shí)讓我很震驚 , 看來自助快遞查詢這塊確實(shí)是個(gè)熱點(diǎn) 。今天我就講一下我手?jǐn)]的快遞查詢系統(tǒng) 。
二、開發(fā)項(xiàng)目地址:github.com/hellowHuaai… 有興趣的可以直接下載源碼 , 覺得項(xiàng)目不錯(cuò)的伙伴記得點(diǎn)個(gè)star,謝謝啦!
2.1技術(shù)棧項(xiàng)目涉及到的技術(shù)棧有:
  • SpringBoot: 一款 Java 微服務(wù)框架 。Spring boot 是 Spring 家族中的一個(gè)新框架,它用來簡化 Spring 應(yīng)用程序的創(chuàng)建和開發(fā) 。
  • Mybitas: 一款ORM框架,即對(duì)象關(guān)系映射 。ORM框架的作用是把持久化對(duì)象的保存、修改、刪除等操作,轉(zhuǎn)換成對(duì)數(shù)據(jù)庫的操作 。
  • Jquery:一個(gè)輕量級(jí)的寫的少 , 做的多的 JavaScript 函數(shù)庫 。
  • Bootstrap:Bootstrap 是一個(gè)用于快速開發(fā) Web 應(yīng)用程序和網(wǎng)站的前端框架 。Bootstrap 是基于 HTML、CSS、JAVASCRIPT 的 。
2.2后端開發(fā)創(chuàng)建entity 創(chuàng)建快遞單實(shí)體類,屬性包括id,用戶名(userName),電話(phone),快遞單號(hào)(kuaidiNo),快遞公司(company),數(shù)據(jù)創(chuàng)建時(shí)間(createTime) 。代碼如下:
@Data@Builderpublic class KuaiDi {private Integer id;/* 收件人姓名 */private String userName;/**收件人電話*/private String phone;/* 快遞單號(hào)*/private String kuaidiNo;/*快遞公司名稱(拼音)*/private String company;/*訂單創(chuàng)建時(shí)間*/private Date createTime;public KuaiDi(Integer id, String userName, String phone, String kuaidiNo, String company, Date createTime) {this.id = id;this.userName = userName;this.phone = phone;this.kuaidiNo = kuaidiNo;this.company = company;this.createTime = createTime;}public KuaiDi(Integer id, String userName, String phone, String kuaidiNo, String company) {this.id = id;this.userName = userName;this.phone = phone;this.kuaidiNo = kuaidiNo;this.company = company;}}service,mapper是常規(guī)的增刪查改操作,就是保存快遞的基本信息在數(shù)據(jù)庫中,并可以對(duì)數(shù)據(jù)進(jìn)行簡單的維護(hù)功能 。詳細(xì)可參考項(xiàng)目源碼 。接下來看核心代碼 。
查詢快遞信息 快遞的基本信息存入數(shù)據(jù)庫,然后就是通過這些信息查詢快遞的詳細(xì)物流信息 。這里我做過很多嘗試,想直接調(diào)用一些快遞公司的快遞信息查詢接口,但是都發(fā)現(xiàn)接口都有session,當(dāng)session失效后就無法查詢到數(shù)據(jù)或者就查詢到的數(shù)據(jù)不正確 。最終在網(wǎng)上找到一種付費(fèi)的方案,使用快遞100接口 。www.kuaidi100.com/ 查詢快遞的demo代碼如下:
public class SynQueryDemo { /*** 實(shí)時(shí)查詢請(qǐng)求地址*/ private static final String SYNQUERY_URL = "http://poll.kuaidi100.com/poll/query.do";private String key;//授權(quán)key private String customer; //實(shí)時(shí)查詢公司編號(hào) public SynQueryDemo(String key, String customer) {this.key = key;this.customer = customer; }/*** 實(shí)時(shí)查詢快遞單號(hào)* @param com快遞公司編碼* @param num快遞單號(hào)* @param phone手機(jī)號(hào)* @param from出發(fā)地城市* @param to目的地城市* @param resultv2開通區(qū)域解析功能:0-關(guān)閉;1-開通* @return*/ public String synQueryData(String com, String num, String phone, String from, String to, int resultv2) {StringBuilder param = new StringBuilder("{");param.append(""com":"").append(com).append(""");param.append(","num":"").append(num).append(""");param.append(","phone":"").append(phone).append(""");param.append(","from":"").append(from).append(""");param.append(","to":"").append(to).append(""");if(1 == resultv2) {param.append(","resultv2":1");} else {param.append(","resultv2":0");}param.append("}");Map<String, String> params = new HashMap<String, String>();params.put("customer", this.customer);String sign = MD5Utils.encode(param + this.key + this.customer);params.put("sign", sign);params.put("param", param.toString());return this.post(params); }/*** 發(fā)送post請(qǐng)求*/ public String post(Map<String, String> params) {StringBuffer response = new StringBuffer("");BufferedReader reader = null;try {StringBuilder builder = new StringBuilder();for (Map.Entry<String, String> param : params.entrySet()) {if (builder.length() > 0) {builder.append('&');}builder.append(URLEncoder.encode(param.getKey(), "UTF-8"));builder.append('=');builder.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));}byte[] bytes = builder.toString().getBytes("UTF-8");URL url = new URL(SYNQUERY_URL);HttpURLConnection conn = (HttpURLConnection) url.openConnection();conn.setConnectTimeout(3000);conn.setReadTimeout(3000);conn.setRequestMethod("POST");conn.setRequestProperty("accept", "*/*");conn.setRequestProperty("connection", "Keep-Alive");conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");conn.setRequestProperty("Content-Length", String.valueOf(bytes.length));conn.setDoOutput(true);conn.getOutputStream().write(bytes);reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));String line = "";while ((line = reader.readLine()) != null) {response.append(line);}} catch (Exception e) {e.printStackTrace();} finally {try {if (null != reader) {reader.close();}} catch (IOException e) {e.printStackTrace();}}return response.toString(); }}

推薦閱讀