Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of calling and docking of api Interface for Identification and query of Express Logistics order number

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you the express logistics order number identification query api interface call docking example analysis, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

Get the source address for free:

Https://github.com/lzy2626/LogisticsInfoTest

Interface for "Instant query":

Both RequestData and DataSign are signed data. The other three are written in a fixed way.

Express Bird api realizes real-time logistics query

1. First of all, there must be an express bird account, according to the requirements of the other side, improve the user application.

two。 Activate services according to your own needs

3. Go to "my API interface", understand the design requirements according to the development documentation in "interface", download the official demo, and edit the code that suits you.

[instant query] Code implementation

1. By modifying the official demo code, I have separated a delivery class here to improve its applicability

two。 Introduce class files, instantiate and test

Demo request data:

Package com.zs.app; import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.io.UnsupportedEncodingException;import java.net.HttpURLConnection;import java.net.URL;import java.net.URLEncoder;import java.security.MessageDigest;import java.util.HashMap;import java.util.Map / * * Express Bird Logistics track Instant query Interface * * @ Technical QQ Group: 456320272 * @ see: http://www.kdniao.com/YundanChaxunAPI.aspx * @ copyright: Shenzhen Express data Technology Service Co., Ltd. * the e-commerce ID and private key in Shenzhen Express data Technology Service Co., Ltd. can only be used for testing. In the formal environment, please register a separate account * more than 500 single queries per day. It is recommended to access our logistics track subscription push interface * * ID and Key. Please go to the official website to apply: http://www.kdniao.com/ServiceApply.aspx * / public class KdniaoTrackQueryAPI {/ / DEMO public static void main (String [] args) {KdniaoTrackQueryAPI api = new KdniaoTrackQueryAPI () Try {String result = api.getOrderTracesByJson ("ANE", "210001633605"); System.out.print (result);} catch (Exception e) {e.printStackTrace ();}} / / E-commerce ID private String EBusinessID= "1330422" / / encrypted private key for e-commerce, provided by express bird, be careful to keep it, do not disclose private String AppKey= "7611818b-6279-4398-8747-df2ca39e86b4"; / / request url private String ReqURL= "http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx";" / * Json query order logistics track * @ throws Exception * / public String getOrderTracesByJson (String expCode, String expNo) throws Exception {String requestData= "{'OrderCode':'','ShipperCode':'" + expCode + "', 'LogisticCode':'" + expNo + "'}"; Map params = new HashMap (); params.put ("RequestData", urlEncoder (requestData, "UTF-8")) Params.put ("EBusinessID", EBusinessID); params.put ("RequestType", "1002"); String dataSign=encrypt (requestData, AppKey, "UTF-8"); params.put ("DataSign", urlEncoder (dataSign, "UTF-8"); params.put ("DataType", "2"); String result=sendPost (ReqURL, params) / / the information returned according to the company's business processing. Return result;} / * MD5 encryption * @ param str content * @ param charset Encoding * @ throws Exception * / @ SuppressWarnings ("unused") private String MD5 (String str, String charset) throws Exception {MessageDigest md = MessageDigest.getInstance ("MD5"); md.update (str.getBytes (charset)); byte [] result = md.digest () StringBuffer sb = new StringBuffer (32); for (int I = 0; I

< result.length; i++) { int val = result[i] & 0xff; if (val 0){ param.append("&"); } param.append(entry.getKey()); param.append("="); param.append(entry.getValue()); //System.out.println(entry.getKey()+":"+entry.getValue()); } //System.out.println("param:"+param.toString()); out.write(param.toString()); } // flush输出流的缓冲 out.flush(); // 定义BufferedReader输入流来读取URL的响应 in = new BufferedReader( new InputStreamReader(conn.getInputStream(), "UTF-8")); String line; while ((line = in.readLine()) != null) { result.append(line); } } catch (Exception e) { e.printStackTrace(); } //使用finally块来关闭输出流、输入流 finally{ try{ if(out!=null){ out.close(); } if(in!=null){ in.close(); } } catch(IOException ex){ ex.printStackTrace(); } } return result.toString(); } private static char[] base64EncodeChars = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' }; public static String base64Encode(byte[] data) { StringBuffer sb = new StringBuffer(); int len = data.length; int i = 0; int b1, b2, b3; while (i < len) { b1 = data[i++] & 0xff; if (i == len) { sb.append(base64EncodeChars[b1 >

> > 2]); sb.append (base64EncodeChars [(b1 & 0x3) > > 2]); sb.append (base64EncodeChars [(b1 & 0x03) > 4)]); sb.append (base64EncodeChars [(b2 & 0x0f) > > 2]); sb.append (base64EncodeChars [(b1 & 0x03) > > 4)]; sb.append (base64EncodeChars [(b2 & 0x0f) > > 6)]) Sb.append (Base64EncodeChars [b3 & 0x3f]);} return sb.toString ();}} above are all the contents of the article "Express Logistics order number Identification query api Interface call docking example Analysis". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report