Authored by Rock Zhang

修改第三方登录有关

... ... @@ -96,7 +96,7 @@ class AbstractAction extends Controller_Abstract
{
$json = json_encode($json);
}
echo $json;
}
... ... @@ -137,4 +137,30 @@ class AbstractAction extends Controller_Abstract
exit;
}
/**
* 设置Cookie
*
* @param string $name cookie的名字
* @param string $value cookie的值
* @param integer $expire cookie过期时间
* @param integer $path cookie可用的路径
* @param string $domain cookie可用域名
*/
protected function setCookie($name, $value, $expire = 0, $path = '/',$domain = 'yohobuy.com')
{
setcookie('alipay_redirect', $value, $expire, $path, $domain);
}
/**
* 返回Cookie变量
*
* @param string $name cookie名称
* @param string $default 未获取到返回的默认值
* @return string 获取到的cookie值
*/
protected function getCookie($name, $default = '')
{
return $this->request->getCookie($name, $default);
}
}
... ...
... ... @@ -50,6 +50,11 @@ class LoginController extends AbstractAction
*/
public function alipayAction()
{
$redirect = $this->_request->getServer('HTTP_REFERER', '');
if($redirect != '')
{
$this->setCookie('alipay_redirect', $redirect);
}
Factory::create('alipay')->getAuthorizeUrl();
exit();
... ... @@ -61,6 +66,11 @@ class LoginController extends AbstractAction
*/
public function qqAction()
{
$redirect = $this->_request->getServer('HTTP_REFERER', '');
if($redirect != '')
{
$this->setCookie('qq_redirect', $redirect);
}
Factory::create('qqconnect')->getAuthorizeUrl();
exit();
... ... @@ -72,6 +82,11 @@ class LoginController extends AbstractAction
*/
public function sinaAction()
{
$redirect = $this->_request->getServer('HTTP_REFERER', '');
if($redirect != '')
{
$this->setCookie('sina_redirect', $redirect);
}
header('Location:' . Factory::create('sinaweibo')->getAuthorizeUrl());
exit();
... ... @@ -108,8 +123,11 @@ class LoginController extends AbstractAction
if($result['code'] == 200)
{
echo '登陆成功';
$redirect = $this->_request->getCookie('alipay_redirect');
$redirect && $this->redirect($redirect);
}
$this->redirect('/');
}
/**
... ... @@ -121,7 +139,6 @@ class LoginController extends AbstractAction
$access = $qqconnect->getAccessToken();
/* 获取QQ腾讯用户的详细信息 */
$partnerInfo = $qqconnect->getUserInfo($access);
var_dump($access, $partnerInfo);
if ($partnerInfo && is_array($partnerInfo))
{
... ... @@ -129,9 +146,12 @@ class LoginController extends AbstractAction
if($result['code'] == 200)
{
echo '登陆成功';
$redirect = $this->_request->getCookie('qq_redirect');
$redirect && $this->redirect($redirect);
}
}
}
$this->redirect('/');
}
/**
... ... @@ -143,7 +163,6 @@ class LoginController extends AbstractAction
$access = $sina->getAccessToken();
/* 获取QQ腾讯用户的详细信息 */
$partnerInfo = $sina->getUserInfo($access);
var_dump($access, $partnerInfo);
if ($partnerInfo && is_array($partnerInfo))
{
... ... @@ -151,8 +170,11 @@ class LoginController extends AbstractAction
if($result['code'] == 200)
{
echo '登陆成功';
$redirect = $this->_request->getCookie('sina_redirect');
$redirect && $this->redirect($redirect);
}
}
}
$this->redirect('/');
}
}
\ No newline at end of file
... ...