Commit 6303c69f by 赵增煜

问诊人短信

parent 59413f0f
...@@ -60,11 +60,16 @@ public function add(Request $request) ...@@ -60,11 +60,16 @@ public function add(Request $request)
if (! validateIdCard($data['id_card'])) { if (! validateIdCard($data['id_card'])) {
return $this->failed('身份证格式错误'); return $this->failed('身份证格式错误');
} }
$mobile = $data['mobile'];
$verificationCode = cache()->get("sms_verification_code_{$mobile}");
$code = $data['code'];
if ($verificationCode != $code) {
return $this->failed('验证码错误');
}
$idCardInfo = Util::getIdCardInfo($data['id_card']); $idCardInfo = Util::getIdCardInfo($data['id_card']);
$patient->name = $data['name']; $patient->name = $data['name'];
$patient->id_card = $data['id_card']; $patient->id_card = $data['id_card'];
$patient->mobile = $data['mobile']; $patient->mobile = $mobile;
$patient->gender = $idCardInfo['gender']; $patient->gender = $idCardInfo['gender'];
$patient->is_default = 0; $patient->is_default = 0;
// $res = PatientModel::create($data); // $res = PatientModel::create($data);
...@@ -91,10 +96,17 @@ public function update(Request $request) ...@@ -91,10 +96,17 @@ public function update(Request $request)
if (! $data) { if (! $data) {
return $this->failed('该问诊人不存在'); return $this->failed('该问诊人不存在');
} }
$mobile = $request->input('mobile');
$verificationCode = cache()->get("sms_verification_code_{$mobile}");
$code = $request->input('code');
if ($verificationCode != $code) {
return $this->failed('验证码错误');
}
$data->name = $request->input('name'); $data->name = $request->input('name');
$data->id_card = $id_card; $data->id_card = $id_card;
$data->gender = $idCardInfo['gender']; $data->gender = $idCardInfo['gender'];
$data->mobile = $request->input('mobile'); $data->mobile = $mobile;
$data->save(); $data->save();
return $this->success($data); return $this->success($data);
......
...@@ -71,7 +71,6 @@ public function smsCode(Request $request) ...@@ -71,7 +71,6 @@ public function smsCode(Request $request)
if (! preg_match('/^1[3-9]\d{9}$/', $mobile)) { if (! preg_match('/^1[3-9]\d{9}$/', $mobile)) {
return response()->json(['error' => '手机号格式不正确']); return response()->json(['error' => '手机号格式不正确']);
} }
// TODO 增加手机验证码发送频率限制 // TODO 增加手机验证码发送频率限制
// 检查手机号在医师或者药店表中是否存在 // 检查手机号在医师或者药店表中是否存在
...@@ -85,15 +84,13 @@ public function smsCode(Request $request) ...@@ -85,15 +84,13 @@ public function smsCode(Request $request)
if (! $doctor) { if (! $doctor) {
return $this->failed('手机号不存在'); return $this->failed('手机号不存在');
} }
} else {
return $this->failed('登录类型错误');
} }
// 生成短信验证码 // 生成短信验证码
$verificationCode = rand(100000, 999999); // 生成6位随机验证码 $verificationCode = rand(100000, 999999); // 生成6位随机验证码
// 存储验证码和有效期(10分钟) // 存储验证码和有效期(10分钟)
cache()->put("sms_verification_code_{$login_type}_{$mobile}", $verificationCode, 600); // 600秒 = 10分钟 cache()->put("sms_verification_code_{$mobile}", $verificationCode, 600); // 600秒 = 10分钟
$templateName = 'verification_code'; $templateName = 'verification_code';
$templateData = ['code' => $verificationCode]; $templateData = ['code' => $verificationCode];
...@@ -114,7 +111,7 @@ public function bindRole(Request $request) ...@@ -114,7 +111,7 @@ public function bindRole(Request $request)
return $this->failed('参数错误'); return $this->failed('参数错误');
} }
$verificationCode = cache()->get("sms_verification_code_{$login_type}_{$mobile}"); $verificationCode = cache()->get("sms_verification_code_{$mobile}");
if ($verificationCode != $code) { if ($verificationCode != $code) {
return $this->failed('验证码错误'); return $this->failed('验证码错误');
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment