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

How to implement the signature of Express Bird API Interface in C #

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the relevant knowledge of "how to achieve express bird API interface signature in C#". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Code implementation of method call / / E-commerce IDstring eEBusinessID = "test1617571"; / / E-commerce encryption private key, provided by express bird, take care to keep it, do not disclose string appKey= "554343b2-7252-439b-b4eb-1af42c8f2175"; / / request urlstring reqURL = "http://sandboxapi.kdniao.com:8080/kdniaosandbox/gateway/exterfaceInvoke.json";// request instruction string reqType=" 1002 "; / / 2-json string dataType =" 2 " / / character encoding is UTF-8 string charset = "UTF-8"; / / JSON string jsonStr = "{\" OrderCode\ ":\"\ ",\" ShipperCode\ ":\" SF\ ",\" LogisticCode\ ":\" 118461988807\ "}"; / / MD5 (jsonStr+APIKey) to encrypt string md5Str=MD5 (jsonStr+ apiKey, charset); / / Base64 encode md5Str to string base64Str=base64 (md5Str,charset) / / URL encoding (utf-8) string datasign = HttpUtility.UrlEncode (base64Str, charset); / / request message parameter string postStr = "RequestType=reqType&EBusinessID= eEBusinessID&RequestData=jsonStr & DataSign= datasign&DataType=dataType"; / / Communication protocol uses Http protocol Post request method to return track data string post = SendPost (reqURL, postStr) / / the post data obtained is the complete message returned by the express bird. Then you can write a method to parse the json and get the field information in it. C # encapsulated method / string MD5 encryption / Encoding / ciphertext private string MD5 (string str, string charset) {byte [] buffer = System.Text.Encoding.GetEncoding (charset) .GetBytes (str); try {System.Security.Cryptography.MD5CryptoServiceProvider check Check = new System.Security.Cryptography.MD5CryptoServiceProvider (); byte [] somme = check.ComputeHash (buffer); string ret = ""; foreach (byte an in somme) {if (a < 16) ret + = "0" + a.ToString ("X") Else ret + = a.ToString ("X");} return ret.ToLower ();} catch {throw } / base64 Encoding / content / Encoding method / private string base64 (String str, String charset) {return Convert.ToBase64String (System.Text.Encoding.GetEncoding (charset) .GetBytes (str)) } / Post method to submit data, return the source code of the web page / request message parameters / the response result of the remote resource private string SendPost (string url, string postData) {string result = "; byte [] byteData = Encoding.GetEncoding (" UTF-8 ") .GetBytes (postData.ToString ()) Try {HttpWebRequest request = (HttpWebRequest) WebRequest.Create (url); request.ContentType = "application/x-www-form-urlencoded"; request.Referer = url; request.Accept = "* / *"; request.Timeout = 30 * 1000; request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) .net CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) "; request.Method =" POST "; request.ContentLength = byteData.Length; Stream stream = request.GetRequestStream (); stream.Write (byteData, 0, byteData.Length); stream.Flush (); stream.Close () HttpWebResponse response = (HttpWebResponse) request.GetResponse (); Stream backStream = response.GetResponseStream (); StreamReader sr = new StreamReader (backStream, Encoding.GetEncoding ("UTF-8")); result = sr.ReadToEnd (); sr.Close (); backStream.Close (); response.Close (); request.Abort () } catch (Exception ex) {result = ex.ToString ();} return result;} "how to implement express bird API interface signature in C#" is introduced here. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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