php - 等待输入有效的短信代码。检查后,数据保存到数据库php
问题描述
嗨我的代码中有一些问题我想在用户输入短信代码后将数据保存在数据库中发送到他的手机
我想在这里等待进程并保存数据我不想在用户输入短信代码后丢失它我将所有数据保存在数据库中
public function registered(IdentityRequest $request) {
$response = Http::get(route('fake') , [
'national_id' => $request->input('national_id'),
'date_birth' => $request->input('date_birth')
]);
if($response['status'] == 200) {
// i saved the data here
$userInformation = $response['data'];
} else {
return $this->returnErrorResponse('E002', 'no user ', '404');
}
// send OTP verification after validate request of user
$otp = new Client(env('ENV_ACCOUNT_SID' , 'sid') , env('ENV_AUTH_TOKEN' , 'token));
$smsCode = rand(100000, 999999);
$message = $otp->messages->create("+".$request->input('phone') , [
"body" => $smsCode, // this code i send to user
"from" => "+11111"
]);
// here i want to whit untill user enter the code and i don't want to lose data
// from $request and $userInformation
// how i can do that
// after the user enter valid code sms and i check it from him
// i saved all the data in database
}
解决方案
你不能那样做。
您必须分 2 个阶段和 4 个步骤进行
- 从用户那里获取信息,将其保存在文件或数据库等持久存储中
- 通过短信发送代码并将代码与用户信息一起保存
- 发送短信,并将用户重定向到另一个页面,因此他/她应该使用电子邮件或 national_id 以及您发送给她/他的代码填写表格
- 验证代码是否与用户信息匹配
推荐阅读
- python - Django 一个一个地获取对象以在模板中渲染
- javascript - 通过公共键对对象数组进行分组,将嵌套属性合并到数组中
- javascript - React JS - 多级下拉菜单
- python - 为什么 copy.deepcopy() 在 Bunch() 上不起作用,但 storemagic 以某种方式修复了它?
- c++ - Cmake 问题:找不到“FreeImage.h”文件
- python - 当我尝试使用 python 和 django 重定向到购物车时,我不断收到此错误
- discord.js - 无法读取未定义的属性“删除”
- docker - 操作系统与 docker 镜像有什么关系?
- angular - Angular 9:找不到命名空间“FullCalendarVDom”?
- javascript - 我在 ajax 中的 XMLHttpRequest 在 Chrome 中不起作用