فهرست منبع

Merge branch 'master' of https://git.97admin.com:433/chendeben/taoqu

chendeben 6 سال پیش
والد
کامیت
23952209b0
1فایلهای تغییر یافته به همراه19 افزوده شده و 13 حذف شده
  1. 19 13
      App/Api/Controller.php

+ 19 - 13
App/Api/Controller.php

@@ -20,13 +20,15 @@ abstract class Controller extends \Heanup\Frame\Controller
     {
 
     }
-    public function addSitemap($url){
+
+    public function addSitemap($url)
+    {
         $urls = array(
             $url,
         );
         $api = 'http://data.zz.baidu.com/urls?site=www.taoqu88.com&token=pKgc8vvoowMXccMI';
         $ch = curl_init();
-        $options =  array(
+        $options = array(
             CURLOPT_URL => $api,
             CURLOPT_POST => true,
             CURLOPT_RETURNTRANSFER => true,
@@ -35,7 +37,7 @@ abstract class Controller extends \Heanup\Frame\Controller
         );
         curl_setopt_array($ch, $options);
         $result = curl_exec($ch);
-        file_put_contents(APP_DIR."/baidu.log", $result);
+        file_put_contents(APP_DIR . "/baidu.log", $result);
 //        $hashKey="sitemap:".md5($url);
 //        $exist=Redis::instance()->get($hashKey);
 //        if (!$exist){
@@ -53,24 +55,28 @@ abstract class Controller extends \Heanup\Frame\Controller
      */
     protected function checkAuth($checkLogin = false)
     {
-        if ($_GET['kw']){
-            $con=new Search();
+        if ($_GET['kw']) {
+            $con = new Search();
             $con->main();
         }
         $this->cache();
         return true;
     }
-    protected function cache(){
-        $key="cache:".md5(json_encode($_REQUEST));
-        $cache=Redis::instance()->get($key);
-        if ($cache){
+
+    protected function cache()
+    {
+        $key = "cache:" . md5(json_encode($this->getQuery()->toArray()));
+        $cache = Redis::instance()->get($key);
+        if ($cache) {
             echo $cache;
             die();
         }
     }
-    protected function setCache($content){
-        $key="cache:".md5(json_encode($_REQUEST));
-        Redis::instance()->set($key, $content,3600*3);
+
+    protected function setCache($content)
+    {
+        $key = "cache:" . md5(json_encode($this->getQuery()->toArray()));
+        Redis::instance()->set($key, $content, 3600 * 3);
         echo $content;
         die();
     }
@@ -137,7 +143,7 @@ abstract class Controller extends \Heanup\Frame\Controller
     {
         header('Content-type: application/json');
         if (is_array($response)) {
-            $response = json_encode($response,JSON_UNESCAPED_UNICODE);
+            $response = json_encode($response, JSON_UNESCAPED_UNICODE);
         }
         if ($this->need_cache) {
             Memcached::instance()->set($this->cache_key, $response, ALL_CACHE_TIME);