...
|
...
|
@@ -39,9 +39,6 @@ class WxloginController extends HomeBaseController |
|
|
$rediUrl = 'http://' .$_SERVER['HTTP_HOST'];
|
|
|
}
|
|
|
}
|
|
|
echo "<pre/>";
|
|
|
print_r($rediUrl);
|
|
|
die;
|
|
|
parent::_initialize(); // TODO: Change the autogenerated stub
|
|
|
if(!Session::get('user.accessToken')){
|
|
|
session('uid',null);
|
...
|
...
|
@@ -86,17 +83,11 @@ class WxloginController extends HomeBaseController |
|
|
*/
|
|
|
public function OAuth($redirect_uri){
|
|
|
if (!Session::get('uid')) {
|
|
|
$a['a'] = 1;
|
|
|
Db::name('Test')->insertGetId($a);
|
|
|
$url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
|
|
|
$temp_one = explode('code=',$url);
|
|
|
if(!empty($temp_one[1])){
|
|
|
$a['a'] = 2;
|
|
|
Db::name('Test')->insertGetId($a);
|
|
|
$temp_two = explode('&state',$temp_one[1]);
|
|
|
if ($temp_two[0]) {
|
|
|
$a['a'] = 4;
|
|
|
Db::name('Test')->insertGetId($a);
|
|
|
//第二步 获取access_token
|
|
|
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".Config::get('WX_APPID')."&secret=".Config::get('WX_APP_SECRET')."&code=" . $temp_two[0] . "&grant_type=authorization_code";
|
|
|
$resp = file_get_contents($url);
|
...
|
...
|
@@ -105,14 +96,10 @@ class WxloginController extends HomeBaseController |
|
|
Session::set('user.accessToken',$resp_arr['access_token']);
|
|
|
Session::set('user.accessTime',time());
|
|
|
//第三步
|
|
|
$a['a'] = 5;
|
|
|
Db::name('Test')->insertGetId($a);
|
|
|
$refresh_token = $resp_arr['refresh_token'];
|
|
|
$url1 = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=".Config::get('WX_APPID')."&grant_type=refresh_token&refresh_token=".$refresh_token;
|
|
|
$resp1 = file_get_contents($url1);
|
|
|
$resp_arr1 = json_decode($resp1, true);
|
|
|
$a['a'] = 6;
|
|
|
Db::name('Test')->insertGetId($a);
|
|
|
//第四步
|
|
|
$access_token = $resp_arr1['access_token'];
|
|
|
$openid = $resp_arr1['openid'];
|
...
|
...
|
@@ -120,8 +107,6 @@ class WxloginController extends HomeBaseController |
|
|
$resp2 = file_get_contents($url2);
|
|
|
$resp_arr2 = json_decode($resp2, true);
|
|
|
$user_headFile['headimgurl'] = $resp_arr2['headimgurl'];
|
|
|
$a['a'] = 7;
|
|
|
Db::name('Test')->insertGetId($a);
|
|
|
// 图片路径
|
|
|
$save_path['wx_name'] = $resp_arr2['nickname'];
|
|
|
$save_path['wx_pic'] = $resp_arr2['headimgurl'];
|
...
|
...
|
@@ -129,8 +114,6 @@ class WxloginController extends HomeBaseController |
|
|
$save_path['create_time'] = time();
|
|
|
$save_path['update_time'] = time();
|
|
|
$is_isset = Db::name('Member')->where(array('openid' => $resp_arr2['openid']))->find();
|
|
|
$a['a'] = 8;
|
|
|
Db::name('Test')->insertGetId($a);
|
|
|
if(!$is_isset){
|
|
|
$user_id = Db::name('Member')->insertGetId($save_path);
|
|
|
Session::set('uid',$user_id);
|
...
|
...
|
@@ -144,13 +127,6 @@ class WxloginController extends HomeBaseController |
|
|
}
|
|
|
}else{
|
|
|
$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".Config::get('WX_APPID')."&redirect_uri=" . $redirect_uri . "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
|
|
|
$a['a'] = 3;
|
|
|
$a['c'] = $url;
|
|
|
https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxae41c1d85ae2b539&redirect_uri=http://pluralism.w.bronet.cn&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect
|
|
|
|
|
|
$a['e'] = Config::get('WX_APPID');
|
|
|
$a['f'] = $redirect_uri;
|
|
|
Db::name('Test')->insertGetId($a);
|
|
|
Header("Location: $url");
|
|
|
exit;
|
|
|
}
|
...
|
...
|
|