Easemob.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use Redis;
  5. use think\Db;
  6. use app\common\library\Easemob as Easemoblib;
  7. /**
  8. * 环信接口
  9. */
  10. class Easemob extends Api
  11. {
  12. protected $noNeedLogin = ["callback"];
  13. protected $noNeedRight = ['*'];
  14. protected $appKey;
  15. protected $redis;
  16. public function __construct() {
  17. //初始化配置
  18. $easemob_config = config('easemob');
  19. $this->appKey = $easemob_config['appkey'];
  20. //redis
  21. $redis = new Redis();
  22. $redisconfig = config("redis");
  23. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  24. if ($redisconfig['redis_pwd']) {
  25. $redis->auth($redisconfig['redis_pwd']);
  26. }
  27. if($redisconfig['redis_selectdb'] > 0){
  28. $redis->select($redisconfig['redis_selectdb']);
  29. }
  30. $this->redis = $redis;
  31. }
  32. /**
  33. * 回调
  34. * https://docs-im-beta.easemob.com/document/server-side/callback_configurations.html
  35. *
  36. * 群组和聊天室操作:
  37. *
  38. * muc:presence 有新成员加入了聊天室
  39. *{"callId":"1101231101159883#demo_1215090885268604500","channel_channel":"1101231101159883#demo_230909515202562@admin.conference.easemob.com","eventType":"chat","channel_user":"1101231101159883#demo_9@easemob.com","chat_type":"muc","security":"845b22a4edcb4fde2185ff7f0374f051","is_downgrade":false,"content_type":"muc:presence","payload":{"muc_id":"1101231101159883#demo_230909515202562@conference.easemob.com","is_chatroom":true,"operation":"presence"},"group_id":"230909515202562","writed_channel":false,"host":"msync@ebs-ali-beijing-msync105","appkey":"1101231101159883#demo","from":"1101231101159883#demo_9@easemob.com","to":"230909515202562","msg_id":"1215090885268604500","timestamp":1700475192937}
  40. *
  41. * muc:kick 踢出聊天室
  42. * {"callId":"1101231101159883#demo_1215088856588617164","channel_channel":"1101231101159883#demo_9@easemob.com","eventType":"chat","channel_user":"1101231101159883#demo_231181574537218@admin.conference.easemob.com","chat_type":"muc","security":"83f9462c7769df1c979fd9dea88e7400","is_downgrade":false,"content_type":"muc:kick","payload":{"muc_id":"1101231101159883#demo_231181574537218@conference.easemob.com","reason":"chatroom kick offline user","is_chatroom":true,"operation":"kick","status":{"description":"","error_code":"ok"}},"group_id":"231181574537218","writed_channel":false,"host":"msync@ebs-ali-beijing-msync71","appkey":"1101231101159883#demo","from":"1101231101159883#demo_9@easemob.com","to":"9","msg_id":"1215088856588617164","timestamp":1700474720591}
  43. *
  44. * muc:absence 有成员离开了聊天室
  45. * {"callId":"1101231101159883#demo_1215088856710252128","channel_channel":"1101231101159883#demo_231181574537218@admin.conference.easemob.com","eventType":"chat","channel_user":"admin@easemob.com","chat_type":"muc","security":"ec7d29ea415ea5930c2236089dff3bc2","is_downgrade":false,"content_type":"muc:absence","payload":{"muc_id":"1101231101159883#demo_231181574537218@conference.easemob.com","is_chatroom":true,"operation":"absence"},"group_id":"231181574537218","writed_channel":false,"host":"msync@ebs-ali-beijing-msync108","appkey":"1101231101159883#demo","from":"1101231101159883#demo_9@easemob.com","to":"231181574537218","msg_id":"1215088856710252128","timestamp":1700474720619}
  46. *
  47. * muc:leave 成员主动退出聊天室
  48. *
  49. *
  50. * 用户登入
  51. * {"callId":"1101231101159883#demo_927e28f2-0e88-4a58-855b-c8d26949ea4f","reason":"login","security":"6b793f812b5ed74f62d3a95d9ea48c8f","os":"android","ip":"182.37.138.94:39768","host":"msync@ebs-ali-beijing-msync60","session_id":"1215076057950983584","appkey":"1101231101159883#demo","user":"1101231101159883#demo_2@easemob.com/android_f9f51032-3369-4f02-95bb-0cbf41b26837","version":"4.1.2","timestamp":1700471740680,"status":"online"}
  52. *
  53. * 用户登出
  54. * {"callId":"1101231101159883#demo_ee82832b-3455-472d-9024-3706b1e519a7","reason":"logout","security":"6266f2a31bc3b603d8458f3d39a49d47","os":"android","ip":"182.37.138.94:39768","host":"msync@ebs-ali-beijing-msync60","session_id":"1215076057950983584","appkey":"1101231101159883#demo","user":"1101231101159883#demo_2@easemob.com/android_f9f51032-3369-4f02-95bb-0cbf41b26837","version":"4.1.2","timestamp":1700472505682,"status":"offline"}
  55. *
  56. * 用户登出(被其他设备踢掉)
  57. * {"callId":"1101231101159883#demo_b2cdc4d9-a499-4e46-8aff-4503fb83a5c5","reason":"replaced","security":"1f4bb2ebb99c2f5da20048c7ca87f352","os":"android","ip":"182.37.138.94:41044","host":"msync@ebs-ali-beijing-msync62","appkey":"1101231101159883#demo","user":"1101231101159883#demo_9@easemob.com/android_fb260fdf-3935-4499-a09d-b270fdd88a0e","version":"4.1.2","timestamp":1700473675582,"status":"offline"}
  58. */
  59. public function callback() {
  60. $this->notify_log_start();
  61. $input = file_get_contents("php://input"); // 主题信息
  62. $input = json_decode($input,true);
  63. //验证加密
  64. //解析数据格式
  65. //用户登入
  66. if(isset($input['reason']) && $input['reason'] == 'login' && isset($input['status']) && $input['status'] == 'online'){
  67. $user = $input['user'];
  68. $uid = $this->get_easemob_uid($user);//用户主键id
  69. //开始处理
  70. $loginToday = Db::name('user')->where('id',$uid)->whereTime('onlinetime', 'today')->find();
  71. if ($loginToday){
  72. \app\common\model\User::update(["is_online"=>1,"onlinetime"=>time()],["id"=>$uid]);
  73. }else{
  74. \app\common\model\User::update(["is_online"=>1,"onlinetime"=>time()],["id"=>$uid]);
  75. }
  76. exit;
  77. }
  78. //用户登出
  79. //用户登出(被其他设备踢掉)
  80. if(isset($input['reason']) && ( $input['reason'] == 'logout' || $input['status'] == 'replaced') && isset($input['status']) && $input['status'] == 'offline'){
  81. $user = $input['user'];
  82. $uid = $this->get_easemob_uid($user);//用户主键id
  83. //开始处理
  84. // 更新用户在线状态为离线
  85. \app\common\model\User::update(["is_online"=>0],["id"=>$uid]);
  86. \app\common\model\User::update(["is_live"=>0],["id"=>$uid]);
  87. $livingUserPartyId = $this->redis->hGet("livingUser", $uid);
  88. if ($livingUserPartyId) {
  89. // 扣除在线用户在房间情况
  90. $this->redis->hDel("livingUser", $uid);
  91. $this->redis->HDel("online_" . $livingUserPartyId, $uid);
  92. $this->redis->zRem("party_user_".$livingUserPartyId,$uid); //新加的
  93. }
  94. // 获取用户所在群信息
  95. $groupids = $this->getJoindGroupList($uid);
  96. // \app\common\model\Test::update(["content"=>json_encode($groupids)],["id"=>1]);
  97. if($groupids["ErrorCode"] == 0) {
  98. $grouplist = $groupids["GroupIdList"];
  99. $groupsites = [];
  100. if($grouplist) foreach($grouplist as $k => $v) {
  101. // 获取群组消息
  102. $groupInfo = $this->getGroupInfo($v["GroupId"]);
  103. if($groupInfo["ErrorCode"] == 0) $groupsites[] = $groupInfo["GroupInfo"][0];
  104. // 踢出用户在线组
  105. $this->redis->HDel("online_".$v["GroupId"],$uid);
  106. $this->redis->zRem("party_user_".$v["GroupId"],$uid); //新加的
  107. // 更新麦位前四
  108. $this->updatePosition($uid,$v["GroupId"]);
  109. // 取消排麦
  110. $this->cancelLineup($uid,$v["GroupId"]);
  111. // 房间状态变更
  112. $partyInfo = $this->redis->get("party_".$v["GroupId"]);
  113. if($partyInfo) {
  114. $partyInfo = json_decode($partyInfo,true);
  115. $memCount = count($this->redis->hGetAll("online_".$v["GroupId"]));
  116. if($memCount <= 0) {
  117. $partyInfo["is_online"] = 0;
  118. $this->redis->set("party_".$v["GroupId"],json_encode($partyInfo));
  119. \app\common\model\Party::update(["is_online"=>0],["id"=>$v["GroupId"]]);
  120. }
  121. }
  122. $liveInfo = $this->redis->get("live_".$v["GroupId"]);
  123. if($liveInfo) {
  124. $liveInfo = json_decode($liveInfo,true);
  125. $memCount = count($this->redis->hGetAll("online_".$v["GroupId"]));
  126. if($memCount <= 0) {
  127. $liveInfo["is_online"] = 0;
  128. $this->redis->set("live_".$v["GroupId"],json_encode($liveInfo));
  129. \app\common\model\Party::update(["is_online"=>0],["id"=>$v["GroupId"]]);
  130. }
  131. }
  132. }
  133. // 强制下麦
  134. print_r($this->downSite($uid,$groupsites));
  135. }
  136. exit;
  137. }
  138. //群组和聊天室操作:
  139. //muc:presence 有新成员加入了聊天室
  140. //muc:kick 踢出聊天室
  141. //muc:absence 有成员离开了聊天室
  142. //muc:leave 成员主动退出聊天室
  143. if(isset($input['chat_type']) && $input['chat_type'] == 'muc' && isset($input['eventType']) && $input['eventType'] == 'chat'){
  144. $room_id = '';
  145. $is_chatroom = false;
  146. $operation = false;
  147. $error_code = false;
  148. if(isset($input['payload'])){
  149. $payload = $input['payload'];
  150. if(isset($payload['muc_id'])){
  151. $room_id = $this->get_easemob_uid($payload['muc_id']);
  152. }
  153. if(isset($payload['is_chatroom']) && $payload['is_chatroom'] == true){
  154. $is_chatroom = true;
  155. }
  156. if(isset($payload['operation']) && in_array($payload['operation'],['kick','absence','leave']) ){
  157. $operation = 'out';
  158. }
  159. if(isset($payload['operation']) && $payload['operation'] = 'presence' ){
  160. $operation = 'in';
  161. }
  162. if(isset($payload['status']['error_code']) && $payload['status']['error_code'] == 'ok'){
  163. $error_code = true;
  164. }
  165. }
  166. //用户
  167. $uid = 0;
  168. if(isset($input['from'])){
  169. $uid = $this->get_easemob_uid($input['from']);
  170. }
  171. //开始处理
  172. //进入房间
  173. if($uid && $room_id && $is_chatroom && $operation == 'in' && $error_code){
  174. $roomId = $room_id;
  175. $userId = $uid;
  176. $this->redis->hSet("online_" . $roomId, $userId, $userId);
  177. $this->redis->zAdd("party_user_".$roomId,$userId,0); //新加的
  178. // 记录在线用户在房间情况
  179. $this->redis->hSet("livingUser",$userId,$roomId);
  180. // 更新房间在线状态
  181. $partyInfo = $this->redis->get("party_" . $roomId);
  182. if ($partyInfo) {
  183. $partyInfo = json_decode($partyInfo, true);
  184. if ($partyInfo["is_online"] != 1) {
  185. $partyInfo["is_online"] = 1;
  186. $this->redis->set("party_" . $roomId, json_encode($partyInfo));
  187. \app\common\model\Party::update(["is_online" => 1], ["id" => $roomId]);
  188. }
  189. }
  190. // 更新房间在线状态
  191. $liveInfo = $this->redis->get("live_" . $roomId);
  192. if ($liveInfo) {
  193. $liveInfo = json_decode($liveInfo, true);
  194. if ($liveInfo["is_online"] != 1) {
  195. $liveInfo["is_online"] = 1;
  196. $this->redis->set("live_" . $roomId, json_encode($liveInfo));
  197. \app\common\model\Party::update(["is_online" => 1], ["id" => $roomId]);
  198. $rs_user = Db::name('user')->where('id',$userId)->update(['is_live'=>1]);
  199. }
  200. }
  201. }
  202. //出去房间
  203. if($uid && $room_id && $is_chatroom && $operation == 'out' && $error_code){
  204. $roomId = $room_id;
  205. $userId = $uid;
  206. $this->redis->HDel("online_" . $roomId, $userId);
  207. $this->redis->zRem("party_user_".$roomId,$userId); //新加的
  208. // 扣除在线用户在房间情况
  209. $this->redis->hDel("livingUser",$userId);
  210. // 更新房间在线状态
  211. $partyInfo = $this->redis->get("party_" . $roomId);
  212. if ($partyInfo) {
  213. $partyInfo = json_decode($partyInfo, true);
  214. $memCount = count($this->redis->hGetAll("online_" . $roomId));
  215. if ($memCount <= 0) {
  216. $partyInfo["is_online"] = 0;
  217. $this->redis->set("party_" . $roomId, json_encode($partyInfo));
  218. \app\common\model\Party::update(["is_online" => 0], ["id" => $roomId]);
  219. }
  220. }
  221. //
  222. $liveInfo = $this->redis->get("live_" . $roomId);
  223. if ($liveInfo) {
  224. $liveInfo = json_decode($liveInfo, true);
  225. $memCount = count($this->redis->hGetAll("online_" . $roomId));
  226. if ($memCount <= 0) {
  227. $liveInfo["is_online"] = 0;
  228. $this->redis->set("live_" . $roomId, json_encode($liveInfo));
  229. \app\common\model\Party::update(["is_online" => 0], ["id" => $roomId]);
  230. $rs_user = Db::name('user')->where('id',$userId)->update(['is_live'=>0]);
  231. }
  232. }
  233. //退出房间获取房间自定义属性
  234. //清理这个人的麦序
  235. $this->clean_seat($roomId,$uid);
  236. }
  237. }
  238. }
  239. //待唱,增加
  240. public function clean_seat($easemob_room_id,$uid){
  241. $party_info = Db::name('party')->where('easemob_room_id',$easemob_room_id)->find();
  242. if(empty($party_info)){
  243. return false;
  244. }
  245. //获取所有麦位,假设8个
  246. $easemob = new Easemoblib();
  247. $seatlist = $easemob->room_getRoomCustomAttribute($easemob_room_id,['seat1','seat2','seat3','seat4','seat5','seat6','seat7','seat8']);
  248. if(empty($seatlist)){
  249. //默认为空
  250. return false;
  251. }
  252. $newseat = [
  253. 'charm' => 0, //红心,魅力值
  254. 'isMaster' => false, // 是否是房主
  255. 'headUrl' => '', // 头像
  256. 'userNo' => '', // 座位上用户no
  257. 'rtcUid' => '', // 座位上用户id,与rtc的userId一致
  258. 'name' => '', // 座位上用户昵称
  259. 'seatIndex' => 0, // 座位编号
  260. 'chorusSongCode' => '', // 是否合唱
  261. 'isAudioMuted' => 1, // 是否静音
  262. 'isVideoMuted' => 0, // 是否开启视频
  263. ];
  264. foreach($seatlist as $k => $seat){
  265. $seat = json_decode($seat,true);
  266. if(isset($seat['rtcUid']) && !empty($seat['rtcUid']) && $seat['rtcUid'] == $uid){
  267. $newseat['seatIndex'] = $seat['seatIndex'];
  268. //重新设置
  269. $matedata = [
  270. $k => json_encode($newseat),
  271. ];
  272. $easemob->room_setRoomCustomAttributeForced($easemob_room_id,$party_info['user_id'],$matedata);
  273. }
  274. }
  275. return true;
  276. }
  277. /**
  278. * 获取用户所加入的聊天室
  279. */
  280. public function getJoindGroupList($user_id) {
  281. $random = rand(10000000,99999999);
  282. $usersig = $this->usersig("administrator");
  283. // 获取配置信息
  284. $config = config("tencent_im");
  285. $url = "https://console.tim.qq.com/v4/group_open_http_svc/get_joined_group_list";
  286. $url .= "?sdkappid=".$config["sdkappid"];
  287. $url .= "&identifier=administrator";
  288. $url .= "&usersig=".$usersig;
  289. $url .= "&random=".$random;
  290. $url .= "&contenttype=json";
  291. $tencentObj = new tencentim($url);
  292. $data = [];
  293. $data["Member_Account"] = $user_id;
  294. $data["WithHugeGroups"] = 1;
  295. $data["GroupType"] = 'AVChatRoom';
  296. $data["ResponseFilter"] = ["GroupBaseInfoFilter" => ['GroupId'] ];
  297. $groupInfo = $tencentObj->toSend($data);
  298. // \app\common\model\Test::update(["content"=>json_encode($groupInfo)],["id"=>1]);
  299. return $groupInfo;
  300. }
  301. /**
  302. * 获取群组信息
  303. */
  304. public function getGroupInfo($party_id='0') {
  305. $party_id = !empty($party_id) ? $party_id : $this->request->param('part_id',0);
  306. $random = rand(10000000,99999999);
  307. $usersig = $this->usersig("administrator");
  308. // 获取配置信息
  309. $config = config("tencent_im");
  310. $url = "https://console.tim.qq.com/v4/group_open_http_svc/get_group_info";
  311. $url .= "?sdkappid=".$config["sdkappid"];
  312. $url .= "&identifier=administrator";
  313. $url .= "&usersig=".$usersig;
  314. $url .= "&random==".$random;
  315. $url .= "&contenttype=json";
  316. $tencentObj = new tencentim($url);
  317. $data = [];
  318. $data["GroupIdList"] = [(string)$party_id];
  319. $data["ResponseFilter"] = [
  320. "GroupBaseInfoFilter" => ["GroupId","Type","Name","FaceUrl","Owner_Account","MemberNum"],
  321. "MemberInfoFilter" => ["Account","Role"],
  322. "AppDefinedDataFilter_Group" => ["roomInfo"],
  323. ];
  324. $groupInfo = $tencentObj->toSend($data);
  325. $this->success('获取成功',$groupInfo['GroupInfo']);
  326. }
  327. /**
  328. * 更新麦位前四
  329. */
  330. public function updatePosition($user_id,$party_id) {
  331. // 获取用户头像
  332. $userInfo = \app\common\model\User::field("avatar")->where(["id"=>$user_id])->find();
  333. $userAvatar = isset($userInfo["avatar"])?$userInfo["avatar"]:"";
  334. // 更新下麦时间
  335. $update = [];
  336. $update["offsite_time"] = time();
  337. $update["status"] = 2;
  338. \app\common\model\UserOnsiteTime::update($update,["user_id"=>$user_id,"status"=>1]);
  339. //
  340. $redis = new Redis();
  341. $redisconfig = config("redis");
  342. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  343. if ($redisconfig['redis_pwd']) {
  344. $redis->auth($redisconfig['redis_pwd']);
  345. }
  346. if($redisconfig['redis_selectdb'] > 0){
  347. $redis->select($redisconfig['redis_selectdb']);
  348. }
  349. $room_type = Db::name('party')->where('id',$party_id)->value('room_type');
  350. $redisData = $redis->get($room_type."_".$party_id);
  351. if(!$redisData){
  352. return true;
  353. }
  354. $partyInfo = json_decode($redisData,true);
  355. // 遍历已有头像
  356. $partyuser = isset($partyInfo["party_user"])?$partyInfo["party_user"]:"";
  357. if(is_array($partyuser)) foreach($partyuser as $k => $v) if($v === $userAvatar) unset($partyInfo["party_user"][$k]);
  358. $redis->set($room_type."_".$party_id,json_encode($partyInfo));
  359. }
  360. /**
  361. * 取消排麦
  362. */
  363. public function cancelLineUp($user_id,$party_id) {
  364. if (!$party_id || !$user_id) {
  365. return false;
  366. }
  367. $redis = new Redis();
  368. $redisconfig = config("redis");
  369. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  370. if ($redisconfig['redis_pwd']) {
  371. $redis->auth($redisconfig['redis_pwd']);
  372. }
  373. if($redisconfig['redis_selectdb'] > 0){
  374. $redis->select($redisconfig['redis_selectdb']);
  375. }
  376. $data=unserialize($redis->hGet("party_lineup",$party_id));
  377. // 更改红点排麦数量
  378. $num = 0;
  379. $send = false;
  380. if($data) foreach($data as $k => $v) {
  381. if($v["user_id"] == $user_id) {
  382. $send = true;
  383. unset($data[$k]);
  384. break;
  385. }
  386. }
  387. $redis->hSet("party_lineup",$party_id,serialize($data));
  388. if($send) {
  389. is_array($data) && $num = count($data);
  390. $random = rand(10000000,99999999);
  391. $usersig = $this->usersig("administrator");
  392. // 获取配置信息
  393. $config = config("tencent_im");
  394. $url = "https://console.tim.qq.com/v4/group_open_http_svc/send_group_msg";
  395. $url .= "?sdkappid=".$config["sdkappid"];
  396. $url .= "&identifier=administrator";
  397. $url .= "&usersig=".$usersig;
  398. $url .= "&random=".$random;
  399. $url .= "&contenttype=json";
  400. $tencentObj = new tencentim($url);
  401. $data = [];
  402. $data["GroupId"] = $party_id;
  403. $data["Random"] = rand(1000000,9999999);
  404. $message = [
  405. "message" => json_encode(["type"=>23,"content"=>$num]),
  406. "version" => "1.0",
  407. "action" => 301,
  408. "command" => ""
  409. ];
  410. $data["MsgBody"][] = [
  411. "MsgType" => "TIMCustomElem",
  412. "MsgContent" => [
  413. "Data"=> json_encode($message)
  414. ],
  415. ];
  416. $tencentObj->toSend($data);
  417. }
  418. }
  419. /**
  420. * 强制下线
  421. */
  422. public function downSite($user_id,$groupsites) {
  423. $random = rand(10000000,99999999);
  424. $usersig = $this->usersig("administrator");
  425. // 获取配置信息
  426. $config = config("tencent_im");
  427. $url = "https://console.tim.qq.com/v4/group_open_http_svc/modify_group_base_info";
  428. $url .= "?sdkappid=".$config["sdkappid"];
  429. $url .= "&identifier=administrator";
  430. $url .= "&usersig=".$usersig;
  431. $url .= "&random=".$random;
  432. $url .= "&contenttype=json";
  433. $tencentObj = new tencentim($url);
  434. // 先更新下麦时间
  435. $update = [];
  436. $update["offsite_time"] = time();
  437. $update["status"] = 2;
  438. \app\common\model\UserOnsiteTime::update($update,["user_id"=>$user_id,"status"=>1]);
  439. // 循环房间
  440. if($groupsites) foreach($groupsites as $k => $v) {
  441. // 循环座位
  442. $data = [];
  443. foreach($v["AppDefinedData"] as $m => $n) {
  444. // 解析字段信息
  445. $siteInfo = json_decode($n["Value"],true);
  446. if($m != 0 && isset($siteInfo["status"]) && $siteInfo["status"] == 1 && isset($siteInfo["status"]) && $siteInfo["user"] == $user_id) {
  447. $data["AppDefinedData"][] = [
  448. "Key" => $n["Key"],
  449. "Value" => '{"mute":false,"status":0,"user":""}',
  450. ];
  451. }
  452. }
  453. if(!empty($data)) {
  454. $data["GroupId"] = $v["GroupId"];
  455. return $tencentObj->toSend($data);
  456. }
  457. }
  458. }
  459. //输入: 1101231101159883#demo_9@easemob.com/android_f9f51032-3369-4f02-95bb-0cbf41b26837
  460. //输出: 9
  461. //输入: 1101231101159883#demo_231181574537218@admin.conference.easemob.com
  462. //输出: 231181574537218
  463. private function get_easemob_uid($user = ''){
  464. //去掉后半段
  465. $easemob = '@';
  466. $start = strpos($user,$easemob);
  467. $uid = substr($user,0,$start);
  468. //echo $uid;
  469. //echo '<br>';
  470. //去掉前缀
  471. $uid = substr($uid,strlen($this->appKey)+1);
  472. //echo $uid;
  473. return intval($uid);
  474. }
  475. //异步日志
  476. private function notify_log_start($paytype = 'easemob'){
  477. //记录支付回调数据
  478. ignore_user_abort(); // run script in background
  479. set_time_limit(30);
  480. // 日志文件 start
  481. $log_base_dir = '../paylog/'.$paytype.'/';
  482. if (!is_dir($log_base_dir))
  483. {
  484. mkdir($log_base_dir, 0770, true);
  485. @chmod($log_base_dir, 0770);
  486. }
  487. $notify_file = $log_base_dir.'notify.txt';
  488. if(!file_exists($notify_file)) {
  489. @touch($notify_file);
  490. @chmod($notify_file, 0770);
  491. }
  492. if(filesize($notify_file)>5242880)//大于5M自动切换
  493. {
  494. rename($notify_file, $log_base_dir.'notify_'.date('Y_m_d_H_i_s').'.txt');
  495. }
  496. if(!file_exists($notify_file)) {
  497. @touch($notify_file);
  498. @chmod($notify_file, 0770);
  499. }
  500. // 日志文件 end
  501. //开始写入
  502. $xml = file_get_contents("php://input");
  503. file_put_contents($notify_file, "\r\n\r\n".date('Y-m-d H:i:s')." [notify][入口接收php://input流原始数据] \n".$xml, FILE_APPEND);
  504. ini_set('display_errors','On');
  505. return $notify_file;
  506. }
  507. }