国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

手把手教你做關鍵詞匹配項目(搜索引擎)---- 第八天

2019-11-15 01:44:50
字體:
來源:轉載
供稿:網(wǎng)友
手把手教你做關鍵詞匹配項目(搜索引擎)---- 第八天

第八天

話說小帥帥自從走進了淘寶開放平臺這個迷霧森林,感覺這迷霧森林好大,正當他無所適從的時候。

一位悅耳動聽的聲音響起來了,甜甜的聲音說道:親,想通過這片森林嗎,我將指引你前進。

小帥帥一聽,那種感覺,身體不由自主的跟隨這聲音而去,突然一道強光閃過,啊.....

小帥帥驚醒了。小帥帥一看時間,我滴個天,這么晚了。就這樣小帥帥從業(yè)一來第一次遲到。

其實小帥帥在平臺里面琢磨了一個晚上,整個晚上其實也沒琢磨個啥出來。

正當要到公司的時候,手機的鈴聲響起來了,一看是于老大的電話,接通電話。

于老大問候到:小帥帥,早啊, 你什么時候到公司丫。

小帥帥答到: 于老大,不好意思丫,昨天晚上研究那個淘寶開放平臺,研究太玩了,今早睡過頭了。不過我快到公司了....

于老大一聽,不好意思責怪小帥帥啥,只好說道:辛苦你了,注意休息,學會勞逸結合...

小帥帥,回到: 好的,謝謝于老大的教誨,沒事就掛了哈。。( 0害怕于老大的糖衣炮彈0 )

小帥帥回到公司后,于老大就給了一份整理后的Topclient給小帥帥,讓他去研究下,看樣子小帥帥還是樂于研究代碼,讓他看開放平臺,還真看不出什么。

淘寶寶貝API文檔:http://open.taobao.com/api/api_cat_detail.htm?spm=a219a.7386789.0.0.AjaroV&cat_id=4&category_id=102

Topclient來自Taobao SDK ,只是稍微修正,去掉了一些框架的依賴,源碼為:

<?phpclass TopClient{    public $appkey;    public $secretKey;    public $gatewayUrl = "http://gw.api.taobao.com/router/rest";    public $format = "json";    /** 是否打開入?yún)heck**/    public $checkRequest = true;    PRotected $signMethod = "md5";    protected $apiVersion = "2.0";    protected $sdkVersion = "top-sdk-php-20110929";    protected function generateSign($params)    {        ksort($params);        $stringToBeSigned = $this->secretKey;        foreach ($params as $k => $v) {            if ("@" != substr($v, 0, 1)) {                $stringToBeSigned .= "$k$v";            }        }        unset($k, $v);        $stringToBeSigned .= $this->secretKey;        return strtoupper(md5($stringToBeSigned));    }    protected function curl($url, $postFields = null)    {        $ch = curl_init();        curl_setopt($ch, CURLOPT_URL, $url);        curl_setopt($ch, CURLOPT_FAILONERROR, false);        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);        curl_setopt($ch, CURLOPT_TIMEOUT, 300);        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);        if (is_array($postFields) && 0 < count($postFields)) {            $postBodyString = "";            $postMultipart = false;            foreach ($postFields as $k => $v) {                if ("@" != substr($v, 0, 1)) //判斷是不是文件上傳                {                    $postBodyString .= "$k=" . urlencode($v) . "&";                } else //文件上傳用multipart/form-data,否則用www-form-urlencoded                {                    $postMultipart = true;                }            }            unset($k, $v);            curl_setopt($ch, CURLOPT_POST, true);            if ($postMultipart) {                curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);            } else {                curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString, 0, -1));            }        }        $reponse = curl_exec($ch);        if (curl_errno($ch)) {            throw new Exception(curl_error($ch), 0);        } else {            $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);            if (200 !== $httpStatusCode) {                throw new Exception($reponse, $httpStatusCode);            }        }        curl_close($ch);        return $reponse;    }    protected function logCommunicationError($apiName, $requestUrl, $errorCode, $responseTxt)    {        $localIp = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : "CLI";        $logData = "NAME:$apiName,KEY:$this->appkey,IP:$localIp,URL:$requestUrl,CODE:$errorCode,MSG:" . str_replace("/n", "", $responseTxt);        $file = fopen('taobao.api.error.log','a+');        fwrite($file,$logData);        fclose($file);    }    public function execute($request, $session = null, $need_replace = false)    {        if ($this->checkRequest) {            try {                $request->check();            } catch (Exception $e) {                $result = new stdClass();                $result->code = $e->getCode();                $result->msg = $e->getMessage();                return $result;            }        }        //組裝系統(tǒng)參數(shù)        $sysParams["v"] = $this->apiVersion;        $sysParams["format"] = $this->format;        $sysParams["method"] = $request->getApiMethodName();        $sysParams["app_key"] = $this->appkey;        $sysParams["timestamp"] = date("Y-m-d H:i:s");        $sysParams["partner_id"] = $this->sdkVersion;        $sysParams["sign_method"] = $this->signMethod;        if (null != $session) {            $sysParams["session"] = $session;        }        //獲取業(yè)務參數(shù)        $apiParams = $request->getApiParas();        //簽名        $sysParams["sign"] = $this->generateSign(array_merge($apiParams, $sysParams));        //系統(tǒng)參數(shù)放入GET請求串        $requestUrl = $this->gatewayUrl . "?";        foreach ($sysParams as $sysParamKey => $sysParamValue) {            $requestUrl .= "$sysParamKey=" . urlencode($sysParamValue) . "&";        }        $requestUrl = substr($requestUrl, 0, -1);        //發(fā)起HTTP請求        try {            $resp = $this->curl($requestUrl, $apiParams);        } catch (Exception $e) {            $this->logCommunicationError($sysParams["method"], $requestUrl, "HTTP_ERROR_" . $e->getCode(), 'RETRY:' . $e->getMessage());            $result = new stdClass();            $result->code = $e->getCode();            $result->msg = $e->getMessage();            return $result;        }        //解析TOP返回結果        $respWellFormed = false;        if ("json" == $this->format) {            if ($need_replace) {                $resp = preg_replace('/[/r/n]+/', '', $resp);            }            $respObject = json_decode($resp);            if (null !== $respObject) {                $respWellFormed = true;                foreach ($respObject as $propKey => $propValue) {                    $respObject = $propValue;                }            }        } else if ("xml" == $this->format) {            $respObject = @simplexml_load_string($resp);            if (false !== $respObject) {                $respWellFormed = true;            }        }        //返回的HTTP文本不是標準JSON或者XML,記下錯誤日志        if (false === $respWellFormed) {            $this->logCommunicationError($sysParams["method"], $requestUrl, "HTTP_RESPONSE_NOT_WELL_FORMED", $resp);            $result = new stdClass();            $result->code = 0;            $result->msg = "HTTP_RESPONSE_NOT_WELL_FORMED";            return $result;        }        return $respObject;    }}

淘寶寶貝請求類:

<?php/** * TOP API: taobao.item.get request * * @author auto create * @since 1.0, 2011-09-29 15:36:21 */class ItemGetRequest{    /**     * 需要返回的商品對象字段。可選值:Item商品結構體中所有字段均可返回;多個字段用“,”分隔。如果想返回整個子對象,那字段為item_img,如果是想返回子對象里面的字段,那字段為item_img.url。新增返回字段:second_kill(是否秒殺商品)、auto_fill(代充商品類型),props_name(商品屬性名稱)     **/    private $fields;    /**     * 商品數(shù)字ID     **/    private $numIid;    private $apiParas = array();    public function setFields($fields)    {        $this->fields = $fields;        $this->apiParas["fields"] = $fields;    }    public function getFields()    {        return $this->fields;    }    public function setNumIid($numIid)    {        $this->numIid = $numIid;        $this->apiParas["num_iid"] = $numIid;    }    public function getNumIid()    {        return $this->numIid;    }    public function getApiMethodName()    {        return "taobao.item.get";    }    public function getApiParas()    {        return $this->apiParas;    }    public function check()    {        RequestCheckUtil::checkNotNull($this->fields, "fields");        RequestCheckUtil::checkNotNull($this->numIid, "numIid");        RequestCheckUtil::checkMinValue($this->numIid, 1, "numIid");    }}

數(shù)據(jù)完整性檢測類

<?php/** * API入?yún)㈧o態(tài)檢查類 * 可以對API的參數(shù)類型、長度、最大值等進行校驗 * **/class RequestCheckUtil{    /**     * 校驗字段 fieldName 的值$value非空     *     **/    public static function checkNotNull($value,$fieldName) {                if(self::checkEmpty($value)){            throw new Exception("client-check-error:Missing Required Arguments: " .$fieldName , 40);        }    }    /**     * 檢驗字段fieldName的值value 的長度     *     **/    public static function checkMaxLength($value,$maxLength,$fieldName){                if(!self::checkEmpty($value) && strlen($value) > $maxLength){            thr
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 迁安市| 武功县| 逊克县| 济宁市| 洪雅县| 旌德县| 泸州市| 灵丘县| 垦利县| 西乡县| 西青区| 崇信县| 德格县| 澄迈县| 嘉兴市| 于都县| 清徐县| 六安市| 金堂县| 常熟市| 佛冈县| 丁青县| 如皋市| 铅山县| 望谟县| 马龙县| 黄陵县| 平乐县| 丹凤县| 青龙| 贡山| 中西区| 丹寨县| 玉山县| 南开区| 灌云县| 乌兰浩特市| 邻水| 来凤县| 台湾省| 澄江县|