pbootCms的会员控制器微信 login方法
public function wxlogin(){ define('APPID', 'wx*****'); define('SECRET', '83******'); if(!isset($_GET@['code'])){ $redirect_uri = urlencode('https://wx.xxx.com/member/wxlogin'); header('Location:https://open.weixin.qq.com/connect/oauth2/authorize?appid='.APPID.'&redirect_uri='.$redirect_uri.'&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect'); exit; } $code=$_GET@['code']; //获取access_token值 $get_token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.APPID.'&secret='.SECRET.'&code='.$code.'&grant_type=authorization_code'; $data = json_decode(curl_get($get_token_url),true); // 得到用户信息 $get_user_info = 'https://api.weixin.qq.com/sns/userinfo?access_token='.$data["access_token"].'&openid='.$data["openid"].'&lang=zh_CN'; $userinfo = json_decode(curl_get($get_user_info),true); $openid=$userinfo['openid']; $login =$this->model->login("wxid='$openid'"); if($login){ session('pboot_uid', $login->id); session('pboot_ucode', $login->ucode); session('pboot_username', $login->username); session('pboot_useremail', $login->seremail); session('pboot_usermobile', $login->usermobile); session('pboot_gid', $login->gid); session('pboot_gcode', $login->gcode); session('pboot_gname', $login->gname); alert_location('登录成功!', Url::home('member/ucenter'), 1); }else{ $score = $this->config('register_score') ?: 0; $group = $this->model->getFirstGroup(); $gid = $this->model->getGroupID($this->config('register_gcode')) ?: $group->id; $password="123456"; $ucode = get_auto_code($this->model->getLastUcode(), 1); $username = $userinfo['nickname']; // 接受用户名、邮箱、手机三种方式 $nickname = $userinfo['nickname']; $password = md5(md5($password)); $rpassword =md5(md5($password)); $useremail = ''; $usermobile = ''; // 构建数据 $data = array( 'ucode' => $ucode, 'username' => $username, 'useremail' => $useremail, 'usermobile' => $usermobile, 'nickname' => $nickname, 'password' => $password, 'headpic' => $userinfo['headimgurl'], 'status' => 1, 'gid' => $gid, 'wxid' => $userinfo['openid'], 'qqid' => '', 'wbid' => '', 'activation' => 1, 'score' => $score, 'register_time' => get_datetime(), 'login_count' => 0, 'last_login_ip' => 0, 'last_login_time' => 0 ); if ($this->model->register($data)) { $login =$this->model->login("wxid='$openid'"); session('pboot_uid', $login->id); session('pboot_ucode', $login->ucode); session('pboot_username', $login->username); session('pboot_useremail', $login->seremail); session('pboot_usermobile', $login->usermobile); session('pboot_gid', $login->gid); session('pboot_gcode', $login->gcode); session('pboot_gname', $login->gname); alert_location('登陆成功!', Url::home('member/ucenter'), 1); } } }
如果您的问题还未解决可以联系站长付费协助。
有问题可以加入技术QQ群一起交流学习
本站vip会员 请加入无忧模板网 VIP群(50604020) PS:加入时备注用户名或昵称
普通注册会员或访客 请加入无忧模板网 技术交流群(50604130)
客服微信号:15898888535
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若内容侵犯了原著者的合法权益,可联系站长删除。