login($accountName,$password); if(!$data){ HelpHander::error(model('User')->getError()); } HelpHander::success($data); } // 公共静态页链接 public function staticUrl(){ $data = [ 'aboutUrl' => (string) url('/h5/index/sysarticle',['name'=>'about'],true,true), 'privacyUrl' => (string) url('/h5/index/sysarticle',['name'=>'privacy'],true,true), 'disclaimerUrl' =>(string) url('/h5/index/sysarticle',['name'=>'disclaimer'],true,true), ]; HelpHander::success($data); } //发送验证码 public function sendSms(){ HelpHander::success([],'操作成功'); } // 小程序手机号登录 public function wxpLogin(){ $code = input('code','','trim'); $encryptedData = input('encryptedData','','trim'); $iv = input('iv','','trim'); $orgId = input('orgId/d',0); // $orgId = $orgId <= 0 ? 3 : $orgId; if($orgId <= 0){ HelpHander::error('请扫描项目二维码进入小程序'); } try{ $config = config('app.wx_mini_config'); $app = \EasyWeChat\Factory::miniProgram($config); $ret = $app->auth->session($code); if(!isset($ret['openid']) || !$ret['openid']){ exception('登录失败'); } $decryptedData = $app->encryptor->decryptData($ret['session_key'], $iv, $encryptedData); if(!isset($decryptedData['phoneNumber']) || !$decryptedData['phoneNumber']){ exception('解密失败'); } // $data = model('User')->wxLogin($ret['openid'],$decryptedData['nickName'],$decryptedData['avatarUrl'],$orgId); }catch (\Exception $e){ trace('小程序登录:'.$e->getMessage()); HelpHander::error('登录失败',-101); } $data = model('User')->wxpLogin($decryptedData['phoneNumber'],$orgId); if(!$data){ HelpHander::error('登录失败',-101); } HelpHander::success($data); } // 小程序登录 public function wxLogin(){ $code = input('code','','trim'); $encryptedData = input('encryptedData','','trim'); $iv = input('iv','','trim'); $orgId = input('orgId/d',0); // $orgId = $orgId <= 0 ? 3 : $orgId; if($orgId <= 0){ HelpHander::error('请扫描项目二维码进入小程序'); } try{ $config = config('app.wx_mini_config'); $app = \EasyWeChat\Factory::miniProgram($config); $ret = $app->auth->session($code); if(!isset($ret['openid']) || !$ret['openid']){ exception('登录失败'); } $decryptedData = $app->encryptor->decryptData($ret['session_key'], $iv, $encryptedData); if(!isset($decryptedData['nickName']) || !$decryptedData['nickName']){ exception('解密失败'); } $data = model('User')->wxLogin($ret['openid'],$decryptedData['nickName'],$decryptedData['avatarUrl'],$orgId); if(!$data){ exception(model('User')->getError()); } }catch (\Exception $e){ trace('小程序登录:'.$e->getMessage()); HelpHander::error('登录失败',-101); } HelpHander::success($data); } // 小程序预登陆 public function wxPreLogin(){ $code = input('code','','trim'); $orgId = input('orgId/d',0); // $orgId = $orgId <= 0 ? 3 : $orgId; if($orgId <= 0){ HelpHander::error('请扫描项目二维码'); } $config = config('app.wx_mini_config'); try{ $app = \EasyWeChat\Factory::miniProgram($config); $ret = $app->auth->session($code); if(!isset($ret['openid']) || !$ret['openid']){ exception('登录失败'); } $data = model('User')->wxPreLogin($ret['openid'],$orgId); if(!$data){ exception(model('User')->getError()); } }catch (\Exception $e){ trace($e->getMessage()); HelpHander::error('登录失败'.$e->getMessage(),-101); } HelpHander::success($data); } public function wxRegister(){ $data = [ 'mobile' => input('phone','','trim'), 'real_name' => input('name','','trim'), 'password' => input('pass','','trim'), 'depId' => input('depId/d',0), 'orgId' => input('orgId/d',0) ]; if($data['orgId'] <= 0){ HelpHander::error('请扫描项目二维码'); } $res = model('User')->wxRegister($data); if(!$res){ HelpHander::error(model('User')->getError()); } HelpHander::success($res); } }