From 687605c97f6f6ce5a7c86452b240d7690ae47ccd Mon Sep 17 00:00:00 2001 From: "yangsai@163.com" <2624183217@qq.com> Date: Wed, 22 May 2024 18:17:43 +0800 Subject: [PATCH] =?UTF-8?q?YS:=E5=BF=98=E8=AE=B0=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/controllers/Api/Login.php | 41 +++++++++++++++++++++++---- application/models/Smscode.php | 13 +++++++++ 2 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 application/models/Smscode.php diff --git a/application/controllers/Api/Login.php b/application/controllers/Api/Login.php index cdda9ee..8157d46 100644 --- a/application/controllers/Api/Login.php +++ b/application/controllers/Api/Login.php @@ -149,21 +149,50 @@ } public function sendcodeAction(){ $phone = empty($this->POST['phone'])||!isset($this->POST['phone'])? Tool_Fnc::apiMsg('请输入手机号', '500'):Tool_fnc::safe_string($this->POST['phone']); - // 使用示例 + // 验证系统是否存在该手机号 + $userinfo = $this->Usermodel->field('username')->where("phone='{$phone}' and is_delete=0 and status=1")->fRow(); + if(empty($userinfo)) Tool_Fnc::apiMsg('当前手机号不存在', '500'); + // 短信接口 $accessKeyId = Yaf_Registry::get("config")->aliyun->sms->accessKeyId; + $smsModel = new SmscodeModel(); $accessKeySecret = Yaf_Registry::get("config")->aliyun->sms->accessKeySecret; $signName = Yaf_Registry::get("config")->aliyun->sms->signName; $templateCode = Yaf_Registry::get("config")->aliyun->sms->templateCode; $sms = new AliyunSms($accessKeyId, $accessKeySecret, $signName, $templateCode); + $code = substr(str_shuffle('0123456789'),0,6); $templateParam = array( - 'code' => substr(str_shuffle('0123456789'),0,6) // 模板中变量的值 + 'code' => $code // 模板中变量的值 ); $result = $sms->sendSMS($phone, $templateParam); - if ($result) { - echo '短信发送成功'; - } else { - echo '短信发送失败'; + if(!$result) Tool_Fnc::apiMsg('短信发送失败', '500'); + $data['phone'] = $phone; + $data['code'] = $code; + $data['created'] = date("Y-m-d H:i:s",time()); + $smsModel->save($data); + Tool_Fnc::apiMsg('短信发送成功', '200'); + } + public function ValidationAction(){ + $phone = empty($this->POST['phone'])||!isset($this->POST['phone'])? Tool_Fnc::apiMsg('请输入手机号', '500'):Tool_fnc::safe_string($this->POST['phone']); + $code = empty($this->POST['code'])||!isset($this->POST['code'])? Tool_Fnc::apiMsg('请输入验证码', '500'):Tool_fnc::safe_string($this->POST['code']); + $smsModel = new SmscodeModel(); + $userinfo = $this->Usermodel->field('id')->where("phone='{$phone}' and is_delete=0 and status=1")->fRow(); + $codedata = $smsModel->field('id')->where("phone='{$phone}' and code='{$code}' and status=0")->fRow(); + if(empty($codedata))Tool_Fnc::apiMsg('验证码不正确', '500'); + $codedata['status']=1; + $smsModel->save($codedata); + Tool_Fnc::apiMsg('验证成功', '200',$userinfo); + } + public function changePwdAction(){ + $id = empty($this->POST['id'])||!isset($this->POST['id'])? Tool_Fnc::apiMsg('非法调用', '500'):Tool_fnc::safe_string($this->POST['id']); + $password = empty($this->POST['password'])||!isset($this->POST['password'])? Tool_Fnc::apiMsg('非法调用', '500'):Tool_fnc::safe_string($this->POST['password']); + $tpassword = empty($this->POST['tpassword'])||!isset($this->POST['tpassword'])? Tool_Fnc::apiMsg('非法调用', '500'):Tool_fnc::safe_string($this->POST['tpassword']); + if($password!=$tpassword) Tool_Fnc::apiMsg('两次密码不一致', '500'); + $data['password'] = md5($password.Yaf_Registry::get("config")->psd->default->appsecret); + $data['id'] = $id; + if(!$this->Usermodel->update($data)){ + Tool_Fnc::apiMsg('新密码与原密码一致', '500'); } + Tool_Fnc::apiMsg('修改成功', '200'); } } diff --git a/application/models/Smscode.php b/application/models/Smscode.php new file mode 100644 index 0000000..0352526 --- /dev/null +++ b/application/models/Smscode.php @@ -0,0 +1,13 @@ + array('type' => "int(11)",'comment' => ''), + 'phone' => array('type' => "varchar(45)",'comment' => '实验室名称'), + 'code' => array('type' => "varchar(45)",'comment' => '是否删除'), + 'created' => array('type' => "int(11)",'comment' => '添加时间'), + 'status' => array('type' => "int(11)",'comment' => '添加时间'), + ); + public $pk = 'id'; +} +