Code前端首页关于Code前端联系我们

PHP代码:真人认证/活人脸验证服务token生成流程

terry 2年前 (2023-09-25) 阅读数 47 #后端开发

1.创建 RAM 用户

PHP代码:实人认证/活体人脸验证服务token生成流程

2。编辑个人授权策略

添加:AdministratorAccess

3.下载SDK,复制aliyun-php-sdk-core、aliyun-php-sdk-cloudauth目录

https://github.com/aliyun/aliyun-openapi-php-sdk

core/config.php更多

//config sdk auto load path.
Autoloader::addAutoloadPath("aliyun-php-sdk-cloudauth");

4。邀请码,可编辑内容为($biz,$accesskeyid,$accesssecret)

define('DS', '/');
define('APP_PATH', realpath(dirname(__FILE__).DS.'..'.DS.'application').DS);
include_once APP_PATH . 'third/aliyun/aliyun-php-sdk-core/Config.php';
use Cloudauth\Request\V20180807 as cloudauth;
$iClientProfile = DefaultProfile::getProfile("cn-hangzhou", $accessKeyId, $accessSecret);
$iClientProfile::addEndpoint("cn-hangzhou", "cn-hangzhou", "Cloudauth", "cloudauth.aliyuncs.com");
$client = new DefaultAcsClient($iClientProfile);

$biz = "yannihealth"; //您在控制台上创建的、采用RPBasic认证方案的认证场景标识, 创建方法:https://help.aliyun.com/document_detail/59975.html
$ticketId = guid(); //认证ID, 由使用方指定, 发起不同的认证任务需要更换不同的认证ID
$token = null; //认证token, 表达一次认证会话
$statusCode = -1; //-1 未认证, 0 认证中, 1 认证通过, 2 认证不通过
//1. 服务端发起认证请求, 获取到token
//GetVerifyToken接口文档:https://help.aliyun.com/document_detail/57050.html
$getVerifyTokenRequest = new cloudauth\GetVerifyTokenRequest();
$getVerifyTokenRequest->setBiz($biz);
$getVerifyTokenRequest->setTicketId($ticketId);
try {
    $response = $client->getAcsResponse($getVerifyTokenRequest);
    $token = $response->Data->VerifyToken->Token; //token默认30分钟时效,每次发起认证时都必须实时获取    Help::print_json(0, ['token' => $token]);//输出token} catch (Exception $e) {
    print_r ($e->getTrace());
}

版权声明

本文仅代表作者观点,不代表Code前端网立场。
本文系作者Code前端网发表,如需转载,请注明页面地址。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门