Browse Source

人脸核身需要用到的,提供给app

lizhen_gitee 3 years ago
parent
commit
4edbbc7995
2 changed files with 65 additions and 0 deletions
  1. 60 0
      application/api/controller/Renlian.php
  2. 5 0
      application/config.php

+ 60 - 0
application/api/controller/Renlian.php

@@ -0,0 +1,60 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 人脸核身
+ */
+class Renlian extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = ['*'];
+
+    public function access_token(){
+        $config = config('renlian');
+        $appid  = $config['appid'];
+        $secret = $config['secret'];
+
+        $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id='.$appid.'&secret='.$secret.'&grant_type=client_credential&version=1.0.0';
+        $result = curl_get($url);
+
+        $token = '';
+        if($result){
+            $result = json_decode($result,true);
+            if($result['code'] == 0 && isset($result['access_token'])){
+                $token = $result['access_token'];
+            }
+        }
+
+        return $token;
+    }
+
+    public function nonce_ticket(){
+        $config = config('renlian');
+        $appid  = $config['appid'];
+        $secret = $config['secret'];
+
+        $token = $this->access_token();
+        $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id='.$appid.'&access_token='.$token.'&type=NONCE&version=1.0.0&user_id='.$this->auth->id;
+
+        $tickets = '';
+        $result = curl_get($url);
+//        dump($result);
+        if($result){
+            $result = json_decode($result,true);
+            if($result['code'] == 0 && isset($result['tickets'][0]['value'])){
+                $tickets = $result['tickets'][0]['value'];
+            }
+        }
+
+        $this->success('success',$tickets);
+
+    }
+
+    public function sdksign(){
+
+    }
+
+}

+ 5 - 0
application/config.php

@@ -355,4 +355,9 @@ return [
         'businessid'      => '31c634cee6364d47a007fe87a46342ea',
     ],
 
+    'renlian' => [
+        'appid' => 'IDAnDqaz',
+        'secret' => 'sAsx6iK7CsrqJm55xfKlOd4jqDwSHJ9jKKFjoXc59be1GzG3oxKVWSJ03eAIWuWU',
+    ],
+
 ];