Certification.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. // 实名认证用的
  3. namespace app\api\controller;
  4. use AlibabaCloud\SDK\Cloudauth\V20190307\Cloudauth;
  5. use \Exception;
  6. use AlibabaCloud\Tea\Exception\TeaError;
  7. use AlibabaCloud\Tea\Utils\Utils;
  8. use AlibabaCloud\SDK\Cloudauth\V20190307\Models\DescribeFaceVerifyRequest;
  9. use Darabonba\OpenApi\Models\Config;
  10. use AlibabaCloud\SDK\Cloudauth\V20190307\Models\InitFaceVerifyRequest;
  11. use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
  12. $path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
  13. if (file_exists($path)) {
  14. require_once $path;
  15. }
  16. class Certification {
  17. /**
  18. * 使用AK&SK初始化账号Client
  19. * @param string $accessKeyId
  20. * @param string $accessKeySecret
  21. * @return Cloudauth Client
  22. */
  23. public static function createClient($accessKeyId, $accessKeySecret){
  24. $config = new Config([
  25. // 您的 AccessKey ID
  26. "accessKeyId" => $accessKeyId,
  27. // 您的 AccessKey Secret
  28. "accessKeySecret" => $accessKeySecret,
  29. ]);
  30. // 访问的域名
  31. $config->endpoint = "cloudauth.aliyuncs.com";
  32. return new Cloudauth($config);
  33. }
  34. /**
  35. * @param string[] $args
  36. * @return void
  37. */
  38. public static function main($certName,$certNo,$metaInfo,$ReturnUrl){
  39. $client = self::createClient("LTAI5tMVT8vs7B1CApqhEgBo", "ESDiEM6zED1vyCMoGc9j5gZ9hWIXkP");
  40. $initFaceVerifyRequest = new InitFaceVerifyRequest([
  41. "sceneId" => '1000006090',
  42. "outerOrderNo" => get32Str(),
  43. // 要接入的认证方案。
  44. "productCode" => "ID_PRO",
  45. "certType" => "IDENTITY_CARD",
  46. "certName" => $certName,
  47. "certNo" => $certNo,
  48. // MetaInfo环境参数,需要通过客户端SDK获取。
  49. "metaInfo" => $metaInfo,
  50. "returnUrl" => $ReturnUrl,
  51. ]);
  52. $runtime = new RuntimeOptions([]);
  53. try {
  54. // 复制代码运行请自行打印 API 的返回值
  55. $res = $client->initFaceVerifyWithOptions($initFaceVerifyRequest, $runtime);
  56. return $res;
  57. } catch (Exception $error) {
  58. if (!($error instanceof TeaError)) {
  59. $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
  60. }
  61. // 如有需要,请打印 error
  62. Utils::assertAsString($error->message);
  63. return '';
  64. }
  65. }
  66. /**
  67. * @param string[] $args
  68. * @return void
  69. */
  70. public static function check($CertifyId){
  71. $client = self::createClient("LTAI5tAVV4VEU4vFVqpune1Q", "IMRENgb7kQsjLXfJ33aCyeTLeNj9DH");
  72. $describeFaceVerifyRequest = new DescribeFaceVerifyRequest([
  73. 'sceneId' => '1000004552',
  74. 'certifyId' => $CertifyId,
  75. ]);
  76. $runtime = new RuntimeOptions([]);
  77. try {
  78. // 复制代码运行请自行打印 API 的返回值
  79. $rs = $client->describeFaceVerifyWithOptions($describeFaceVerifyRequest, $runtime);
  80. return $rs;
  81. }
  82. catch (Exception $error) {
  83. if (!($error instanceof TeaError)) {
  84. $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
  85. }
  86. // 如有需要,请打印 error
  87. Utils::assertAsString($error->message);
  88. return false;
  89. }
  90. }
  91. }