common.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. use AlibabaCloud\SDK\Cloudauth\V20190307\Cloudauth;
  3. use AlibabaCloud\SDK\Cloudauth\V20190307\Models\DescribeFaceVerifyRequest;
  4. use AlibabaCloud\SDK\Cloudauth\V20190307\Models\InitFaceVerifyRequest;
  5. use AlibabaCloud\Tea\Exception\TeaError;
  6. use AlibabaCloud\Tea\Utils\Utils;
  7. use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
  8. use Darabonba\OpenApi\Models\Config;
  9. use think\admin\model\SystemConfig;
  10. function systemConfig($name,$value=null){
  11. $nameArr=array_filter(explode('.',$name));
  12. if(is_null($value)){
  13. if(count($nameArr)==1) {
  14. $source = SystemConfig::where('type', $nameArr[0])->select();
  15. $data=[];
  16. foreach ($source as $model){
  17. $value=$model['value'];
  18. if($decode=json_decode($value,true)){
  19. $value=$decode;
  20. }
  21. $data[$model['name']]=$value;
  22. }
  23. return $data?:null;
  24. }else{
  25. $model = SystemConfig::where('type', $nameArr[0])->where('name',$nameArr[1])->find();
  26. $value=$model['value'];
  27. if($decode=json_decode($value,true)){
  28. $value=$decode;
  29. }
  30. return $value;
  31. }
  32. }else{
  33. SystemConfig::where('type', $nameArr[0])->delete();
  34. if(count($nameArr)==1) {
  35. if(is_array($value)){
  36. foreach ($value as $key=>$val){
  37. SystemConfig::insert([
  38. 'type'=>$nameArr[0],
  39. 'name'=>$key,
  40. 'value'=>is_array($val)?json_encode($val,256):$val,
  41. ]);
  42. }
  43. }
  44. }else{
  45. SystemConfig::insert([
  46. 'type'=>$nameArr[0],
  47. 'name'=>$nameArr[1],
  48. 'value'=>$value,
  49. ]);
  50. }
  51. }
  52. }
  53. /**
  54. * 生成??位随机数
  55. */
  56. function get32Str($length='32'){
  57. // $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  58. $str = 'abcdefghijklmnopqrstuvwxyz0123456789';
  59. $len = strlen($str)-1;
  60. $randstr = '';
  61. for ($i=0;$i<$length;$i++) {
  62. $num=mt_rand(0,$len);
  63. $randstr .= $str[$num];
  64. }
  65. return $randstr;
  66. }
  67. /**
  68. * 使用AK&SK初始化账号Client
  69. * @param string $accessKeyId
  70. * @param string $accessKeySecret
  71. * @return Cloudauth Client
  72. */
  73. function createClient($accessKeyId, $accessKeySecret){
  74. $config = new Config([
  75. // 您的 AccessKey ID
  76. "accessKeyId" => $accessKeyId,
  77. // 您的 AccessKey Secret
  78. "accessKeySecret" => $accessKeySecret,
  79. ]);
  80. // 访问的域名
  81. $config->endpoint = "cloudauth.aliyuncs.com";
  82. return new Cloudauth($config);
  83. }
  84. /**
  85. * @param string[] $args
  86. * @return void
  87. */
  88. function main($certName,$certNo,$metaInfo,$ReturnUrl){
  89. $client = createClient("LTAI5tMVT8vs7B1CApqhEgBo", "ESDiEM6zED1vyCMoGc9j5gZ9hWIXkP");
  90. $initFaceVerifyRequest = new InitFaceVerifyRequest([
  91. "sceneId" => '1000006090',
  92. "outerOrderNo" => get32Str(),
  93. // 要接入的认证方案。
  94. "productCode" => "ID_PRO",
  95. "certType" => "IDENTITY_CARD",
  96. "certName" => $certName,
  97. "certNo" => $certNo,
  98. // MetaInfo环境参数,需要通过客户端SDK获取。
  99. "metaInfo" => $metaInfo,
  100. "returnUrl" => $ReturnUrl,
  101. ]);
  102. $runtime = new RuntimeOptions([]);
  103. try {
  104. // 复制代码运行请自行打印 API 的返回值
  105. $res = $client->initFaceVerifyWithOptions($initFaceVerifyRequest, $runtime);
  106. return $res;
  107. } catch (Exception $error) {
  108. if (!($error instanceof TeaError)) {
  109. $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
  110. }
  111. // 如有需要,请打印 error
  112. Utils::assertAsString($error->message);
  113. return '';
  114. }
  115. }
  116. /**
  117. * @param string[] $args
  118. * @return void
  119. */
  120. function check($CertifyId){
  121. $client = createClient("LTAI5tMVT8vs7B1CApqhEgBo", "ESDiEM6zED1vyCMoGc9j5gZ9hWIXkP");
  122. $describeFaceVerifyRequest = new DescribeFaceVerifyRequest([
  123. 'sceneId' => '1000006090',
  124. 'certifyId' => $CertifyId,
  125. ]);
  126. $runtime = new RuntimeOptions([]);
  127. try {
  128. // 复制代码运行请自行打印 API 的返回值
  129. $rs = $client->describeFaceVerifyWithOptions($describeFaceVerifyRequest, $runtime);
  130. return $rs;
  131. }
  132. catch (Exception $error) {
  133. if (!($error instanceof TeaError)) {
  134. $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
  135. }
  136. // 如有需要,请打印 error
  137. Utils::assertAsString($error->message);
  138. return false;
  139. }
  140. }
  141. /**
  142. * 生成二维码
  143. */
  144. function setqrcode($value,$name){
  145. $dir = dirname(realpath(dirname($_SERVER['SCRIPT_FILENAME']))) . '/public/';
  146. if(!file_exists($dir)){
  147. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  148. mkdir($dir, 0700,true);
  149. }
  150. $filename = $dir.'/'.$name.'.png';
  151. QRcode::png($value,$filename,QR_ECLEVEL_L,7);
  152. $url = 'http://'.$_SERVER['SERVER_NAME']."/user/".$name.'.png';
  153. return $url;
  154. }
  155. //生成邀请二维码
  156. function setappcode($address){
  157. $name = time();
  158. $url = setqrcode($address,$name);
  159. return $url;
  160. }