Init(); return self::$Instance; } private static function Init() { self::getDb(); self::getRedis(); self::getGlbData(); } //workman 的共享数据插件 public static function getGlbData() { if (empty(self::$global)) { self::$global = new \GlobalData\Client('127.0.0.1:2207'); } return self::$global; } public static function getDb() { if (empty(self::$db)) { $mds = DIRECTORY_SEPARATOR; if (strtolower(substr(PHP_OS, 0, 3)) == 'win') { $dbcfg = realpath(dirname(__FILE__) . $mds . '..' . $mds . '..' . $mds . '..' . $mds . '..') . $mds . 'application' . $mds . 'database.php'; } else { $dbcfg = realpath(dirname(__FILE__) . $mds . '..' . $mds . '..' . $mds . '..' . $mds . '..' . $mds . '..') . $mds . 'application' . $mds . 'database.php'; } $conf = require($dbcfg); self::$db = new \Workerman\MySQL\Connection($conf['hostname'], $conf['hostport'], $conf['username'], $conf['password'], $conf['database']); } return self::$db; } //实例化redis public static function getRedis($force = 0) { if (!empty(self::$redis) && !$force) { return self::$redis; } $mds = DIRECTORY_SEPARATOR; if (strtolower(substr(PHP_OS, 0, 3)) == 'win') { $dbcfg = realpath(dirname(__FILE__) . $mds . '..' . $mds . '..' . $mds . '..' . $mds . '..') . $mds . 'application' . $mds . 'redis.php'; } else { $dbcfg = realpath(dirname(__FILE__) . $mds . '..' . $mds . '..' . $mds . '..' . $mds . '..' . $mds . '..') . $mds . 'application' . $mds . 'redis.php'; } $conf = require($dbcfg); $redis = new \Redis(); $ret = $redis->connect($conf['host'], $conf['port']); if (!$ret) { return false; } if (!empty($conf['passwd'])) { $ret = $redis->auth($conf['passwd']); if (!$ret) { return false; } } $redis->select($conf['db']); self::$redisTime = time(); self::$redis = $redis; return self::$redis; } //redis ping ,看是否断线 public static function RedisPing() { $ret = self::$redis->ping(); if (strpos("PONG", strtolower($ret)) !== false) { return true; } return false; } //发送消息的代理 public static function MySendMsg($clientId, $msg) { Gateway::sendToClient($clientId, $msg); } //客服是否正在登陆,或已经登陆 0未登陆 1正在登陆 2已登陆成功 public static function userIsLogin($client_id, $kfuid, $groupid) { $hakey = self::$redis->hget("loginTmp:" . $kfuid, $kfuid); if ($hakey) { return 1; } $cids = Gateway::getClientIdByUid($kfuid); if (count($cids) > 0) { return 2; } return 0; } }