我无法在注册表格中集成“发送OTP”功能。我从SMS提供商处获得了API,但是我不知道如何将其集成到表单中。验证OTP之后,我需要将用户数据记录在我的数据库中。但是验证过程如何工作?系统如何为用户生成6位数的随机代码?我一直在尝试不同的方法并在线搜索,但没有一个起作用。有人可以帮忙吗?
这是我的表格:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import * as WC from 'woocommerce-api';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
Woocommerce : any;
constructor(public navCtrl: NavController) {
this.Woocommerce = WC ({
url : "https://freelancerdemoweb.000webhostapp.com",
consumerKey : "ck_b34a9b3d45b59e519cabf6ac64576f1c42365039",
consumerSecret : "cs_b534fca91deeffef9403e4b2c7846d2ad20c7253"
});
this.Woocommerce.get('products/99', function(err, data, res) {
console.log(res);
})
}
}
这是我的短信提供商API:
<div class="modal-body">
<form action="includes/signup.inc.php" method="POST" class="p-3">
<div class="form-group">
<label for="recipient-name" class="col-form-label">First Name</label>
<input type="text" class="form-control" placeholder="First Name" name="first" required="">
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Last Name</label>
<input type="text" class="form-control" placeholder="Last Name" name="last" required="">
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Username</label>
<input type="text" class="form-control" placeholder="Username" name="uid" required="" >
</div>
<div class="form-group">
<label for="recipient-name1" class="col-form-label">Date of Birth</label>
<input type="date" class="form-control" placeholder="dob" name="dob" required="">
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Email Address</label>
<input type="email" class="form-control" placeholder="Email" name="email" required="" >
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Password</label>
<input type="password" class="form-control" placeholder="Password" name="pass" required="">
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Confirm Password</label>
<input type="password" class="form-control" placeholder="Confirm Password" name="c_pass" required="">
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Are You Previously an Existing Member?</label>
<select class="form-control" id="recipient-name10" name="member">
<option>Yes</option>
<option>No</option>
</select>
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Where do you know about this membership?</label>
<select class="form-control" id="recipient-name11" name="outlet">
<option>The Metallic Kitchen @ Golden Triangle Pelangi, JB</option>
<option>The Metallic Kitchen @ Taman Mount Austin, JB</option>
<option>The Metallic Kitchen & Bar @ Setapak Village, KL</option>
<option>None of the above</option>
</select>
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">OTP</label>
<input type="text" class="form-control" placeholder="OTP" name="otp" required="">
</div>
<div class="right-w3l mt-4 mb-3">
<input type="submit" class="form-control" value="Create account" name="submit">
</div>
</form>
</div>
这是我向数据库添加数据的代码:
<?php
function sendSmsToEsms() {
$url = 'https://api.esms.com.my/sms/send';
// replace yourusername, yourpassword, and 60123456789 to suits your need
$data = array('user' => 'yourusername',
'pass' => 'yourpassword',
'to' => '60123456789',
'msg' => 'RM0.00 Hello from ESMS');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded; charset=utf-8",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }
var_dump($result);
}
?>
答案 0 :(得分:0)
您应该将用户数据以及生成的OTP以及其他一栏临时保存到数据库中,以指示用户是否已通过验证。 (我建议在保存之前对OTP进行哈希处理。)
稍后,当用户尝试使用用户名和OTP进行登录时,应对照数据库检查输入的数据。如果用户和OTP正确,请检查该列以验证注册。如果OTP错误,则可以将该列留作更多尝试(或根据您的意见删除用户帐户或使OTP无效或重新生成新的OTP)。
要生成一个随机数,请使用mt_rand algorythm:
$password=mt_rand (10,100);
并按照以下说明在API中使用它:
'pass' => $password,