生活随笔
收集整理的這篇文章主要介紹了
静态代理和依赖注入方式获取网店管家查询仓库信息接口
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
請(qǐng)求的URL地址http://localhost/tp5.1/public/index.php/index/wdgj/wdgjwarehouselistGet?page=1&pageSize=10
進(jìn)行字典序排序 或者 ASCII碼排序將AppSecret加到該串的首和尾并進(jìn)行MD5加密生成32位字符串生成Sign簽名將所有的系統(tǒng)級(jí)參數(shù)與應(yīng)用級(jí)參數(shù) ( 指的是必填類(lèi)參數(shù) ) 發(fā)送post 請(qǐng)求獲取網(wǎng)店管家數(shù)據(jù)
<?php
namespace app\index\controller
;
use app\facade\HttpRequest
;
use \think\Request
;
class Wdgj
{public $Appkey
= "71005530";public $AppSecret
= "n800m9iaei27l1n3b5eh7ko87gfl2k0g";public $AccessToken
= "191167eb31f242bfa4a089359b77f5e4";public $Method
= "wdgj.warehouse.list.get";public $Format
="json";public $Versions
= "1.0";
public $Apiurl
= "http://api.wdgj.com/wdgjcloud/api";public $Heades
= array('application/x-www-form-urlencoded;charset=UTF8');public function wdgjwarehouselistGet(Request $request
){$paramArr
= array();$paramArr
['Appkey'] = $
this->Appkey
;$paramArr
['Accesstoken'] = $
this->AccessToken
;$paramArr
['Method'] = $
this->Method
;$paramArr
['Format'] = $
this->Format
;$paramArr
['Versions'] = $
this->Versions
;$paramArr
['Timestamp'] = (string
)time();$paramArr
['pageno'] = $request
->get('page');$paramArr
['pagesize'] = $request
->get('pageSize');$paramArrDemo
= $paramArr
;if($paramArr
['Versions']=='1.1'){
sort($paramArrDemo
,SORT_LOCALE_STRING);}else{sort($paramArrDemo
,SORT_LOCALE_STRING);}$paramString
= join($paramArrDemo
);$sign
= MD5($
this->AppSecret
.$paramString
.$
this->AppSecret
);$paramArr
['Sign'] = $sign
;\think\Facade
::bind('app\facade\HttpRequest','\app\common\HttpRequest');$res
= HttpRequest
::httprequest($
this->Apiurl
, $paramArr
, $
this->Heades
);dump($res
);}}
/**
* 如果想靜態(tài)調(diào)用一個(gè)動(dòng)態(tài)方法,需要給當(dāng)前的類(lèi)綁定一個(gè)靜態(tài)代理的類(lèi)
*如果沒(méi)有在靜態(tài)代理類(lèi)中顯示指定要綁定的類(lèi)名,就需要?jiǎng)討B(tài)顯示綁定一下
* \think\Facade::bind()
*/
<?php
namespace app\facade
;class HttpRequest extends \think\Facade
{}
如果想靜態(tài)調(diào)用一個(gè)動(dòng)態(tài)方法,需要給當(dāng)前的類(lèi)綁定一個(gè)靜態(tài)代理的類(lèi)
<?php
namespace app\common
;class HttpRequest
{public function httpRequest($url
, $postData
, $head
){$curl
= curl_init();curl_setopt($curl
, CURLOPT_URL, $url
);curl_setopt($curl
, CURLOPT_HEADER, 0);curl_setopt($curl
, CURLOPT_HTTPHEADER, $head
);curl_setopt($curl
, CURLINFO_HEADER_OUT, true);if (0 === strpos(strtolower($url
), 'https')) {curl_setopt($curl
, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl
, CURLOPT_SSL_VERIFYHOST, false); }if (!empty($postData
)) {curl_setopt($curl
, CURLOPT_POST, true); curl_setopt($curl
, CURLOPT_POSTFIELDS, http_build_query($postData
)); }curl_setopt($curl
, CURLOPT_RETURNTRANSFER, 1);$json
= curl_exec($curl
);$error
= curl_error($curl
);curl_close($curl
);if ($json
=== false) {return ['success' => false, 'desc' => 'curl錯(cuò)誤,錯(cuò)誤編碼:' . $error
];}if (preg_match('/^\xEF\xBB\xBF/', $json
)) {$output
= substr($json
, 3);} else {$output
= $json
;}$obj
= json_decode(trim($output
), true);return ['code'=>1,'msg'=>'抓取成功','data'=>$obj
];}
}
查詢返回結(jié)果
網(wǎng)店管家應(yīng)用驗(yàn)證數(shù)據(jù)來(lái)源真實(shí)性
接口對(duì)應(yīng)管家:【管家】->【設(shè)置】->【倉(cāng)庫(kù)目錄】,接口查詢出的數(shù)據(jù)即為該界面的倉(cāng)庫(kù)信息。
參看網(wǎng)店管家接口調(diào)用說(shuō)明文檔
http://open.wdgj.com/OpenApiDoc/DocCenter.html
http://open.wdgj.com/OpenApiDoc/ApiInfo.html?openApiID=70000&dictID=87&name%20=
總結(jié)
以上是生活随笔為你收集整理的静态代理和依赖注入方式获取网店管家查询仓库信息接口的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。