public static function createForWechat($accountId) { $account = Account::findByPk($accountId); if (empty($account)) { throw new Exception("Illegal accountId"); } $expire = 3600 * 24 * 10000; //never expired $token = new Token(); $token->accessToken = StringUtil::uuid(); $token->expireTime = new \MongoDate(time() + $expire); $token->userId = ''; $token->accountId = $account['_id']; $token->language = self::DEFAULT_LANGUAGE; $token->enabledMods = ['chat']; $token->role = User::ROLE_WECONNECT; if ($token->save()) { return $token; } throw new Exception("Faile to create token for database problems"); }