首页 > 解决方案 > 等待输入有效的短信代码。检查后,数据保存到数据库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

}

标签: phplaravelapismsreset

解决方案


你不能那样做。

您必须分 2 个阶段和 4 个步骤进行

  1. 从用户那里获取信息,将其保存在文件或数据库等持久存储中
  2. 通过短信发送代码并将代码与用户信息一起保存
  3. 发送短信,并将用户重定向到另一个页面,因此他/她应该使用电子邮件或 national_id 以及您发送给她/他的代码填写表格
  4. 验证代码是否与用户信息匹配

推荐阅读