| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239 | 
							- <?php
 
- namespace app\api\controller;
 
- use app\common\controller\Api;
 
- use app\common\service\TenimService;
 
- use think\Request;
 
- use getusersig\getusersig;
 
- use tencentim\tencentim;
 
- use Redis;
 
- use think\Db;
 
- /**
 
-  * 腾讯im接口
 
-  */
 
- class Tenim extends Api
 
- {
 
-     protected $noNeedLogin = ['trtc_callback',"callback",'test','createIMGroup','updateRoomInfo','setImManage','sendMessageToUser','outMemberFromRoom',
 
-         'autoUserLine','getRoomUser','getGroupList','getGroupInfo'];
 
-     protected $noNeedRight = ['*'];
 
-     public function test() {
 
-         $groupinfo = $this->getGroupInfo("112");
 
-         print_r($groupinfo);
 
-         exit;
 
-         // 获取所有派对信息
 
-         $partyList = \app\common\model\Party::field("id,user_id,party_name")->where(["status"=>1])->order("id","asc")->select();
 
-         foreach($partyList as $k => $v) {
 
-             if($k>=140 && $k<180) {
 
-                 $groupinfo = $this->getGroupInfo((string)$v["id"]);
 
-                 print_r($groupinfo);
 
- //                $groupinfo = json_encode($groupinfo);
 
- //                Db::table("hx_aaaa")->insert(["party_id"=>$v["id"],"user_id"=>$v["user_id"],"party_name"=>$v["party_name"],"json"=>$groupinfo]);
 
-             }
 
-         }
 
- exit;
 
- //        $this->success("",$partyList);
 
-     }
 
-     /**
 
-      * 创建im群组
 
-      */
 
-     public function createIMGroup() {
 
-         $random = rand(10000000,99999999);
 
-         $usersig = $this->usersig("administrator");
 
-         // 获取配置信息
 
-         $config = config("tencent_im");
 
-         $url = "https://console.tim.qq.com/v4/group_open_http_svc/create_group";
 
-         $url .= "?sdkappid=".$config["sdkappid"];
 
-         $url .= "&identifier=administrator";
 
-         $url .= "&usersig=".$usersig;
 
-         $url .= "&random==".$random;
 
-         $url .= "&contenttype=json";
 
-         $tencentObj = new tencentim($url);
 
-         // 获取群im信息
 
-         $imInfo = Db::table("hx_aaaa")->where(["party_id"=>112])->select();
 
-         if($imInfo) foreach($imInfo as $k => $v) {
 
- //            if($k>=160 && $k<200) {
 
-                 $grouparr = json_decode($v["json"], true);
 
-                 $grouparr = $grouparr["GroupInfo"][0];
 
-                 $AppDefinedData = $grouparr["AppDefinedData"];
 
-                 $data = [];
 
-                 $data["Owner_Account"] = (string)$v["user_id"];
 
-                 $data["Type"] = "AVChatRoom";
 
-                 $data["GroupId"] = (string)$v["party_id"];
 
-                 $data["Name"] = $this->substr((string)$v["party_name"],0,7);
 
-                 $AppDefinedDataNew = [
 
-                     [
 
-                         "Key" => "roomInfo",
 
-                         "Value" => "sssssss"
 
-                     ],
 
-                     [
 
-                         "Key" => "seat0",
 
-                         "Value" => '{"mute":false,"status":0,"user":""}'
 
-                     ],
 
-                     [
 
-                         "Key" => "seat1",
 
-                         "Value" => $AppDefinedData[2]["Value"]
 
-                     ],
 
-                     [
 
-                         "Key" => "seat2",
 
-                         "Value" => $AppDefinedData[3]["Value"]
 
-                     ],
 
-                     [
 
-                         "Key" => "seat3",
 
-                         "Value" => $AppDefinedData[4]["Value"]
 
-                     ],
 
-                     [
 
-                         "Key" => "seat4",
 
-                         "Value" => $AppDefinedData[5]["Value"]
 
-                     ],
 
-                     [
 
-                         "Key" => "seat5",
 
-                         "Value" => $AppDefinedData[6]["Value"]
 
-                     ],
 
-                     [
 
-                         "Key" => "seat6",
 
-                         "Value" => $AppDefinedData[7]["Value"]
 
-                     ],
 
-                     [
 
-                         "Key" => "seat7",
 
-                         "Value" => $AppDefinedData[8]["Value"]
 
-                     ],
 
-                     [
 
-                         "Key" => "seat8",
 
-                         "Value" => $AppDefinedData[9]["Value"]
 
-                     ]
 
-                 ];
 
-                 $data["AppDefinedData"] = json_encode($AppDefinedDataNew);
 
-                 $groupInfo = $tencentObj->toSend($data);
 
-                 if($groupInfo["ActionStatus"] != 'OK') {
 
-                     echo $v["party_id"];
 
-                     break;
 
-                 }
 
- //            }
 
-         }
 
-         print_r($groupInfo);exit;
 
-     }
 
-     public function substr(string $string, int $start, int $length = null)
 
-     {
 
-         return mb_substr($string, $start, $length, 'UTF-8');
 
-     }
 
-     /**
 
-      * 更新房间信息
 
-      */
 
-     public function updateRoomInfo() {
 
-         $random = rand(10000000, 99999999);
 
-         $usersig = $this->usersig("administrator");
 
-         // 获取配置信息
 
-         $config = config("tencent_im");
 
-         $url = "https://console.tim.qq.com/v4/group_open_http_svc/modify_group_base_info";
 
-         $url .= "?sdkappid=" . $config["sdkappid"];
 
-         $url .= "&identifier=administrator";
 
-         $url .= "&usersig=" . $usersig;
 
-         $url .= "&random=" . $random;
 
-         $url .= "&contenttype=json";
 
-         $tencentObj = new tencentim($url);
 
-         // 获取群im信息
 
-         $imInfo = Db::table("hx_aaaa")->select();
 
-         if($imInfo) foreach($imInfo as $k => $v) {
 
-             if($k>=120 && $k<180) {
 
-                 $grouparr = json_decode($v["json"], true);
 
-                 $groupsites = $grouparr["GroupInfo"];
 
-                 // 循环房间
 
-                 if ($groupsites) foreach ($groupsites as $k => $v) {
 
-                     // 循环座位
 
-                     $data = [];
 
-                     foreach ($v["AppDefinedData"] as $m => $n) {
 
-                         // 解析字段信息
 
-                         $siteInfo = json_decode($n["Value"], true);
 
-                         $data["AppDefinedData"][] = [
 
-                             "Key" => $n["Key"],
 
-                             "Value" => $n["Value"],
 
-                         ];
 
-                     }
 
-                     if (!empty($data)) {
 
-                         $data["GroupId"] = $v["GroupId"];
 
-                         $res = $tencentObj->toSend($data);
 
-                     } else {
 
-                         echo "error!";
 
-                         break;
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         print_r($res);
 
-         exit;
 
-     }
 
-     /**
 
-      * 获取群组信息
 
-      */
 
-     public function getGroupInfo($party_id='0') {
 
-         $party_id = !empty($party_id) ? $party_id : $this->request->param('part_id',0);
 
-         $random = rand(10000000,99999999);
 
-         $usersig = $this->usersig("administrator");
 
-         // 获取配置信息
 
-         $config = config("tencent_im");
 
-         $url = "https://console.tim.qq.com/v4/group_open_http_svc/get_group_info";
 
-         $url .= "?sdkappid=".$config["sdkappid"];
 
-         $url .= "&identifier=administrator";
 
-         $url .= "&usersig=".$usersig;
 
-         $url .= "&random==".$random;
 
-         $url .= "&contenttype=json";
 
-         $tencentObj = new tencentim($url);
 
-         $data = [];
 
-         $data["GroupIdList"] = [(string)$party_id];
 
-         $data["ResponseFilter"] = [
 
-             "GroupBaseInfoFilter" => ["GroupId","Type","Name","FaceUrl","Owner_Account","MemberNum"],
 
-             "MemberInfoFilter" => ["Account","Role"],
 
-             "AppDefinedDataFilter_Group" => ["roomInfo"],
 
-         ];
 
-         $groupInfo = $tencentObj->toSend($data);
 
-         $this->success('获取成功',$groupInfo['GroupInfo']);
 
-     }
 
-     /**
 
-      * 获取所有群组
 
-      */
 
-     public function getGroupList() {
 
-         $random = rand(10000000,99999999);
 
-         $usersig = $this->usersig("administrator");
 
-         // 获取配置信息
 
-         $config = config("tencent_im");
 
-         $url = "https://console.tim.qq.com/v4/group_open_http_svc/get_appid_group_list";
 
-         $url .= "?sdkappid=".$config["sdkappid"];
 
-         $url .= "&identifier=administrator";
 
-         $url .= "&usersig=".$usersig;
 
-         $url .= "&random==".$random;
 
-         $url .= "&contenttype=json";
 
-         $tencentObj = new tencentim($url);
 
-         $data = [];
 
-         $data["Limit"] = 100;//本次获取的群组 ID 数量的上限,不得超过 10000。如果不填,默认为最大值 10000
 
-         $data["GroupType"] = 'AVChatRoom';//群组形态包括 Public(公开群),Private(即 Work,好友工作群),ChatRoom(即 Meeting,会议群),AVChatRoom(音视频聊天室),BChatRoom(在线成员广播大群)和社群(Community)
 
-         $groupList = $tencentObj->toSend($data);
 
-         $result = [];
 
-         if (isset($groupList['ActionStatus']) && $groupList['ActionStatus'] == 'OK') {
 
-             $result = isset($groupList['GroupIdList']) ? $groupList['GroupIdList'] : [];
 
-         }
 
-         $this->success('获取成功',$result);
 
-     }
 
-     /**
 
-      * 获取用户所加入的群组
 
-      */
 
-     public function getJoindGroupList($user_id) {
 
-         $random = rand(10000000,99999999);
 
-         $usersig = $this->usersig("administrator");
 
-         // 获取配置信息
 
-         $config = config("tencent_im");
 
-         $url = "https://console.tim.qq.com/v4/group_open_http_svc/get_joined_group_list";
 
-         $url .= "?sdkappid=".$config["sdkappid"];
 
-         $url .= "&identifier=administrator";
 
-         $url .= "&usersig=".$usersig;
 
-         $url .= "&random=".$random;
 
-         $url .= "&contenttype=json";
 
-         $tencentObj = new tencentim($url);
 
-         $data = [];
 
-         $data["Member_Account"] = $user_id;
 
-         $data["WithHugeGroups"] = 1;
 
-         $data["GroupType"] = 'AVChatRoom';
 
-         $data["ResponseFilter"] = ["GroupBaseInfoFilter" => ['GroupId'] ];
 
-         $groupInfo = $tencentObj->toSend($data);
 
- //        \app\common\model\Test::update(["content"=>json_encode($groupInfo)],["id"=>1]);
 
-         return $groupInfo;
 
-     }
 
- //"https:\/\/console.tim.qq.com\/v4\/group_open_http_svc\/get_joined_group_list?sdkappid=1400458032&identifier=administrator&usersig=eJyrVgrxCdYrSy1SslIy0jNQ0gHzM1NS80oy0zLBwqamUNHilOzEgoLMFCUrQxMDAxNTCwNjI4hMakVBZlEqUNzU1NTIwMAAIlqSmQsSMzO0MDY0NDOwhJqSmQ40NNwowsvMzzXKw8wsLNIwRr9S28giPKjMPSkpKLPcLcfFPd3TO7swz9fXOdLTVqkWADrXLzo_&random=73931990&contenttype=json"
 
- //    /**
 
- //     * 删除群成员
 
- //     */
 
- //    public function delMemberFromGroup($user_id,$party_id) {
 
- //        $random = rand(10000000,99999999);
 
- //        $usersig = $this->usersig($user_id);
 
- //        // 获取配置信息
 
- //        $config = config("tencent_im");
 
- //        $url = "https://console.tim.qq.com/v4/group_open_http_svc/delete_group_member";
 
- //        $url .= "?sdkappid=".$config["sdkappid"];
 
- //        $url .= "&identifier=administrator";
 
- //        $url .= "&usersig=".$usersig;
 
- //        $url .= "&random=".$random;
 
- //        $url .= "&contenttype=json";
 
- //        $tencentObj = new tencentim($url);
 
- //        $data = [];
 
- //        $data["GroupId"] = $party_id;
 
- //        $data["Silence"] = 1;
 
- //        $data["MemberToDel_Account"] = [$user_id];
 
- //        $res = $tencentObj->toSend($data);
 
- //        \app\common\model\Test::update(["content"=>json_encode($res)],["id"=>1]);
 
- //        return $res;
 
- //    }
 
-     /**
 
-      * 设置管理员
 
-      */
 
-     public function setImManage($manage_user_id,$party_id) {
 
- //        $manage_user_id = "2";
 
- //        $party_id = "6";
 
-         $random = rand(10000000,99999999);
 
-         $usersig = $this->usersig("administrator");
 
-         // 获取配置信息
 
-         $config = config("tencent_im");
 
-         $url = "https://console.tim.qq.com/v4/group_open_http_svc/modify_group_base_info";
 
-         $url .= "?sdkappid=".$config["sdkappid"];
 
-         $url .= "&identifier=administrator";
 
-         $url .= "&usersig=".$usersig;
 
-         $url .= "&random=".$random;
 
-         $url .= "&contenttype=json";
 
-         $tencentObj = new tencentim($url);
 
-         // 获取群组信息
 
-         $groupInfo = $this->getGroupInfo($party_id);
 
-         if($groupInfo["GroupInfo"][0]["ErrorCode"] > 0) return false;
 
-         $roomInfoData = $groupInfo["GroupInfo"][0]["AppDefinedData"];
 
-         $roomInfo = [];
 
-         if($roomInfoData) foreach($roomInfoData as $k => $v) {
 
-             if($v["Key"] == "roomInfo") $roomInfo = $v["Value"];
 
-         }
 
-         $roomInfo = json_decode($roomInfo,true);
 
-         // 更新的信息
 
-         if(isset($roomInfo["managers"])) {
 
-             if(!$roomInfo["managers"]) $roomInfo["managers"] = [];
 
-             array_push($roomInfo["managers"],$manage_user_id);
 
-             $roomInfo["managers"] = array_unique($roomInfo["managers"]);
 
-         }
 
-         $data = [];
 
-         $data["GroupId"] = $party_id;
 
-         $data["AppDefinedData"][0] = [
 
-             "Key" => "roomInfo",
 
-             "Value" => json_encode($roomInfo),
 
- //            "Value" => json_encode(json_decode('{"bg":"","cover":"","isScreen":0,"managers":["14","29"],"needRequest":0,"onMode":2,"ownerId":"55","ownerName":"过户手续","pwd":"","roomName":"告白气球~满眼是✨✨","seatSize":9,"silencers":[]}',true)),
 
-         ];
 
-         if(isset($roomInfo["ownerId"]) && isset($roomInfo["roomName"])) {
 
-             $tencentObj->toSend($data);
 
-         }
 
-     }
 
-     /**
 
-      * 强制下线
 
-      */
 
-     public function downSite($user_id,$groupsites) {
 
-         $random = rand(10000000,99999999);
 
-         $usersig = $this->usersig("administrator");
 
-         // 获取配置信息
 
-         $config = config("tencent_im");
 
-         $url = "https://console.tim.qq.com/v4/group_open_http_svc/modify_group_base_info";
 
-         $url .= "?sdkappid=".$config["sdkappid"];
 
-         $url .= "&identifier=administrator";
 
-         $url .= "&usersig=".$usersig;
 
-         $url .= "&random=".$random;
 
-         $url .= "&contenttype=json";
 
-         $tencentObj = new tencentim($url);
 
-         // 先更新下麦时间
 
-         $update = [];
 
-         $update["offsite_time"] = time();
 
-         $update["status"] = 2;
 
-         \app\common\model\UserOnsiteTime::update($update,["user_id"=>$user_id,"status"=>1]);
 
-         // 循环房间
 
-         if($groupsites) foreach($groupsites as $k => $v) {
 
-             // 循环座位
 
-             $data = [];
 
-             foreach($v["AppDefinedData"] as $m => $n) {
 
-                 // 解析字段信息
 
-                 $siteInfo = json_decode($n["Value"],true);
 
-                 if($m != 0 && isset($siteInfo["status"]) && $siteInfo["status"] == 1 && isset($siteInfo["status"]) && $siteInfo["user"] == $user_id) {
 
-                     $data["AppDefinedData"][] = [
 
-                         "Key" => $n["Key"],
 
-                         "Value" => '{"mute":false,"status":0,"user":""}',
 
-                     ];
 
-                 }
 
-             }
 
-             if(!empty($data)) {
 
-                 $data["GroupId"] = $v["GroupId"];
 
-                 return $tencentObj->toSend($data);
 
-             }
 
-         }
 
-     }
 
-     /**
 
-      * 踢出房间内所有用户
 
-      */
 
-     public function outMemberFromRoom($party_id) {
 
-         if($party_id <= 0) return false;
 
-         $message = [];
 
-         $message["type"] = "91";
 
-         $message["content"] = "房间已被管理员关闭!详情请联系客服!";
 
-         $msgData = [];
 
-         $msgData["version"] = "1.0";
 
-         $msgData["action"] = 301;
 
-         $msgData["command"] = "";
 
-         $msgData["message"] = json_encode($message);
 
-         $random = rand(10000000,99999999);
 
-         $usersig = $this->usersig("administrator");
 
-         // 获取配置信息
 
-         $config = config("tencent_im");
 
-         $url = "https://console.tim.qq.com/v4/group_open_http_svc/send_group_msg";
 
-         $url .= "?sdkappid=".$config["sdkappid"];
 
-         $url .= "&identifier=administrator";
 
-         $url .= "&usersig=".$usersig;
 
-         $url .= "&random=".$random;
 
-         $url .= "&contenttype=json";
 
-         $tencentObj = new tencentim($url);
 
-         $data = [];
 
-         $data["GroupId"] = $party_id;
 
-         $data["Random"] = rand(1000000,9999999);
 
-         $data["MsgBody"][] = [
 
-             "MsgType" => "TIMCustomElem",
 
-             "MsgContent" => [
 
-                 "Data"=> json_encode($msgData)
 
-             ],
 
-         ];
 
-         $tencentObj->toSend($data);
 
-     }
 
-     /**
 
-      * 获取usersig签名
 
-      */
 
-     public function getUsersig() {
 
-         $user_id = $this->auth->id;
 
-         $this->success("获取成功!",$this->usersig($user_id));
 
-     }
 
-     /**
 
-      * 获取usersig签名-具体操作
 
-      */
 
-     private function usersig($user_id) {
 
-         // 获取配置信息
 
-         $config = config("tencent_im");
 
-         $usersigObj = new getusersig($config["sdkappid"],$config["key"]);
 
-         $usersig = $usersigObj->genUserSig($user_id);
 
-         return $usersig;
 
-     }
 
-     /**
 
-      * 强制下麦
 
-      */
 
-     public function updateSiteInfo() {
 
-         $user_id = $this->request->request("user_id");// 用户ID
 
-         if(!$user_id) $this->error("参数缺失!");
 
-         // 更新用户在线状态为离线
 
-         \app\common\model\User::update(["is_online"=>0],["id"=>$user_id]);
 
-         \app\common\model\User::update(["is_live"=>0],["id"=>$user_id]);
 
-         \app\common\model\Party::update(["is_online"=>0],["user_id"=>$user_id]);
 
-         // 获取用户所在群信息
 
-         $groupids = $this->getJoindGroupList($user_id);
 
-         if($groupids["ErrorCode"] == 0) {
 
-             $grouplist = $groupids["GroupIdList"];
 
-             $groupsites = [];
 
-             if($grouplist) foreach($grouplist as $k => $v) {
 
-                 // 获取群组消息
 
-                 $groupInfo = $this->getGroupInfo($v["GroupId"]);
 
-                 if($groupInfo["ErrorCode"] == 0) $groupsites[] = $groupInfo["GroupInfo"][0];
 
-                 // 踢出用户在线组
 
-                 $redis = new Redis();
 
-                 $redisconfig = config("redis");
 
-                 $redis->connect($redisconfig["host"], $redisconfig["port"]);
 
-                 if ($redisconfig['redis_pwd']) {
 
-                     $redis->auth($redisconfig['redis_pwd']);
 
-                 }
 
-                 if($redisconfig['redis_selectdb'] > 0){
 
-                     $redis->select($redisconfig['redis_selectdb']);
 
-                 }
 
-                 $redis->HDel("online_".$v["GroupId"],$user_id);
 
-             }
 
-             // 强制下麦
 
-             $this->downSite($user_id,$groupsites);
 
-         }
 
-         $this->success("状态更新成功!");
 
-     }
 
-     /**
 
-      * 更新麦位前四
 
-      */
 
-     public function updatePosition($user_id,$party_id) {
 
-         // 获取用户头像
 
-         $userInfo = \app\common\model\User::field("avatar")->where(["id"=>$user_id])->find();
 
-         $userAvatar = isset($userInfo["avatar"])?$userInfo["avatar"]:"";
 
-         // 更新下麦时间
 
-         $update = [];
 
-         $update["offsite_time"] = time();
 
-         $update["status"] = 2;
 
-         \app\common\model\UserOnsiteTime::update($update,["user_id"=>$user_id,"status"=>1]);
 
-         //
 
-         $redis = new Redis();
 
-         $redisconfig = config("redis");
 
-         $redis->connect($redisconfig["host"], $redisconfig["port"]);
 
-         if ($redisconfig['redis_pwd']) {
 
-             $redis->auth($redisconfig['redis_pwd']);
 
-         }
 
-         if($redisconfig['redis_selectdb'] > 0){
 
-             $redis->select($redisconfig['redis_selectdb']);
 
-         }
 
-         $room_type = Db::name('party')->where('id',$party_id)->value('room_type');
 
-         $redisData = $redis->get($room_type."_".$party_id);
 
-         if(!$redisData){
 
-             return true;
 
-         }
 
-         $partyInfo = json_decode($redisData,true);
 
-         // 遍历已有头像
 
-         $partyuser = isset($partyInfo["party_user"])?$partyInfo["party_user"]:"";
 
-         if(is_array($partyuser)) foreach($partyuser as $k => $v) if($v === $userAvatar) unset($partyInfo["party_user"][$k]);
 
-         $redis->set($room_type."_".$party_id,json_encode($partyInfo));
 
-     }
 
-     /**
 
-      * 取消排麦
 
-      */
 
-     public function cancelLineUp($user_id,$party_id) {
 
-         if (!$party_id || !$user_id) {
 
-             return false;
 
-         }
 
-         $redis = new Redis();
 
-         $redisconfig = config("redis");
 
-         $redis->connect($redisconfig["host"], $redisconfig["port"]);
 
-         if ($redisconfig['redis_pwd']) {
 
-             $redis->auth($redisconfig['redis_pwd']);
 
-         }
 
-         if($redisconfig['redis_selectdb'] > 0){
 
-             $redis->select($redisconfig['redis_selectdb']);
 
-         }
 
-         $data=unserialize($redis->hGet("party_lineup",$party_id));
 
-         // 更改红点排麦数量
 
-         $num = 0;
 
-         $send = false;
 
-         if($data) foreach($data as $k => $v) {
 
-             if($v["user_id"] == $user_id) {
 
-                 $send = true;
 
-                 unset($data[$k]);
 
-                 break;
 
-             }
 
-         }
 
-         $redis->hSet("party_lineup",$party_id,serialize($data));
 
-         if($send) {
 
-             is_array($data) &&  $num = count($data);
 
-             $random = rand(10000000,99999999);
 
-             $usersig = $this->usersig("administrator");
 
-             // 获取配置信息
 
-             $config = config("tencent_im");
 
-             $url = "https://console.tim.qq.com/v4/group_open_http_svc/send_group_msg";
 
-             $url .= "?sdkappid=".$config["sdkappid"];
 
-             $url .= "&identifier=administrator";
 
-             $url .= "&usersig=".$usersig;
 
-             $url .= "&random=".$random;
 
-             $url .= "&contenttype=json";
 
-             $tencentObj = new tencentim($url);
 
-             $data = [];
 
-             $data["GroupId"] = $party_id;
 
-             $data["Random"] = rand(1000000,9999999);
 
-             $message = [
 
-                 "message" => json_encode(["type"=>23,"content"=>$num]),
 
-                 "version" => "1.0",
 
-                 "action" => 301,
 
-                 "command" => ""
 
-             ];
 
-             $data["MsgBody"][] = [
 
-                 "MsgType" => "TIMCustomElem",
 
-                 "MsgContent" => [
 
-                     "Data"=> json_encode($message)
 
-                 ],
 
-             ];
 
-             $tencentObj->toSend($data);
 
-         }
 
-     }
 
-     public function trtc_callback(){
 
-         $input = file_get_contents("php://input");
 
-         //filePut('start:'.$input,'callback.txt');
 
-         /*$input = '{
 
-             "EventGroupId":	1,
 
-             "EventType":	104,
 
-             "CallbackTs":	1640331295244,
 
-             "EventInfo":	{
 
-                 "RoomId":	140,
 
-                 "EventTs":	1640331295,
 
-                 "EventMsTs": 1640331295239,
 
-                 "UserId":	"179",
 
-                 "Role":	21,
 
-                 "Reason":	5
 
-             }
 
-         }';*/
 
-         $input = json_decode($input,true);
 
-         $roomId = $input['EventInfo']['RoomId'];
 
-         //房间事件组
 
-         if($input['EventGroupId'] == 1){
 
-             if($input['EventType'] == 101){
 
-                 //创建房间,第一个进来的
 
-             }elseif($input['EventType'] == 102){
 
-                 //解散房间,最后一个走的
 
-                 //没有UserId
 
-             }elseif($input['EventType'] == 103){
 
-                 //进入房间,主播role=20 观众role=21
 
-                 $redis = new Redis();
 
-                 $redisconfig = config("redis");
 
-                 $redis->connect($redisconfig["host"], $redisconfig["port"]);
 
-                 if ($redisconfig['redis_pwd']) {
 
-                     $redis->auth($redisconfig['redis_pwd']);
 
-                 }
 
-                 if($redisconfig['redis_selectdb'] > 0){
 
-                     $redis->select($redisconfig['redis_selectdb']);
 
-                 }
 
-                 $userId = $input['EventInfo']['UserId'];
 
-                 $redis->hSet("online_" . $roomId, $userId, $userId);
 
-                 $redis->zAdd("party_user_".$roomId,$userId,0); //新加的
 
-                 // 记录在线用户在房间情况
 
-                 $redis->hSet("livingUser",$userId,$roomId);
 
-                 // 更新房间在线状态
 
-                 $partyInfo = $redis->get("party_" . $roomId);
 
-                 if ($partyInfo) {
 
-                     $partyInfo = json_decode($partyInfo, true);
 
-                     if ($partyInfo["is_online"] != 1) {
 
-                         $partyInfo["is_online"] = 1;
 
-                         $redis->set("party_" . $roomId, json_encode($partyInfo));
 
-                         \app\common\model\Party::update(["is_online" => 1], ["id" => $roomId]);
 
-                     }
 
-                 }
 
-                 // 更新房间在线状态
 
-                 $liveInfo = $redis->get("live_" . $roomId);
 
-                 if ($liveInfo) {
 
-                     $liveInfo = json_decode($liveInfo, true);
 
-                     if ($input['EventInfo']['Role'] == 20) {
 
-                         $liveInfo["is_online"] = 1;
 
-                         $redis->set("live_" . $roomId, json_encode($liveInfo));
 
-                         \app\common\model\Party::update(["is_online" => 1], ["id" => $roomId]);
 
-                         $rs_user = Db::name('user')->where('id',$userId)->update(['is_live'=>1]);
 
-                     }
 
-                 }
 
-             }elseif($input['EventType'] == 104){
 
-                 //退出房间,主播role=20 观众role=21
 
-                 $redis = new Redis();
 
-                 $redisconfig = config("redis");
 
-                 $redis->connect($redisconfig["host"], $redisconfig["port"]);
 
-                 if ($redisconfig['redis_pwd']) {
 
-                     $redis->auth($redisconfig['redis_pwd']);
 
-                 }
 
-                 if($redisconfig['redis_selectdb'] > 0){
 
-                     $redis->select($redisconfig['redis_selectdb']);
 
-                 }
 
-                 $userId = $input['EventInfo']['UserId'];
 
-                 $redis->HDel("online_" . $roomId, $userId);
 
-                 $redis->zRem("party_user_".$roomId,$userId); //新加的
 
-                 // 扣除在线用户在房间情况
 
-                 $redis->hDel("livingUser",$userId);
 
-                 // 更新房间在线状态
 
-                 $partyInfo = $redis->get("party_" . $roomId);
 
-                 if ($partyInfo) {
 
-                     $partyInfo = json_decode($partyInfo, true);
 
-                     $memCount = count($redis->hGetAll("online_" . $roomId));
 
-                     if ($memCount <= 0) {
 
-                         $partyInfo["is_online"] = 0;
 
-                         $redis->set("party_" . $roomId, json_encode($partyInfo));
 
-                         \app\common\model\Party::update(["is_online" => 0], ["id" => $roomId]);
 
-                     }
 
-                 }
 
-                 //
 
-                 $liveInfo = $redis->get("live_" . $roomId);
 
-                 if ($liveInfo) {
 
-                     $liveInfo = json_decode($liveInfo, true);
 
-                     if($input['EventInfo']['Role'] == 20){
 
-                         $liveInfo["is_online"] = 0;
 
-                         $redis->set("live_" . $roomId, json_encode($liveInfo));
 
-                         \app\common\model\Party::update(["is_online" => 0], ["id" => $roomId]);
 
-                         $rs_user = Db::name('user')->where('id',$userId)->update(['is_live'=>0]);
 
-                     }
 
-                 }
 
-                 //退出房间获取房间自定义属性
 
-                 $tenimService = new TenimService();
 
-                 $imParams = ['party_id' => (string)$roomId];
 
-                 $imRes = $tenimService->getGroupAttr($imParams);
 
-                 if ($imRes['status'] == 1) {
 
-                     if (isset($imRes['data']) && !empty($imRes['data'])) {
 
-                         $imFieldArr = ['seat0','seat1','seat2','seat3','seat4','seat5','seat6','seat7','seat8','seat9'];
 
-                         foreach ($imRes['data'] as $imKey => &$imVal) {
 
-                             if (in_array($imVal['key'],$imFieldArr)) {
 
-                                 $tempData = json_decode($imVal['value'],true);
 
-                                 if (isset($tempData['user'])) {
 
-                                     if ($tempData['user'] == $userId) {//找到用户清理麦序
 
-                                         $tempData['status'] = 0;
 
-                                         $tempData['user'] = "";
 
-                                     } else {
 
-                                         if (empty($tempData['user']) && $tempData['status'] == 1) {
 
-                                             $tempData['status'] = 0;
 
-                                         }
 
-                                     }
 
-                                 }
 
-                                 $imVal['value'] = json_encode($tempData);
 
-                             }
 
-                         }
 
-                         $imAttrParams = [
 
-                             'party_id' => $roomId,
 
-                             'party_attr' => $imRes['data'],
 
-                         ];
 
-                         $tenimService->getGroupAttrEdit($imAttrParams);
 
-                     }
 
-                 }
 
-             }
 
-         }elseif($input['EventGroupId'] == 2){
 
-         }
 
-         //结束
 
-         echo json_encode(['code' => 0]);exit;
 
-     }
 
-     /**
 
-      * 回调
 
-      */
 
-     public function callback() {
 
-         $input = file_get_contents("php://input"); // 主题信息
 
-         $input = json_decode($input,true);
 
-         $CallbackCommand = $input["CallbackCommand"];
 
-         switch ($CallbackCommand) {
 
-             case 'State.StateChange': // 用户在线状态变更
 
-                 $info = $input["Info"];
 
-                 if($info["Action"] == "Login") { // 用户登录
 
-                     $loginToday = Db::name('user')->where('id',$info["To_Account"])->whereTime('onlinetime', 'today')->find();
 
-                     if ($loginToday){
 
-                         \app\common\model\User::update(["is_online"=>1,"onlinetime"=>time()],["id"=>$info["To_Account"]]);
 
-                     }else{
 
-                         \app\common\model\User::update(["is_online"=>1,"onlinetime"=>time()],["id"=>$info["To_Account"]]);
 
-                     }
 
-                     $res = [];
 
-                     $res["ActionStatus"] = "OK";
 
-                     $res["ErrorCode"] = 0;
 
-                     $res["ErrorInfo"] = "";
 
-                     echo json_encode($res);exit;
 
-                 } elseif($info["Action"] == "Logout" || $info["Action"] == "Disconnect") { // 用户退出 不需要管什么原因
 
-                     // 更新用户在线状态为离线
 
-                     \app\common\model\User::update(["is_online"=>0],["id"=>$info["To_Account"]]);
 
-                     \app\common\model\User::update(["is_live"=>0],["id"=>$info["To_Account"]]);
 
-                     // 获取用户在派对直播间情况信息
 
-                     $redis = new Redis();
 
-                     $redisconfig = config("redis");
 
-                     $redis->connect($redisconfig["host"], $redisconfig["port"]);
 
-                     if ($redisconfig['redis_pwd']) {
 
-                         $redis->auth($redisconfig['redis_pwd']);
 
-                     }
 
-                     if($redisconfig['redis_selectdb'] > 0){
 
-                         $redis->select($redisconfig['redis_selectdb']);
 
-                     }
 
-                     $livingUserPartyId = $redis->hGet("livingUser", $info["To_Account"]);
 
-                     if ($livingUserPartyId) {
 
-                         // 扣除在线用户在房间情况
 
-                         $redis->hDel("livingUser", $info["To_Account"]);
 
-                         $redis->HDel("online_" . $livingUserPartyId, $info["To_Account"]);
 
-                         $redis->zRem("party_user_".$livingUserPartyId,$info["To_Account"]); //新加的
 
-                     }
 
-                     // 获取用户所在群信息
 
-                     $groupids = $this->getJoindGroupList($info["To_Account"]);
 
- //                    \app\common\model\Test::update(["content"=>json_encode($groupids)],["id"=>1]);
 
-                     if($groupids["ErrorCode"] == 0) {
 
-                         $grouplist = $groupids["GroupIdList"];
 
-                         $groupsites = [];
 
-                         if($grouplist) foreach($grouplist as $k => $v) {
 
-                             // 获取群组消息
 
-                             $groupInfo = $this->getGroupInfo($v["GroupId"]);
 
-                             if($groupInfo["ErrorCode"] == 0) $groupsites[] = $groupInfo["GroupInfo"][0];
 
-                             // 踢出用户在线组
 
-                             $redis = new Redis();
 
-                             $redisconfig = config("redis");
 
-                             $redis->connect($redisconfig["host"], $redisconfig["port"]);
 
-                             if ($redisconfig['redis_pwd']) {
 
-                                 $redis->auth($redisconfig['redis_pwd']);
 
-                             }
 
-                             if($redisconfig['redis_selectdb'] > 0){
 
-                                 $redis->select($redisconfig['redis_selectdb']);
 
-                             }
 
-                             $redis->HDel("online_".$v["GroupId"],$info["To_Account"]);
 
-                             $redis->zRem("party_user_".$v["GroupId"],$info["To_Account"]); //新加的
 
-                             // 更新麦位前四
 
-                             $this->updatePosition($info["To_Account"],$v["GroupId"]);
 
-                             // 取消排麦
 
-                             $this->cancelLineup($info["To_Account"],$v["GroupId"]);
 
-                             // 房间状态变更
 
-                             $partyInfo = $redis->get("party_".$v["GroupId"]);
 
-                             if($partyInfo) {
 
-                                 $partyInfo = json_decode($partyInfo,true);
 
-                                 $memCount = count($redis->hGetAll("online_".$v["GroupId"]));
 
-                                 if($memCount <= 0) {
 
-                                     $partyInfo["is_online"] = 0;
 
-                                     $redis->set("party_".$v["GroupId"],json_encode($partyInfo));
 
-                                     \app\common\model\Party::update(["is_online"=>0],["id"=>$v["GroupId"]]);
 
-                                 }
 
-                             }
 
-                             $liveInfo = $redis->get("live_".$v["GroupId"]);
 
-                             if($liveInfo) {
 
-                                 $liveInfo = json_decode($liveInfo,true);
 
-                                 $memCount = count($redis->hGetAll("online_".$v["GroupId"]));
 
-                                 if($memCount <= 0) {
 
-                                     $liveInfo["is_online"] = 0;
 
-                                     $redis->set("live_".$v["GroupId"],json_encode($liveInfo));
 
-                                     \app\common\model\Party::update(["is_online"=>0],["id"=>$v["GroupId"]]);
 
-                                 }
 
-                             }
 
-                         }
 
-                         // 强制下麦
 
-                         print_r($this->downSite($info["To_Account"],$groupsites));
 
-                     }
 
-                 }
 
-                 break;
 
-             /*case 'Group.CallbackAfterNewMemberJoin': // 新成员入群
 
-                 $redis = new Redis();
 
-                 $redisconfig = config("redis");
 
-                 $redis->connect($redisconfig["host"], $redisconfig["port"]);
 
-                 if ($redisconfig['redis_pwd']) {
 
-                     $redis->auth($redisconfig['redis_pwd']);
 
-                 }
 
-                 if($redisconfig['redis_selectdb'] > 0){
 
-                     $redis->select($redisconfig['redis_selectdb']);
 
-                 }
 
-                 $members = $input["NewMemberList"];
 
-                 if($members) foreach($members as $k => $v) {
 
-                     $redis->hSet("online_".$input["GroupId"],$v["Member_Account"],$v["Member_Account"]);
 
-                     // 更新房间在线状态
 
-                     $party_id = $input["GroupId"];
 
-                     $partyInfo = $redis->get("party_".$party_id);
 
-                     if($partyInfo) {
 
-                         $partyInfo = json_decode($partyInfo,true);
 
-                         if($partyInfo["is_online"] != 1) {
 
-                             $partyInfo["is_online"] = 1;
 
-                             $redis->set("party_".$party_id,json_encode($partyInfo));
 
-                             \app\common\model\Party::update(["is_online"=>1],["id"=>$party_id]);
 
-                         }
 
-                     }
 
-                 }
 
-                 $res = [];
 
-                 $res["ActionStatus"] = "OK";
 
-                 $res["ErrorCode"] = 0;
 
-                 $res["ErrorInfo"] = "";
 
-                 echo json_encode($res);
 
-                 break;*/
 
-             /*case 'Group.CallbackAfterMemberExit': // 成员离开
 
-                 $redis = new Redis();
 
-                 $redisconfig = config("redis");
 
-                 $redis->connect($redisconfig["host"], $redisconfig["port"]);
 
-                 if ($redisconfig['redis_pwd']) {
 
-                     $redis->auth($redisconfig['redis_pwd']);
 
-                 }
 
-                 if($redisconfig['redis_selectdb'] > 0){
 
-                     $redis->select($redisconfig['redis_selectdb']);
 
-                 }
 
-                 $members = $input["ExitMemberList"];
 
-                 if($members) foreach($members as $k => $v) {
 
-                     $redis->HDel("online_".$input["GroupId"],$v["Member_Account"]);
 
-                 }
 
-                 // 更新房间在线状态
 
-                 $party_id = $input["GroupId"];
 
-                 $partyInfo = $redis->get("party_".$party_id);
 
-                 if($partyInfo) {
 
-                     $partyInfo = json_decode($partyInfo,true);
 
-                     $memCount = count($redis->hGetAll("online_".$party_id));
 
-                     if($memCount <= 0) {
 
-                         $partyInfo["is_online"] = 0;
 
-                         $redis->set("party_".$party_id,json_encode($partyInfo));
 
-                         \app\common\model\Party::update(["is_online"=>0],["id"=>$party_id]);
 
-                     }
 
-                 }
 
-                 $liveInfo = $redis->get("live_".$party_id);
 
-                 if($liveInfo) {
 
-                     $liveInfo = json_decode($liveInfo,true);
 
-                     $memCount = count($redis->hGetAll("online_".$party_id));
 
-                     if($memCount <= 0) {
 
-                         $liveInfo["is_online"] = 0;
 
-                         $redis->set("live_".$party_id,json_encode($liveInfo));
 
-                         \app\common\model\Party::update(["is_online"=>0],["id"=>$party_id]);
 
-                     }
 
-                 }
 
-                 $res = [];
 
-                 $res["ActionStatus"] = "OK";
 
-                 $res["ErrorCode"] = 0;
 
-                 $res["ErrorInfo"] = "";
 
-                 echo json_encode($res);
 
-                 break;*/
 
-            /* case 'Group.CallbackBeforeSendMsg': // 群内发送消息之前
 
-                 $config = config("wxMiniProgram");
 
-                 $access_token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$config["appid"]."&secret=".$config["secret"];
 
-                 $access_token_arr = $this->getJson($access_token_url);
 
-                 $access_token = isset($access_token_arr["access_token"])?$access_token_arr["access_token"]:"";
 
-                 if(!$access_token) {
 
-                     $res = [];
 
-                     $res["ActionStatus"] = "OK";
 
-                     $res["ErrorInfo"] = "";
 
-                     $res["ErrorCode"] = 0;
 
-                     echo json_encode($res);
 
-                     break;
 
-                 }
 
- //                \app\common\model\Test::update(["content"=>json_encode($access_token)],["id"=>1]);
 
-                 $infoMessage = $input["MsgBody"];
 
-                 $badMessage = false;
 
-                 if($infoMessage) foreach($infoMessage as $k => $v) {
 
-                     if(isset($v["MsgContent"]["Text"])) {
 
-                         $message = json_decode($v["MsgContent"]["Text"],true);
 
-                         $content = isset($message["content"])?$message["content"]:"";
 
-                         $message_check_url ='https://api.weixin.qq.com/wxa/msg_sec_check?access_token='.$access_token;
 
-                         $tencentObj = new tencentim($message_check_url);
 
-                         $content_json = '{"content": "'.$content.'"}';
 
-                         $body = $tencentObj->messageCheck($content_json);
 
-                         if($body["errcode"] == 87014) {
 
- //                        \app\common\model\Test::update(["content"=>$body["errcode"]],["id"=>1]);
 
- //                        $res = [];
 
- //                        $res["ActionStatus"] = "OK";
 
- //                        $res["ErrorInfo"] = "检测到敏感词汇!";
 
- //                        $res["ErrorCode"] = 1;
 
- //                        echo json_encode($res);exit;
 
-                             $message["content"] = "*******";
 
-                             $infoMessage[$k]["MsgContent"]["Text"] = json_encode($message);
 
-                             $badMessage = true;
 
-                         }
 
-                     }
 
-                 }
 
-                 if($badMessage) {
 
-                     $res = [];
 
-                     $res["ActionStatus"] = "OK";
 
-                     $res["ErrorInfo"] = "检测到敏感词汇!";
 
-                     $res["ErrorCode"] = 10102;
 
-                     $res["MsgBody"] = $infoMessage;
 
-                 } else {
 
-                     $res = [];
 
-                     $res["ActionStatus"] = "OK";
 
-                     $res["ErrorInfo"] = "";
 
-                     $res["ErrorCode"] = 0;
 
-                 }
 
- //                \app\common\model\Test::update(["content"=>json_encode($res)],["id"=>1]);
 
-                 echo json_encode($res);exit;
 
-                 break;*/
 
-             default:
 
-                 break;
 
-         }
 
-         exit;
 
-     }
 
-     private function getJson($url){
 
-         $ch = curl_init();
 
-         curl_setopt($ch, CURLOPT_URL, $url);
 
-         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
 
-         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
 
-         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
-         $output = curl_exec($ch);
 
-         curl_close($ch);
 
-         return json_decode($output, true);
 
-     }
 
-     /**
 
-      * 发送消息给某人
 
-      */
 
-     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);
 
-     }
 
-     /**
 
-      * 发送消息给某人-接口调用
 
-      */
 
-     public function sendToUser() {
 
-         $from_user = $this->request->request("from_user");// 发送者
 
-         $to_user = $this->request->request("to_user");// 接收者
 
-         $message = $this->request->request("message");// 接收者
 
-         if(!$from_user || !$to_user || !$message) $this->error("参数缺失!");
 
-         $this->sendMessageToUser($from_user,$to_user,$message);
 
-     }
 
-     //请求的基础参数
 
-     private function baseTencentObj($url)
 
-     {
 
-         $random = rand(10000000,99999999);
 
-         $usersig = $this->usersig("administrator");
 
-         // 获取配置信息
 
-         $config = config("tencent_im");
 
-         $url = "$url";
 
-         $url .= "?sdkappid=".$config["sdkappid"];
 
-         $url .= "&identifier=administrator";
 
-         $url .= "&usersig=".$usersig;
 
-         $url .= "&random=".$random;
 
-         $url .= "&contenttype=json";
 
-         return new tencentim($url);
 
-     }
 
-     /** 设置管理员(im端的改变)
 
-      * @param $user_id
 
-      * @param $party_id
 
-      * @param int $status 1:yes 0:no
 
-      * @return array|false|mixed
 
-      */
 
-     public function setUpIMAdmin($user_id, $party_id, int $status=0) {
 
-         $url = "https://console.tim.qq.com/v4/group_open_http_svc/modify_group_member_info";
 
-         $tencentObj = $this->baseTencentObj($url);
 
-         $groupInfo = $this->getGroupInfo($party_id);
 
-         if($groupInfo["GroupInfo"][0]["ErrorCode"] > 0) return false;
 
-         // 更新的信息
 
-         $data = [];
 
-         $data["GroupId"] = $party_id;
 
-         if ($status==1){
 
-             $data['Role'] = 'Admin';
 
-         }else{
 
-             $data['Role'] = 'Member';
 
-         }
 
-         $data['Member_Account'] = $user_id;
 
-         return $tencentObj->toSend($data);
 
-     }
 
-     //获取群成员详细资料(目前没用到)
 
-     private function getGroupMemberDetails($party_id)
 
-     {
 
-         $url = "https://console.tim.qq.com/v4/group_open_http_svc/get_group_member_info";
 
-         $tencentObj = $this->baseTencentObj($url);
 
-         // 获取群组信息
 
-         $groupInfo = $this->getGroupInfo($party_id);
 
-         if($groupInfo["GroupInfo"][0]["ErrorCode"] > 0) return false;
 
-         // 更新的信息
 
-         $data = [];
 
-         $data["GroupId"] = $party_id;
 
-         return  $tencentObj->toSend($data);
 
-     }
 
-     //IM管理员维护,同步本地管理员
 
-     public function imAdminMaintenance()
 
-     {
 
-         $partyIds = \app\admin\model\party\Party::column('id');
 
-         foreach ($partyIds as $party_id){
 
-             $groupInfo = $this->getGroupInfo($party_id);
 
-             if($groupInfo["GroupInfo"][0]["ErrorCode"] > 0) continue;
 
-             $roomInfoData = $groupInfo["GroupInfo"][0]["AppDefinedData"];
 
-             $roomInfo = [];
 
-             if($roomInfoData) foreach($roomInfoData as $k => $v) {
 
-                 if($v["Key"] == "roomInfo") $roomInfo = $v["Value"];
 
-             }
 
-             $roomInfo = json_decode($roomInfo,true);
 
-             // 更新管理员
 
-             if(isset($roomInfo["managers"]) && !empty($roomInfo['managers'])) {
 
-                 foreach ($roomInfo['managers'] as $v){
 
-                     $this->setUpIMAdmin($v,$party_id,1);
 
-                 }
 
-             }
 
-         }
 
-         $this->success("成功!");
 
-     }
 
-     /**
 
-      * 获取用户在线更新
 
-      */
 
-     public function autoUserLine() {
 
-         $random = rand(10000000,99999999);
 
-         $usersig = $this->usersig("administrator");
 
-         // 获取配置信息
 
-         $config = config("tencent_im");
 
-         $url = "https://console.tim.qq.com/v4/openim/query_online_status";
 
-         $url .= "?sdkappid=".$config["sdkappid"];
 
-         $url .= "&identifier=administrator";
 
-         $url .= "&usersig=".$usersig;
 
-         $url .= "&random=".$random;
 
-         $url .= "&contenttype=json";
 
-         $tencentObj = new tencentim($url);
 
-         // 获取用户
 
-         $where = [];
 
-         $userData = model('User')->field('id')->where($where)->order('id asc')->select();
 
-         $userArr = array_column($userData,'id');
 
-         $data = [];
 
-         $data["To_Account"] = $userArr;
 
-         $result = [];
 
-         if(!empty($data)) {
 
-             $result = $tencentObj->toSend($data);
 
-             if (isset($result['ActionStatus']) && $result['ActionStatus'] == 'OK') {
 
-                 if (isset($result['ErrorList'])) {//没有人员
 
-                     unset($result['ErrorList']);
 
-                     /*foreach ($result['ErrorList'] as $errKey => $errVal) {
 
-                         $userError[] = $errVal['To_Account'];
 
-                     }*/
 
-                 }
 
-                 if (isset($result['QueryResult'])) {
 
-                     $userOnline = $userOffline=[];
 
-                     foreach ($result['QueryResult'] as $key => $value) {
 
-                         if (in_array($value['Status'],['Online','PushOnline'])) {//在线(前台在线和后台在线)
 
-                             $userOnline[] = intval($value['To_Account']);
 
-                         } else {//离线
 
-                             $userOffline[] = intval($value['To_Account']);
 
-                         }
 
-                     }
 
-                     if (!empty($userOnline)) {//处理在线
 
-                         $onlineWhere['id'] = ['in',$userOnline];
 
-                         $onlineWhere['is_online'] = 0;
 
-                         model('User')->where($onlineWhere)->update(['is_online'=>1]);
 
-                     }
 
-                     if (!empty($userOffline)) {//处理离线
 
-                         $offlineWhere['id'] = ['in',$userOffline];
 
-                         $offlineWhere['is_online'] = 1;
 
-                         model('User')->where($offlineWhere)->update(['is_online'=>0]);
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         $this->success('操作成功');
 
-     }
 
-     /**
 
-      * 获取房间用户
 
-      */
 
-     public function getRoomUser() {
 
-         $partyIds = $this->request->param('party_ids','');
 
-         if (!empty($partyIds)) {
 
-             $partyIds = explode(',',$partyIds);
 
-         }
 
-         $random = rand(10000000,99999999);
 
-         $usersig = $this->usersig("administrator");
 
-         // 获取配置信息
 
-         $config = config("tencent_im");
 
-         $url = "https://console.tim.qq.com/v4/group_open_avchatroom_http_svc/get_members";
 
-         $url .= "?sdkappid=".$config["sdkappid"];
 
-         $url .= "&identifier=administrator";
 
-         $url .= "&usersig=".$usersig;
 
-         $url .= "&random=".$random;
 
-         $url .= "&contenttype=json";
 
-         $tencentObj = new tencentim($url);
 
-         //获取用户 ["57","62","63","105","106","107","108","109","116","119"]
 
-         $partyArr = $partyIds;
 
-         $memberList = [];
 
-         if(!empty($partyArr)) {
 
-             foreach ($partyArr as $key => $value) {
 
-                 $data["GroupId"] = $value;
 
-                 $result = $tencentObj->toSend($data);
 
-                 if (isset($result['ActionStatus']) && $result['ActionStatus'] == 'OK') {
 
-                     if (isset($result['MemberList']) && !empty($result['MemberList'])) {
 
-                         foreach ($result['MemberList'] as $ukey => $uval) {
 
-                             $memberList[$value]['member_list'][] = [
 
-                                 'avatar' => $uval['Avatar'],
 
-                                 'user_id'=> $uval['Member_Account'],
 
-                                 'nickname' => $uval['NickName'],
 
-                             ];
 
-                         }
 
-                         $memberList[$value]['online_num'] = count($memberList[$value]['member_list']);
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         $result = $memberList;
 
-         $this->success('操作成功',$result);
 
-     }
 
-     /**
 
-      * 获取房间用户
 
-      */
 
-     public function getGroupAttr() {
 
-         $partyId = $this->request->param('party_id','');
 
-         if (!empty($partyIds)) {
 
-             $this->error('参数错误');
 
-         }
 
-         $random = rand(10000000,99999999);
 
-         $usersig = $this->usersig("administrator");
 
-         // 获取配置信息
 
-         $config = config("tencent_im");
 
-         $url = "https://console.tim.qq.com/v4/group_open_attr_http_svc/get_group_attr";
 
-         $url .= "?sdkappid=".$config["sdkappid"];
 
-         $url .= "&identifier=administrator";
 
-         $url .= "&usersig=".$usersig;
 
-         $url .= "&random=".$random;
 
-         $url .= "&contenttype=json";
 
-         $tencentObj = new tencentim($url);
 
-         $result = [];
 
-         if(!empty($partyId)) {
 
-             $data["GroupId"] = $partyId;
 
-             $result = $tencentObj->toSend($data);
 
-         }
 
-         $this->success('操作成功',$result);
 
-     }
 
- }
 
 
  |