Userauth.php 4.4 KB

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