wesmiler 6 lat temu
rodzic
commit
b47de2200e

+ 4 - 102
app/api/controller/IndexController.php

@@ -12,108 +12,10 @@ use app\weixin\service\PRedis;
 class IndexController extends BaseController
 {
 
-    /**
-     * 获取JSSDK参数
-     */
-    public function getJssdkParams(){
-        $url = input('url', '');
-        $jssdkParams = Wechat::getJssdkParams($url);
-        PRedis::set('shares:'.date('YmdHis'), ['url'=> $url,'params'=> $jssdkParams], 600);
-        showJson(1005,1001, $jssdkParams);
-    }
-
-    /**
-     * 获取微信信息
-     */
-    public function getWxInfo(){       
-        $wxInfo = session('wxInfo');
-        showJson(1005,1001, $wxInfo);
-    }
-
-    /**
-     * 获取条件参数
-     */
-    public function params(){
-        $params['ages'] = config('weixin.ages');
-        $params['heights'] = config('weixin.heights');
-        $params['weights'] = config('weixin.weights');
-        $params['incomes'] = config('weixin.incomes');
-        $params['educations'] = config('weixin.educations');
-        $params['positions'] = config('weixin.positions');
-        $params['marrieds'] = config('weixin.marrieds');
-        $params['propertys'] = config('weixin.propertys');
-        showJson(1005,1001, $params);
-    }
-
-    /**
-     * 获取网站信息
-     */
-    public function getSiteInfo(){
-        $siteInfo =  $siteInfo = cmf_get_site_info();
-        $chooseNum = isset($siteInfo['choose_num'])? intval($siteInfo['choose_num']) : 0;
-        $data = [
-            'site_name'=> isset($siteInfo['site_name'])? $siteInfo['site_name'] : '',
-            'site_seo_title'=> isset($siteInfo['site_seo_title'])? $siteInfo['site_seo_title'] : '',
-            'site_seo_keywords'=> isset($siteInfo['site_seo_keywords'])? $siteInfo['site_seo_keywords'] : '',
-            'site_seo_description'=> isset($siteInfo['site_seo_description'])? $siteInfo['site_seo_description'] : '',
-            'contact_type'=> isset($siteInfo['contact_type'])? $siteInfo['contact_type'] : 1,
-            'choose_num'=> $chooseNum? $chooseNum : 3,
-            'custom_intro'=> isset($siteInfo['custom_intro'])? htmlspecialchars_decode($siteInfo['custom_intro']) : '',
-        ];
-        showJson(1005,1001, $data);
-    }
-
-    /**
-     * 获取广告列表
-     */
-    public function getAdvertList(){
-        $id = input('type', 1);
-        $pages = config('config.pages');
-        $slideNum = isset($pages['slideNum'])? intval($pages['slideNum']) : 0;
-        $dataList = db('slide')->alias('s')
-            ->join('slide_item si','si.slide_id=s.id','left')
-            ->where(['s.id'=> $id,'s.status'=> 1])
-            ->field('si.id,si.title,si.image,si.url,si.description')
-            ->order('si.list_order')
-            ->limit($slideNum? $slideNum :6)
-            ->select()
-            ->toArray();
-
-        foreach($dataList as &$item){
-            $item['image'] = $item['image']? cmf_get_image_preview_url($item['image']) : '';
-        }
-
-        showJson(1005,1001, $dataList);
-    }
-
-    /**
-     * 获取单页文章内容
-     */
-    public function getPage(){
-        $info = [];
-        $type = input('type', 'about');
-        $articles = config('weixin.articles');
-        $articleId = isset($articles[$type])? intval($articles[$type]) : 0;
-        if($articleId){
-            $field = 'id,thumbnail,post_title,post_excerpt,post_content,published_time,post_source,user_id';
-            $info = PortalPostModel::where(['id'=> $articleId,'post_type'=> 2,'post_status'=>1])
-                ->field($field)
-                ->find();
-            if($info){
-                $info['post_content'] = htmlspecialchars_decode($info['post_content']);
-            }
-        }
-        showJson(1005,1001, $info);
-    }
-
-    /**
-     * 获取客服列表
-     */
-    public function getCustomList(){
-        $params = input();
-        $pageSize = input('pageSize', 20);
-        $dataList = Article::getList($params, $pageSize);
-        showJson(1005, 1001, $dataList);
+    public function index(){
+        $ua = isset($_SERVER['HTTP_USER_AGENT'])? trim($_SERVER['HTTP_USER_AGENT']) : '';
+        var_dump($ua);
+        exit;
     }
 
 }

+ 9 - 3
app/api/controller/TaskController.php

@@ -9,10 +9,16 @@ class TaskController extends Controller
 {
 
     public function grabPublishGoods(){
-
-
-        Grab::instance()->grabData('nike_cn');
+        ini_set('user_agent', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)');
+        set_time_limit(0);
+        Grab::instance()->grabData('test');
 
         showJson(1001, 1004);
     }
+
+    public function test(){
+        $ua = isset($_SERVER['HTTP_USER_AGENT'])? trim($_SERVER['HTTP_USER_AGENT']) : '';
+        var_dump($ua);
+        exit;
+    }
 }

+ 6 - 2
app/index/service/Grab.php

@@ -39,7 +39,10 @@ class Grab
         $url = isset($urls['url'])? trim($urls['url']) : '';
         echo $url."\n";
         if($url){
-            $cookie = file_get_contents("./logs/{$resource}.cookie");
+            $cookie = '';
+            if(file_exists("./logs/{$resource}.cookie")){
+                $cookie = file_get_contents("./logs/{$resource}.cookie");
+            }
             $header = [
                 "User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36",
                 "Host:www.nike.com",
@@ -49,7 +52,8 @@ class Grab
 //                "Cookie:{$cookie}",
             ];
 //            $content = file_get_contents($url);
-            $content = grabRequest($url, $header,'s=upcoming');
+            $content = file_get_contents($url);
+//            $content = grabRequest($url, '','');
             file_put_contents('./logs/'.$resource.'_'.date('YmdHis').'.html', $content);
 
         }

+ 6 - 0
data/config/grab.php

@@ -7,6 +7,12 @@ return [
             'url'=> 'http://www.nike.com/cn'
 //            'url'=> 'https://www.nike.com/cn/launch?s=upcoming'
         ],
+        'test'=> [
+            'name'=> '测试',
+            'url'=>'http://127.0.0.39/api/index/index'
+//            'url'=>'https://www.nike.com:443/launch?s=upcoming'
+//            'url'=>'https://www.nike.com/'
+        ],
         'nike_us'=> [
             'name'=> '美国官网',
             'url'=> 'https://www.nike.com/launch?s=upcoming'

+ 2 - 2
vendor/thinkcmf/cmf/src/common.php

@@ -2316,7 +2316,6 @@ function httpRequest($url, $data=[], $type='post', $dataType='array', $timeout=6
  * @return mixed
  */
 function grabRequest($url, $header=[], $data=[], $type='post', $timeout=60){
-    header('Content-type:text/html;charset=utf-8');
     $data = $data && is_array($data)? http_build_query($data) : '';
     $url = strtolower($type) == 'get'? $url.(strpos($url, '?') === false ? '?' : ''). $data : $url;
     $ch = curl_init($url);
@@ -2325,7 +2324,7 @@ function grabRequest($url, $header=[], $data=[], $type='post', $timeout=60){
     }else{
         curl_setopt($ch, CURLOPT_HEADER, 0);
     }
-echo $url."<br>";
+echo $url."<br>";exit;
     curl_setopt($ch, CURLOPT_HEADER,0 );
     curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@@ -2336,6 +2335,7 @@ echo $url."<br>";
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
     $ret = curl_exec($ch);
+    echo $ret;
     curl_close($ch);
     return $ret;
 }