How to use JS to implement Base64 coding and MD5 encryption to complete express bird API interface call
This article mainly explains "how to use JS to achieve Base64 coding and MD5 encryption to complete express bird API interface call", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn "how to use JS to achieve Base64 coding and MD5 encryption to complete express bird API interface call"!
JS calls the API interface function GetAPI () {var key= "Express Bird API Key"; var id = "Express Bird Registration ID"; var requestData= "{'OrderCode':'','ShipperCode':'ZTO','LogisticCode':'78120038107849'}" / / MD5 encryption var md5str = md5 (requestData + key). ToLowerCase (); / / base64 var dataSign = Base64.encode (md5str); / / concatenate string (express bird request message format) url encoding 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" / / trigger before calling SubmitPost ({method: 'post', url:' / api/dist', data: reqData, beforeSend: function (xhr) {/ /) Such as loading effect, success: function (data, status) {if (status) {document.getElementById ("msg") [xss_clean] = "" For (var I = 0, len = data.Traces.length; I < len; itemstation) {var acceptTime = data.Tracs [I] .AcceptTime; var acceptStation = data.Traces [I] .AcceptStation / / the display effect of the page is developed by itself. Here, only the function document.getElementById ("msg") [xss_clean] + = acceptTime + "" + acceptStation+ "" is implemented. }}, error: function (data, status, e) {if (data.status = = "401") {alert (data.status); return });}