verifymycontent / identity-check
VerifyMyContent 身份验证 API SDK
2.2.0
2024-06-11 16:23 UTC
Requires
- verifymycontent/sdk: ^2.4.0
This package is auto-updated.
Last update: 2024-09-14 17:11:15 UTC
README
PHP SDK 用于使用 VerifyMyContent 身份验证 OAuth 服务。
安装
composer require verifymycontent/identity-check
开始使用
处理审查集成过程的主要类是 \VerifyMyContent\IdentityCheck\VMC。它将抽象 API 调用的 HMAC 生成。
启动身份验证
<?php require(__DIR__ . "/vendor/autoload.php"); $vmc = new \VerifyMyContent\IdentityCheck\VMC(getenv('VMC_API_KEY'), getenv('VMC_API_SECRET')); //$vmc->useSandbox(); try { $response = $vmc->createIdentityVerification([ "customer" => [ "id" => "YOUR-CUSTOMER-UNIQUE-ID", "email" => "person@example.com", "phone" => "+4412345678" ], "redirect_uri" => "https://example.com/callback", "webhook" => "https://example.com/webhook", ] ); // save $response->id if you want to save the verification of your customer // redirect user to check identity header("Location: {$response->redirect_uri}"); } catch (Exception $e) { echo $e; }
通过 ID 获取身份验证
检索特定身份验证以获取当前状态。
- 将身份验证的
id
传递给getIdentityVerification
方法。 - 接收
\VerifyMyContent\SDK\IdentityVerification\Entity\Responses\GetIdentityVerificationResponse
(该 SDK 内部使用的库)。
<?php require(__DIR__ . "/vendor/autoload.php"); $vmc = new \VerifyMyContent\IdentityCheck\VMC(getenv('VMC_API_KEY'), getenv('VMC_API_SECRET')); //$vmc->useSandbox(); $response = $vmc->getIdentityVerification("YOUR-IDENTITY-VERIFICATION-ID"); // Printing current status echo "Status: {$response->status}";
接收身份验证 Webhook
当身份验证状态更改时,从 VerifyMyContent 接收 webhook。
- 从 VerifyMyContent 接收带有
$_POST
数据的 webhook,可以使用方法parseIdentityVerificationWebhookPayload
解析。
<?php require(__DIR__ . "/vendor/autoload.php"); $vmc = new \VerifyMyContent\IdentityCheck\VMC(getenv('VMC_API_KEY'), getenv('VMC_API_SECRET')); $jsonPayload = '{ "id": "ABC-123-5678-ABC", "customer_id": "customer_id", "status": "pending" }'; $data = json_decode($jsonPayload, true); $webhook = $vmc->parseIdentityVerificationWebhookPayload($data); // Printing current status echo "Status: {$webhook->status} received from verification {$webhook->id}"; // This is how you can check if the identity verification is approved. if ($webhook->status === \VerifyMyContent\SDK\IdentityVerification\IdentityVerificationStatus::APPROVED) { // do your thing }
添加允许的重定向 URL
更新允许的重定向 URL 列表
<?php require(__DIR__ . "/vendor/autoload.php"); $vmc = new \VerifyMyContent\IdentityCheck\VMC(getenv('VMC_API_KEY'), getenv('VMC_API_SECRET')); $vmc->useSandbox(); try{ $vmc->addAllowedRedirectUrls(["https://teste1.com", "https://teste2.com"]); echo "Urls replaced with success"; }catch(Exception $e){ echo "Error"; var_export($e); }
删除允许的重定向 URL
从列表中删除允许的重定向 URL
<?php require(__DIR__ . "/vendor/autoload.php"); $vmc = new \VerifyMyContent\IdentityCheck\VMC(getenv('VMC_API_KEY'), getenv('VMC_API_SECRET')); $vmc->useSandbox(); try{ $vmc->removeAllowedRedirectUrls(["https://teste1.com"]); echo "Urls removed with success"; }catch(Exception $e){ echo "Error"; var_export($e); }