|  | @@ -3,14 +3,12 @@
 | 
	
		
			
				|  |  |  namespace app\index\controller;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  use think\Controller;
 | 
	
		
			
				|  |  | -use getusersig\getusersig;
 | 
	
		
			
				|  |  | -use tencentim\tencentim;
 | 
	
		
			
				|  |  |  use think\Db;
 | 
	
		
			
				|  |  |  use think\Cache;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  class Plantask extends Controller
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +    //计划任务
 | 
	
		
			
				|  |  |      //定时跑用户活跃,改成离线
 | 
	
		
			
				|  |  |      public function user_active(){
 | 
	
		
			
				|  |  |          $actitime = time() - 600;
 | 
	
	
		
			
				|  | @@ -20,6 +18,7 @@ class Plantask extends Controller
 | 
	
		
			
				|  |  |          //echo $sql;
 | 
	
		
			
				|  |  |          db()->query($sql);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +    //计划任务
 | 
	
		
			
				|  |  |      //代替公会的人10秒内发出五句话
 | 
	
		
			
				|  |  |      public function firstuser_send()
 | 
	
		
			
				|  |  |      {
 | 
	
	
		
			
				|  | @@ -53,16 +52,17 @@ class Plantask extends Controller
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          if($times < 5){
 | 
	
		
			
				|  |  | +            $tenim = new \app\common\library\Tenim;
 | 
	
		
			
				|  |  |              for($i = 0;$i < 5;$i++){
 | 
	
		
			
				|  |  |                  $ghuser_one  = isset($ghuser[$i])  ? $ghuser[$i]  : $ghuser[array_rand($ghuser)];
 | 
	
		
			
				|  |  |                  $oneword_one = isset($oneword[$i]) ? $oneword[$i] : $oneword[array_rand($oneword)];
 | 
	
		
			
				|  |  | -                $this->sendMessageToUser($ghuser_one,$oneuser,$oneword_one);
 | 
	
		
			
				|  |  | +                $tenim->sendMessageToUser($ghuser_one,$oneuser,$oneword_one);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              $cache->set('plantask_first_word_'.$oneuser, 5);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -    //二期之后,废弃
 | 
	
		
			
				|  |  | +    //计划任务,二期之后,废弃
 | 
	
		
			
				|  |  |      //代替公会的人发出第一句话
 | 
	
		
			
				|  |  |      public function firstword_send()
 | 
	
		
			
				|  |  |      {
 | 
	
	
		
			
				|  | @@ -95,12 +95,14 @@ class Plantask extends Controller
 | 
	
		
			
				|  |  |              $times = 0;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          if($times < 5){
 | 
	
		
			
				|  |  | -            $this->sendMessageToUser($ghuser,$oneuser,$oneword);
 | 
	
		
			
				|  |  | +            $tenim = new \app\common\library\Tenim;
 | 
	
		
			
				|  |  | +            $tenim->sendMessageToUser($ghuser,$oneuser,$oneword);
 | 
	
		
			
				|  |  |              $cache->set('plantask_first_word_'.$oneuser, $times + 1);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    //计划任务
 | 
	
		
			
				|  |  |      //清空没用的redis
 | 
	
		
			
				|  |  |      public function firstword_clear(){
 | 
	
		
			
				|  |  |          $map = [
 | 
	
	
		
			
				|  | @@ -124,6 +126,7 @@ class Plantask extends Controller
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    //测试用
 | 
	
		
			
				|  |  |      //清空redis
 | 
	
		
			
				|  |  |      public function clear_redis(){
 | 
	
		
			
				|  |  |          $val = input('uid');
 | 
	
	
		
			
				|  | @@ -131,64 +134,4 @@ class Plantask extends Controller
 | 
	
		
			
				|  |  |          $cache->rm('plantask_first_word_'.$val);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    /**
 | 
	
		
			
				|  |  | -     * 发送消息给某人-接口调用
 | 
	
		
			
				|  |  | -     */
 | 
	
		
			
				|  |  | -    public function sendToUser() {
 | 
	
		
			
				|  |  | -        $from_user = '26';// 发送者
 | 
	
		
			
				|  |  | -        $to_user = '32';// 接收者
 | 
	
		
			
				|  |  | -        $message = 'hello许犇';// 接收者
 | 
	
		
			
				|  |  | -        if(!$from_user || !$to_user || !$message) $this->error("参数缺失!");
 | 
	
		
			
				|  |  | -        $this->sendMessageToUser($from_user,$to_user,$message);
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    /**
 | 
	
		
			
				|  |  | -     * 发送消息给某人
 | 
	
		
			
				|  |  | -     */
 | 
	
		
			
				|  |  | -//https://console.tim.qq.com/v4/openim/sendmsg?sdkappid=88888888&identifier=admin&usersig=xxx&random=99999999&contenttype=json
 | 
	
		
			
				|  |  | -    public function sendMessageToUser($from_user,$to_user,$message) {
 | 
	
		
			
				|  |  | -//        $from_user = 54;
 | 
	
		
			
				|  |  | -//        $to_user = 6;
 | 
	
		
			
				|  |  | -//        $message = "sdsd";
 | 
	
		
			
				|  |  | -        $random = rand(10000000,99999999);
 | 
	
		
			
				|  |  | -        $usersig = $this->usersig("administrator");
 | 
	
		
			
				|  |  | -        // 获取配置信息
 | 
	
		
			
				|  |  | -        $config = config("tencent_im");
 | 
	
		
			
				|  |  | -        $url = "https://console.tim.qq.com/v4/openim/sendmsg";
 | 
	
		
			
				|  |  | -        $url .= "?sdkappid=".$config["sdkappid"];
 | 
	
		
			
				|  |  | -        $url .= "&identifier=administrator";
 | 
	
		
			
				|  |  | -        $url .= "&usersig=".$usersig;
 | 
	
		
			
				|  |  | -        $url .= "&random=".$random;
 | 
	
		
			
				|  |  | -        $url .= "&contenttype=json";
 | 
	
		
			
				|  |  | -        $tencentObj = new tencentim($url);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        $data = [];
 | 
	
		
			
				|  |  | -        $data["SyncOtherMachine"] = 1;
 | 
	
		
			
				|  |  | -        $data["From_Account"] = (string)$from_user;
 | 
	
		
			
				|  |  | -        $data["To_Account"] = (string)$to_user;
 | 
	
		
			
				|  |  | -        $data["MsgRandom"] = rand(1000000,9999999);
 | 
	
		
			
				|  |  | -        $data["MsgTimeStamp"] = time();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        $data["MsgBody"][] = [
 | 
	
		
			
				|  |  | -            "MsgType" => "TIMTextElem",
 | 
	
		
			
				|  |  | -            "MsgContent" => [
 | 
	
		
			
				|  |  | -                "Text"=> $message
 | 
	
		
			
				|  |  | -            ],
 | 
	
		
			
				|  |  | -        ];
 | 
	
		
			
				|  |  | -        $tencentObj->toSend($data);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    /**
 | 
	
		
			
				|  |  | -     * 获取usersig签名-具体操作
 | 
	
		
			
				|  |  | -     */
 | 
	
		
			
				|  |  | -    private function usersig($user_id) {
 | 
	
		
			
				|  |  | -        // 获取配置信息
 | 
	
		
			
				|  |  | -        $config = config("tencent_im");
 | 
	
		
			
				|  |  | -        $usersigObj = new getusersig($config["sdkappid"],$config["key"]);
 | 
	
		
			
				|  |  | -        $usersig = $usersigObj->genUserSig($user_id);
 | 
	
		
			
				|  |  | -        return $usersig;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  }
 |