Quellcode durchsuchen

计划任务修改

lizhen_gitee vor 1 Jahr
Ursprung
Commit
6bb7fabba1
1 geänderte Dateien mit 3 neuen und 294 gelöschten Zeilen
  1. 3 294
      application/index/controller/Plantask.php

+ 3 - 294
application/index/controller/Plantask.php

@@ -12,125 +12,8 @@ class Plantask extends Controller
     //只有 public 方法,auto_开头的才是计划任务,其他private 方法都是工具方法
 
 ////////////////////////////////////////下面都是计划任务方法///////////////////////////////////////////////////////////////
-    //主动拉取im群组内 聊天记录
-    public function auto_imgroup(){
-        $im_config = config('tencent_im');
-        $sdkappid  = $im_config['sdkappid'];
-        $sdkappkey = $im_config['key'];
-        $identifier= $im_config['identifier'];
-        $usersig   = $this->usersig($sdkappid,$sdkappkey,$identifier);
 
 
-        $random = rand(10000000,99999999);
-        $url = 'https://console.tim.qq.com/v4/open_msg_svc/get_history?sdkappid='.$sdkappid.'&identifier=administrator&usersig='.$usersig.'&random='.$random.'&contenttype=json';
-
-        $data = [
-            'ChatType' => 'Group',
-            'MsgTime'  => date('YmdH',strtotime('-3 Hours')),
-        ];
-        $tasklog = [
-            'type' => $data['ChatType'] == 'C2C' ? 1 : 2,
-            'datehour' => $data['MsgTime'],
-            'createtime' => time(),
-            'status' => 0,
-        ];
-        dump($data);
-        $jsonStr = json_encode($data);
-
-        $header = array(
-            'Content-Type: application/json; charset=utf-8',
-            'Content-Length: ' . strlen($jsonStr)
-        );
-        $rs = curl_post($url,$jsonStr,$header);
-        $rs = json_decode($rs,true);
-        dump($rs);
-        if(is_array($rs) && isset($rs['ErrorCode']) && $rs['ErrorCode'] == 0){
-            $tasklog['status'] = 1;
-            //正常的,可以下载了
-            if(isset($rs['File']) && !empty($rs['File'])){
-                foreach($rs['File'] as $key => $val){
-                    echo $val['URL'];
-                    //下载
-                    $gz_path = $this->downloadfile($val['URL'],$data['ChatType'],$data['MsgTime'].'_'.$data['ChatType'].'.json.gz');
-                    dump($gz_path);
-                    //解压
-                    $json_path = $this->jieyagz($gz_path);
-                    dump($json_path);
-                    //分析
-                    $content = $this->readjson_group($json_path);
-                    dump(count($content));
-                    //入库
-                    if(!empty($content)){
-                        Db::name('imlog_group')->insertAll($content);
-                    }
-                }
-            }
-        }
-        Db::name('imlog_tasklog')->insertGetId($tasklog);
-
-        echo '结束';
-        exit;
-    }
-
-    //主动拉取im用户私聊 聊天记录
-    public function auto_imc2c(){
-        $im_config = config('tencent_im');
-        $sdkappid  = $im_config['sdkappid'];
-        $sdkappkey = $im_config['key'];
-        $identifier= $im_config['identifier'];
-        $usersig   = $this->usersig($sdkappid,$sdkappkey,$identifier);
-
-
-        $random = rand(10000000,99999999);
-        $url = 'https://console.tim.qq.com/v4/open_msg_svc/get_history?sdkappid='.$sdkappid.'&identifier=administrator&usersig='.$usersig.'&random='.$random.'&contenttype=json';
-
-        $data = [
-            'ChatType' => 'C2C',
-            'MsgTime'  => date('YmdH',strtotime('-3 Hours')),
-        ];
-        $tasklog = [
-            'type' => $data['ChatType'] == 'C2C' ? 1 : 2,
-            'datehour' => $data['MsgTime'],
-            'createtime' => time(),
-            'status' => 0,
-        ];
-        dump($data);
-        $jsonStr = json_encode($data);
-
-        $header = array(
-            'Content-Type: application/json; charset=utf-8',
-            'Content-Length: ' . strlen($jsonStr)
-        );
-        $rs = curl_post($url,$jsonStr,$header);
-        $rs = json_decode($rs,true);
-        dump($rs);
-        if(is_array($rs) && isset($rs['ErrorCode']) && $rs['ErrorCode'] == 0){
-            $tasklog['status'] = 1;
-            //正常的,可以下载了
-            if(isset($rs['File']) && !empty($rs['File'])){
-                foreach($rs['File'] as $key => $val){
-                    //下载
-                    $gz_path = $this->downloadfile($val['URL'],$data['ChatType'],$data['MsgTime'].'_'.$data['ChatType'].'.json.gz');
-                    dump($gz_path);
-                    //解压
-                    $json_path = $this->jieyagz($gz_path);
-                    dump($json_path);
-                    //分析
-                    $content = $this->readjson($json_path);
-                    dump(count($content));
-                    //入库
-                    if(!empty($content)){
-                        Db::name('imlog_c2c')->insertAll($content);
-                    }
-                }
-            }
-        }
-        Db::name('imlog_tasklog')->insertGetId($tasklog);
-
-        echo '结束';
-        exit;
-    }
-
     //送礼物(api/party/giveGiftToYou)拆分出来的异步用户升级方法,
     public function auto_user_level_up(){
         Db::startTrans();
@@ -143,7 +26,7 @@ class Plantask extends Controller
 
         try {
             $money_to_jewel = config('site.money_to_jewel') ?: 10; //余额兑换钻石
-            $getempirical_conf = config("site.getempirical");
+//            $getempirical_conf = config("site.getempirical");
 
             foreach($tasklist as $key => $giftuserparty){
                 echo $giftuserparty['id'].'<br>';
@@ -194,7 +77,7 @@ class Plantask extends Controller
                 }*/
 
                 //用户经验升级
-                $getempirical = $getempirical_conf * $hotValue;
+                //$getempirical = $getempirical_conf * $hotValue;
                 // 获取用户贵族信息
                 /*$noble = \app\common\model\User::getUserNoble($giftuserparty['user_id']);
                 if(isset($noble["noble_on"]) && $noble["noble_on"] == 1) {
@@ -202,7 +85,7 @@ class Plantask extends Controller
                 }*/
 
                 // 增加用户经验值
-                $res = \app\common\model\User::addEmpirical($giftuserparty['user_id'],$getempirical);
+                //$res = \app\common\model\User::addEmpirical($giftuserparty['user_id'],$getempirical);
                 /*if ($res){
                     $this->auth->level = $res->level;
                 }*/
@@ -241,180 +124,6 @@ class Plantask extends Controller
     }
 
 /////////////////////////////////////////下面都是工具方法////////////////////////////////////////////////
-    //下载远程文件 到指定目录
-    private function downloadfile($file_url, $path = '', $save_file_name = '')
-    {
-        $basepath = '/uploaded/';
-        if ($path) {
-            $basepath = $basepath . $path . '/';
-        }
-        $basepath = $basepath . date('Ymd');
-        $dir_path = ROOT_PATH . '/public' . $basepath;
-        if (!is_dir($dir_path)) {
-            mkdir($dir_path, 0777, true);
-        }
-
-
-        $file = file_get_contents($file_url);
-
-
-        //传入保存文件的名称
-        $filename = $save_file_name ?: pathinfo($file_url, PATHINFO_BASENAME);
-
-        $resource = fopen($dir_path. '/'. $filename, 'w');
-
-        fwrite($resource, $file);
-
-        fclose($resource);
-
-        return $dir_path . '/' . $filename;
-    }
-
-    //解压
-    private function jieyagz($gz_path = ''){
-        $json_path = substr($gz_path,0,-3);
-
-
-        if ($zp = gzopen($gz_path, 'r')) { // 打开压缩文件
-            if ($fp = fopen($json_path, 'w')) { // 打开目标文件
-                while (!gzeof($zp)) {
-                    fwrite($fp, gzread($zp, 1024 * 512)); // 逐块读取和解压缩后写入
-                }
-                fclose($fp);
-            }
-            gzclose($zp);
-        }
-        return $json_path;
-    }
-
-    //读取json并分析,c2c
-    private function readjson($json_path = ''){
-        $newMsgList = [];
-        $json_content = file_get_contents($json_path);
-        $json_content = json_decode($json_content,true);
-
-        if(!empty($json_content) && is_array($json_content) && isset($json_content['MsgList'])){
-            $MsgList = $json_content['MsgList'];
-
-            if(!empty($MsgList)){
-                foreach($MsgList as $key => $val)
-                {
-                    $newone = [
-                        'ClientIP'        => isset($val['ClientIP'])        ? $val['ClientIP']             : '',
-                        'CloudCustomData' => isset($val['CloudCustomData']) ? $val['CloudCustomData']      : '',
-                        'From_Account'    => isset($val['From_Account'])    ? intval($val['From_Account']) : 0,
-                        //'MsgBody'         => isset($val['MsgBody'])         ? json_encode($val['MsgBody']) : '',
-                        'MsgFromPlatform' => isset($val['MsgFromPlatform']) ? $val['MsgFromPlatform']      : '',
-                        'MsgRandom'       => isset($val['MsgRandom'])       ? $val['MsgRandom']            : '',
-                        'MsgSeq'          => isset($val['MsgSeq'])          ? $val['MsgSeq']               : '',
-                        'MsgTimestamp'    => isset($val['MsgTimestamp'])    ? $val['MsgTimestamp']         : '',
-                        'To_Account'      => isset($val['To_Account'])      ? intval($val['To_Account'])   : 0,
-                    ];
-                    //解析数据类型
-                    if(isset($val['MsgBody'][0]['MsgType'])){
-                        $newone['MsgType'] = $val['MsgBody'][0]['MsgType'];
-                        //文本
-                        if($val['MsgBody'][0]['MsgType'] == 'TIMTextElem'){
-                            $newone['MsgInfo'] = '';
-                            if(isset($val['MsgBody'][0]['MsgContent']['Text'])){
-                                $newone['MsgInfo'] = $val['MsgBody'][0]['MsgContent']['Text'];
-                            }
-                        }
-                        //图片
-                        if($val['MsgBody'][0]['MsgType'] == 'TIMImageElem'){
-                            $newone['MsgInfo'] = '';
-                            if(isset($val['MsgBody'][0]['MsgContent']['ImageInfoArray'][0]['URL'])){
-                                $newone['MsgInfo'] = $val['MsgBody'][0]['MsgContent']['ImageInfoArray'][0]['URL'];
-                            }
-                        }
-                        //声音
-                        if($val['MsgBody'][0]['MsgType'] == 'TIMSoundElem'){
-                            $newone['MsgInfo'] = '';
-                            if(isset($val['MsgBody'][0]['MsgContent']['Url'])){
-                                $newone['MsgInfo'] = $val['MsgBody'][0]['MsgContent']['Url'];
-                            }
-                        }
-                        //视频
-                        if($val['MsgBody'][0]['MsgType'] == 'TIMVideoFileElem'){
-                            $newone['MsgInfo'] = '';
-                            if(isset($val['MsgBody'][0]['MsgContent']['VideoUrl'])){
-                                $newone['MsgInfo'] = $val['MsgBody'][0]['MsgContent']['VideoUrl'];
-                            }
-                        }
-                        //其他
-                        continue;
-                    }else{
-                        continue;
-                    }
-
-                    $newMsgList[] = $newone;
-                }
-            }
-        }
-
-        return $newMsgList;
-    }
-
-    //读取json并分析,group
-    private function readjson_group($json_path = ''){
-        $newMsgList = [];
-        $json_content = file_get_contents($json_path);
-        $json_content = json_decode($json_content,true);
-
-        if(!empty($json_content) && is_array($json_content) && isset($json_content['MsgList'])){
-            $MsgList = $json_content['MsgList'];
-
-            if(!empty($MsgList)){
-                foreach($MsgList as $key => $val)
-                {
-                    $newone = [
-                        //'key' => $key,辅助查找
-                        'ClientIP'        => isset($val['ClientIP'])        ? $val['ClientIP']             : '',
-                        'From_Account'    => isset($val['From_Account'])    ? intval($val['From_Account']) : 0,
-                        'GroupId'         => isset($val['GroupId'])         ? intval($val['GroupId'])      : 0,
-                        //'MsgBody'         => isset($val['MsgBody'])         ? json_encode($val['MsgBody']) : '',
-                        'MsgFromPlatform' => isset($val['MsgFromPlatform']) ? $val['MsgFromPlatform']      : '',
-                        'MsgSeq'          => isset($val['MsgSeq'])          ? $val['MsgSeq']               : '',
-                        'MsgTimestamp'    => isset($val['MsgTimestamp'])    ? $val['MsgTimestamp']         : '',
-                    ];
-                    //解析数据类型
-                    if(isset($val['MsgBody'][0]['MsgType'])){
-                        $newone['MsgType'] = $val['MsgBody'][0]['MsgType'];
-                        //文本
-                        if($val['MsgBody'][0]['MsgType'] == 'TIMTextElem'){
-                            $newone['MsgInfo'] = '';
-                            if(isset($val['MsgBody'][0]['MsgContent']['Text'])){
-                                //继续解析
-                                $text = json_decode($val['MsgBody'][0]['MsgContent']['Text'],true);
-                                if(isset($text['type']) && $text['type'] == 1){
-                                    //TYPE_NORMAL =1;//普通消息
-                                    $newone['MsgInfo'] = isset($text['content']) ? $text['content'] : '';
-                                    $newMsgList[] = $newone;
-                                }
-                                //其他$text['type']的值都是房间内的,礼物的,表情等,不需要记录
-                            }
-                        }
-                        //房间内的不需要显示的内容
-                        if($val['MsgBody'][0]['MsgType'] == 'TIMCustomElem'){
-
-                        }
-
-                    }
-
-                    //大循环结束
-                }
-            }
-        }
-
-        return $newMsgList;
-    }
-
-    //请求im的签名
-    private function usersig($sdkappid,$key,$identifier){
-        $api = new TLSSigAPIv2($sdkappid,$key );
-        $sig = $api->genUserSig($identifier);
-        return $sig;
-    }
 
 
 }