123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- use AlibabaCloud\SDK\Cloudauth\V20190307\Cloudauth;
- use AlibabaCloud\SDK\Cloudauth\V20190307\Models\DescribeFaceVerifyRequest;
- use AlibabaCloud\SDK\Cloudauth\V20190307\Models\InitFaceVerifyRequest;
- use AlibabaCloud\Tea\Exception\TeaError;
- use AlibabaCloud\Tea\Utils\Utils;
- use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
- use Darabonba\OpenApi\Models\Config;
- use think\admin\model\SystemConfig;
- function systemConfig($name,$value=null){
- $nameArr=array_filter(explode('.',$name));
- if(is_null($value)){
- if(count($nameArr)==1) {
- $source = SystemConfig::where('type', $nameArr[0])->select();
- $data=[];
- foreach ($source as $model){
- $value=$model['value'];
- if($decode=json_decode($value,true)){
- $value=$decode;
- }
- $data[$model['name']]=$value;
- }
- return $data?:null;
- }else{
- $model = SystemConfig::where('type', $nameArr[0])->where('name',$nameArr[1])->find();
- $value=$model['value'];
- if($decode=json_decode($value,true)){
- $value=$decode;
- }
- return $value;
- }
- }else{
- SystemConfig::where('type', $nameArr[0])->delete();
- if(count($nameArr)==1) {
- if(is_array($value)){
- foreach ($value as $key=>$val){
- SystemConfig::insert([
- 'type'=>$nameArr[0],
- 'name'=>$key,
- 'value'=>is_array($val)?json_encode($val,256):$val,
- ]);
- }
- }
- }else{
- SystemConfig::insert([
- 'type'=>$nameArr[0],
- 'name'=>$nameArr[1],
- 'value'=>$value,
- ]);
- }
- }
- }
- /**
- * 生成??位随机数
- */
- function get32Str($length='32'){
- // $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
- $str = 'abcdefghijklmnopqrstuvwxyz0123456789';
- $len = strlen($str)-1;
- $randstr = '';
- for ($i=0;$i<$length;$i++) {
- $num=mt_rand(0,$len);
- $randstr .= $str[$num];
- }
- return $randstr;
- }
- /**
- * 使用AK&SK初始化账号Client
- * @param string $accessKeyId
- * @param string $accessKeySecret
- * @return Cloudauth Client
- */
- 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
- */
- function main($certName,$certNo,$metaInfo,$ReturnUrl){
- $client = createClient("LTAI5tMVT8vs7B1CApqhEgBo", "ESDiEM6zED1vyCMoGc9j5gZ9hWIXkP");
- $initFaceVerifyRequest = new InitFaceVerifyRequest([
- "sceneId" => '1000006090',
- "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
- */
- function check($CertifyId){
- $client = createClient("LTAI5tMVT8vs7B1CApqhEgBo", "ESDiEM6zED1vyCMoGc9j5gZ9hWIXkP");
- $describeFaceVerifyRequest = new DescribeFaceVerifyRequest([
- 'sceneId' => '1000006090',
- '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;
- }
- }
- /**
- * 生成二维码
- */
- function setqrcode($value,$name){
- $dir = dirname(realpath(dirname($_SERVER['SCRIPT_FILENAME']))) . '/public/';
- if(!file_exists($dir)){
- //检查是否有该文件夹,如果没有就创建,并给予最高权限
- mkdir($dir, 0700,true);
- }
- $filename = $dir.'/'.$name.'.png';
- QRcode::png($value,$filename,QR_ECLEVEL_L,7);
- $url = 'http://'.$_SERVER['SERVER_NAME']."/user/".$name.'.png';
- return $url;
- }
- //生成邀请二维码
- function setappcode($address){
- $name = time();
- $url = setqrcode($address,$name);
- return $url;
- }
|