Commit f56aa2ae by doszhang

d

parent 6bc4966b
<?php <?php
namespace Home\Controller; namespace Home\Controller;
use Think\Log; use Think\Log;
use SignedCookie; use SignedCookie;
use Zhida\OAuthHelperV3; use Zhida\OAuthHelperV3;
//use Common\Common\OAuthHelperV3; //use Common\Common\OAuthHelperV3;
trait ControllerTrait trait ControllerTrait
{ {
protected function get_user_info_from_cookie() protected function get_user_info_from_cookie()
...@@ -17,24 +14,13 @@ trait ControllerTrait ...@@ -17,24 +14,13 @@ trait ControllerTrait
// } // }
$cookie_secret = C('cookie_sign'); $cookie_secret = C('cookie_sign');
$openid = \SignedCookie::get_cookie($this->cookie_uid_key, $cookie_secret, 86400 * 60); $openid = \SignedCookie::get_cookie($this->cookie_uid_key, $cookie_secret, 86400 * 60);
echo 3;die();
if (!$openid) { if (!$openid) {
return false; return false;
} }
if($user['last_date'] != date('Ymd'))
{
M('user')->where(array(
'openid' => $openid
))->save(array(
'last_date' => date('Ymd'),
'answer_time' => 5
));
}
$user = M('User')->where(array('openid' => $openid))->find(); $user = M('User')->where(array('openid' => $openid))->find();
return $user; return $user;
} }
protected function request_auth($redirect_url = '/') protected function request_auth($redirect_url = '/')
{ {
$app_id = C('auth_app_id'); $app_id = C('auth_app_id');
...@@ -44,7 +30,7 @@ trait ControllerTrait ...@@ -44,7 +30,7 @@ trait ControllerTrait
$helper = new OAuthHelperV3($app_id, $client_id, $client_password, $support_fake_openid); $helper = new OAuthHelperV3($app_id, $client_id, $client_password, $support_fake_openid);
$site_url = C('SITE_URL'); $site_url = C('SITE_URL');
if (!$site_url) { if (!$site_url) {
$sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'https://'; $sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';
$site_url = $sys_protocal . $_SERVER['HTTP_HOST']; $site_url = $sys_protocal . $_SERVER['HTTP_HOST'];
} }
$callback_url = "{$site_url}/auth"; $callback_url = "{$site_url}/auth";
...@@ -54,16 +40,14 @@ trait ControllerTrait ...@@ -54,16 +40,14 @@ trait ControllerTrait
redirect($auth_url); redirect($auth_url);
exit(0); exit(0);
} }
protected function get_url() protected function get_url()
{ {
$sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'https://'; $sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';
$php_self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']; $php_self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
$path_info = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : ''; $path_info = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
$relate_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $php_self . (isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : $path_info); $relate_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $php_self . (isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : $path_info);
return $sys_protocal . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '') . $relate_url; return $sys_protocal . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '') . $relate_url;
} }
public function auth() public function auth()
{ {
//如果是分享出去的链接,重新授权 //如果是分享出去的链接,重新授权
...@@ -71,13 +55,11 @@ trait ControllerTrait ...@@ -71,13 +55,11 @@ trait ControllerTrait
$this->request_auth(); $this->request_auth();
exit(0); exit(0);
} }
$app_id = C('auth_app_id'); $app_id = C('auth_app_id');
$client_id = C('auth_client_id'); $client_id = C('auth_client_id');
$client_password = C('auth_client_password'); $client_password = C('auth_client_password');
$support_fake_openid = C('AUTH_SUPPORT_FAKE_OPENID') ? '1' : ''; $support_fake_openid = C('AUTH_SUPPORT_FAKE_OPENID') ? '1' : '';
$helper = new OAuthHelperV3($app_id, $client_id, $client_password, $support_fake_openid); $helper = new OAuthHelperV3($app_id, $client_id, $client_password, $support_fake_openid);
$check = $helper->check_callback_param_signature($_GET); $check = $helper->check_callback_param_signature($_GET);
if (!$check) { if (!$check) {
exit('auth failed'); exit('auth failed');
...@@ -116,7 +98,6 @@ trait ControllerTrait ...@@ -116,7 +98,6 @@ trait ControllerTrait
$user['last_visit'] = time(); $user['last_visit'] = time();
$user['last_ip'] = $this->getIP(); $user['last_ip'] = $this->getIP();
$user['created_at']= time(); $user['created_at']= time();
$user['last_date'] = date('Ymd');
M('User')->token(false)->add($user); M('User')->token(false)->add($user);
} }
$_SESSION['is_wechat'] = 1; $_SESSION['is_wechat'] = 1;
...@@ -135,7 +116,6 @@ trait ControllerTrait ...@@ -135,7 +116,6 @@ trait ControllerTrait
redirect("/"); redirect("/");
exit(0); exit(0);
} }
protected function log_user_action($user_id, $action_name, protected function log_user_action($user_id, $action_name,
$action_value_str, $action_value_str,
$action_value_int = null) $action_value_int = null)
...@@ -169,7 +149,6 @@ trait ControllerTrait ...@@ -169,7 +149,6 @@ trait ControllerTrait
} }
return current(explode(',', $realip)); return current(explode(',', $realip));
} }
function isWeixin() function isWeixin()
{ {
//return true; //return true;
...@@ -184,13 +163,11 @@ trait ControllerTrait ...@@ -184,13 +163,11 @@ trait ControllerTrait
echo 'success'; echo 'success';
redirect("/"); redirect("/");
} }
public function debug_close() public function debug_close()
{ {
session('X-DEBUG', null); session('X-DEBUG', null);
echo 'success'; echo 'success';
} }
public function test_magic() public function test_magic()
{ {
cookie('X-PUB_MODE', 'development'); cookie('X-PUB_MODE', 'development');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment