Tenim.php 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\utils\RedisUtil;
  5. use think\Request;
  6. use getusersig\getusersig;
  7. use tencentim\tencentim;
  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','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. RedisUtil::getInstance('online',$v["GroupId"])->HDel($user_id);
  437. }
  438. // 强制下麦
  439. $this->downSite($user_id,$groupsites);
  440. }
  441. $this->success("状态更新成功!");
  442. }
  443. /**
  444. * 更新麦位前四
  445. */
  446. public function updatePosition($user_id,$party_id) {
  447. // 获取用户头像
  448. $userInfo = \app\common\model\User::field("avatar")->where(["id"=>$user_id])->find();
  449. $userAvatar = isset($userInfo["avatar"])?$userInfo["avatar"]:"";
  450. $redisData = RedisUtil::getInstance('party',$party_id)->get();
  451. if(!$redisData) {
  452. return true;
  453. }
  454. $partyInfo = json_decode($redisData,true);
  455. // 遍历已有头像
  456. $partyuser = isset($partyInfo["party_user"])?$partyInfo["party_user"]:"";
  457. if(is_array($partyuser)) foreach($partyuser as $k => $v) if($v === $userAvatar) unset($partyInfo["party_user"][$k]);
  458. RedisUtil::getInstance('party',$party_id)->set(json_encode($partyInfo));
  459. }
  460. /**
  461. * 取消排麦
  462. */
  463. public function cancelLineUp($user_id,$party_id) {
  464. if (!$party_id || !$user_id) {
  465. return false;
  466. }
  467. $data=unserialize(RedisUtil::getInstance('party_lineup')->hGet($party_id));
  468. // 更改红点排麦数量
  469. $num = 0;
  470. $send = false;
  471. if($data) foreach($data as $k => $v) {
  472. if($v["user_id"] == $user_id) {
  473. $send = true;
  474. unset($data[$k]);
  475. break;
  476. }
  477. }
  478. RedisUtil::getInstance('party_lineup')->hSet($party_id,serialize($data));
  479. if($send) {
  480. is_array($data) && $num = count($data);
  481. $random = rand(10000000,99999999);
  482. $usersig = $this->usersig("administrator");
  483. // 获取配置信息
  484. $config = config("tencent_im");
  485. $url = "https://console.tim.qq.com/v4/group_open_http_svc/send_group_msg";
  486. $url .= "?sdkappid=".$config["sdkappid"];
  487. $url .= "&identifier=administrator";
  488. $url .= "&usersig=".$usersig;
  489. $url .= "&random=".$random;
  490. $url .= "&contenttype=json";
  491. $tencentObj = new tencentim($url);
  492. $data = [];
  493. $data["GroupId"] = $party_id;
  494. $data["Random"] = rand(1000000,9999999);
  495. $message = [
  496. "message" => json_encode(["type"=>23,"content"=>$num]),
  497. "version" => "1.0",
  498. "action" => 301,
  499. "command" => ""
  500. ];
  501. $data["MsgBody"][] = [
  502. "MsgType" => "TIMCustomElem",
  503. "MsgContent" => [
  504. "Data"=> json_encode($message)
  505. ],
  506. ];
  507. $tencentObj->toSend($data);
  508. }
  509. }
  510. //trtc_callback,直播callback
  511. //https://cloud.tencent.com/document/product/647/51586#eventId
  512. /*
  513. 2021-12-24 15:34:22 start2:{
  514. "EventGroupId": 1,
  515. "EventType": 103,
  516. "CallbackTs": 1640331262241,
  517. "EventInfo": {
  518. "RoomId": 1604,
  519. "EventTs": 1640331262,
  520. "EventMsTs": 1640331262238,
  521. "UserId": "26",
  522. "Role": 20,
  523. "TerminalType": 2,
  524. "UserType": 3,
  525. "Reason": 1
  526. }
  527. }
  528. 2021-12-24 15:34:22 start2:{
  529. "EventGroupId": 1,
  530. "EventType": 101,
  531. "CallbackTs": 1640331262247,
  532. "EventInfo": {
  533. "RoomId": 1604,
  534. "EventTs": 1640331262,
  535. "EventMsTs": 1640331262238,
  536. "UserId": "26"
  537. }
  538. }
  539. 2021-12-24 15:34:55 start2:{
  540. "EventGroupId": 1,
  541. "EventType": 102,
  542. "CallbackTs": 1640331295244,
  543. "EventInfo": {
  544. "RoomId": 1604,
  545. "EventTs": 1640331295,
  546. "EventMsTs": 1640331295239
  547. }
  548. }
  549. 2021-12-24 15:34:55 start2:{
  550. "EventGroupId": 1,
  551. "EventType": 104,
  552. "CallbackTs": 1640331295244,
  553. "EventInfo": {
  554. "RoomId": 1604,
  555. "EventTs": 1640331295,
  556. "EventMsTs": 1640331295239,
  557. "UserId": "26",
  558. "Role": 20,
  559. "Reason": 1
  560. }
  561. }
  562. */
  563. public function trtc_callback(){
  564. $input = file_get_contents("php://input");
  565. filePut('start:'.$input,'callback.txt');
  566. /*$input = '{
  567. "EventGroupId": 1,
  568. "EventType": 104,
  569. "CallbackTs": 1640331295244,
  570. "EventInfo": {
  571. "RoomId": 1604,
  572. "EventTs": 1640331295,
  573. "EventMsTs": 1640331295239,
  574. "UserId": "26",
  575. "Role": 20,
  576. "Reason": 1
  577. }
  578. }';*/
  579. $input = json_decode($input,true);
  580. $roomId = $input['EventInfo']['RoomId'];
  581. //房间事件组
  582. if($input['EventGroupId'] == 1){
  583. if($input['EventType'] == 101){
  584. //创建房间,第一个进来的
  585. }elseif($input['EventType'] == 102){
  586. //解散房间,最后一个走的
  587. //没有UserId
  588. }elseif($input['EventType'] == 103){
  589. //进入房间,主播role=20 观众role=21
  590. $userId = $input['EventInfo']['UserId'];
  591. RedisUtil::getInstance('online',$roomId)->hSet($userId, $userId);
  592. // 记录在线用户在房间情况
  593. RedisUtil::getInstance('livingUser')->hSet($userId,$roomId);
  594. // 更新房间在线状态
  595. $partyInfo = $redis->get("party_" . $roomId);
  596. if ($partyInfo) {
  597. $partyInfo = json_decode($partyInfo, true);
  598. if ($partyInfo["is_online"] != 1) {
  599. $partyInfo["is_online"] = 1;
  600. $redis->set("party_" . $roomId, json_encode($partyInfo));
  601. \app\common\model\Party::update(["is_online" => 1], ["id" => $roomId]);
  602. }
  603. }
  604. // 更新房间在线状态
  605. $liveInfo = $redis->get("livebc_" . $roomId);
  606. if ($liveInfo) {
  607. $liveInfo = json_decode($liveInfo, true);
  608. if ($input['EventInfo']['Role'] == 20) {
  609. $liveInfo["is_online"] = 1;
  610. $redis->set("livebc_" . $roomId, json_encode($liveInfo));
  611. \app\common\model\Party::update(["is_online" => 1], ["id" => $roomId]);
  612. $rs_user = Db::name('user')->where('id',$userId)->update(['is_livebc'=>1]);
  613. }
  614. }
  615. }elseif($input['EventType'] == 104){
  616. //退出房间,主播role=20 观众role=21
  617. $userId = $input['EventInfo']['UserId'];
  618. RedisUtil::getInstance('online',$roomId)->HDel($userId);
  619. // 扣除在线用户在房间情况
  620. RedisUtil::getInstance('livingUser')->hDel($userId);
  621. // 更新房间在线状态
  622. $partyInfo = RedisUtil::getInstance('party',$roomId)->get();
  623. if ($partyInfo) {
  624. $partyInfo = json_decode($partyInfo, true);
  625. $memCount = count(RedisUtil::getInstance('online',$roomId)->hGetAll());
  626. if ($memCount <= 0) {
  627. $partyInfo["is_online"] = 0;
  628. RedisUtil::getInstance('party',$roomId)->set(json_encode($partyInfo));
  629. \app\common\model\Party::update(["is_online" => 0], ["id" => $roomId]);
  630. }
  631. }
  632. //
  633. $liveInfo = RedisUtil::getInstance('livebc',$roomId)->get();
  634. if ($liveInfo) {
  635. $liveInfo = json_decode($liveInfo, true);
  636. if($input['EventInfo']['Role'] == 20){
  637. $liveInfo["is_online"] = 0;
  638. RedisUtil::getInstance('livebc',$roomId)->set(json_encode($liveInfo));
  639. \app\common\model\Party::update(["is_online" => 0], ["id" => $roomId]);
  640. $rs_user = Db::name('user')->where('id',$userId)->update(['is_livebc'=>0]);
  641. }
  642. }
  643. }
  644. }elseif($input['EventGroupId'] == 2){
  645. }
  646. //结束
  647. echo json_encode(['code' => 0]);exit;
  648. }
  649. /**
  650. * 回调
  651. */
  652. public function callback() {
  653. $input = file_get_contents("php://input"); // 主题信息
  654. if(!$input) {
  655. echo '无数据';exit;
  656. }
  657. $input = json_decode($input,true);
  658. $CallbackCommand = $input["CallbackCommand"];
  659. switch ($CallbackCommand) {
  660. case 'State.StateChange': // 用户在线状态变更
  661. $info = $input["Info"];
  662. if($info["Action"] == "Login") { // 用户登录
  663. $loginToday = Db::name('user')->where('id',$info["To_Account"])->whereTime('onlinetime', 'today')->find();
  664. if ($loginToday){
  665. \app\common\model\User::update(["is_online"=>1,"onlinetime"=>time()],["id"=>$info["To_Account"]]);
  666. }else{
  667. \app\common\model\User::update(["is_online"=>1,"onlinetime"=>time()],["id"=>$info["To_Account"]]);
  668. }
  669. $res = [];
  670. $res["ActionStatus"] = "OK";
  671. $res["ErrorCode"] = 0;
  672. $res["ErrorInfo"] = "";
  673. echo json_encode($res);exit;
  674. } elseif($info["Action"] == "Logout" || $info["Action"] == "Disconnect") { // 用户退出 不需要管什么原因
  675. // 更新用户在线状态为离线
  676. $updateData['is_online'] = 0;
  677. $user = Db::name('user')->where('id',$info["To_Account"])->find();
  678. if (!empty($user)) {
  679. // 客户觉得实时判断导致在线用户数量过少,此处,不再根据IM处理用户在线状态,已在API父类中做接口访问频率处理用户在线状态
  680. // if ($user['gender'] == 1) {
  681. // $updateData['is_active'] = 0;
  682. // }
  683. }
  684. \app\common\model\User::update($updateData,["id"=>$info["To_Account"]]);
  685. //\app\common\model\User::update(["is_live"=>0],["id"=>$info["To_Account"]]);
  686. // 获取用户在派对直播间情况信息
  687. $livingUserPartyId = RedisUtil::getInstance('livingUser')->hGet($info["To_Account"]);
  688. if ($livingUserPartyId) {
  689. // 扣除在线用户在房间情况
  690. RedisUtil::getInstance('livingUser')->hDel( $info["To_Account"]);
  691. RedisUtil::getInstance('online',$livingUserPartyId)->HDel($info["To_Account"]);
  692. }
  693. // 获取用户所在群信息
  694. $groupids = $this->getJoindGroupList($info["To_Account"]);
  695. // \app\common\model\Test::update(["content"=>json_encode($groupids)],["id"=>1]);
  696. if($groupids["ErrorCode"] == 0) {
  697. $grouplist = $groupids["GroupIdList"];
  698. $groupsites = [];
  699. if($grouplist) foreach($grouplist as $k => $v) {
  700. // 获取群组消息
  701. $groupInfo = $this->getGroupInfo($v["GroupId"]);
  702. if($groupInfo["ErrorCode"] == 0) $groupsites[] = $groupInfo["GroupInfo"][0];
  703. // 踢出用户在线组
  704. RedisUtil::getInstance('online',$v["GroupId"])->HDel($info["To_Account"]);
  705. // 更新麦位前四
  706. $this->updatePosition($info["To_Account"],$v["GroupId"]);
  707. // 取消排麦
  708. $this->cancelLineup($info["To_Account"],$v["GroupId"]);
  709. // 房间状态变更
  710. $partyInfo = RedisUtil::getInstance('party',$v["GroupId"])->get();
  711. if($partyInfo) {
  712. $partyInfo = json_decode($partyInfo,true);
  713. $memCount = count(RedisUtil::getInstance('online',$v["GroupId"])->hGetAll());
  714. if($memCount <= 0) {
  715. $partyInfo["is_online"] = 0;
  716. RedisUtil::getInstance('party',$v["GroupId"])->set(json_encode($partyInfo));
  717. \app\common\model\Party::update(["is_online"=>0],["id"=>$v["GroupId"]]);
  718. }
  719. }
  720. $liveInfo = RedisUtil::getInstance('live',$v["GroupId"])->get();
  721. if($liveInfo) {
  722. $liveInfo = json_decode($liveInfo,true);
  723. $memCount = count(RedisUtil::getInstance('online',$v["GroupId"])->hGetAll());
  724. if($memCount <= 0) {
  725. $liveInfo["is_online"] = 0;
  726. RedisUtil::getInstance('live',$v["GroupId"])->set(json_encode($liveInfo));
  727. \app\common\model\Party::update(["is_online"=>0],["id"=>$v["GroupId"]]);
  728. }
  729. }
  730. }
  731. // 强制下麦
  732. print_r($this->downSite($info["To_Account"],$groupsites));
  733. }
  734. }
  735. break;
  736. // case 'Group.CallbackAfterNewMemberJoin': // 新成员入群
  737. // $members = $input["NewMemberList"];
  738. // if($members) foreach($members as $k => $v) {
  739. // RedisUtil::getInstance('online',$input["GroupId"])->hSet($v["Member_Account"],$v["Member_Account"]);
  740. // // 更新房间在线状态
  741. // $party_id = $input["GroupId"];
  742. // $partyInfo = $redis->get("party_".$party_id);
  743. // if($partyInfo) {
  744. // $partyInfo = json_decode($partyInfo,true);
  745. // if($partyInfo["is_online"] != 1) {
  746. // $partyInfo["is_online"] = 1;
  747. // $redis->set("party_".$party_id,json_encode($partyInfo));
  748. // \app\common\model\Party::update(["is_online"=>1],["id"=>$party_id]);
  749. // }
  750. // }
  751. // }
  752. // $res = [];
  753. // $res["ActionStatus"] = "OK";
  754. // $res["ErrorCode"] = 0;
  755. // $res["ErrorInfo"] = "";
  756. // echo json_encode($res);
  757. // break;
  758. // case 'Group.CallbackAfterMemberExit': // 成员离开
  759. // $members = $input["ExitMemberList"];
  760. // if($members) foreach($members as $k => $v) {
  761. // RedisUtil::getInstance('online',$input["GroupId"])->HDel($v["Member_Account"]);
  762. // }
  763. // // 更新房间在线状态
  764. // $party_id = $input["GroupId"];
  765. // $partyInfo = RedisUtil::getInstance('party',$party_id)->get();
  766. // if($partyInfo) {
  767. // $partyInfo = json_decode($partyInfo,true);
  768. // $memCount = count(RedisUtil::getInstance('online',$party_id)->hGetAll());
  769. // if($memCount <= 0) {
  770. // $partyInfo["is_online"] = 0;
  771. // RedisUtil::getInstance('party',$party_id)->set(json_encode($partyInfo));
  772. // \app\common\model\Party::update(["is_online"=>0],["id"=>$party_id]);
  773. // }
  774. // }
  775. //
  776. // $liveInfo = RedisUtil::getInstance('live',$party_id)->get();
  777. // if($liveInfo) {
  778. // $liveInfo = json_decode($liveInfo,true);
  779. // $memCount = count(RedisUtil::getInstance('online',$party_id)->hGetAll());
  780. // if($memCount <= 0) {
  781. // $liveInfo["is_online"] = 0;
  782. // RedisUtil::getInstance('live',$party_id)->set(json_encode($liveInfo));
  783. // \app\common\model\Party::update(["is_online"=>0],["id"=>$party_id]);
  784. // }
  785. // }
  786. //
  787. // $res = [];
  788. // $res["ActionStatus"] = "OK";
  789. // $res["ErrorCode"] = 0;
  790. // $res["ErrorInfo"] = "";
  791. // echo json_encode($res);
  792. // break;
  793. /*case 'Group.CallbackBeforeSendMsg': // 群内发送消息之前
  794. $config = config("wxMiniProgram");
  795. $access_token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$config["appid"]."&secret=".$config["secret"];
  796. $access_token_arr = $this->getJson($access_token_url);
  797. $access_token = isset($access_token_arr["access_token"])?$access_token_arr["access_token"]:"";
  798. if(!$access_token) {
  799. $res = [];
  800. $res["ActionStatus"] = "OK";
  801. $res["ErrorInfo"] = "";
  802. $res["ErrorCode"] = 0;
  803. echo json_encode($res);
  804. break;
  805. }
  806. // \app\common\model\Test::update(["content"=>json_encode($access_token)],["id"=>1]);
  807. $infoMessage = $input["MsgBody"];
  808. $badMessage = false;
  809. if($infoMessage) foreach($infoMessage as $k => $v) {
  810. if(isset($v["MsgContent"]["Text"])) {
  811. $message = json_decode($v["MsgContent"]["Text"],true);
  812. $content = isset($message["content"])?$message["content"]:"";
  813. $message_check_url ='https://api.weixin.qq.com/wxa/msg_sec_check?access_token='.$access_token;
  814. $tencentObj = new tencentim($message_check_url);
  815. $content_json = '{"content": "'.$content.'"}';
  816. $body = $tencentObj->messageCheck($content_json);
  817. if($body["errcode"] == 87014) {
  818. // \app\common\model\Test::update(["content"=>$body["errcode"]],["id"=>1]);
  819. // $res = [];
  820. // $res["ActionStatus"] = "OK";
  821. // $res["ErrorInfo"] = "检测到敏感词汇!";
  822. // $res["ErrorCode"] = 1;
  823. // echo json_encode($res);exit;
  824. $message["content"] = "*******";
  825. $infoMessage[$k]["MsgContent"]["Text"] = json_encode($message);
  826. $badMessage = true;
  827. }
  828. }
  829. }
  830. if($badMessage) {
  831. $res = [];
  832. $res["ActionStatus"] = "OK";
  833. $res["ErrorInfo"] = "检测到敏感词汇!";
  834. $res["ErrorCode"] = 10102;
  835. $res["MsgBody"] = $infoMessage;
  836. } else {
  837. $res = [];
  838. $res["ActionStatus"] = "OK";
  839. $res["ErrorInfo"] = "";
  840. $res["ErrorCode"] = 0;
  841. }
  842. // \app\common\model\Test::update(["content"=>json_encode($res)],["id"=>1]);
  843. echo json_encode($res);exit;
  844. break;*/
  845. default:
  846. break;
  847. }
  848. exit;
  849. }
  850. private function getJson($url){
  851. $ch = curl_init();
  852. curl_setopt($ch, CURLOPT_URL, $url);
  853. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  854. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  855. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  856. $output = curl_exec($ch);
  857. curl_close($ch);
  858. return json_decode($output, true);
  859. }
  860. /**
  861. * 发送消息给某人
  862. * type:0普通消息 1自定义消息
  863. */
  864. public function sendMessageToUser($from_user,$to_user,$message, $type = 0) {
  865. // $from_user = 54;
  866. // $to_user = 6;
  867. // $message = "sdsd";
  868. $random = rand(10000000,99999999);
  869. $usersig = $this->usersig("administrator");
  870. // 获取配置信息
  871. $config = config("tencent_im");
  872. $url = "https://console.tim.qq.com/v4/openim/sendmsg";
  873. $url .= "?sdkappid=".$config["sdkappid"];
  874. $url .= "&identifier=administrator";
  875. $url .= "&usersig=".$usersig;
  876. $url .= "&random=".$random;
  877. $url .= "&contenttype=json";
  878. $tencentObj = new tencentim($url);
  879. $data = [];
  880. $data["SyncOtherMachine"] = 1;
  881. $data["From_Account"] = (string)$from_user;
  882. $data["To_Account"] = (string)$to_user;
  883. $data["MsgRandom"] = rand(1000000,9999999);
  884. $data["MsgTimeStamp"] = time();
  885. if ($type == 1) { //自定义消息
  886. $body_message = '{"businessID":"custom_tips_message","receiverShow":true,"senderId":"'.$from_user.'","text":"'.$message.'","tipType":257,"version":0}';
  887. $data["MsgBody"][] = [
  888. "MsgType" => "TIMCustomElem",
  889. "MsgContent" => [
  890. "Data" => $body_message,
  891. "Desc" => $body_message,
  892. "Ext" => 'custom_tips_message',
  893. "Sound" => ''
  894. ],
  895. ];
  896. } else {
  897. $data["MsgBody"][] = [
  898. "MsgType" => "TIMTextElem",
  899. "MsgContent" => [
  900. "Text" => $message
  901. ],
  902. ];
  903. }
  904. $rs = $tencentObj->toSend($data);//p($rs);
  905. }
  906. /**
  907. * 发送消息给某人-接口调用
  908. */
  909. public function sendToUser() {
  910. $from_user = $this->request->request("from_user");// 发送者
  911. $to_user = $this->request->request("to_user");// 接收者
  912. $message = $this->request->request("message");// 接收者
  913. if(!$from_user || !$to_user || !$message) $this->error("参数缺失!");
  914. $this->sendMessageToUser($from_user,$to_user,$message, 1);
  915. }
  916. //请求的基础参数
  917. private function baseTencentObj($url)
  918. {
  919. $random = rand(10000000,99999999);
  920. $usersig = $this->usersig("administrator");
  921. // 获取配置信息
  922. $config = config("tencent_im");
  923. $url = "$url";
  924. $url .= "?sdkappid=".$config["sdkappid"];
  925. $url .= "&identifier=administrator";
  926. $url .= "&usersig=".$usersig;
  927. $url .= "&random=".$random;
  928. $url .= "&contenttype=json";
  929. return new tencentim($url);
  930. }
  931. /** 设置管理员(im端的改变)
  932. * @param $user_id
  933. * @param $party_id
  934. * @param int $status 1:yes 0:no
  935. * @return array|false|mixed
  936. */
  937. public function setUpIMAdmin($user_id, $party_id, int $status=0) {
  938. $url = "https://console.tim.qq.com/v4/group_open_http_svc/modify_group_member_info";
  939. $tencentObj = $this->baseTencentObj($url);
  940. $groupInfo = $this->getGroupInfo($party_id);
  941. if($groupInfo["GroupInfo"][0]["ErrorCode"] > 0) return false;
  942. // 更新的信息
  943. $data = [];
  944. $data["GroupId"] = $party_id;
  945. if ($status==1){
  946. $data['Role'] = 'Admin';
  947. }else{
  948. $data['Role'] = 'Member';
  949. }
  950. $data['Member_Account'] = $user_id;
  951. return $tencentObj->toSend($data);
  952. }
  953. //获取群成员详细资料(目前没用到)
  954. private function getGroupMemberDetails($party_id)
  955. {
  956. $url = "https://console.tim.qq.com/v4/group_open_http_svc/get_group_member_info";
  957. $tencentObj = $this->baseTencentObj($url);
  958. // 获取群组信息
  959. $groupInfo = $this->getGroupInfo($party_id);
  960. if($groupInfo["GroupInfo"][0]["ErrorCode"] > 0) return false;
  961. // 更新的信息
  962. $data = [];
  963. $data["GroupId"] = $party_id;
  964. return $tencentObj->toSend($data);
  965. }
  966. //IM管理员维护,同步本地管理员
  967. public function imAdminMaintenance()
  968. {
  969. $partyIds = \app\admin\model\party\Party::column('id');
  970. foreach ($partyIds as $party_id){
  971. $groupInfo = $this->getGroupInfo($party_id);
  972. if($groupInfo["GroupInfo"][0]["ErrorCode"] > 0) continue;
  973. $roomInfoData = $groupInfo["GroupInfo"][0]["AppDefinedData"];
  974. $roomInfo = [];
  975. if($roomInfoData) foreach($roomInfoData as $k => $v) {
  976. if($v["Key"] == "roomInfo") $roomInfo = $v["Value"];
  977. }
  978. $roomInfo = json_decode($roomInfo,true);
  979. // 更新管理员
  980. if(isset($roomInfo["managers"]) && !empty($roomInfo['managers'])) {
  981. foreach ($roomInfo['managers'] as $v){
  982. $this->setUpIMAdmin($v,$party_id,1);
  983. }
  984. }
  985. }
  986. $this->success("成功!");
  987. }
  988. //拉黑
  989. public function black_one($from_user = '',$to_user = '') {
  990. $from_user = (string)$from_user;
  991. $to_user = (string)$to_user;
  992. $random = rand(10000000,99999999);
  993. $usersig = $this->usersig("administrator");
  994. // 获取配置信息
  995. $config = config("tencent_im");
  996. $url = "https://console.tim.qq.com/v4/sns/black_list_add";
  997. $url .= "?sdkappid=".$config["sdkappid"];
  998. $url .= "&identifier=administrator";
  999. $url .= "&usersig=".$usersig;
  1000. $url .= "&random=".$random;
  1001. $url .= "&contenttype=json";
  1002. $tencentObj = new tencentim($url);
  1003. $data = [];
  1004. $data["From_Account"] = $from_user;
  1005. $data["To_Account"] = [$to_user];
  1006. $rs = $tencentObj->toSend($data);
  1007. return $rs;
  1008. }
  1009. //取消拉黑
  1010. public function un_black_one($from_user = '',$to_user = '') {
  1011. $from_user = (string)$from_user;
  1012. $to_user = (string)$to_user;
  1013. $random = rand(10000000,99999999);
  1014. $usersig = $this->usersig("administrator");
  1015. // 获取配置信息
  1016. $config = config("tencent_im");
  1017. $url = "https://console.tim.qq.com/v4/sns/black_list_delete";
  1018. $url .= "?sdkappid=".$config["sdkappid"];
  1019. $url .= "&identifier=administrator";
  1020. $url .= "&usersig=".$usersig;
  1021. $url .= "&random=".$random;
  1022. $url .= "&contenttype=json";
  1023. $tencentObj = new tencentim($url);
  1024. $data = [];
  1025. $data["From_Account"] = $from_user;
  1026. $data["To_Account"] = [$to_user];
  1027. $rs = $tencentObj->toSend($data);
  1028. return $rs;
  1029. }
  1030. //撤回单聊消息
  1031. public function withdraw_message($from_user = '', $to_user = '',$msgkey = '') {
  1032. // $from_user = 54;
  1033. // $to_user = 6;
  1034. // $message = "sdsd";
  1035. $random = rand(10000000,99999999);
  1036. $usersig = $this->usersig("administrator");
  1037. // 获取配置信息
  1038. $config = config("tencent_im");
  1039. $url = "https://console.tim.qq.com/v4/openim/admin_msgwithdraw";
  1040. $url .= "?sdkappid=".$config["sdkappid"];
  1041. $url .= "&identifier=administrator";
  1042. $url .= "&usersig=".$usersig;
  1043. $url .= "&random=".$random;
  1044. $url .= "&contenttype=json";
  1045. $tencentObj = new tencentim($url);
  1046. $data = [];
  1047. $data["From_Account"] = (string)$from_user;
  1048. $data["To_Account"] = (string)$to_user;
  1049. $data["MsgKey"] = (string)$msgkey;
  1050. $rs = $tencentObj->toSend($data);//p($rs);
  1051. return $rs;
  1052. }
  1053. }