sendToAll() публичный статический Метод

向所有客户端(或者client_id_array指定的客户端)广播消息
public static sendToAll ( string $message, array $client_id_array = null )
$message string 向客户端发送的消息(可以是二进制数据)
$client_id_array array 客户端id数组
Пример #1
0
 public function pushMessage($toUids, $data)
 {
     $clients = $this->getClientByUser($toUids);
     if ($clients) {
         if (!class_exists('Gateway', false)) {
             require ADDON_PATH . '/library/GatewayClient/Gateway.php';
         }
         foreach ($data as &$rs) {
             $rs['message_id'] = (int) $rs['message_id'];
             $rs['from_uid'] = (int) $rs['from_uid'];
             $rs['room_id'] = (int) $rs['list_id'];
             $rs['mtime'] = (int) $rs['mtime'];
             $rs['from_uname'] = (string) getUserName($rs['from_uid']);
             if (isset($rs['attach_id'])) {
                 $rs['attach_id'] = @desencrypt($rs['attach_id'], C('SECURE_CODE'));
             }
             $rs['content'] = $this->htmlDecode($rs['content']);
             if (isset($rs['location'])) {
                 $rs['location'] = $this->htmlDecode($rs['location']);
             }
             if (isset($rs['title'])) {
                 $rs['title'] = $this->htmlDecode($rs['title']);
             }
             unset($rs['list_id']);
         }
         $data = json_encode(array('type' => 'push_message', 'result' => array('from' => 'web', 'length' => count($data), 'list' => $data), 'status' => 0, 'msg' => ''));
         Gateway::sendToAll($data, $clients);
     }
 }
Пример #2
0
 public function actionGateway()
 {
     //var_dump( Yii::app()->request->baseUrl.'/protected/components/Config/Store.php');exit;
     var_dump(Gateway::getOnlineStatus());
     $store = Store::instance('wymenu');
     $printData = $store->get('0000000012');
     var_dump($printData);
     exit;
     $ret = $store->set('0000000012', '上海滩的愛している222');
     echo "ddd";
     //Gateway::sendToAll(json_encode(array(a=>"上海滩的愛している",b=>"ddddd11111:")));
     Gateway::sendToAll('{"a":"上海滩的愛している","b":"ddddd11111:"}');
     echo "eee";
 }