Commit f56aa2ae by doszhang

d

parent 6bc4966b
<?php
namespace Home\Controller;
use Think\Log;
use SignedCookie;
use Zhida\OAuthHelperV3;
//use Common\Common\OAuthHelperV3;
trait ControllerTrait
{
protected function get_user_info_from_cookie()
......@@ -17,24 +14,13 @@ trait ControllerTrait
// }
$cookie_secret = C('cookie_sign');
$openid = \SignedCookie::get_cookie($this->cookie_uid_key, $cookie_secret, 86400 * 60);
echo 3;die();
if (!$openid) {
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();
return $user;
}
protected function request_auth($redirect_url = '/')
{
$app_id = C('auth_app_id');
......@@ -44,7 +30,7 @@ trait ControllerTrait
$helper = new OAuthHelperV3($app_id, $client_id, $client_password, $support_fake_openid);
$site_url = C('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'];
}
$callback_url = "{$site_url}/auth";
......@@ -54,16 +40,14 @@ trait ControllerTrait
redirect($auth_url);
exit(0);
}
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'];
$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);
return $sys_protocal . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '') . $relate_url;
}
public function auth()
{
//如果是分享出去的链接,重新授权
......@@ -71,13 +55,11 @@ trait ControllerTrait
$this->request_auth();
exit(0);
}
$app_id = C('auth_app_id');
$client_id = C('auth_client_id');
$client_password = C('auth_client_password');
$support_fake_openid = C('AUTH_SUPPORT_FAKE_OPENID') ? '1' : '';
$helper = new OAuthHelperV3($app_id, $client_id, $client_password, $support_fake_openid);
$check = $helper->check_callback_param_signature($_GET);
if (!$check) {
exit('auth failed');
......@@ -116,7 +98,6 @@ trait ControllerTrait
$user['last_visit'] = time();
$user['last_ip'] = $this->getIP();
$user['created_at']= time();
$user['last_date'] = date('Ymd');
M('User')->token(false)->add($user);
}
$_SESSION['is_wechat'] = 1;
......@@ -135,7 +116,6 @@ trait ControllerTrait
redirect("/");
exit(0);
}
protected function log_user_action($user_id, $action_name,
$action_value_str,
$action_value_int = null)
......@@ -169,7 +149,6 @@ trait ControllerTrait
}
return current(explode(',', $realip));
}
function isWeixin()
{
//return true;
......@@ -184,13 +163,11 @@ trait ControllerTrait
echo 'success';
redirect("/");
}
public function debug_close()
{
session('X-DEBUG', null);
echo 'success';
}
public function test_magic()
{
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