verifykit/verifykit-sdk-php

VerifyKit 是下一代手机号码验证系统。用户可以轻松验证他们的手机号码,无需输入手机号码或PIN码。

1.2.7 2024-03-26 14:21 UTC

README

Status License

VerifyKit 是下一代手机号码验证系统。用户可以轻松验证他们的手机号码,无需输入手机号码或PIN码。

此SDK是您更轻松地使用VerifyKit Rest API的工具。

要求

  • PHP >= 5.5
  • PHP-Curl
  • PHP-Json

安装

您可以通过composer安装

composer require verifykit/verifykit-sdk-php

使用方法

重要提示

为了您应用程序的安全性,您应该在所有请求中发送最终用户的IP地址。为此,您需要在所有类构造中设置$clientIp参数。

验证方法列表

首先,获取验证方法列表。

$vfk = new \VerifyKit\Web($serverKey, $clientIp);

/** @var \VerifyKit\Entity\ValidationMethodList $validationMethodList */
$validationMethodList = $vfk->getValidationMethodList();

/** @var \VerifyKit\Entity\ValidationMethod $validationMethod */
foreach ($validationMethodList->getList() as $validationMethod) {
    // $validationMethod-> getName, getApp, getText, getTextColour, getBgColour, getIcon...
}

// if you want to handle all localizations for validation steps, use this way.
/** @var \VerifyKit\Entity\Localization $localization */
foreach ($validationMethodList->getLocalizationList() as $localization){
    // getKey, getValue of localization.
}

开始验证(WhatsApp或Telegram)

$vfk = new \VerifyKit\Web($serverKey, $clientIp);

$validationMethod = 'whatsapp'; // or telegram. Required.

$lang = 'en'; // Language of end user. Default value is 'en' (English). This parameter is not required.   

// We can give both deeplink and qrCode in response to the start request. If you send qrCode parameter as (bool)true, you can see that you have received a base64 qrCode. By showing this qrCode to users coming from desktop browsers, you can make it easier to verify.
// We recommend that you do not send qrCode parameter as (bool)true for requests from mobile applications or mobile browsers. You should use deeplink for these platforms.
// This two parameters cannot be (bool)true at the same time. If you send both (bool)true at the same time, we will only give the deeplink in the response.
// Default value is true for deeplink, and false for qrCode. These parameters are not required.
$deeplink = true;
$qrCode = false;

/** @var \VerifyKit\Entity\ValidationStart $result */
$validationStart = $vfk->startValidation($validationMethod, $lang, $deeplink, $qrCode);

// if you want to redirect your user for validation, get deeplink.
echo $validationStart->getDeeplink();

// if you want to view a Qr code to your user for validation, get base64 png string and set it as an image source on web browsers.
echo $validationStart->getQrCode();

// keep this reference code for next step.
echo $validationStart->getReference();

检查验证(WhatsApp或Telegram)

$vfk = new \VerifyKit\Web($serverKey, $clientIp);

$reference = "111111"; // reference from startValidation step.

/** @var \VerifyKit\Entity\ValidationCheck $validation */
$validationCheck = $vfk->checkValidation($reference);
if ($validationCheck->getValidationStatus()) {
    $sessionId = $validationCheck->getSessionId(); // session id for the validation result
    $appPlatform = $validationCheck->getAppPlatform(); // web, android or ios
}

开始验证(OTP)

国家列表

我们建议用户在输入号码之前选择他们的国家,以避免对国家代码的混淆。因此,在OTP验证之前获取国家列表可能会有所帮助。

$vfk = new \VerifyKit\Web($serverKey, $clientIp);

$countryCode = "TR"; // country code parameter for the request. We return the sent countryCode parameter at the top of the list in the response. If you want a specific country (user's country detected by ip on your side for example) to be the first response parameter, you can send $countryCode with your request. Not required.

$result = $vfk->getCountryList($countryCode);

/** @var \VerifyKit\Entity\Country $country */
foreach ($result->getCountryList() as $country){
    echo $country->getPhoneCode(); // phone code.
    echo $country->getCountryCode(); // country code
    echo $country->getTitle(); // country name
}

然后,开始OTP验证

$vfk = new \VerifyKit\Web($serverKey, $clientIp);

$phoneNumber = '+90........'; // End user phone number. Required.

$countryCode = 'TR'; // Country code of the end user's phone number. This parameter should exist in the country list request's response array as only the listed countries could be used for OTP validations. Required.

// For OTP verification to work best, you should send us the MCC and MNC code of the sim card in the user's device.
$mcc = '999'; // Mobile Country Code (MCC) of the sim card in the user's device. Default value is '999'. Not required.
$mnc = '999'; // Mobile Network Code (MNC) of the sim card in the user's device. Default value is '999'. Not required.

$lang = 'en'; // Language of end user. Default value is 'en' (English). You can set the language of the sent message. This parameter is not required.   


/** @var \VerifyKit\Entity\OTPSend $result */
$result = $vfk->sendOTP($phoneNumber, $countryCode, $mcc, $mnc, $lang);

$reference = $result->getReference(); // This parameter is required for a check OTP request.

检查验证(OTP)

$phoneNumber, $countryCode, $reference, $code

$vfk = new \VerifyKit\Web($serverKey, $clientIp);

$phoneNumber = '+90........'; // End user phone number. Required.

$countryCode = 'TR'; // Country code of the end user's phone number. This parameter should exist in the country list request's response array as only the listed countries could be used for OTP vadlidations. Required.

$reference = "111111"; // reference from sendOtp step. Required.

$code = "123456"; // The code to be entered by the user receiving the OTP.

/** @var \VerifyKit\Entity\OtpCheck $validation */
$otpCheck = $vfk->checkOtp($phoneNumber, $countryCode, $reference, $code);
if ($otpCheck->getValidationStatus()) {
    $sessionId = $otpCheck->getSessionId(); // session id for the OTP validation result
}

完成验证

最后,通过会话ID获取结果。

$vfk = new \VerifyKit\VerifyKit($serverKey, $clientIp);

/** @var \VerifyKit\Entity\Response $result */
$result = $vfk->getResult($sessionId);

if ($result->isSuccess()) {
    echo "Phone number : " . $result->getPhoneNumber() .
        ", Validation Type : " . $result->getValidationType() .
        ", Validation Date : " . $result->getValidationDate()->format('Y-m-d H:i:s') . PHP_EOL;
} else {
    echo "Error message : " . $result->getErrorMessage() . ", error code : " . $result->getErrorCode() . PHP_EOL;
}

WhatsApp会话消息

如果您想在24小时内通过WhatsApp会话消息向已验证用户发送消息,可以使用这种方式。

$waMessage = new \VerifyKit\WASessionMessage($serverKey, $clientIp);


/** @var \VerifyKit\Entity\WAMessageResponse $result */
$result = $waMessage->sendMessage($phoneNumber, $textMessage); // Phone number that you received using the session id in the previous method.

if ($result->isSuccess()) {
    echo "Phone number : " . $result->getPhoneNumber() . ", Message : " . $result->getMessage() . ", Status : " . $result->getStatus() . PHP_EOL;
} else {
    echo "Error message : " . $result->getErrorMessage() . ", error code : " . $result->getErrorCode() . PHP_EOL;
}

Web SDK

如果您想使用VerifyKit Web SDK,请使用唯一ID获取访问令牌。有关其他详细信息,请点击此处

$vfk = new \VerifyKit\VerifyKit($serverKey, $clientIp);

/** @var \VerifyKit\Entity\AccessToken $result */
$result = $vfk->getWebAccessToken();

if ($result->isSuccess()) {
    echo "Access Token : " . $result->getAccessToken() .
        ", Timeout : " . $result->getTimeout()->format('Y-m-d H:i:s') . PHP_EOL;
} else {
    echo "Error message : " . $result->getErrorMessage() . ", error code : " . $result->getErrorCode() . PHP_EOL;
}

作者

VerifyKit 由VerifyKit DevTeam拥有并维护。

许可证

MIT许可证

版权所有 (c) 2019-2020 VerifyKit. https://verifykit.com

以下是对任何获得此软件及其相关文档副本(“软件”)的人的免费许可,允许其在不受限制的情况下处理软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本,并允许向提供软件的个人提供这样做,前提是满足以下条件

上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。

本软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、适用于特定目的和不侵犯版权的保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论这些索赔、损害或其他责任是由于合同、侵权或其他方式产生的,与软件或其使用或其他方式相关。