您好,登錄后才能下訂單哦!
本篇內容主要講解“怎么用JS實現Base64編碼和MD5加密完成快遞鳥API接口調用”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“怎么用JS實現Base64編碼和MD5加密完成快遞鳥API接口調用”吧!
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>JS調用快遞鳥API接口</title> <meta charset="utf-8" /> <script src="/base64.js"></script> <script src="/md5.js"></script> <script src="/jquery.json-2.2.min.js"></script> <script src="/common.js"></script> <script type="text/javascript"> function GetAPI() { var key="快遞鳥API Key"; var id = "快遞鳥注冊ID號"; var requestData="{'OrderCode':'','ShipperCode':'ZTO','LogisticCode':'78120038107849'}"; //MD5加密 var md5str = md5(requestData + key).toLowerCase(); //base64 var dataSign = Base64.encode(md5str); //拼接字符串(快遞鳥請求報文格式)url編碼 var reqData = "RequestData=" + escape(requestData) + "&EBusinessID=" + id + "&RequestType=1002&DataSign=" + escape(dataSign) + "&DataType=2"; //reqData = "RequestData=%7b%27OrderCode%27%3a%27%27%2c%27ShipperCode%27%3a%27ZTO%27%2c%27LogisticCode%27%3a%2778120038107849%27%7d&EBusinessID=1264783&RequestType=1002&DataSign=NzMxNTAzZWYxYTJiOGIyMDhiNTVjMTc4MDQ0NjdlZDg%3d&DataType=2"; //調用 SubmitPost({ method: 'post', url: '/api/dist', data: reqData, beforeSend: function (xhr) { //調用前觸發,如加載效果等 }, success: function (data, status) { if (status) { document.getElementById("msg").innerHTML = ""; for (var i = 0, len = data.Traces.length; i < len; i++) { var acceptTime = data.Traces[i].AcceptTime; var acceptStation = data.Traces[i].AcceptStation; //頁面展示效果自己開發,這里只實現功能 document.getElementById("msg").innerHTML += acceptTime + " " + acceptStation+"<br/>"; } } }, error: function (data, status, e) { if (data.status == "401") { alert(data.status); return; } } }); } </script></head><body> <input id="Button1" onclick="GetAPI();" type="button" value="JS調用快遞鳥API接口" /> <div id="msg"></div></body></html>
注意:
<script src="/base64.js"></script>
<script src="/md5.js"></script>
<script src="/jquery.json-2.2.min.js"></script>
這3個js文件引用,網上都能下載到,都是通用的js。
到此,相信大家對“怎么用JS實現Base64編碼和MD5加密完成快遞鳥API接口調用”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。