request->post('code'); $config=[ 'appid'=>site_config("uniapp.miniapp_id"), 'appsecret'=>site_config("uniapp.miniapp_secret") ]; $mini = new \WeMini\Crypt($config); $data = $mini->session($code); $openid=$data['openid']; $unionid=isset($data['unionid'])?$data['unionid']:''; $avatar=$this->request->post('avatar'); $nickname=$this->request->post('nickname'); $mobile=$this->request->post('mobile'); //判断是否启用账号绑定 $third=Third::connect(Third::PLATFORM('微信小程序'), compact('openid', 'unionid', 'avatar', 'nickname', 'mobile')); $this->auth->loginByThirdPlatform(Third::PLATFORM('微信小程序'),$third); $token=$this->auth->getToken(); $userinfo=$this->auth->userinfo(); $this->success('登录成功',compact('token','userinfo')); } public function getMobile() { $code=$this->request->post('code'); $config=[ 'appid'=>site_config("uniapp.miniapp_id"), 'appsecret'=>site_config("uniapp.miniapp_secret") ]; $mini = new \WeMini\Crypt($config); $result=$mini->getPhoneNumber($code); $this->success('',$result['phone_info']['phoneNumber']); } //模拟登陆 public function mockLogin() { $openid=$this->request->post('openid'); $third=Third::where(['openid'=>$openid,'platform'=>Third::PLATFORM('微信小程序')])->find(); $this->auth->loginByThirdPlatform(Third::PLATFORM('微信小程序'),$third); $token=$this->auth->getToken(); $userinfo=$this->auth->userinfo(); $this->success('登录成功',compact('token','userinfo')); } }