Renlian.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 人脸核身
  7. */
  8. class Renlian extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['*'];
  12. public function access_token(){
  13. $config = config('renlian');
  14. $appid = $config['appid'];
  15. $secret = $config['secret'];
  16. $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id='.$appid.'&secret='.$secret.'&grant_type=client_credential&version=1.0.0';
  17. $result = curl_get($url);
  18. $token = '';
  19. if($result){
  20. $result = json_decode($result,true);
  21. if($result['code'] == 0 && isset($result['access_token'])){
  22. $token = $result['access_token'];
  23. }
  24. }
  25. return $token;
  26. }
  27. public function nonce_ticket(){
  28. $config = config('renlian');
  29. $appid = $config['appid'];
  30. $secret = $config['secret'];
  31. $token = $this->access_token();
  32. $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;
  33. $tickets = '';
  34. $result = curl_get($url);
  35. // dump($result);
  36. if($result){
  37. $result = json_decode($result,true);
  38. if($result['code'] == 0 && isset($result['tickets'][0]['value'])){
  39. $tickets = $result['tickets'][0]['value'];
  40. }
  41. }
  42. $this->success('success',$tickets);
  43. }
  44. public function sdksign(){
  45. $config = config('renlian');
  46. $appid = $config['appid'];
  47. $secret = $config['secret'];
  48. }
  49. }