日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

静态代理和依赖注入方式获取网店管家查询仓库信息接口

發(fā)布時(shí)間:2024/3/24 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 静态代理和依赖注入方式获取网店管家查询仓库信息接口 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

請求的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)級參數(shù)與應(yīng)用級參數(shù) ( 指的是必填類參數(shù) ) 發(fā)送post 請求獲取網(wǎng)店管家數(shù)據(jù)
  • <?php //獲取網(wǎng)店管家測試數(shù)據(jù) namespace app\index\controller; use app\facade\HttpRequest; use \think\Request; class Wdgj {/** 問題 1.弄清楚 ASCII排序 與 字典序排序* 系統(tǒng)級參數(shù)* Appkey = "71005530" //接入應(yīng)用需要的key* AppSecret = "n800m9iaei27l1n3b5eh7ko87gfl2k0g" //用于生成sign* AccessToken = "191167eb31f242bfa4a089359b77f5e4" //授權(quán)碼*/public $Appkey = "71005530";public $AppSecret = "n800m9iaei27l1n3b5eh7ko87gfl2k0g";public $AccessToken = "191167eb31f242bfa4a089359b77f5e4";// 查詢倉庫信息public $Method = "wdgj.warehouse.list.get";public $Format ="json";public $Versions = "1.0"; // public $Timestamp = "1581228150";public $Apiurl = "http://api.wdgj.com/wdgjcloud/api";public $Heades = array('application/x-www-form-urlencoded;charset=UTF8');// 查詢倉庫信息的接口public function wdgjwarehouselistGet(Request $request){//1. 進(jìn)行字典序排序 或者 ASCII碼排序//系統(tǒng)級參數(shù)$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();//應(yīng)用級參數(shù) 依賴注入方式調(diào)用$paramArr['pageno'] = $request->get('page');$paramArr['pagesize'] = $request->get('pageSize');$paramArrDemo = $paramArr;//生成Sign簽名 將除Sign參數(shù)外的所有系統(tǒng)級參數(shù)和應(yīng)用級級參數(shù)的值進(jìn)行字典排序生成串(versions=1.1時(shí)按ASCII碼排序)if($paramArr['Versions']=='1.1'){// 發(fā)現(xiàn)問題 ASCCII的排序與測試工具的排序是不一樣的 所以version值我改成1.0的字典排序 // ksort($paramArrDemo);sort($paramArrDemo,SORT_LOCALE_STRING);}else{sort($paramArrDemo,SORT_LOCALE_STRING);}//2. 將AppSecret加到該串的首和尾并進(jìn)行MD5加密生成32位字符串$paramString = join($paramArrDemo);//Sign簽名 所有系統(tǒng)級參數(shù) 和 必要的應(yīng)用級參數(shù) 的值進(jìn)行 字典排序 生成串$sign = MD5($this->AppSecret.$paramString.$this->AppSecret);$paramArr['Sign'] = $sign;//3. 發(fā)送post 請求獲取網(wǎng)店管家數(shù)據(jù)\think\Facade::bind('app\facade\HttpRequest','\app\common\HttpRequest');/*** 請求數(shù)據(jù)* @param string $url 請求地址* @param array $postData 請求數(shù)據(jù)* @param string $head 請求頭* @return array*///靜態(tài)代理方式調(diào)用$res = HttpRequest::httprequest($this->Apiurl, $paramArr, $this->Heades);dump($res);}}

    /**
    * 如果想靜態(tài)調(diào)用一個(gè)動(dòng)態(tài)方法,需要給當(dāng)前的類綁定一個(gè)靜態(tài)代理的類
    *如果沒有在靜態(tà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)前的類綁定一個(gè)靜態(tài)代理的類

    <?php namespace app\common;class HttpRequest {/*** 請求數(shù)據(jù)* @param string $url 請求地址* @param array $postData 請求數(shù)據(jù)* @param string $head 請求頭* @return array*/public function httpRequest($url, $postData, $head){//初始化$curl = curl_init();//設(shè)置抓取的url;curl_setopt($curl, CURLOPT_URL, $url);//設(shè)置頭文件的信息作為數(shù)據(jù)流輸出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); // 對認(rèn)證證書來源的檢查curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 從證書中檢查SSL加密算法是否存在 7.2 強(qiáng)制https 使用2}if (!empty($postData)) {curl_setopt($curl, CURLOPT_POST, true); //設(shè)置post方式提交curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postData)); //使用給出的關(guān)聯(lián)(或下標(biāo))數(shù)組生成一個(gè)經(jīng)過 URL-encode 的請求字符串。參數(shù) formdata 可以是數(shù)組或包含屬性的對象。//設(shè)置post數(shù)據(jù)}curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//執(zhí)行命令$json = curl_exec($curl);$error = curl_error($curl);//關(guān)閉URL請求curl_close($curl);if ($json === false) //請求失敗{return ['success' => false, 'desc' => 'curl錯(cuò)誤,錯(cuò)誤編碼:' . $error];}if (preg_match('/^\xEF\xBB\xBF/', $json)) //去除boom 頭{$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ù)來源真實(shí)性

    接口對應(yīng)管家:【管家】->【設(shè)置】->【倉庫目錄】,接口查詢出的數(shù)據(jù)即為該界面的倉庫信息。

    參看網(wǎng)店管家接口調(diào)用說明文檔
    http://open.wdgj.com/OpenApiDoc/DocCenter.html

    http://open.wdgj.com/OpenApiDoc/ApiInfo.html?openApiID=70000&dictID=87&name%20=

    總結(jié)

    以上是生活随笔為你收集整理的静态代理和依赖注入方式获取网店管家查询仓库信息接口的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。