常用快递API接口方案_第1页
常用快递API接口方案_第2页
常用快递API接口方案_第3页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、常用快递API接口方案电商企业从接收订单-配货-打印快递单到后期的快递员收件 -快递配送-轨迹查询-签收短信通知等,都需要快递接口的接入。整理目前较为常见的接口dem o如下:对接流程:快递鸟网站申请接口一对接一联调测试一上线预约取件-在线预约寄件importimportpublic class KdGoldAPIDemo return result;/* MD5 加密* param str 内容* param charset编码方式* throws Exceptio n*/SuppressWar nin gs(" unu sed")private String MD5(S

2、tring str, String charset) throws Exception MessageDigest md = ("MD5");(charset);byte result =();Strin gBuffer sb = new Strin gBuffer(32);for (int i = 0; i < ; i+) int val = resulti & 0xff;if (val <= 0xf) ("0");(val);retur n ().toLowerCase();* base64 编码* param str 内容* p

3、aram charset 编码方式* throws Un supportedE ncodi ngExcepti on*/private String base64(Stri ngstr, String charset) throwsUn supportedE ncodi ngExcepti onString en coded = (charset);retur n en coded;SuppressWar nin gs(" unu sed")private String urlE ncoder(Stri ngstr, String charset) throwsUn sup

4、portedE ncodi ngExcepti onString result = (str, charset);return result;/* 电商Sign签名生成* param content内容* param keyValue Appkey* param charset编码方式* throws Un supportedE ncodi ngExcepti on ,Excepti on* return DataSig n 签名*/SuppressWar nin gs(" unu sed")private String encrypt (String content. S

5、tring keyValue, String charset) throwsUn supportedE ncodi ngExcepti on, Excepti onif (keyValue != n ull)retur n base64(MD5(c ontent + keyValue, charset), charset);retur n base64(MD5(c ontent, charset), charset);/*向指定URL发送POST方法的请求* param url发送请求的URL* param params请求的参数集合* return远程资源的响应结果*/SuppressWar

6、 nin gs(" unu sed")private String sendPost(String url, Map<String, Stringparams) OutputStreamWriter out = n ull;BufferedReader in = n ull;Stri ngBuilder result = new Stri ngBuilder();try URL realUrl = new URL(url);HttpURLConnection conn =(HttpURLConnection)();return result;/* MD5 加密* pa

7、ram str 内容* param charset编码方式* throws Exceptio n*/SuppressWar nin gs(" unu sed")private String MD5(String str, String charset) throws Exception MessageDigest md = ("MD5");(charset);byte result =();Strin gBuffer sb = new Strin gBuffer(32);for (int i = 0; i < ; i+) int val = res

8、ulti & 0xff;if (val <= 0xf) ("0");(val);retur n ().toLowerCase();* base64 编码* param str 内容* param charset编码方式* throws Un supportedE ncodi ngExcepti on*/private Stringbase64(Stri ngstr, String charset) throwsUn supportedE ncodi ngExcepti onString en coded = (charset);retur n en coded

9、;SuppressWar nin gs(" unu sed")private String urlE ncoder(Stri ngstr, String charset) throwsUn supportedE ncodi ngExcepti onString result = (str, charset);return result;* 电商Sign签名生成* param content内容* param keyValue Appkey* param charset编码方式* throws Un supportedE ncodi ngExcepti on ,Excepti

10、 on* return DataSig n 签名*/SuppressWar nin gs(" unu sed")private String encrypt (Stringcontent, String keyValue, String charset) throwsUn supportedE ncodi ngExcepti on, Excepti onif (keyValue != n ull)retur n base64(MD5(c ontent + keyValue, charset), charset);retur n base64(MD5(c ontent, ch

11、arset), charset);向指定URL发送POST方法的请求* param url发送请求的 URL* param params请求的参数集合* return远程资源的响应结果*/SuppressWar nin gs(" unu sed")private String sendPost(String url, Map<String, Stringparams) OutputStreamWriter out = n ull;BufferedReader in = n ull;Stri ngBuilder result = new Stri ngBuilder()

12、;try URL realUrl = new URL(url);HttpURLConnection conn =(HttpURLConnection)();return result;/* MD5 加密* param str 内容* param charset 编码方式* throws Exceptio n*/SuppressWar nin gs(" unu sed")private String MD5(String str, String charset) throws Exception MessageDigest md = ("MD5");(ch

13、arset);byte result =();Strin gBuffer sb = new Strin gBuffer(32);for (int i = 0; i < ; i+) in t val = resulti & 0xff;if (val <= 0xf) ("0");(val);return ().toLowerCase();* base64 编码* param str 内容* param charset 编码方式* throws Un supportedE ncodi ngExcepti on*/private Stringbase64(Str

14、i ngstr, String charset) throwsUn supportedE ncodi ngExcepti onString en coded = base64E ncode(charset);retur n en coded;SuppressWar nin gs(" unu sed")private StringurlE ncoder(Stri ngstr, String charset) throwsUn supportedE ncodi ngExcepti onString result = (str, charset);return result;/*

15、 电商Sign签名生成* param content内容* param keyValue Appkey* param charset编码方式* throws Un supportedE ncodi ngExcepti on ,Excepti on* return DataSig n 签名*/SuppressWar nin gs(" unu sed")private String encrypt (Stringcontent, String keyValue, String charset) throwsUn supportedE ncodi ngExcepti on, Ex

16、cepti onif (keyValue != n ull)retur n base64(MD5(c ontent + keyValue, charset), charset);retur n base64(MD5(c ontent, charset), charset);向指定URL发送POST方法的请求* param url 发送请求的 URL* param params请求的参数集合* return远程资源的响应结果*/SuppressWar nin gs(" unu sed")private String sendPost(String url, Map<St

17、ring, Stringparams) OutputStreamWriter out = n ull;BufferedReader in = n ull;Stri ngBuilder result = new Stri ngBuilder();try URL realUrl = new URL(url);HttpURLConnection conn =(HttpURLConnection)();return result;/* MD5 加密* param str 内容* param charset编码方式* throws Exceptio n*/SuppressWar nin gs("

18、; unu sed")private String MD5(String str, String charset) throws Exception MessageDigest md = ("MD5");(charset);byte result =();Strin gBuffer sb = new Strin gBuffer(32);for (int i = 0; i < ; i+) in t val = resulti & 0xff;if (val <= 0xf) ("0");(val);return ().toLowe

19、rCase();* base64 编码* param str 内容* param charset 编码方式* throws Un supportedE ncodi ngExcepti on*/private Stringbase64(Stri ngstr, String charset) throwsUn supportedE ncodi ngExcepti onString en coded = base64E ncode(charset);retur n en coded;SuppressWar nin gs(" unu sed")private StringurlE

20、ncoder(Stri ngstr, String charset) throwsUn supportedE ncodi ngExcepti onString result = (str, charset);return result;/*电商Sign签名生成* param content内容* param keyValue Appkey* param charset编码方式* throws Un supportedE ncodi ngExcepti on ,Excepti on* return DataSig n 签名*/SuppressWar nin gs(" unu sed&q

21、uot;)private String encrypt (Stringcontent, String keyValue, String charset) throwsUn supportedE ncodi ngExcepti on, Excepti onif (keyValue != n ull)retur n base64(MD5(c ontent + keyValue, charset), charset);retur n base64(MD5(c ontent, charset), charset);向指定URL发送POST方法的请求* param url发送请求的 URL* param

22、 params请求的参数集合* return远程资源的响应结果*/SuppressWar nin gs(" unu sed")private String sendPost(String url, Map<String, Stringparams) OutputStreamWriter out = n ull;BufferedReader in = n ull;StringBuilder result = new StringBuilder();try URL realUrl = new URL(url);HttpURLConnection conn =(HttpUR

23、LConnection)();/发送POST请求必须设置如下两行(true);(true);/ POST方法("POST");/设置通用的请求属性("accept", "*/*");("connection", "Keep-Alive");("user-age nt","Mozilla/ (compatible; MSIE ; Win dows NT ;SV1)"); ("C on te nt-Type", "applicat

24、io n/x-www-form-urle ncoded"); ();/获取URLConnection对象对应的输出流out = new OutputStreamWriter(), "UTF-8");/发送请求参数if (params != nu II) Strin gBuilder param = new Strin gBuilder();for <Stri ng, Stri ng> entry : () if()>0)("&");();();":"+();"param:"+()

25、;();/ flush输出流的缓冲();/定义BufferedReader 输入流来读取 URL的响应in = new BufferedReader(new InputStreamReader(), "UTF-8");String line;while (li ne = () != n ull) (li ne); catch (Exceptio n e) ();/ 使用fin ally块来关闭输出流、输入流fin allytryif(out!=n ull)();if(in!=n ull)();catch(IOExcepti on ex)();return ();privat

26、e static char base64E ncodeChars = new char 'A', 'B', C, 'D', 'E', 'F', 'G', 'H',T, 'J', 'K', 'L', 'M', 'N', 'O', 'P','Q', 'R', 'S', 'T', 'U', '

27、V', W, 'X','Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f,'g', 'h', 'i', 'j', 'k', T, 'm', 'n','o', 'p', 'q', 'r', 's', 't', 'u', 'v','w', 'x', 'y', 'z', '0', &

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论