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

2019-03-0117:00:46后端程序开发Comments4,523 views字数 1492阅读模式

1. 创建 RAM 用户文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9785.html

PHP代码:实人认证/活体人脸验证服务token生成流程文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9785.html

2. 编辑个人授权策略文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9785.html

添加:  AdministratorAccess文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9785.html

3. 下载SDK, 复制aliyun-php-sdk-core,aliyun-php-sdk-cloudauth目录文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9785.html

https://github.com/aliyun/aliyun-openapi-php-sdk文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9785.html

core/config.php里增加文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9785.html

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

4. 调用代码, 需要修改的内容有($biz, $accesskeyid,$accesssecret)文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9785.html

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());
}
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9785.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/bc/9785.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定