wechatService = $wechatService; $this->authService = $authService; $this->geetestService = $geetestService; $this->registerService = $registerService; $this->qqService = $qqService; } public function officialLogin() { $this->authService->logout(); if (request()->has('redirect_url')) { session(['redirect_url'=>urldecode(request()->get('redirect_url'))]); } session(['wechat_state'=>time(), 'subsite_id'=>get_subsite_id(), 'type'=>'mobile', "is_bind"=>0]); $wechat_url="https://open.weixin.qq.com/connect/oauth2/authorize?" ."appid=".subsite_config('aix.system.oauth.wechat_official.app_id') ."&redirect_uri=".urlencode(config('app.url').route('auth.thirdlogin', ['login_type'=>'wechat'], false)) ."&response_type=code&scope=snsapi_userinfo&state=".session('wechat_state')."#wechat_redirect"; return redirect($wechat_url); } public function officialGetOpenid() { if (!session()->has('wechat_pay_state') || !request()->has('state')) { return $this->showMessage("非法访问, 请重试", config('app.url'), true, "首页"); } if (session('wechat_pay_state') != request()->get('state')) { return $this->showMessage("非法访问, 请重试", config('app.url'), true, "首页"); } $officialAccount=$this->wechatService->getPayOfficialAccount(); $wechatUser=$officialAccount->oauth->user()->getOriginal(); session(['wechat_pay_openid'=>$wechatUser['openid']]); return redirect(session()->pull('wechat_pay_redirect_url', '/mobile')); } public function officialLoginToWeb($ticket) { if (!Cache::has($ticket)) { return $this->showMessage("Ticket错误, 请重试", config('app.url'), true, "首页"); } Cache::put($ticket.'_status', 1, 60); return view('mobile.app.official_login_success'); } public function bindAccount($login_type) { $data=[ 'type_name'=>$this->getTypeName($login_type), 'type'=>$login_type, 'wap_title'=>"绑定个人账号" ]; return view('mobile.app.auth.thirdlogin_binding', $data); } public function bindCompanyAccount($login_type) { $data=[ 'type_name'=>$this->getTypeName($login_type), 'type'=>$login_type, 'wap_title'=>"绑定企业账号" ]; return view('mobile.app.auth.thirdlogin_binding_company', $data); } public function bindAccountPost($login_type, $utype, AuthValidatorRequest $request) { if (!$user=$this->authService->checkUser($request->username, $request->password, $utype)) { return $this->sendErrorResponse("用户名或密码错误"); } if (($utype == 1 && $user->user_status == 0) || ($utype == 2 && $user->status == 0)) { return $this->sendErrorResponse("你的账号处于封禁状态, 请联系管理员"); } if ($login_type == 'wechat') { if ($this->authService->wechatCheck(session('wechatUser'), false)) { return $this->sendErrorResponse("你已绑定了其它账号, 请直接登录"); } $this->authService->wechatRegister(session('wechatUser'), $user, false, 3); $this->authService->login($user); return $this->sendSuccessResponse(['redirect_url'=>url($request->session()->pull('url.intended', '/mobile'))]); } if ($login_type == 'qq') { if ($this->authService->qqCheck(session('qqUser'), false)) { return $this->sendErrorResponse("你已绑定了其它账号, 请直接登录"); } $this->authService->qqRegister(session('qqUser'), $user); $this->authService->login($user); return $this->sendSuccessResponse(['redirect_url'=>url($request->session()->pull('url.intended', '/mobile'))]); } return $this->sendErrorResponse("数据错误, 请刷新页面重试"); } public function bindNewAccount($login_type) { $data=[ 'type_name'=>$this->getTypeName($login_type), 'type'=>$login_type, 'wap_title'=>"绑定个人账号" ]; return view('mobile.app.auth.thirdlogin_binding_new', $data); } public function bindNewCompanyAccount($login_type) { $data=[ 'type_name'=>$this->getTypeName($login_type), 'type'=>$login_type, 'wap_title'=>"绑定企业账号" ]; return view('mobile.app.auth.thirdlogin_binding_new_company', $data); } public function bindNewAccountPost($login_type, $utype, RegisterValidatorRequest $registerValidatorRequest, SmsService $smsService, MembersSetmealService $membersSetmealService, TaskService $taskService, EmailService $emailService) { if (!$this->geetestService->checkGeetest()) { return $this->sendErrorResponse("极验不通过,请重新验证"); } if ($utype == 2) { if (!$smsService->checkAuthSms($registerValidatorRequest->mobile, Smser::TEMPLATE_AUTH_REGISTER, $registerValidatorRequest->mobile_vcode)) { return $this->sendErrorResponse("短信验证码不通过,请重新输入"); } } if ($login_type == 'wechat') { if ($this->authService->wechatCheck(session('wechatUser'), false)) { return $this->sendErrorResponse("你已绑定了其它账号, 请直接登录"); } } if ($login_type == 'qq') { if ($this->authService->qqCheck(session('qqUser'), false)) { return $this->sendErrorResponse("你已绑定了其它账号, 请直接登录"); } } if ($utype == 2) { $user=$this->registerService->registerPerson($registerValidatorRequest->all()); $this->authService->login($user); } else { $user=$this->registerService->registerCompany($registerValidatorRequest->all()); $this->authService->login($user); $membersSetmealService->addMemberSetmeal($user, 1); $taskService->doTask(17); $emailService->setAuthTag('company') ->setCallback('App\Services\Company\CompanyService', 'sendAuthEmailHook', [$registerValidatorRequest->email, $user]) ->sendAuthMail($registerValidatorRequest->email, EmailService::TEMPLATE_VALIDATION); } if ($login_type == 'wechat') { $this->authService->wechatRegister(session('wechatUser'), $user, true, 3); } if ($login_type == 'qq') { $this->authService->qqRegister(session('qqUser'), $user, true); } if ($utype == 2) { return $this->sendSuccessResponse(['url'=>route('mobile.person.index')]); } else { return $this->sendSuccessResponse(['url'=>route('mobile.register.send_email', ['type'=>1])]); } } protected function getTypeName($type) { switch ($type) { case "wechat": return "微信"; case "qq": return "QQ"; } } }