这份文档还在翻译中,预期年底前完成。欢迎您提供宝贵的意见及建议。
Verify API
Verify API 可让您确认可使用特定号码与用户联系,以便您:
- 通过确保您拥有正确的电话号码随时联系用户
- 通过防止一个用户创建多个帐户规避欺诈和垃圾邮件
- 增加额外安全性,以帮助在用户想执行某些活动时确认其身份
工作原理
验证是一个两个阶段过程,需要两次 API 呼叫:
验证请求
用户通过您的应用程序或网站注册您的服务,并提供电话号码。
为确认用户可使用其注册的号码,您的应用程序将对验证请求端点进行 API 呼叫。
-
Verify API 会生成 PIN 码并带有关联的
request_id
。在某些情况下可提供您自己的 PIN 码,请与您的客户经理联系。
然后,Verify API 会尝试将此 PIN 发送给用户。这些尝试的格式(SMS 或文本转语音 (TTS))和计时由您选择的工作流定义。 如果用户不重新访问您的应用或网站以输入他们收到的 PIN,则验证请求最终将超时。否则,您将需要通过执行验证检查来验证他们输入的号码。
验证检查
5 . 用户收到 PIN 并将其输入您的应用程中。
6 .您的应用程序将对验证检查端点进行 API 呼叫,并传入 request_id
和用户输入的 PIN。
7 . Verify API 会检查输入的 PIN 与发送的 PIN 是否匹配,并将结果返回到您的应用程序。
入门
以下示例显示了如何通过向用户发送验证码来开始验证过程。要了解如何验证用户提供的代码并执行其他操作,请参阅代码片段。
Write the code
Add the following to send-verification-code.sh
:
curl -X GET "https://api.nexmo.com/verify/json?&api_key=$VONAGE_API_KEY&api_secret=$VONAGE_API_SECRET&number=$RECIPIENT_NUMBER&brand=AcmeInc"
Run your code
Save this file to your machine and run it:
sh send-verification-code.sh
Prerequisites
npm install @vonage/server-sdk
Create a file named request.js
and add the following code:
const Vonage = require('@vonage/server-sdk');
const vonage = new Vonage({
apiKey: VONAGE_API_KEY,
apiSecret: VONAGE_API_SECRET
});
Write the code
Add the following to request.js
:
vonage.verify.request({
number: RECIPIENT_NUMBER,
brand: BRAND_NAME
}, (err, result) => {
if (err) {
console.error(err);
} else {
const verifyRequestId = result.request_id;
console.log('request_id', verifyRequestId);
}
});
Run your code
Save this file to your machine and run it:
node request.js
Prerequisites
Add the following to `build.gradle`:
compile 'com.vonage:client:5.5.0'
Create a class named StartVerification
and add the following code to the main
method:
VonageClient client = VonageClient.builder().apiKey(VONAGE_API_KEY).apiSecret(VONAGE_API_SECRET).build();
Write the code
Add the following to the main
method of the StartVerification
class:
VerifyResponse response = client.getVerifyClient().verify(RECIPIENT_NUMBER, BRAND_NAME);
if (response.getStatus() == VerifyStatus.OK) {
System.out.printf("RequestID: %s", response.getRequestId());
} else {
System.out.printf("ERROR! %s: %s", response.getStatus(), response.getErrorText());
}
Run your code
We can use the application
plugin for Gradle to simplify the running of our application.
Update your build.gradle
with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''
Run the following gradle
command to execute your application, replacing com.vonage.quickstart.verify
with the package containing StartVerification
:
gradle run -Pmain=com.vonage.quickstart.verify.StartVerification
Prerequisites
Install-Package Vonage
Create a file named SendVerificationRequest.cs
and add the following code:
using Vonage.Verify;
using Vonage;
using Vonage.Request;
Add the following to SendVerificationRequest.cs
:
var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SECRET);
var client = new VonageClient(credentials);
Write the code
Add the following to SendVerificationRequest.cs
:
var request = new VerifyRequest() { Brand = BRAND_NAME, Number = RECIPIENT_NUMBER };
var response = client.VerifyClient.VerifyRequest(request);
Prerequisites
composer require vonage/client
Create a file named request.php
and add the following code:
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Container($basic));
Write the code
Add the following to request.php
:
$request = new \Vonage\Verify\Request(NUMBER, BRAND_NAME);
$response = $client->verify()->start($request);
echo "Started verification, `request_id` is " . $response->getRequestId();
Run your code
Save this file to your machine and run it:
php request.php
Prerequisites
pip install vonage
Create a file named request.py
and add the following code:
client = vonage.Client(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)
verify = vonage.Verify(client)
Write the code
Add the following to request.py
:
response = verify.start_verification(number=RECIPIENT_NUMBER, brand="AcmeInc")
if response["status"] == "0":
print("Started verification request_id is %s" % (response["request_id"]))
else:
print("Error: %s" % response["error_text"])
Run your code
Save this file to your machine and run it:
python request.py
Prerequisites
gem install vonage
Create a file named request.rb
and add the following code:
client = Vonage::Client.new(
api_key: VONAGE_API_KEY,
api_secret: VONAGE_API_SECRET
)
Write the code
Add the following to request.rb
:
response = client.verify.request(
number: TO_NUMBER,
brand: 'AcmeInc'
)
if response
# display the Verify `request_id`
puts response.request_id
end
Run your code
Save this file to your machine and run it:
ruby request.rb
指南
- Verify Languages: The available languges for Verify API
- Workflows and Events: The stages and timings of the verification processes
- Change the event timings: How to change the timings for each verification event.
- Verify Velocity Rules: Verify's anti-fraud system
代码片段
- Before you begin
- Search for Verify request
- Send verification code
- Send verification code with workflow
- Check verification code
- Send payment auth code (PSD2)
- Send payment auth code with workflow (PSD2)
- Cancel verification request
- Trigger next verification process