Userauth.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use think\Cache;
  6. use TencentCloud\Common\Credential;
  7. use TencentCloud\Common\Profile\ClientProfile;
  8. use TencentCloud\Common\Profile\HttpProfile;
  9. use TencentCloud\Common\Exception\TencentCloudSDKException;
  10. //use TencentCloud\Faceid\V20180301\FaceidClient;
  11. //use TencentCloud\Faceid\V20180301\Models\IdCardVerificationRequest;
  12. use TencentCloud\Iai\V20200303\IaiClient;
  13. use TencentCloud\Iai\V20200303\Models\CompareFaceRequest;
  14. use fast\Random;
  15. /**
  16. * 实名认证,真人认证相关
  17. */
  18. class Userauth extends Api
  19. {
  20. protected $noNeedLogin = [];
  21. protected $noNeedRight = '*';
  22. //实名认证信息
  23. public function idcard_info(){
  24. $check = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->order('id desc')->find();
  25. $this->success('success',$check);
  26. }
  27. //申请实名认证
  28. public function apply_idcard_confirm(){
  29. $truename = input('truename','');
  30. $idcard = input('idcard' ,'');
  31. if(empty($truename) || empty($idcard)){
  32. $this->error('实名认证信息必填');
  33. }
  34. if($this->auth->idcard_status == 1){
  35. $this->error('您已经完成实名认证');
  36. }
  37. if($this->auth->idcard_status == 0){
  38. $this->error('您已经提交实名认证,请等待审核');
  39. }
  40. Db::startTrans();
  41. $check = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->lock(true)->find();
  42. if(!empty($check)){
  43. if($check['status'] == 0){
  44. Db::rollback();
  45. $this->error('您已经提交实名认证,请等待审核');
  46. }
  47. if($check['status'] == 1){
  48. Db::rollback();
  49. $this->error('您已经完成实名认证');
  50. }
  51. }
  52. $count = Db::name('user_idconfirm')->where(['idcard' => $idcard, 'user_id' => ['neq', $this->auth->id]])->count('id');
  53. if ($count) {
  54. $this->error('该身份证号已被他人使用');
  55. }
  56. $data = [
  57. 'user_id' => $this->auth->id,
  58. 'truename' => $truename,
  59. 'idcard' => $idcard,
  60. 'status' => 0, //人工审核
  61. 'createtime' => time(),
  62. 'updatetime' => time(),
  63. ];
  64. //更新
  65. $update_rs = Db::name('user')->where('id',$this->auth->id)->update(['idcard_status'=>$data['status']]);
  66. if(!empty($check)){
  67. $rs = Db::name('user_idconfirm')->where('id',$check['id'])->update($data);
  68. }else{
  69. $rs = Db::name('user_idconfirm')->insertGetId($data);
  70. }
  71. if(!$rs || !$update_rs){
  72. Db::rollback();
  73. $this->error('提交失败');
  74. }
  75. Db::commit();
  76. $this->success('提交成功,请等待审核');
  77. }
  78. //产品链接:https://market.aliyun.com/products/57000002/cmapi026109.html#sku=yuncode20109000025
  79. //阿里云-数脉api
  80. //姓名+身份证号
  81. private function userauth_aliyun_two($cardNo = '',$realname = ''){
  82. if(!$cardNo || !$realname){
  83. return false;
  84. }
  85. $config = config('aliyun_auth_shumai_two');
  86. $host = "https://eid.shumaidata.com";
  87. $path = "/eid/check";
  88. $method = "POST";
  89. $appcode = $config['app_code'];
  90. $headers = array();
  91. array_push($headers, "Authorization:APPCODE " . $appcode);
  92. $querys = "idcard=".$cardNo."&name=".urlencode($realname);
  93. $bodys = '';
  94. $url = $host . $path . "?" . $querys;
  95. $curl = curl_init();
  96. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  97. curl_setopt($curl, CURLOPT_URL, $url);
  98. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  99. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  100. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  101. //设定返回信息中是否包含响应信息头,启用时会将头文件的信息作为数据流输出,true 表示输出信息头, false表示不输出信息头
  102. //如果需要将字符串转成json,请将 CURLOPT_HEADER 设置成 false
  103. curl_setopt($curl, CURLOPT_HEADER, false);
  104. if (1 == strpos("$".$host, "https://"))
  105. {
  106. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  107. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  108. }
  109. $returnRes = curl_exec($curl);
  110. //var_dump($returnRes);
  111. curl_close($curl);
  112. $result = json_decode($returnRes,true);
  113. //dump($result);
  114. if(is_array($result) && isset($result['code']) && $result['code'] == 0){
  115. if(isset($result['result']) && isset($result['result']['res'])){
  116. if($result['result']['res'] == 1){
  117. //实名过了
  118. return true;
  119. }
  120. }
  121. }
  122. return false;
  123. }
  124. }