testDao; // } public function __construct(LoginDao $loginDao) { parent::__construct(); $this->loginDao = $loginDao; } public function login($params) { $params['username'] = base64_decode($params['username']); if($params['username'] == '123') { if(!(isset($_SERVER['HTTP_ZSKK_INSTITUTION']) && $_SERVER['HTTP_ZSKK_INSTITUTION'] == '06300006')) { $this->throwError('账号或密码错误',1); } } // $params['password'] = base64_decode($params['password']); $key = 'zskk'.date('Ymd').'zskk'; $password = openssl_decrypt($params['password'], 'AES-128-ECB', $key); $user = $this->loginDao->checkIsSet($params,$password); if($user['is_send_message'] == "1") { $check = $this->check_phone($user['phone']); if(!$check){ $this->throwError('手机号为空或手机号格式错误','0912'); } $phone = $user['phone']; $code = rand('1000','9999'); $handle_id = $phone.rand('10000000','99999999'); $this->loginDao->setCache('sendcode_'.$phone,$code,600); $this->loginDao->setCache('sendcode_handle_id'.$handle_id,$phone,600); $info = send_message::sendSms2UpDate($phone,$code); log::record("login() set code => {handle_id: $handle_id \t code: $code \t phone: $phone \t}"); $data = ['need_code'=> true, 'phone' => $check, 'handle_id' => $handle_id]; return $data; } $token = $this->loginDao->saveCache($user); // 存储登录信息 $this->loginDao->saveLoginInfo($user['id']); $institution = $this->loginDao->getInsInfo($user['institution_id']); $otherIns = $this->loginDao->getOtherRules($user['id']); $insList = []; if(!empty($otherIns)) { $insList = $otherIns; } $insList[] = ['id'=>$user['institution_id'],'name'=>$user['institution']]; $data = [ 'token' => $token, 'realname' => $user['realname'], 'is_admin' => $user['is_admin'], 'username' => $user['username'], 'institution' => $user['institution'], 'institution_id'=> $user['institution_id'], 'report_full'=> $user['report_full'], 'is_new_browser'=> $institution['is_new_browser'], 'department_name' => $user['department'], 'role'=> $user['doctor_role'], 'message_push' => $user['message_push'], 'need_code'=> false, 'user_id' =>$user['id'], 'is_auto_mode' =>$institution['is_auto_mode'], 'remote' =>empty($institution['parent_institution']) ? '0' : '1', 'institution_list'=>$insList, 'message_voice'=>$user['message_voice'] ?? 0 ]; log::record('当前登陆的医生id为:'.$user['id'].',登陆token为:'.$token); $arr = ['type'=>2,'doctor_id'=>$user['id'],'doctor_name'=>$user['realname'],'institution_id'=>$user['institution_id']]; $this->loginDao->saveDoctorVisit($arr); return $data; } public function send_message_again($param) { // 获取 handle_id if(!isset($param['handle_id']) || empty($param['handle_id'])) { $this->throwError('系统错误 not find handle id',2001); } $handle_id = $param['handle_id']; // 获取 phone if(!$this->loginDao->getCache('sendcode_handle_id'.$handle_id)) { $this->throwError('操作过时,请重新登录',2002); } // 发送验证码并记录 $phone = $this->loginDao->getCache('sendcode_handle_id'.$handle_id); $this->loginDao->delCache('sendcode_handle_id'.$handle_id); $code = rand('1000','9999'); $info = send_message::sendSms2UpDate($phone,$code); $handle_id = $phone.rand('10000000','99999999'); log::record('目前的手机号是'.$phone.'存储的缓存为sendcode_handle_id'.$handle_id); log::record('目前的验证码是'.$code.'存储的手机号为sendcode_'.$phone); $this->loginDao->setCache('sendcode_'.$phone, $code, 600); $this->loginDao->setCache('sendcode_handle_id'.$handle_id, $phone, 600); log::record("send_message_again() set code => {handle_id: $handle_id \t code: $code \t phone: $phone \t}"); $data =['info'=>$info,'handle_id'=>$handle_id]; return $data; } public function check_code($param) { if(!isset($param['handle_id']) || !isset($param['code'])) { $this->throwError('系统错误 not find handle id or code',2003); } $handle_id = $param['handle_id']; $code = $param['code']; if(empty($handle_id) || empty($code)) { $this->throwError('handle id or code is null or empty',2004); } // 获取 phone if(!$this->loginDao->getCache('sendcode_handle_id'.$handle_id)) { $this->throwError('操作过时,请重新登录',2002); } $phone = $this->loginDao->getCache('sendcode_handle_id'.$handle_id); if(!$this->loginDao->getCache('sendcode_'.$phone)) { $this->throwError('操作过时,请重新登录',2002); } $check_code = $this->loginDao->getCache('sendcode_'.$phone); if(!empty($check_code) && $code != $check_code) { log::record('当前的手机号是'.$phone.'存储的为sendcode_handle_id'.$handle_id); log::record('当前的验证码是'.$code); log::record('缓存的验证码是'.$check_code.'存储的为sendcode_'.$phone); $this->throwError('错误的验证码','0090'); } log::record("check_code() params => {handle_id: $handle_id \t code: $code \t phone: $phone \t check_code: $check_code }"); $sessionid = UUIDUtils::uuid(); log::record($sessionid); $user = $this->loginDao->getDoctorByPhone($phone); $this->loginDao->setCache($sessionid,$user,43200); log::record('----登录信息----'); log::record($this->loginDao->getCache($sessionid)); log::record('----登录信息----'); $institution = $this->loginDao->getInsInfo($user['institution_id']); unset($user['password']); $data = [ 'token' => $sessionid, 'realname' => $user['realname'], 'is_admin' => $user['is_admin'], 'username' => $user['username'], 'institution' => $user['institution'], 'department_name' => $user['department'], 'role'=> $user['doctor_role'], 'message_push' => $user['message_push'], 'user_id' =>$user['id'], 'is_auto_mode' =>$institution['is_auto_mode'], 'remote' =>empty($institution['parent_institution']) ? '0' : '1', ]; log::record('当前登陆的医生id为:'.$user['id'].',登陆token为:'.$sessionid); return $data; } public function check_phone($mobile) { if(empty($mobile)){ return false; } if(strlen($mobile) != 11){ return false; } $preg = preg_match('/^1[34578]\d{9}$/', $mobile); if(!$preg){ return false; } $start = substr($mobile,0,3); $end = substr($mobile,7,4); $phone = $start.'****'.$end; return $phone; } public function logout($token) { $data = $this->loginDao->logout($token); return $data; } public function out($session) { $data = $this->loginDao->out($session); return $data; } }