Tenim.php 46 KB

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