Tenim.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Request;
  5. use getusersig\getusersig;
  6. use tencentim\tencentim;
  7. use Redis;
  8. use think\Db;
  9. /**
  10. * 腾讯im接口
  11. */
  12. class Tenim extends Api
  13. {
  14. protected $noNeedLogin = ['trtc_callback',"callback",'test','createIMGroup','updateRoomInfo','setImManage','sendMessageToUser','outMemberFromRoom',
  15. 'autoUserLine','getRoomUser','getGroupList','getGroupInfo'];
  16. protected $noNeedRight = ['*'];
  17. public function test() {
  18. $groupinfo = $this->getGroupInfo("112");
  19. print_r($groupinfo);
  20. exit;
  21. // 获取所有派对信息
  22. $partyList = \app\common\model\Party::field("id,user_id,party_name")->where(["status"=>1])->order("id","asc")->select();
  23. foreach($partyList as $k => $v) {
  24. if($k>=140 && $k<180) {
  25. $groupinfo = $this->getGroupInfo((string)$v["id"]);
  26. print_r($groupinfo);
  27. // $groupinfo = json_encode($groupinfo);
  28. // Db::table("hx_aaaa")->insert(["party_id"=>$v["id"],"user_id"=>$v["user_id"],"party_name"=>$v["party_name"],"json"=>$groupinfo]);
  29. }
  30. }
  31. exit;
  32. // $this->success("",$partyList);
  33. }
  34. /**
  35. * 创建im群组
  36. */
  37. public function createIMGroup() {
  38. $random = rand(10000000,99999999);
  39. $usersig = $this->usersig("administrator");
  40. // 获取配置信息
  41. $config = config("tencent_im");
  42. $url = "https://console.tim.qq.com/v4/group_open_http_svc/create_group";
  43. $url .= "?sdkappid=".$config["sdkappid"];
  44. $url .= "&identifier=administrator";
  45. $url .= "&usersig=".$usersig;
  46. $url .= "&random==".$random;
  47. $url .= "&contenttype=json";
  48. $tencentObj = new tencentim($url);
  49. // 获取群im信息
  50. $imInfo = Db::table("hx_aaaa")->where(["party_id"=>112])->select();
  51. if($imInfo) foreach($imInfo as $k => $v) {
  52. // if($k>=160 && $k<200) {
  53. $grouparr = json_decode($v["json"], true);
  54. $grouparr = $grouparr["GroupInfo"][0];
  55. $AppDefinedData = $grouparr["AppDefinedData"];
  56. $data = [];
  57. $data["Owner_Account"] = (string)$v["user_id"];
  58. $data["Type"] = "AVChatRoom";
  59. $data["GroupId"] = (string)$v["party_id"];
  60. $data["Name"] = $this->substr((string)$v["party_name"],0,7);
  61. $AppDefinedDataNew = [
  62. [
  63. "Key" => "roomInfo",
  64. "Value" => "sssssss"
  65. ],
  66. [
  67. "Key" => "seat0",
  68. "Value" => '{"mute":false,"status":0,"user":""}'
  69. ],
  70. [
  71. "Key" => "seat1",
  72. "Value" => $AppDefinedData[2]["Value"]
  73. ],
  74. [
  75. "Key" => "seat2",
  76. "Value" => $AppDefinedData[3]["Value"]
  77. ],
  78. [
  79. "Key" => "seat3",
  80. "Value" => $AppDefinedData[4]["Value"]
  81. ],
  82. [
  83. "Key" => "seat4",
  84. "Value" => $AppDefinedData[5]["Value"]
  85. ],
  86. [
  87. "Key" => "seat5",
  88. "Value" => $AppDefinedData[6]["Value"]
  89. ],
  90. [
  91. "Key" => "seat6",
  92. "Value" => $AppDefinedData[7]["Value"]
  93. ],
  94. [
  95. "Key" => "seat7",
  96. "Value" => $AppDefinedData[8]["Value"]
  97. ],
  98. [
  99. "Key" => "seat8",
  100. "Value" => $AppDefinedData[9]["Value"]
  101. ]
  102. ];
  103. $data["AppDefinedData"] = json_encode($AppDefinedDataNew);
  104. $groupInfo = $tencentObj->toSend($data);
  105. if($groupInfo["ActionStatus"] != 'OK') {
  106. echo $v["party_id"];
  107. break;
  108. }
  109. // }
  110. }
  111. print_r($groupInfo);exit;
  112. }
  113. public function substr(string $string, int $start, int $length = null)
  114. {
  115. return mb_substr($string, $start, $length, 'UTF-8');
  116. }
  117. /**
  118. * 更新房间信息
  119. */
  120. public function updateRoomInfo() {
  121. $random = rand(10000000, 99999999);
  122. $usersig = $this->usersig("administrator");
  123. // 获取配置信息
  124. $config = config("tencent_im");
  125. $url = "https://console.tim.qq.com/v4/group_open_http_svc/modify_group_base_info";
  126. $url .= "?sdkappid=" . $config["sdkappid"];
  127. $url .= "&identifier=administrator";
  128. $url .= "&usersig=" . $usersig;
  129. $url .= "&random=" . $random;
  130. $url .= "&contenttype=json";
  131. $tencentObj = new tencentim($url);
  132. // 获取群im信息
  133. $imInfo = Db::table("hx_aaaa")->select();
  134. if($imInfo) foreach($imInfo as $k => $v) {
  135. if($k>=120 && $k<180) {
  136. $grouparr = json_decode($v["json"], true);
  137. $groupsites = $grouparr["GroupInfo"];
  138. // 循环房间
  139. if ($groupsites) foreach ($groupsites as $k => $v) {
  140. // 循环座位
  141. $data = [];
  142. foreach ($v["AppDefinedData"] as $m => $n) {
  143. // 解析字段信息
  144. $siteInfo = json_decode($n["Value"], true);
  145. $data["AppDefinedData"][] = [
  146. "Key" => $n["Key"],
  147. "Value" => $n["Value"],
  148. ];
  149. }
  150. if (!empty($data)) {
  151. $data["GroupId"] = $v["GroupId"];
  152. $res = $tencentObj->toSend($data);
  153. } else {
  154. echo "error!";
  155. break;
  156. }
  157. }
  158. }
  159. }
  160. print_r($res);
  161. exit;
  162. }
  163. /**
  164. * 获取群组信息
  165. */
  166. public function getGroupInfo($party_id='0') {
  167. $party_id = !empty($party_id) ? $party_id : $this->request->param('part_id',0);
  168. $random = rand(10000000,99999999);
  169. $usersig = $this->usersig("administrator");
  170. // 获取配置信息
  171. $config = config("tencent_im");
  172. $url = "https://console.tim.qq.com/v4/group_open_http_svc/get_group_info";
  173. $url .= "?sdkappid=".$config["sdkappid"];
  174. $url .= "&identifier=administrator";
  175. $url .= "&usersig=".$usersig;
  176. $url .= "&random==".$random;
  177. $url .= "&contenttype=json";
  178. $tencentObj = new tencentim($url);
  179. $data = [];
  180. $data["GroupIdList"] = [$party_id];
  181. $data["ResponseFilter"] = [
  182. "GroupBaseInfoFilter" => ["GroupId","Type","Name","FaceUrl","Owner_Account","MemberNum"],
  183. "MemberInfoFilter" => ["Account","Role"],
  184. "AppDefinedDataFilter_Group" => ["roomInfo"],
  185. ];
  186. $groupInfo = $tencentObj->toSend($data);
  187. $this->success('获取成功',$groupInfo['GroupInfo']);
  188. }
  189. /**
  190. * 获取所有群组
  191. */
  192. public function getGroupList() {
  193. $random = rand(10000000,99999999);
  194. $usersig = $this->usersig("administrator");
  195. // 获取配置信息
  196. $config = config("tencent_im");
  197. $url = "https://console.tim.qq.com/v4/group_open_http_svc/get_appid_group_list";
  198. $url .= "?sdkappid=".$config["sdkappid"];
  199. $url .= "&identifier=administrator";
  200. $url .= "&usersig=".$usersig;
  201. $url .= "&random==".$random;
  202. $url .= "&contenttype=json";
  203. $tencentObj = new tencentim($url);
  204. $data = [];
  205. $data["Limit"] = 100;//本次获取的群组 ID 数量的上限,不得超过 10000。如果不填,默认为最大值 10000
  206. $data["GroupType"] = 'AVChatRoom';//群组形态包括 Public(公开群),Private(即 Work,好友工作群),ChatRoom(即 Meeting,会议群),AVChatRoom(音视频聊天室),BChatRoom(在线成员广播大群)和社群(Community)
  207. $groupList = $tencentObj->toSend($data);
  208. $result = [];
  209. if (isset($groupList['ActionStatus']) && $groupList['ActionStatus'] == 'OK') {
  210. $result = isset($groupList['GroupIdList']) ? $groupList['GroupIdList'] : [];
  211. }
  212. $this->success('获取成功',$result);
  213. }
  214. /**
  215. * 获取用户所加入的群组
  216. */
  217. public function getJoindGroupList($user_id) {
  218. $random = rand(10000000,99999999);
  219. $usersig = $this->usersig("administrator");
  220. // 获取配置信息
  221. $config = config("tencent_im");
  222. $url = "https://console.tim.qq.com/v4/group_open_http_svc/get_joined_group_list";
  223. $url .= "?sdkappid=".$config["sdkappid"];
  224. $url .= "&identifier=administrator";
  225. $url .= "&usersig=".$usersig;
  226. $url .= "&random=".$random;
  227. $url .= "&contenttype=json";
  228. $tencentObj = new tencentim($url);
  229. $data = [];
  230. $data["Member_Account"] = $user_id;
  231. $data["WithHugeGroups"] = 1;
  232. $data["GroupType"] = 'AVChatRoom';
  233. $data["ResponseFilter"] = ["GroupBaseInfoFilter" => ['GroupId'] ];
  234. $groupInfo = $tencentObj->toSend($data);
  235. // \app\common\model\Test::update(["content"=>json_encode($groupInfo)],["id"=>1]);
  236. return $groupInfo;
  237. }
  238. //"https:\/\/console.tim.qq.com\/v4\/group_open_http_svc\/get_joined_group_list?sdkappid=1400458032&identifier=administrator&usersig=eJyrVgrxCdYrSy1SslIy0jNQ0gHzM1NS80oy0zLBwqamUNHilOzEgoLMFCUrQxMDAxNTCwNjI4hMakVBZlEqUNzU1NTIwMAAIlqSmQsSMzO0MDY0NDOwhJqSmQ40NNwowsvMzzXKw8wsLNIwRr9S28giPKjMPSkpKLPcLcfFPd3TO7swz9fXOdLTVqkWADrXLzo_&random=73931990&contenttype=json"
  239. // /**
  240. // * 删除群成员
  241. // */
  242. // public function delMemberFromGroup($user_id,$party_id) {
  243. // $random = rand(10000000,99999999);
  244. // $usersig = $this->usersig($user_id);
  245. // // 获取配置信息
  246. // $config = config("tencent_im");
  247. // $url = "https://console.tim.qq.com/v4/group_open_http_svc/delete_group_member";
  248. // $url .= "?sdkappid=".$config["sdkappid"];
  249. // $url .= "&identifier=administrator";
  250. // $url .= "&usersig=".$usersig;
  251. // $url .= "&random=".$random;
  252. // $url .= "&contenttype=json";
  253. // $tencentObj = new tencentim($url);
  254. // $data = [];
  255. // $data["GroupId"] = $party_id;
  256. // $data["Silence"] = 1;
  257. // $data["MemberToDel_Account"] = [$user_id];
  258. // $res = $tencentObj->toSend($data);
  259. // \app\common\model\Test::update(["content"=>json_encode($res)],["id"=>1]);
  260. // return $res;
  261. // }
  262. /**
  263. * 设置管理员
  264. */
  265. public function setImManage($manage_user_id,$party_id) {
  266. // $manage_user_id = "2";
  267. // $party_id = "6";
  268. $random = rand(10000000,99999999);
  269. $usersig = $this->usersig("administrator");
  270. // 获取配置信息
  271. $config = config("tencent_im");
  272. $url = "https://console.tim.qq.com/v4/group_open_http_svc/modify_group_base_info";
  273. $url .= "?sdkappid=".$config["sdkappid"];
  274. $url .= "&identifier=administrator";
  275. $url .= "&usersig=".$usersig;
  276. $url .= "&random=".$random;
  277. $url .= "&contenttype=json";
  278. $tencentObj = new tencentim($url);
  279. // 获取群组信息
  280. $groupInfo = $this->getGroupInfo($party_id);
  281. if($groupInfo["GroupInfo"][0]["ErrorCode"] > 0) return false;
  282. $roomInfoData = $groupInfo["GroupInfo"][0]["AppDefinedData"];
  283. $roomInfo = [];
  284. if($roomInfoData) foreach($roomInfoData as $k => $v) {
  285. if($v["Key"] == "roomInfo") $roomInfo = $v["Value"];
  286. }
  287. $roomInfo = json_decode($roomInfo,true);
  288. // 更新的信息
  289. if(isset($roomInfo["managers"])) {
  290. if(!$roomInfo["managers"]) $roomInfo["managers"] = [];
  291. array_push($roomInfo["managers"],$manage_user_id);
  292. $roomInfo["managers"] = array_unique($roomInfo["managers"]);
  293. }
  294. $data = [];
  295. $data["GroupId"] = $party_id;
  296. $data["AppDefinedData"][0] = [
  297. "Key" => "roomInfo",
  298. "Value" => json_encode($roomInfo),
  299. // "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)),
  300. ];
  301. if(isset($roomInfo["ownerId"]) && isset($roomInfo["roomName"])) {
  302. $tencentObj->toSend($data);
  303. }
  304. }
  305. /**
  306. * 强制下线
  307. */
  308. public function downSite($user_id,$groupsites) {
  309. $random = rand(10000000,99999999);
  310. $usersig = $this->usersig("administrator");
  311. // 获取配置信息
  312. $config = config("tencent_im");
  313. $url = "https://console.tim.qq.com/v4/group_open_http_svc/modify_group_base_info";
  314. $url .= "?sdkappid=".$config["sdkappid"];
  315. $url .= "&identifier=administrator";
  316. $url .= "&usersig=".$usersig;
  317. $url .= "&random=".$random;
  318. $url .= "&contenttype=json";
  319. $tencentObj = new tencentim($url);
  320. // 先更新下麦时间
  321. $update = [];
  322. $update["offsite_time"] = time();
  323. $update["status"] = 2;
  324. \app\common\model\UserOnsiteTime::update($update,["user_id"=>$user_id,"status"=>1]);
  325. // 循环房间
  326. if($groupsites) foreach($groupsites as $k => $v) {
  327. // 循环座位
  328. $data = [];
  329. foreach($v["AppDefinedData"] as $m => $n) {
  330. // 解析字段信息
  331. $siteInfo = json_decode($n["Value"],true);
  332. if($m != 0 && isset($siteInfo["status"]) && $siteInfo["status"] == 1 && isset($siteInfo["status"]) && $siteInfo["user"] == $user_id) {
  333. $data["AppDefinedData"][] = [
  334. "Key" => $n["Key"],
  335. "Value" => '{"mute":false,"status":0,"user":""}',
  336. ];
  337. }
  338. }
  339. if(!empty($data)) {
  340. $data["GroupId"] = $v["GroupId"];
  341. return $tencentObj->toSend($data);
  342. }
  343. }
  344. }
  345. /**
  346. * 踢出房间内所有用户
  347. */
  348. public function outMemberFromRoom($party_id) {
  349. if($party_id <= 0) return false;
  350. $message = [];
  351. $message["type"] = "91";
  352. $message["content"] = "房间已被管理员关闭!详情请联系客服!";
  353. $msgData = [];
  354. $msgData["version"] = "1.0";
  355. $msgData["action"] = 301;
  356. $msgData["command"] = "";
  357. $msgData["message"] = json_encode($message);
  358. $random = rand(10000000,99999999);
  359. $usersig = $this->usersig("administrator");
  360. // 获取配置信息
  361. $config = config("tencent_im");
  362. $url = "https://console.tim.qq.com/v4/group_open_http_svc/send_group_msg";
  363. $url .= "?sdkappid=".$config["sdkappid"];
  364. $url .= "&identifier=administrator";
  365. $url .= "&usersig=".$usersig;
  366. $url .= "&random=".$random;
  367. $url .= "&contenttype=json";
  368. $tencentObj = new tencentim($url);
  369. $data = [];
  370. $data["GroupId"] = $party_id;
  371. $data["Random"] = rand(1000000,9999999);
  372. $data["MsgBody"][] = [
  373. "MsgType" => "TIMCustomElem",
  374. "MsgContent" => [
  375. "Data"=> json_encode($msgData)
  376. ],
  377. ];
  378. $tencentObj->toSend($data);
  379. }
  380. /**
  381. * 获取usersig签名
  382. */
  383. public function getUsersig() {
  384. $user_id = $this->auth->id;
  385. $this->success("获取成功!",$this->usersig($user_id));
  386. }
  387. /**
  388. * 获取usersig签名-具体操作
  389. */
  390. private function usersig($user_id) {
  391. // 获取配置信息
  392. $config = config("tencent_im");
  393. $usersigObj = new getusersig($config["sdkappid"],$config["key"]);
  394. $usersig = $usersigObj->genUserSig($user_id);
  395. return $usersig;
  396. }
  397. /**
  398. * 强制下麦
  399. */
  400. public function updateSiteInfo() {
  401. $user_id = $this->request->request("user_id");// 用户ID
  402. if(!$user_id) $this->error("参数缺失!");
  403. // 更新用户在线状态为离线
  404. \app\common\model\User::update(["is_online"=>0],["id"=>$user_id]);
  405. \app\common\model\User::update(["is_live"=>0],["id"=>$user_id]);
  406. \app\common\model\Party::update(["is_online"=>0],["user_id"=>$user_id]);
  407. // 获取用户所在群信息
  408. $groupids = $this->getJoindGroupList($user_id);
  409. if($groupids["ErrorCode"] == 0) {
  410. $grouplist = $groupids["GroupIdList"];
  411. $groupsites = [];
  412. if($grouplist) foreach($grouplist as $k => $v) {
  413. // 获取群组消息
  414. $groupInfo = $this->getGroupInfo($v["GroupId"]);
  415. if($groupInfo["ErrorCode"] == 0) $groupsites[] = $groupInfo["GroupInfo"][0];
  416. // 踢出用户在线组
  417. $redis = new Redis();
  418. $redisconfig = config("redis");
  419. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  420. if ($redisconfig['redis_pwd']) {
  421. $redis->auth($redisconfig['redis_pwd']);
  422. }
  423. if($redisconfig['redis_selectdb'] > 0){
  424. $redis->select($redisconfig['redis_selectdb']);
  425. }
  426. $redis->HDel("online_".$v["GroupId"],$user_id);
  427. }
  428. // 强制下麦
  429. $this->downSite($user_id,$groupsites);
  430. }
  431. $this->success("状态更新成功!");
  432. }
  433. /**
  434. * 更新麦位前四
  435. */
  436. public function updatePosition($user_id,$party_id) {
  437. // 获取用户头像
  438. $userInfo = \app\common\model\User::field("avatar")->where(["id"=>$user_id])->find();
  439. $userAvatar = isset($userInfo["avatar"])?$userInfo["avatar"]:"";
  440. // 更新下麦时间
  441. $update = [];
  442. $update["offsite_time"] = time();
  443. $update["status"] = 2;
  444. \app\common\model\UserOnsiteTime::update($update,["user_id"=>$user_id,"status"=>1]);
  445. //
  446. $redis = new Redis();
  447. $redisconfig = config("redis");
  448. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  449. if ($redisconfig['redis_pwd']) {
  450. $redis->auth($redisconfig['redis_pwd']);
  451. }
  452. if($redisconfig['redis_selectdb'] > 0){
  453. $redis->select($redisconfig['redis_selectdb']);
  454. }
  455. $room_type = Db::name('party')->where('id',$party_id)->value('room_type');
  456. $redisData = $redis->get($room_type."_".$party_id);
  457. if(!$redisData){
  458. return true;
  459. }
  460. $partyInfo = json_decode($redisData,true);
  461. // 遍历已有头像
  462. $partyuser = isset($partyInfo["party_user"])?$partyInfo["party_user"]:"";
  463. if(is_array($partyuser)) foreach($partyuser as $k => $v) if($v === $userAvatar) unset($partyInfo["party_user"][$k]);
  464. $redis->set($room_type."_".$party_id,json_encode($partyInfo));
  465. }
  466. /**
  467. * 取消排麦
  468. */
  469. public function cancelLineUp($user_id,$party_id) {
  470. if (!$party_id || !$user_id) {
  471. return false;
  472. }
  473. $redis = new Redis();
  474. $redisconfig = config("redis");
  475. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  476. if ($redisconfig['redis_pwd']) {
  477. $redis->auth($redisconfig['redis_pwd']);
  478. }
  479. if($redisconfig['redis_selectdb'] > 0){
  480. $redis->select($redisconfig['redis_selectdb']);
  481. }
  482. $data=unserialize($redis->hGet("party_lineup",$party_id));
  483. // 更改红点排麦数量
  484. $num = 0;
  485. $send = false;
  486. if($data) foreach($data as $k => $v) {
  487. if($v["user_id"] == $user_id) {
  488. $send = true;
  489. unset($data[$k]);
  490. break;
  491. }
  492. }
  493. $redis->hSet("party_lineup",$party_id,serialize($data));
  494. if($send) {
  495. is_array($data) && $num = count($data);
  496. $random = rand(10000000,99999999);
  497. $usersig = $this->usersig("administrator");
  498. // 获取配置信息
  499. $config = config("tencent_im");
  500. $url = "https://console.tim.qq.com/v4/group_open_http_svc/send_group_msg";
  501. $url .= "?sdkappid=".$config["sdkappid"];
  502. $url .= "&identifier=administrator";
  503. $url .= "&usersig=".$usersig;
  504. $url .= "&random=".$random;
  505. $url .= "&contenttype=json";
  506. $tencentObj = new tencentim($url);
  507. $data = [];
  508. $data["GroupId"] = $party_id;
  509. $data["Random"] = rand(1000000,9999999);
  510. $message = [
  511. "message" => json_encode(["type"=>23,"content"=>$num]),
  512. "version" => "1.0",
  513. "action" => 301,
  514. "command" => ""
  515. ];
  516. $data["MsgBody"][] = [
  517. "MsgType" => "TIMCustomElem",
  518. "MsgContent" => [
  519. "Data"=> json_encode($message)
  520. ],
  521. ];
  522. $tencentObj->toSend($data);
  523. }
  524. }
  525. public function trtc_callback(){
  526. $input = file_get_contents("php://input");
  527. filePut('start:'.$input,'callback.txt');
  528. /*$input = '{
  529. "EventGroupId": 1,
  530. "EventType": 104,
  531. "CallbackTs": 1640331295244,
  532. "EventInfo": {
  533. "RoomId": 1604,
  534. "EventTs": 1640331295,
  535. "EventMsTs": 1640331295239,
  536. "UserId": "26",
  537. "Role": 20,
  538. "Reason": 1
  539. }
  540. }';*/
  541. $input = json_decode($input,true);
  542. $roomId = $input['EventInfo']['RoomId'];
  543. //房间事件组
  544. if($input['EventGroupId'] == 1){
  545. if($input['EventType'] == 101){
  546. //创建房间,第一个进来的
  547. }elseif($input['EventType'] == 102){
  548. //解散房间,最后一个走的
  549. //没有UserId
  550. }elseif($input['EventType'] == 103){
  551. //进入房间,主播role=20 观众role=21
  552. $redis = new Redis();
  553. $redisconfig = config("redis");
  554. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  555. if ($redisconfig['redis_pwd']) {
  556. $redis->auth($redisconfig['redis_pwd']);
  557. }
  558. if($redisconfig['redis_selectdb'] > 0){
  559. $redis->select($redisconfig['redis_selectdb']);
  560. }
  561. $userId = $input['EventInfo']['UserId'];
  562. $redis->hSet("online_" . $roomId, $userId, $userId);
  563. // 记录在线用户在房间情况
  564. $redis->hSet("livingUser",$userId,$roomId);
  565. // 更新房间在线状态
  566. $partyInfo = $redis->get("party_" . $roomId);
  567. if ($partyInfo) {
  568. $partyInfo = json_decode($partyInfo, true);
  569. if ($partyInfo["is_online"] != 1) {
  570. $partyInfo["is_online"] = 1;
  571. $redis->set("party_" . $roomId, json_encode($partyInfo));
  572. \app\common\model\Party::update(["is_online" => 1], ["id" => $roomId]);
  573. }
  574. }
  575. // 更新房间在线状态
  576. $liveInfo = $redis->get("live_" . $roomId);
  577. if ($liveInfo) {
  578. $liveInfo = json_decode($liveInfo, true);
  579. if ($input['EventInfo']['Role'] == 20) {
  580. $liveInfo["is_online"] = 1;
  581. $redis->set("live_" . $roomId, json_encode($liveInfo));
  582. \app\common\model\Party::update(["is_online" => 1], ["id" => $roomId]);
  583. $rs_user = Db::name('user')->where('id',$userId)->update(['is_livebc'=>1]);
  584. }
  585. }
  586. }elseif($input['EventType'] == 104){
  587. //退出房间,主播role=20 观众role=21
  588. $redis = new Redis();
  589. $redisconfig = config("redis");
  590. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  591. if ($redisconfig['redis_pwd']) {
  592. $redis->auth($redisconfig['redis_pwd']);
  593. }
  594. if($redisconfig['redis_selectdb'] > 0){
  595. $redis->select($redisconfig['redis_selectdb']);
  596. }
  597. $userId = $input['EventInfo']['UserId'];
  598. $redis->HDel("online_" . $roomId, $userId);
  599. // 扣除在线用户在房间情况
  600. $redis->hDel("livingUser",$userId);
  601. // 更新房间在线状态
  602. $partyInfo = $redis->get("party_" . $roomId);
  603. if ($partyInfo) {
  604. $partyInfo = json_decode($partyInfo, true);
  605. $memCount = count($redis->hGetAll("online_" . $roomId));
  606. if ($memCount <= 0) {
  607. $partyInfo["is_online"] = 0;
  608. $redis->set("party_" . $roomId, json_encode($partyInfo));
  609. \app\common\model\Party::update(["is_online" => 0], ["id" => $roomId]);
  610. }
  611. }
  612. //
  613. $liveInfo = $redis->get("live_" . $roomId);
  614. if ($liveInfo) {
  615. $liveInfo = json_decode($liveInfo, true);
  616. if($input['EventInfo']['Role'] == 20){
  617. $liveInfo["is_online"] = 0;
  618. $redis->set("live_" . $roomId, json_encode($liveInfo));
  619. \app\common\model\Party::update(["is_online" => 0], ["id" => $roomId]);
  620. $rs_user = Db::name('user')->where('id',$userId)->update(['is_livebc'=>0]);
  621. }
  622. }
  623. }
  624. }elseif($input['EventGroupId'] == 2){
  625. }
  626. //结束
  627. echo json_encode(['code' => 0]);exit;
  628. }
  629. /**
  630. * 回调
  631. */
  632. public function callback() {
  633. $input = file_get_contents("php://input"); // 主题信息
  634. $input = json_decode($input,true);
  635. $CallbackCommand = $input["CallbackCommand"];
  636. switch ($CallbackCommand) {
  637. case 'State.StateChange': // 用户在线状态变更
  638. $info = $input["Info"];
  639. if($info["Action"] == "Login") { // 用户登录
  640. $loginToday = Db::name('user')->where('id',$info["To_Account"])->whereTime('onlinetime', 'today')->find();
  641. if ($loginToday){
  642. \app\common\model\User::update(["is_online"=>1,"onlinetime"=>time()],["id"=>$info["To_Account"]]);
  643. }else{
  644. \app\common\model\User::update(["is_online"=>1,"onlinetime"=>time()],["id"=>$info["To_Account"]]);
  645. }
  646. $res = [];
  647. $res["ActionStatus"] = "OK";
  648. $res["ErrorCode"] = 0;
  649. $res["ErrorInfo"] = "";
  650. echo json_encode($res);exit;
  651. } elseif($info["Action"] == "Logout" || $info["Action"] == "Disconnect") { // 用户退出 不需要管什么原因
  652. // 更新用户在线状态为离线
  653. \app\common\model\User::update(["is_online"=>0],["id"=>$info["To_Account"]]);
  654. \app\common\model\User::update(["is_live"=>0],["id"=>$info["To_Account"]]);
  655. // 获取用户在派对直播间情况信息
  656. $redis = new Redis();
  657. $redisconfig = config("redis");
  658. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  659. if ($redisconfig['redis_pwd']) {
  660. $redis->auth($redisconfig['redis_pwd']);
  661. }
  662. if($redisconfig['redis_selectdb'] > 0){
  663. $redis->select($redisconfig['redis_selectdb']);
  664. }
  665. $livingUserPartyId = $redis->hGet("livingUser", $info["To_Account"]);
  666. if ($livingUserPartyId) {
  667. // 扣除在线用户在房间情况
  668. $redis->hDel("livingUser", $info["To_Account"]);
  669. $redis->HDel("online_" . $livingUserPartyId, $info["To_Account"]);
  670. $redis->zRem("party_user_".$livingUserPartyId,$info["To_Account"]); //新加的
  671. }
  672. // 获取用户所在群信息
  673. $groupids = $this->getJoindGroupList($info["To_Account"]);
  674. // \app\common\model\Test::update(["content"=>json_encode($groupids)],["id"=>1]);
  675. if($groupids["ErrorCode"] == 0) {
  676. $grouplist = $groupids["GroupIdList"];
  677. $groupsites = [];
  678. if($grouplist) foreach($grouplist as $k => $v) {
  679. // 获取群组消息
  680. $groupInfo = $this->getGroupInfo($v["GroupId"]);
  681. if($groupInfo["ErrorCode"] == 0) $groupsites[] = $groupInfo["GroupInfo"][0];
  682. // 踢出用户在线组
  683. $redis = new Redis();
  684. $redisconfig = config("redis");
  685. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  686. if ($redisconfig['redis_pwd']) {
  687. $redis->auth($redisconfig['redis_pwd']);
  688. }
  689. if($redisconfig['redis_selectdb'] > 0){
  690. $redis->select($redisconfig['redis_selectdb']);
  691. }
  692. $redis->HDel("online_".$v["GroupId"],$info["To_Account"]);
  693. $redis->zRem("party_user_".$v["GroupId"],$info["To_Account"]); //新加的
  694. // 更新麦位前四
  695. $this->updatePosition($info["To_Account"],$v["GroupId"]);
  696. // 取消排麦
  697. $this->cancelLineup($info["To_Account"],$v["GroupId"]);
  698. // 房间状态变更
  699. $partyInfo = $redis->get("party_".$v["GroupId"]);
  700. if($partyInfo) {
  701. $partyInfo = json_decode($partyInfo,true);
  702. $memCount = count($redis->hGetAll("online_".$v["GroupId"]));
  703. if($memCount <= 0) {
  704. $partyInfo["is_online"] = 0;
  705. $redis->set("party_".$v["GroupId"],json_encode($partyInfo));
  706. \app\common\model\Party::update(["is_online"=>0],["id"=>$v["GroupId"]]);
  707. }
  708. }
  709. $liveInfo = $redis->get("live_".$v["GroupId"]);
  710. if($liveInfo) {
  711. $liveInfo = json_decode($liveInfo,true);
  712. $memCount = count($redis->hGetAll("online_".$v["GroupId"]));
  713. if($memCount <= 0) {
  714. $liveInfo["is_online"] = 0;
  715. $redis->set("live_".$v["GroupId"],json_encode($liveInfo));
  716. \app\common\model\Party::update(["is_online"=>0],["id"=>$v["GroupId"]]);
  717. }
  718. }
  719. }
  720. // 强制下麦
  721. print_r($this->downSite($info["To_Account"],$groupsites));
  722. }
  723. }
  724. break;
  725. /*case 'Group.CallbackAfterNewMemberJoin': // 新成员入群
  726. $redis = new Redis();
  727. $redisconfig = config("redis");
  728. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  729. if ($redisconfig['redis_pwd']) {
  730. $redis->auth($redisconfig['redis_pwd']);
  731. }
  732. if($redisconfig['redis_selectdb'] > 0){
  733. $redis->select($redisconfig['redis_selectdb']);
  734. }
  735. $members = $input["NewMemberList"];
  736. if($members) foreach($members as $k => $v) {
  737. $redis->hSet("online_".$input["GroupId"],$v["Member_Account"],$v["Member_Account"]);
  738. // 更新房间在线状态
  739. $party_id = $input["GroupId"];
  740. $partyInfo = $redis->get("party_".$party_id);
  741. if($partyInfo) {
  742. $partyInfo = json_decode($partyInfo,true);
  743. if($partyInfo["is_online"] != 1) {
  744. $partyInfo["is_online"] = 1;
  745. $redis->set("party_".$party_id,json_encode($partyInfo));
  746. \app\common\model\Party::update(["is_online"=>1],["id"=>$party_id]);
  747. }
  748. }
  749. }
  750. $res = [];
  751. $res["ActionStatus"] = "OK";
  752. $res["ErrorCode"] = 0;
  753. $res["ErrorInfo"] = "";
  754. echo json_encode($res);
  755. break;*/
  756. /*case 'Group.CallbackAfterMemberExit': // 成员离开
  757. $redis = new Redis();
  758. $redisconfig = config("redis");
  759. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  760. if ($redisconfig['redis_pwd']) {
  761. $redis->auth($redisconfig['redis_pwd']);
  762. }
  763. if($redisconfig['redis_selectdb'] > 0){
  764. $redis->select($redisconfig['redis_selectdb']);
  765. }
  766. $members = $input["ExitMemberList"];
  767. if($members) foreach($members as $k => $v) {
  768. $redis->HDel("online_".$input["GroupId"],$v["Member_Account"]);
  769. }
  770. // 更新房间在线状态
  771. $party_id = $input["GroupId"];
  772. $partyInfo = $redis->get("party_".$party_id);
  773. if($partyInfo) {
  774. $partyInfo = json_decode($partyInfo,true);
  775. $memCount = count($redis->hGetAll("online_".$party_id));
  776. if($memCount <= 0) {
  777. $partyInfo["is_online"] = 0;
  778. $redis->set("party_".$party_id,json_encode($partyInfo));
  779. \app\common\model\Party::update(["is_online"=>0],["id"=>$party_id]);
  780. }
  781. }
  782. $liveInfo = $redis->get("live_".$party_id);
  783. if($liveInfo) {
  784. $liveInfo = json_decode($liveInfo,true);
  785. $memCount = count($redis->hGetAll("online_".$party_id));
  786. if($memCount <= 0) {
  787. $liveInfo["is_online"] = 0;
  788. $redis->set("live_".$party_id,json_encode($liveInfo));
  789. \app\common\model\Party::update(["is_online"=>0],["id"=>$party_id]);
  790. }
  791. }
  792. $res = [];
  793. $res["ActionStatus"] = "OK";
  794. $res["ErrorCode"] = 0;
  795. $res["ErrorInfo"] = "";
  796. echo json_encode($res);
  797. break;*/
  798. /* case 'Group.CallbackBeforeSendMsg': // 群内发送消息之前
  799. $config = config("wxMiniProgram");
  800. $access_token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$config["appid"]."&secret=".$config["secret"];
  801. $access_token_arr = $this->getJson($access_token_url);
  802. $access_token = isset($access_token_arr["access_token"])?$access_token_arr["access_token"]:"";
  803. if(!$access_token) {
  804. $res = [];
  805. $res["ActionStatus"] = "OK";
  806. $res["ErrorInfo"] = "";
  807. $res["ErrorCode"] = 0;
  808. echo json_encode($res);
  809. break;
  810. }
  811. // \app\common\model\Test::update(["content"=>json_encode($access_token)],["id"=>1]);
  812. $infoMessage = $input["MsgBody"];
  813. $badMessage = false;
  814. if($infoMessage) foreach($infoMessage as $k => $v) {
  815. if(isset($v["MsgContent"]["Text"])) {
  816. $message = json_decode($v["MsgContent"]["Text"],true);
  817. $content = isset($message["content"])?$message["content"]:"";
  818. $message_check_url ='https://api.weixin.qq.com/wxa/msg_sec_check?access_token='.$access_token;
  819. $tencentObj = new tencentim($message_check_url);
  820. $content_json = '{"content": "'.$content.'"}';
  821. $body = $tencentObj->messageCheck($content_json);
  822. if($body["errcode"] == 87014) {
  823. // \app\common\model\Test::update(["content"=>$body["errcode"]],["id"=>1]);
  824. // $res = [];
  825. // $res["ActionStatus"] = "OK";
  826. // $res["ErrorInfo"] = "检测到敏感词汇!";
  827. // $res["ErrorCode"] = 1;
  828. // echo json_encode($res);exit;
  829. $message["content"] = "*******";
  830. $infoMessage[$k]["MsgContent"]["Text"] = json_encode($message);
  831. $badMessage = true;
  832. }
  833. }
  834. }
  835. if($badMessage) {
  836. $res = [];
  837. $res["ActionStatus"] = "OK";
  838. $res["ErrorInfo"] = "检测到敏感词汇!";
  839. $res["ErrorCode"] = 10102;
  840. $res["MsgBody"] = $infoMessage;
  841. } else {
  842. $res = [];
  843. $res["ActionStatus"] = "OK";
  844. $res["ErrorInfo"] = "";
  845. $res["ErrorCode"] = 0;
  846. }
  847. // \app\common\model\Test::update(["content"=>json_encode($res)],["id"=>1]);
  848. echo json_encode($res);exit;
  849. break;*/
  850. default:
  851. break;
  852. }
  853. exit;
  854. }
  855. private function getJson($url){
  856. $ch = curl_init();
  857. curl_setopt($ch, CURLOPT_URL, $url);
  858. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  859. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  860. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  861. $output = curl_exec($ch);
  862. curl_close($ch);
  863. return json_decode($output, true);
  864. }
  865. /**
  866. * 发送消息给某人
  867. */
  868. public function sendMessageToUser($from_user,$to_user,$message) {
  869. // $from_user = 54;
  870. // $to_user = 6;
  871. // $message = "sdsd";
  872. $random = rand(10000000,99999999);
  873. $usersig = $this->usersig("administrator");
  874. // 获取配置信息
  875. $config = config("tencent_im");
  876. $url = "https://console.tim.qq.com/v4/openim/sendmsg";
  877. $url .= "?sdkappid=".$config["sdkappid"];
  878. $url .= "&identifier=administrator";
  879. $url .= "&usersig=".$usersig;
  880. $url .= "&random=".$random;
  881. $url .= "&contenttype=json";
  882. $tencentObj = new tencentim($url);
  883. $data = [];
  884. $data["SyncOtherMachine"] = 1;
  885. $data["From_Account"] = (string)$from_user;
  886. $data["To_Account"] = (string)$to_user;
  887. $data["MsgRandom"] = rand(1000000,9999999);
  888. $data["MsgTimeStamp"] = time();
  889. $data["MsgBody"][] = [
  890. "MsgType" => "TIMTextElem",
  891. "MsgContent" => [
  892. "Text"=> $message
  893. ],
  894. ];
  895. $tencentObj->toSend($data);
  896. }
  897. /**
  898. * 发送消息给某人-接口调用
  899. */
  900. public function sendToUser() {
  901. $from_user = $this->request->request("from_user");// 发送者
  902. $to_user = $this->request->request("to_user");// 接收者
  903. $message = $this->request->request("message");// 接收者
  904. if(!$from_user || !$to_user || !$message) $this->error("参数缺失!");
  905. $this->sendMessageToUser($from_user,$to_user,$message);
  906. }
  907. //请求的基础参数
  908. private function baseTencentObj($url)
  909. {
  910. $random = rand(10000000,99999999);
  911. $usersig = $this->usersig("administrator");
  912. // 获取配置信息
  913. $config = config("tencent_im");
  914. $url = "$url";
  915. $url .= "?sdkappid=".$config["sdkappid"];
  916. $url .= "&identifier=administrator";
  917. $url .= "&usersig=".$usersig;
  918. $url .= "&random=".$random;
  919. $url .= "&contenttype=json";
  920. return new tencentim($url);
  921. }
  922. /** 设置管理员(im端的改变)
  923. * @param $user_id
  924. * @param $party_id
  925. * @param int $status 1:yes 0:no
  926. * @return array|false|mixed
  927. */
  928. public function setUpIMAdmin($user_id, $party_id, int $status=0) {
  929. $url = "https://console.tim.qq.com/v4/group_open_http_svc/modify_group_member_info";
  930. $tencentObj = $this->baseTencentObj($url);
  931. $groupInfo = $this->getGroupInfo($party_id);
  932. if($groupInfo["GroupInfo"][0]["ErrorCode"] > 0) return false;
  933. // 更新的信息
  934. $data = [];
  935. $data["GroupId"] = $party_id;
  936. if ($status==1){
  937. $data['Role'] = 'Admin';
  938. }else{
  939. $data['Role'] = 'Member';
  940. }
  941. $data['Member_Account'] = $user_id;
  942. return $tencentObj->toSend($data);
  943. }
  944. //获取群成员详细资料(目前没用到)
  945. private function getGroupMemberDetails($party_id)
  946. {
  947. $url = "https://console.tim.qq.com/v4/group_open_http_svc/get_group_member_info";
  948. $tencentObj = $this->baseTencentObj($url);
  949. // 获取群组信息
  950. $groupInfo = $this->getGroupInfo($party_id);
  951. if($groupInfo["GroupInfo"][0]["ErrorCode"] > 0) return false;
  952. // 更新的信息
  953. $data = [];
  954. $data["GroupId"] = $party_id;
  955. return $tencentObj->toSend($data);
  956. }
  957. //IM管理员维护,同步本地管理员
  958. public function imAdminMaintenance()
  959. {
  960. $partyIds = \app\admin\model\party\Party::column('id');
  961. foreach ($partyIds as $party_id){
  962. $groupInfo = $this->getGroupInfo($party_id);
  963. if($groupInfo["GroupInfo"][0]["ErrorCode"] > 0) continue;
  964. $roomInfoData = $groupInfo["GroupInfo"][0]["AppDefinedData"];
  965. $roomInfo = [];
  966. if($roomInfoData) foreach($roomInfoData as $k => $v) {
  967. if($v["Key"] == "roomInfo") $roomInfo = $v["Value"];
  968. }
  969. $roomInfo = json_decode($roomInfo,true);
  970. // 更新管理员
  971. if(isset($roomInfo["managers"]) && !empty($roomInfo['managers'])) {
  972. foreach ($roomInfo['managers'] as $v){
  973. $this->setUpIMAdmin($v,$party_id,1);
  974. }
  975. }
  976. }
  977. $this->success("成功!");
  978. }
  979. /**
  980. * 获取用户在线更新
  981. */
  982. public function autoUserLine() {
  983. $random = rand(10000000,99999999);
  984. $usersig = $this->usersig("administrator");
  985. // 获取配置信息
  986. $config = config("tencent_im");
  987. $url = "https://console.tim.qq.com/v4/openim/query_online_status";
  988. $url .= "?sdkappid=".$config["sdkappid"];
  989. $url .= "&identifier=administrator";
  990. $url .= "&usersig=".$usersig;
  991. $url .= "&random=".$random;
  992. $url .= "&contenttype=json";
  993. $tencentObj = new tencentim($url);
  994. // 获取用户
  995. $where = [];
  996. $userData = model('User')->field('id')->where($where)->order('id asc')->select();
  997. $userArr = array_column($userData,'id');
  998. $data = [];
  999. $data["To_Account"] = $userArr;
  1000. $result = [];
  1001. if(!empty($data)) {
  1002. $result = $tencentObj->toSend($data);
  1003. if (isset($result['ActionStatus']) && $result['ActionStatus'] == 'OK') {
  1004. if (isset($result['ErrorList'])) {//没有人员
  1005. unset($result['ErrorList']);
  1006. /*foreach ($result['ErrorList'] as $errKey => $errVal) {
  1007. $userError[] = $errVal['To_Account'];
  1008. }*/
  1009. }
  1010. if (isset($result['QueryResult'])) {
  1011. $userOnline = $userOffline=[];
  1012. foreach ($result['QueryResult'] as $key => $value) {
  1013. if (in_array($value['Status'],['Online','PushOnline'])) {//在线(前台在线和后台在线)
  1014. $userOnline[] = intval($value['To_Account']);
  1015. } else {//离线
  1016. $userOffline[] = intval($value['To_Account']);
  1017. }
  1018. }
  1019. if (!empty($userOnline)) {//处理在线
  1020. $onlineWhere['id'] = ['in',$userOnline];
  1021. $onlineWhere['is_online'] = 0;
  1022. model('User')->where($onlineWhere)->update(['is_online'=>1]);
  1023. }
  1024. if (!empty($userOffline)) {//处理离线
  1025. $offlineWhere['id'] = ['in',$userOffline];
  1026. $offlineWhere['is_online'] = 1;
  1027. model('User')->where($offlineWhere)->update(['is_online'=>0]);
  1028. }
  1029. }
  1030. }
  1031. }
  1032. $this->success('操作成功');
  1033. }
  1034. /**
  1035. * 获取房间用户
  1036. */
  1037. public function getRoomUser() {
  1038. $partyIds = $this->request->param('party_ids','');
  1039. if (!empty($partyIds)) {
  1040. $partyIds = explode(',',$partyIds);
  1041. }
  1042. $random = rand(10000000,99999999);
  1043. $usersig = $this->usersig("administrator");
  1044. // 获取配置信息
  1045. $config = config("tencent_im");
  1046. $url = "https://console.tim.qq.com/v4/group_open_avchatroom_http_svc/get_members";
  1047. $url .= "?sdkappid=".$config["sdkappid"];
  1048. $url .= "&identifier=administrator";
  1049. $url .= "&usersig=".$usersig;
  1050. $url .= "&random=".$random;
  1051. $url .= "&contenttype=json";
  1052. $tencentObj = new tencentim($url);
  1053. //获取用户 ["57","62","63","105","106","107","108","109","116","119"]
  1054. $partyArr = $partyIds;
  1055. $memberList = [];
  1056. if(!empty($partyArr)) {
  1057. foreach ($partyArr as $key => $value) {
  1058. $data["GroupId"] = $value;
  1059. $result = $tencentObj->toSend($data);
  1060. if (isset($result['ActionStatus']) && $result['ActionStatus'] == 'OK') {
  1061. if (isset($result['MemberList']) && !empty($result['MemberList'])) {
  1062. foreach ($result['MemberList'] as $ukey => $uval) {
  1063. $memberList[$value]['member_list'][] = [
  1064. 'avatar' => $uval['Avatar'],
  1065. 'user_id'=> $uval['Member_Account'],
  1066. 'nickname' => $uval['NickName'],
  1067. ];
  1068. }
  1069. $memberList[$value]['online_num'] = count($memberList[$value]['member_list']);
  1070. }
  1071. }
  1072. }
  1073. }
  1074. $result = $memberList;
  1075. $this->success('操作成功',$result);
  1076. }
  1077. /**
  1078. * 获取房间用户
  1079. */
  1080. public function getGroupAttr() {
  1081. $partyId = $this->request->param('party_id','');
  1082. if (!empty($partyIds)) {
  1083. $this->error('参数错误');
  1084. }
  1085. $random = rand(10000000,99999999);
  1086. $usersig = $this->usersig("administrator");
  1087. // 获取配置信息
  1088. $config = config("tencent_im");
  1089. $url = "https://console.tim.qq.com/v4/group_open_attr_http_svc/get_group_attr";
  1090. $url .= "?sdkappid=".$config["sdkappid"];
  1091. $url .= "&identifier=administrator";
  1092. $url .= "&usersig=".$usersig;
  1093. $url .= "&random=".$random;
  1094. $url .= "&contenttype=json";
  1095. $tencentObj = new tencentim($url);
  1096. $result = [];
  1097. if(!empty($partyId)) {
  1098. $data["GroupId"] = $partyId;
  1099. $result = $tencentObj->toSend($data);
  1100. }
  1101. $this->success('操作成功',$result);
  1102. }
  1103. }