user_id = $user_id;
$this->room_id = $room_id;
$this->topic_room = 'room_' . $this->room_id;
$this->topic_client = 'user_' . $this->user_id;
}
public function setUser($user_id)
{
$this->user_id = $user_id;
$this->topic_client = 'user_' . $user_id;
}
public function setRoom($room_id)
{
$this->room_id = $room_id;
$this->topic_room = 'room_' . $room_id;
}
private function push($push_type, $topic, $data = [])
{
Loader::import('Mqtt.Mqtt', EXTEND_PATH, '.php');
$mqtt = new \Mqtt();
$content = json_encode(
[
'type' => $push_type,
'time' => getMillisecond(),
'msg' => $data,
]
);
$mqtt->publishs($topic, $content);
}
/**
* 推送许愿池手气榜记录
*/
public function luckyRank($data)
{
$topic = 'room';
$this->push(self::PUSH_LUCKYRANK, $topic, $data);
return true;
}
//推送人气
public function updatePopularity($popularity)
{
$topic = '$delayed/1/' . $this->topic_room;
$data = ['popularity' => $popularity, 'room_id' => $this->room_id];
$this->push(self::PUSH_POPULARITY, $topic, $data);
}
//推送上麦
public function pitOn($pit_number, $data)
{
$topic = $this->topic_room;
$data['room_id'] = $this->room_id;
$data['pit_number'] = intval($pit_number);
$ball = S('room:user:ball:' . $this->room_id . ':' . $this->user_id);
$data['ball_state'] = $ball === false ? 0 : 1;
$this->push(self::PUSH_PIT_ON, $topic, $data);
}
//推送下麦
public function pitDown($down_info)
{
$topic = $this->topic_room;
$data = ['room_id' => $this->room_id,
'pit_number' => intval($down_info['pit_number']),
'user_id' => intval($this->user_id),
'emchat_username'=>$down_info['emchat_username']];
$this->push(self::PUSH_PIT_DOWN, $topic, $data);
}
//带坐骑用户进场特效通知
public function ride($ride_info)
{
$topic = '$delayed/1/' . $this->topic_room;
$data = [
'room_id' => $this->room_id,
'ride_url' => $ride_info['special'],
'show_type' => $ride_info['show_type']
];
$this->push(self::PUSH_RIDE, $topic, $data);
}
//带爵位用户进场特效通知
public function nobility($data)
{
$topic = '$delayed/1/' . $this->topic_room;
if ($data['nobilityId'] == 6) {
$special = 'https://yutangyuyin.oss-cn-hangzhou.aliyuncs.com/nobility/' . $data['nobilityId'] . '.svga';
} else {
$special = '';
}
//爵位特效暂时不推
$special = '';
$data = [
'room_id' => $this->room_id,
'user_id' => $this->user_id,
'nobility_name' => $data['nobilityName'],
'nobility_id' => $data['nobilityId'],
'nobility_icon' => $data['nobility_icon'],
'avatar' => $data['headPicture'],
'nickname' => $data['userName'],
'special' => $special,
'sex' => $data['sex'],
];
$this->push(self::PUSH_NOBILITY, $topic, $data);
}
//上麦申请人数变化通知
public function applyCount($count, $user_ids = '')
{
$topic = $this->topic_room;
$count_8 = M('RoomPitApply')->where(['room_id' => $this->room_id, 'pit_number' => 8])->count();
$count_8 = $count_8 > 0 ? $count_8 : 0;
$total_count = $count - $count_8;
$data = [
'room_id' => $this->room_id,
'count' => $total_count > 0 ? $total_count : 0,
'count_8' => $count_8,
'user_ids' => $user_ids
];
$this->push(self::PUSH_APPLY_COUNT, $topic, $data);
}
//用户被禁言 action 1禁言2解禁
public function bannedUser($action)
{
$topic = $this->topic_room;
$data = ['room_id' => $this->room_id, 'user_id' => $this->user_id, 'action' => $action];
$this->push(self::PUSH_BANNED_USER, $topic, $data);
}
//是否封麦 1.封麦 2.解除封麦
public function closePit($pit_number, $action)
{
$topic = $this->topic_room;
$data = ['room_id' => $this->room_id, 'pit_number' => $pit_number, 'action' => $action];
$this->push(self::PUSH_CLOSE_PIT, $topic, $data);
}
//清空单个麦位心动值
public function clearCardiac($pit_number)
{
$topic = $this->topic_room;
$data = ['room_id' => $this->room_id, 'pit_number' => $pit_number];
$this->push(self::PUSH_CLEAR_CARDIAC, $topic, $data);
}
//清空所有麦位心动值
public function clearCardiacAll()
{
$topic = $this->topic_room;
$data = ['room_id' => $this->room_id];
$this->push(self::PUSH_CLEAR_CARDIAC_ALL, $topic, $data);
}
//设置房间管理员
public function setManager()
{
$topic = $this->topic_room;
$data = ['room_id' => $this->room_id, 'user_id' => $this->user_id];
$this->push(self::PUSH_SET_MANAGER, $topic, $data);
}
//删除房间管理员
public function deleteManager()
{
$topic = $this->topic_room;
$data = ['room_id' => $this->room_id, 'user_id' => $this->user_id];
$this->push(self::PUSH_DELETE_MANAGER, $topic, $data);
}
//开关麦 action 1开0关
public function switchVoice($action, $pit_number = 0)
{
$topic = $this->topic_room;
$data = [
'room_id' => $this->room_id,
'user_id' => $this->user_id,
'pit_number' => $pit_number,
'action' => $action
];
$this->push(self::PUSH_SWITCH_VOICE, $topic, $data);
}
// =======================================================================================================
// ========================================秘地使用开始=====================================================================
//横幅礼物通知
public function giftBanner($gift_list)
{
$topic = 'qx_room_topic';
//数组重组下标从0开始
$gift_list = array_values($gift_list);
$data = ['room_id' => $this->room_id, 'list' => $gift_list];
$this->push(self::PUSH_GIFT_BANNER, $topic, $data);
}
//系统消息
public function systemMessage($text_list)
{
$topic = 'system_message';
$data = ['list' => $text_list];
$this->push(self::PUSH_SYSTEM_MESSAGE, $topic, $data);
}
//巡乐会推送
public function xunlehui($data){
$topic = 'qx_xunlehui';
$this->push(self::PUSH_ROOM_PAN_XLH_PROGRESS, $topic, $data);
}
//小时榜推送
public function hourRanking($data){
$topic = 'qx_hour_ranking';
$this->push(self::PUSH_ROOM_PAN_HOUR_PROGRESS, $topic, $data);
}
//红包来了
public function redpacketArrive($data){
$topic = 'qx_redpacket_arrive';
$this->push(self::PUSH_ROOM_PAN_RED_PROGRESS, $topic, $data);
}
// =========================================秘地使用结束=====================================================
// =============================================================================================================
//聊天室礼物通知
public function giftChatRoom($gift_list, $cardiac, $contribution, $show_cat = 0)
{
$topic = $this->topic_room;
$data = [
'room_id' => $this->room_id,
'gift_list' => $gift_list,
'cardiac_list' => $cardiac,
'contribution' => $contribution,
'show_cat' => $show_cat,
'user_id' => $this->user_id
];
$this->push(self::PUSH_GIFT_CHAT_ROOM, $topic, $data);
}
//自由上麦换麦通知
public function sendPitNumber($data)
{
$topic = $this->topic_room;
$data = $data;
$this->push(self::PUSH_CHANGE_PIT, $topic, $data);
}
//聊天室心动值变化通知
public function heartChatRoom($heart)
{
$topic = $this->topic_room;
$data['list'] = $heart;
$data['room_id'] = $this->room_id;
$this->push(self::PUSH_CHANGE_HEARTBEAT, $topic, $data);
}
//推送房间-交友-心动连线环节 延时推送
public function friendDelayed($endtime)
{
$topic = $this->topic_room;
$data = $endtime;
$this->push(self::PUSH_FRIEND_ADD_TIME, $topic, $data);
}
//私密小屋刷礼物后推送
public function heartSmallRoom($heart)
{
$topic = $this->topic_room;
$data = $heart;
$this->push(self::PUSH_SMALL_ROOM_ADD_TIME, $topic, $data);
}
//聊天室排行榜通知
public function rankChatRoom($data_list)
{
$topic = $this->topic_room;
$data['list'] = $data_list;
$data['room_id'] = $this->room_id;
$this->push(self::PUSH_PIT_CHANGE, $topic, $data);
}
//进入小黑屋
//退出小黑屋
public function blackRoom($cp_room_id,$users,$action,$room_on_line_cp=0,$heart_id=0,$heart_value=0)
{
$topic = $this->topic_room;
if($action == 1){ //进入小黑屋
$data = ['room_id' => $this->room_id,'cp_room_id'=>$cp_room_id,'users' => $users,'room_on_line_cp' => $room_on_line_cp,'heart_id'=>$heart_id,'heart_value'=>$heart_value,'end_time'=>time()+600];
$this->push(self::PUSH_PIT_JOIN_SMALL_ROOM, $topic, $data);
}else{//退出小黑屋
$data = ['room_id' => $this->room_id,'pid_room_id'=>$cp_room_id,'users' => $users,'room_on_line_cp' => $room_on_line_cp,'heart_id'=>$heart_id,'heart_value'=>$heart_value];
$this->push(self::PUSH_PIT_OUT_SMALL_ROOM, $topic, $data);
}
}
//交由环节状态
public function stage($roomid,$stage,$end_time="")
{
$topic = $this->topic_room;
if($stage == 2) {
$data = ['room_id' => $roomid, 'status' => $stage,'end_time'=>$end_time];
}else{
$data = ['room_id' => $roomid, 'status' => $stage];
}
$this->push(self::PUSH_FRIEND_STATUS, $topic, $data);
}
//聊天室在线心动人数 PUSH_ONLINE_DATING_NUM
public function onlineDatingNum($room_id,$online_num)
{
$topic = $this->topic_room;
$data = ['room_id' => $room_id, 'online_num' => $online_num];
$this->push(self::PUSH_ONLINE_DATING_NUM, $topic, $data);
}
//许愿池钓到大礼物时通知
public function fish($data, $user_info,$name)
{
$gift_list = $data['gift_list'];
$txt = "哇塞".$user_info['nickname']."在{$name}中获得";
$txt_extra = [];
foreach ($gift_list as $key => $value) {
if ($value['price'] >= C('WISH_PUSH_MONEY')) {
$txt_extra [] = [
'text' => $txt."".$value['prize_title']."X".$value['number']."",
'picture' => $value['picture'],
];
}
}
if (!empty($txt_extra)) {
$topic = 'room';
$this->push(self::PUSH_FISH, $topic, $txt_extra);
}
}
//房间密码 0取消密码1设置或修改密码
public function roomPassword($action)
{
$topic = $this->topic_room;
$data = ['room_id' => $this->room_id, 'action' => $action];
$this->push(self::PUSH_ROOM_PASSWORD, $topic, $data);
}
//房间心动值开关 1开2关
public function cardiacSwitch($action)
{
$topic = $this->topic_room;
$data = ['room_id' => $this->room_id, 'action' => $action];
$this->push(self::PUSH_CARDIAC_SWITCH, $topic, $data);
}
//上麦模式变化 1自由2排麦
public function roomWheat($action)
{
$topic = $this->topic_room;
$data = ['room_id' => $this->room_id, 'action' => $action];
$this->push(self::PUSH_ROOM_WHEAT, $topic, $data);
}
//修改房间名称
public function updateRoomName($room_name)
{
$topic = $this->topic_room;
$data = ['room_id' => $this->room_id, 'room_name' => $room_name];
$this->push(self::PUSH_UPDATE_ROOM_NAME, $topic, $data);
}
//周星用户进场
public function weekStar($nickname, $rank)
{
$topic = $this->topic_room;
$data = ['room_id' => $this->room_id, 'nickname' => $nickname, 'rank' => $rank];
$this->push(self::PUSH_WEEK_STAR, $topic, $data);
}
//修改房间背景
public function updateRoomBackground($background)
{
$topic = $this->topic_room;
$data = ['room_id' => $this->room_id, 'background' => $background];
$this->push(self::PUSH_UPDATE_ROOM_BACKGROUND, $topic, $data);
}
//修改房间玩法|公告
public function updateRoomPlaying($playing, $greeting)
{
$topic = $this->topic_room;
$data = ['room_id' => $this->room_id, 'playing' => $playing, 'greeting' => $greeting];
$this->push(self::PUSH_UPDATE_ROOM_PLAYING, $topic, $data);
}
//boss大作战 超过99999金币 发送所有人消息
public function AttackBoss($gift_list, $user_info)
{
$txt = "哇塞" . $user_info['nickname'] . "在BOSS大作战中获得";
$txt_extra = [];
foreach ($gift_list as $key => $value) {
if ($value['price'] >= 5200) {
$txt_extra [] = [
'text' => $txt."".$value['prize_title']."X".$value['number']."",
'picture' => $value['picture'],
];
}
}
if (!empty($txt_extra)) {
$topic = 'room';
$this->push(self::PUSH_BOSS_ATTACK, $topic, $txt_extra);
}
}
//boss大作战血量变化推送
public function bossBlood($left_blood = 0, $total_blood = 0, $gift_list = [], $user_info = [])
{
if ($gift_list) {
foreach ($gift_list as $key => $value) {
if ($value['price'] >= 520) {
$gift_list[$key]['nickname'] = $user_info['nickname'];
} else {
unset($gift_list[$key]);
}
}
}
$topic = 'boss';
$data = ['left_blood' => $left_blood, 'total_blood' => $total_blood, 'gift_list' => array_values($gift_list)];
$this->push(self::PUSH_BOSS_BLOOD, $topic, $data);
}
//定向推送给上麦的用户
public function agreeApplyUser($pit_number)
{
$topic = $this->topic_client;
$data = ['room_id' => $this->room_id, 'pit_number' => $pit_number];
$this->push(self::PUSH_APPLY_USER, $topic, $data);
}
//定向推送给被踢出房间的用户
public function kickOut()
{
$topic = $this->topic_client;
$data = ['room_id' => $this->room_id, 'user_id' => $this->user_id];
$this->push(self::PUSH_KICK_OUT, $topic, $data);
}
//用户禁麦 action 1禁麦2解禁
public function shutUp($action, $pit_number)
{
$topic = $this->topic_room;
$data = [
'room_id' => $this->room_id,
'action' => $action,
'pit_number' => $pit_number,
'user_id' => $this->user_id
];
$this->push(self::PUSH_SHUT_UP, $topic, $data);
}
//用户进入房间
public function joinRoom($nickname, $rank_icon, $role, $user_is_new)
{
$topic = $this->topic_room;
$data = [
'room_id' => $this->room_id,
'user_id' => $this->user_id,
'nickname' => $nickname,
'rank_icon' => $rank_icon,
'role' => $role,
'user_is_new' => $user_is_new
];
$this->push(self::PUSH_JOIN_ROOM, $topic, $data);
}
//麦位倒计时
public function countDown($pit_number, $seconds)
{
$topic = $this->topic_room;
$data = ['room_id' => $this->room_id, 'pit_number' => $pit_number, 'seconds' => $seconds];
$this->push(self::PUSH_COUNT_DOWN, $topic, $data);
}
//扔骰子
public function roll($number, $pit_number)
{
$topic = $this->topic_room;
$data = [
'room_id' => $this->room_id,
'user_id' => $this->user_id,
'number' => $number,
'pit_number' => $pit_number
];
$this->push(self::PUSH_ROLL, $topic, $data);
}
//电台房开通黄金守护
public function fmGold($nickname_from, $nickname_to)
{
$topic = 'room';
$data = ['room_id' => $this->room_id, 'nickname_from' => $nickname_from, 'nickname_to' => $nickname_to];
$this->push(self::PUSH_FM_GOLD, $topic, $data);
}
//发送表情
public function face($pit_number, $picture, $special)
{
$topic = $this->topic_room;
$data = [
'room_id' => $this->room_id,
'pit_number' => $pit_number,
'picture' => $picture,
'special' => $special
];
$this->push(self::PUSH_FACE, $topic, $data);
}
//上传即构日志
public function zegoLog()
{
$topic = $this->topic_client;
$data = ['user_id' => $this->user_id];
$this->push(self::PUSH_ZEGO_LOG, $topic, $data);
}
//公屏状态
public function roomChatStatus($status)
{
$topic = $this->topic_room;
$data = ['room_id' => $this->room_id, 'status' => $status];
$this->push(self::PUSH_ROOM_CHAT_STATUS, $topic, $data);
}
//球球大作战-开球
public function ballStart($pit_number)
{
$topic = $this->topic_room;
$data = ['room_id' => $this->room_id, 'pit_number' => $pit_number];
$this->push(self::PUSH_BALL_START, $topic, $data);
}
//球球大作战-弃球
public function ballThrow($pit_number)
{
$topic = $this->topic_room;
$data = ['room_id' => $this->room_id, 'pit_number' => $pit_number];
$this->push(self::PUSH_BALL_THROW, $topic, $data);
}
//球球大作战-亮球
public function ballShow($pit_number, $first, $second, $third)
{
$topic = $this->topic_room;
$data = [
'room_id' => $this->room_id,
'pit_number' => $pit_number,
'first' => $first,
'second' => $second,
'third' => $third,
'user_id' => $this->user_id
];
$this->push(self::PUSH_BALL_SHOW, $topic, $data);
}
//房间音效改变
public function soundEffectChange($sound_effect_detail)
{
$topic = $this->topic_room;
$data = [
'room_id' => $this->room_id,
'id' => $sound_effect_detail['id'],
'config' => $sound_effect_detail['config']
];
$this->push(self::PUSH_SOUND_EFFECT_CHANGE, $topic, $data);
}
//更新房主模式
public function ownerModel($data)
{
$topic = $this->topic_room;
$this->push(self::PUSH_ROOM_OWNER_MODEL, $topic, $data);
}
//退出房间
public function quitRoom($data)
{
$topic = $this->topic_room;
$this->push(self::PUSH_ROOM_QUIT, $topic, $data);
}
public function gamePush($data){
$topic = 'room';
$this->push(self::PUSH_GAME_TIPS, $topic, $data);
}
public function gameProgressPush($data){
$topic = 'room';
$this->push(self::PUSH_WISH_PROGRESS, $topic, $data);
}
//游戏达到大礼物时通知
public function game($giftInfo, $nickname,$title)
{
$txt = "哇塞".$nickname."在{$title}中获得";
$txt_extra = [];
foreach ($giftInfo as $key => $value) {
if ($value['price'] >= 5200) {
$txt_extra [] = [
'text' => $txt."".$value['prize_title']."X".$value['number']."",
'picture' => $value['picture']
];
}
}
if (!empty($txt_extra)) {
$topic = 'room';
$this->push(self::PUSH_FISH, $topic, $txt_extra);
}
}
//推送房间类型发生变化
public function roomTypeChange($data)
{
$topic = $this->topic_room;
$this->push(self::PUSH_CHANGE_ROOM_LABEL, $topic, $data);
}
}