Ejemplo n.º 1
0
 public static function getConfig()
 {
     $time = time();
     if (empty(self::$configs) || self::$configs['mtime'] + 1800 < $time) {
         self::$configs = array();
         $db = \Lib\Message::db();
         $table = \Lib\Message::table('system_data');
         $sql = "SELECT `value` FROM `{$table}` WHERE `key`='jpush'";
         $value = @unserialize($db->single($sql));
         if ($value) {
             self::$configs['app_key'] = $value['key'];
             self::$configs['master_secret'] = $value['secret'];
             self::$configs['mtime'] = $time;
         }
     }
     return self::$configs;
 }
Ejemplo n.º 2
0
 /**
  * 用户注销登录
  * @param string $packid 客户端的包ID
  * @param bool $send_notice 是否发送登录通知
  * @return bool 如果已登录返回true,否则返回false
  */
 protected static function logged($packid, $send_notice = true)
 {
     $logged = Message::logged();
     if (!$logged && $send_notice) {
         self::sendDataToCurrentClient('login', $packid, 1003, 'Not logged in');
     }
     return $logged;
 }
Ejemplo n.º 3
0
// 分布式部署时请设置成内网ip(非127.0.0.1)
$gateway->lanIp = '127.0.0.1';
// 内部通讯起始端口,假如$gateway->count=4,起始端口为4000
// 则一般会使用4001 4002 4003 4004 4个端口作为内部通讯端口
$gateway->startPort = 4000;
// 心跳间隔10s
$gateway->pingInterval = 10;
// 20s内客户端未发送任何数据,断开客户端连接
$gateway->pingNotResponseLimit = 2;
// 心跳数据
$gateway->pingData = '{"type":"ping"}';
$gateway->onWorkerStart = function ($worker) {
};
$gateway->onWorkerStop = function ($worker) {
    //当停止时清空已存在的用户和客户端映射
    \Lib\Message::clearUserToClientMap();
};
/* 
// 当客户端连接上来时,设置连接的onWebSocketConnect,即在websocket握手时的回调
$gateway->onConnect = function($connection)
{
    $connection->onWebSocketConnect = function($connection , $http_header)
    {
        // 可以在这里判断连接来源是否合法,不合法就关掉连接
        // $_SERVER['HTTP_ORIGIN']标识来自哪个站点的页面发起的websocket链接
        if($_SERVER['HTTP_ORIGIN'] != 'http://chat.workerman.net')
        {
            $connection->close();
        }
        // onWebSocketConnect 里面$_GET $_SERVER是可用的
        // var_dump($_GET, $_SERVER);