예제 #1
0
 /**
  * 向客户端推送消息
  * @param array $data 需要推送的消息列表
  * @param array|string $users 需要推送到的用户UID列表
  * @param bool $remove_current_user 是否包含当前用户
  * @throws Exception
  */
 protected static function pushMessageData($data, $users, $remove_current_user = true)
 {
     $client_ids = Message::getClientByUser($users, $remove_current_user);
     $message = json_encode(array('type' => 'push_message', 'result' => array('length' => count($data), 'list' => $data), 'status' => 0, 'msg' => ''));
     Gateway::sendToAll($message, $client_ids);
 }
예제 #2
0
 /**
  * 向客户端推送消息
  * @param array $data 需要推送的消息列表
  * @param array|string $users 需要推送到的用户UID列表
  * @param bool $remove_current_user 是否包含当前用户
  * @throws Exception
  */
 protected static function pushMessageData($data, $users, $remove_current_user = true)
 {
     $count = count($data);
     $client_ids = Message::getClientByUser($users, $remove_current_user);
     if ($client_ids) {
         $message = json_encode(array('type' => 'push_message', 'result' => array('from' => 'app', 'length' => $count, 'list' => $data), 'status' => 0, 'msg' => ''));
         Gateway::sendToAll($message, array_values($client_ids));
         $users = array_diff($users, array_keys($client_ids));
     }
     if ($remove_current_user) {
         $uid = (int) Message::getLoggedUserInfo('uid');
         if (in_array($uid, $users)) {
             $key = @array_search($uid, $users);
             if (isset($users[$key])) {
                 unset($users[$key]);
             }
         }
     }
     if ($users) {
         $data = array_pop($data);
         $alert = $data['content'];
         $data['push_type'] = 'message';
         \Lib\Jpush::pushMessage($users, $alert, $data);
     }
 }