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 Express Bird API Interface with php

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

What this article shares to you is about how php realizes the express bird API interface, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Code implementation of method call / / E-commerce IDdefined ('EBusinessID') or define (' EBusinessID',') Please go to the official website of express bird to apply for http://kdniao.com/reg');// encryption private key, express bird to provide, pay attention to keep, do not leak defined ('AppKey') or define (' AppKey',') please go to express bird official website to apply for http://kdniao.com/reg'); / / request urldefined ('ReqURL') or define (' ReqURL', 'http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx');// call to query logistics track / /-$logisticResult=getOrderTracesByJson (); echo logisticResult Php encapsulation method / /-/ * Json query order logistics track * / function getOrderTracesByJson () {$requestData= "{'OrderCode':'','ShipperCode':'YTO','LogisticCode':'12345678'}" $datas = array ('EBusinessID' = > EBusinessID,' RequestType' = > '1002 steps,' RequestData' = > urlencode ($requestData), 'DataType' = >' 2 steps,); $datas ['DataSign'] = encrypt ($requestData, AppKey); $result=sendPost (ReqURL, $datas); / / information returned according to the company's business processing. Return $result;} / * post submission data * @ param string $url request Url * @ param array $datas submitted data * @ return url response returned html * / function sendPost ($url, $datas) {$temps = array (); foreach ($datas as $key = > $value) {$temps [] = sprintf ('% slots% slots, $key, $value);} $post_data = implode ('&', $temps) $url_info = parse_url ($url); if (empty ($url_info ['port'])) {$url_info [' port'] = 80;} $httpheader = "POST". $url_info ['path']. "HTTP/1.0\ r\ n"; $httpheader.= "Host:". $url_info ['host']. "\ r\ n"; $httpheader.= "Content-Type:application/x-www-form-urlencoded\ r\ n"; $httpheader.= "Content-Length:". Strlen ($post_data). "\ r\ n"; $httpheader.= "Connection:close\ r\ n\ r\ n"; $httpheader.= $post_data; $fd = fsockopen ($url_info ['host'], $url_info [' port']); fwrite ($fd, $httpheader); $gets = ""; $headerFlag = true While (! feof ($fd)) {if (($header = @ fgets ($fd)) & & ($header = = "\ r\ n" | | $header = = "\ n") {break;} while (! feof ($fd)) {$gets.= fread ($fd);} fclose ($fd); return $gets } / * E-commerce Sign signature generation * @ param data content * @ param appkey Appkey * @ return DataSign signature * / function encrypt ($data,$appkey) {return urlencode (base64_encode (md5 ($data,$appkey);} above is how php implements the express bird API interface. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report