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 use the API interface of C#

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

Share

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

This article mainly introduces "how to use the API interface of C#". In the daily operation, I believe that many people have doubts about how to use the API interface of C#. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use the API interface of C#". Next, please follow the editor to study!

1. Complete the preparatory work

1.1, go to the official website of express bird to sign up for an account for free.

1.2, get an apiKey for free (API permission verification is required)

1.3, complete the real name verification process

1.4, order a free package

2.API interface

2.1.Test call address: http://sandboxapi.kdniao.com:8080/kdniaosandbox/gateway/exterfaceInvoke.json

2.2.2.The official calling address: http://api.kdniao.com/api/dist

2.3The request method: POST

2.4.Encoding format (utf-8): application/x-www-form-urlencoded;charset=utf-8

2.5. Return type: JSON

2.6.Debug page: http://kdniao.com/UserCenter/v2/SandBox/TrackQuery.aspx

2.7, debugging tools: to debug (log in using the express bird account)

3. Request parameter (Headers) parameter name type description must require RequestDataString request content to be URL (utf-8) encoded. The request content must be in JSON format, which must be consistent with DataType. REBusinessIDString merchant ID, please check it on my service page. RRequestTypeString request instruction type: 2002RDataSignString data content signature: (request content (unencoded) + AppKey) is encrypted by MD5, then encoded by Base64, and finally encoded by URL (utf-8). For more information, please see Demo. RDataTypeString request, return data type: only support JSON format R parameter name type description whether LogisticCodeString logistics order number R5. Return parameter (Return) parameter name type description must require EBusinessIDString e-commerce user IDRLogisticCodeString logistics order number RSuccessBool success or RCodeInt failure reason OShipperShipperCodeString express company code OShipperNameString express company name O6. Request message (example) {"LogisticCode": "3967950525457"} 7. Successful return message (example) {"EBusinessID": "1257021", "Success": true, "LogisticCode": "3967950525457", "Shippers": [{"ShipperCode": "YD", "ShipperName": "Yunda Express"]} 8. Step by step explanation (C# version)

8.1, request packet structure

8.2 call code example for CJ #

/ / E-commerce IDstring eEBusinessID = "test1617571"; / / E-commerce encryption private key, provided by express bird, be careful 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=" 2002 "; / / 2-json string dataType =" 2 "; / / character encoding is UTF-8 string charset =" UTF-8 " / / JSON string jsonStr = "{\" LogisticCode\ ":\" JT0000052600488\ "}"; / / MD5 encrypting (jsonStr+APIKey) string md5Str=MD5 (jsonStr+ apiKey, charset); / / Base64 encoding md5Str 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" / / the communication protocol returns the track data string post = SendPost (reqURL, postStr) using the Http protocol Post request method; / / the post data obtained is the complete message returned by the express bird, and then you can write a method to parse the json to obtain the field information.

8.3 the method of calling C# in Magi

/ string MD5 encryption / string to be encrypted / / Encoding / ciphertext private string MD5 (string str, string9. Application effect of actual scene of the project

10. About signature

Express bird and third-party e-commerce company system docking, there is a certain security mechanism. Use IP authentication and signature

The specific solutions are as follows:

To prevent data from being tampered with, 5 must be passed in the POST request: (r) parameters RequestData== data content (URL encoding: UTF-8) EBusinessID== user ID RequestType= request instruction type DataSign== data content signature: (request content (unencoded) + ApiKey) is encrypted by MD5, then Base64 is encoded, and finally URL (utf-8) encoding DataType==2 (return data type is json) Note: after DataSign is generated, the other party receives the data. Use the same algorithm to sign (the push interface RequestType is 101DB 102 does not require URL coding) to generate a summary and compare whether the two abstracts are the same. If different, data tampering occurs in the process of transmission. After the identity authentication of the calling API is registered as an express bird user, the corresponding user ID and APIKey will be generated. The user ID is equivalent to the user name and APIKey is equivalent to the password. At this point, the study on "how to use the API interface of C #" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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