songxingwei 2 年 前
コミット
5342601df1

+ 98 - 0
app/data/controller/Certification.php

@@ -0,0 +1,98 @@
+<?php
+// 实名认证用的
+namespace app\api\controller;
+
+use AlibabaCloud\SDK\Cloudauth\V20190307\Cloudauth;
+use \Exception;
+use AlibabaCloud\Tea\Exception\TeaError;
+use AlibabaCloud\Tea\Utils\Utils;
+use AlibabaCloud\SDK\Cloudauth\V20190307\Models\DescribeFaceVerifyRequest;
+use Darabonba\OpenApi\Models\Config;
+use AlibabaCloud\SDK\Cloudauth\V20190307\Models\InitFaceVerifyRequest;
+use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
+$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
+if (file_exists($path)) {
+    require_once $path;
+}
+class Certification {
+
+    /**
+     * 使用AK&SK初始化账号Client
+     * @param string $accessKeyId
+     * @param string $accessKeySecret
+     * @return Cloudauth Client
+     */
+    public static function createClient($accessKeyId, $accessKeySecret){
+        $config = new Config([
+            // 您的 AccessKey ID
+            "accessKeyId" => $accessKeyId,
+            // 您的 AccessKey Secret
+            "accessKeySecret" => $accessKeySecret,
+        ]);
+        // 访问的域名
+        $config->endpoint = "cloudauth.aliyuncs.com";
+        return new Cloudauth($config);
+    }
+
+    /**
+     * @param string[] $args
+     * @return void
+     */
+    public static function main($certName,$certNo,$metaInfo,$ReturnUrl){
+        $client = self::createClient("LTAI5tMVT8vs7B1CApqhEgBo", "ESDiEM6zED1vyCMoGc9j5gZ9hWIXkP");
+        $initFaceVerifyRequest = new InitFaceVerifyRequest([
+            "sceneId" => '1000004552',
+            "outerOrderNo" => get32Str(),
+            // 要接入的认证方案。
+            "productCode" => "ID_PRO",
+            "certType" => "IDENTITY_CARD",
+            "certName" => $certName,
+            "certNo" => $certNo,
+            // MetaInfo环境参数,需要通过客户端SDK获取。
+            "metaInfo" => $metaInfo,
+            "returnUrl" => $ReturnUrl,
+        ]);
+        $runtime = new RuntimeOptions([]);
+        try {
+            // 复制代码运行请自行打印 API 的返回值
+            $res = $client->initFaceVerifyWithOptions($initFaceVerifyRequest, $runtime);
+            return $res;
+        } catch (Exception $error) {
+            if (!($error instanceof TeaError)) {
+                $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
+            }
+            // 如有需要,请打印 error
+            Utils::assertAsString($error->message);
+            return '';
+        }
+    }
+
+    /**
+     * @param string[] $args
+     * @return void
+     */
+    public static function check($CertifyId){
+        $client = self::createClient("LTAI5tAVV4VEU4vFVqpune1Q", "IMRENgb7kQsjLXfJ33aCyeTLeNj9DH");
+        $describeFaceVerifyRequest = new DescribeFaceVerifyRequest([
+                'sceneId'           => '1000004552',
+                'certifyId'         => $CertifyId,
+            ]);
+        $runtime = new RuntimeOptions([]);
+        try {
+            // 复制代码运行请自行打印 API 的返回值
+            $rs =  $client->describeFaceVerifyWithOptions($describeFaceVerifyRequest, $runtime);
+            return $rs;
+        }
+        catch (Exception $error) {
+            if (!($error instanceof TeaError)) {
+                $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
+            }
+            // 如有需要,请打印 error
+            Utils::assertAsString($error->message);
+            return false;
+        }
+    }
+
+}
+
+

+ 32 - 0
app/data/controller/api/auth/Center.php

@@ -2,6 +2,7 @@
 
 namespace app\data\controller\api\auth;
 
+use app\api\controller\Certification;
 use app\data\controller\api\Auth;
 use app\data\controller\api\Data;
 use app\data\model\BaseUserMessage;
@@ -60,6 +61,37 @@ class Center extends Auth
     protected $noNeedLogin=['upload','image','uploadmore','messagelist'];
 
 
+
+    /**
+     * @title 阿里云金融级实名认证初始化
+     * @desc 阿里云金融级实名认证初始化
+     * @author QC
+     * @method POST
+     * @tag 编辑信息
+     * @url /api/User_center/initFaceVerify
+     * @header name:Authorization require:1 desc:Token
+     * @param  name:name type:string default:1 desc:姓名
+     * @param  name:id_no type:string default:1 desc:身份证号
+     * @param  name:MetaInfo type:string  default:1 desc:MetaInfo
+     * @param  name:ReturnUrl type:string default:1 desc:业务页面回跳的目标地址
+     * @return name:RequestId type:String default:-- desc:请求ID
+     * @return name:Message type:String default:-- desc:返回信息
+     * @return name:Code type:String default:-- desc:返返回码:200为成功,其他为失败。【具体的参考阿里云文档】
+     * @return name:ResultObject.CertifyId type:String default:-- desc:实人认证唯一标识
+     * @return name:ResultObject.CertifyUrl type:String default:-- desc:Web认证URL,认证结束后根据入参ReturnUrl进行进行转赠跳转
+     */
+    function initFaceVerify(){
+        $name = input('name');
+        $id_no = input('id_no');
+        $MetaInfo = input('MetaInfo');
+        $ReturnUrl = input('ReturnUrl');
+        $res = Certification::main($name,$id_no,$MetaInfo,$ReturnUrl);
+        if(!$res) $this->error('初始化错误');
+        $result = json_decode(json_encode($res),true)['body'];
+        $result['code'] != 200 ? $this->error($result['message']):$this->success('ok',$result);
+    }
+
+
     /**
      * @Title("获取用户资料")
      * @Method("post")