/** * 测试AuthLoggerListener::onTokenPost() */ public function testOnTokenPost() { $e = new Event(); $e->setParam('access_token', 'qihu_token'); $e->setParam('account', "_qihu_m_test_id"); $e->setParam('ip', '192.168.0.1'); $e->setParam('nickname', iconv('utf-8', 'gbk', 'test_name')); $e->setResult(array('id' => 'test_id', 'name' => 'test_name', 'avator' => 'test_avator', 'nick' => 'test_nick')); $e->setZfirm(array('token' => 'zfirm_token')); $this->events->trigger(Event::EVENT_TOKEN_POST, $e); $this->assertStringMatchesFormat('%s INFO (6): 360, access_token: qihu_token, account: _qihu_m_test_id, ip: 192.168.0.1, token: zfirm_token%w', file_get_contents($this->destfile)); }
/** * 执行Zfirm用户平台的Token验证 * * @param AuthEvent $e * @return mixed */ public function onToken(AuthEvent $e) { $user = $e->getResult(); $e->setParam('account', "_jiuyao_m_{$user['Uin']}"); $e->setParam('ip', (new RemoteAddress())->getIpAddress()); $e->setParam('nickname', iconv('utf-8', 'gbk', $user['UserName'])); $user = $this->getUserService(); if (false === ($zfirm = $user->setToken($e->getParam('account'), $e->getParam('ip'), $e->getParam('nickname')))) { return new Failure('获取Zfirm用户平台登陆Token失败。'); } $e->setZfirm($zfirm); return $e->getZfirm(); }