作者 郭鑫
1 个管道 的构建 通过 耗费 0 秒

登录

... ... @@ -67,11 +67,17 @@ 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);
... ... @@ -80,10 +86,14 @@ 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'];
... ... @@ -91,6 +101,8 @@ 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'];
... ... @@ -98,6 +110,8 @@ 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);
... ... @@ -110,6 +124,8 @@ class WxloginController extends HomeBaseController
exit;
}
}else{
$a['a'] = 3;
Db::name('Test')->insertGetId($a);
$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";
Header("Location: $url");
exit;
... ...