فهرست منبع

实名认证+真人认证

lizhen_gitee 1 سال پیش
والد
کامیت
655adb32d6
3فایلهای تغییر یافته به همراه357 افزوده شده و 118 حذف شده
  1. 0 118
      application/api/controller/User.php
  2. 356 0
      application/api/controller/Userauth.php
  3. 1 0
      application/extra/site.php

+ 0 - 118
application/api/controller/User.php

@@ -302,124 +302,6 @@ class User extends Api
 
 
 
-
-
-    //申请真人认证
-    public function apply_real_confirm(){
-        $avatar = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
-        if(!$avatar){
-            $this->error('请上传真人头像');
-        }
-
-        Db::startTrans();
-
-        $data = [
-            'avatar' => $avatar,
-            'real_status' => 1,
-        ];
-        $rs = Db::name('user')->where('id',$this->auth->id)->update($data);
-        if($rs === false){
-            Db::rollback();
-            $this->error('认证失败');
-        }
-        //tag任务赠送金币
-        //完成本人基本资料 +15金币《所有资料完善,包括真人认证和实名认证》
-        $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,5);
-        if($task_rs === false){
-            Db::rollback();
-            $this->error('完成任务赠送奖励失败');
-        }
-        //完成真人头像 +5金币
-        $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,7);
-        if($task_rs === false){
-            Db::rollback();
-            $this->error('完成任务赠送奖励失败');
-        }
-        //邀请人拿奖励,男性3元
-        $intro_money = $this->auth->gender == 1 ? config('site.intro_man_money') : config('site.intro_woman_money');
-        if($this->auth->idcard_status == 1 && !empty($this->auth->intro_uid) && $intro_money > 0){
-            $task_rs = model('wallet')->lockChangeAccountRemain($this->auth->intro_uid,'money',$intro_money,63,$remark='');
-            if($task_rs['status'] === false){
-                Db::rollback();
-                $this->error($task_rs['msg']);
-            }
-        }
-        //系统消息
-        $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证已经审核通过');
-
-        Db::commit();
-        $this->success();
-    }
-
-    //实名认证信息
-    public function idcard_confirm_info(){
-        $check = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->order('id desc')->find();
-        $this->success('success',$check);
-    }
-
-
-
-    //申请实名认证
-    public function apply_idcard_confirm(){
-        $truename = input('truename','');
-        $idcard = input('idcard','');
-        //$idcard_images = input('idcard_images','');
-        $alipay_account = input('alipay_account','');
-
-        if(empty($truename) || empty($idcard) || empty($alipay_account)){
-            $this->error('实名认证信息必填');
-        }
-
-        if($this->auth->idcard_status == 1){
-            $this->error('您已经完成实名认证');
-        }
-
-        if($this->auth->idcard_status == 0){
-            $this->error('您已经提交实名认证,请等待审核');
-        }
-
-        Db::startTrans();
-        $check = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->lock(true)->find();
-        if(!empty($check)){
-            if($check['status'] == 0){
-                Db::rollback();
-                $this->error('您已经提交实名认证,请等待审核');
-            }
-            if($check['status'] == 1){
-                Db::rollback();
-                $this->error('您已经完成实名认证');
-            }
-        }
-
-        $data = [
-            'user_id' => $this->auth->id,
-            'truename' => $truename,
-            'idcard' => $idcard,
-            //'idcard_images' => $idcard_images,
-            'alipay_account' => $alipay_account,
-            'status' => 0,
-            'createtime' => time(),
-            'updatetime' => time(),
-        ];
-
-        //更新
-        $update_rs = Db::name('user')->where('id',$this->auth->id)->update(['idcard_status'=>0]);
-        if(!empty($check)){
-            $rs = Db::name('user_idconfirm')->where('id',$check['id'])->update($data);
-        }else{
-            $rs = Db::name('user_idconfirm')->insertGetId($data);
-        }
-
-        if(!$rs || !$update_rs){
-            Db::rollback();
-            $this->error('提交失败');
-        }
-
-        Db::commit();
-        $this->success('提交成功,请等待审核');
-
-    }
-
     /**
      * 退出登录
      * @ApiMethod (POST)

+ 356 - 0
application/api/controller/Userauth.php

@@ -0,0 +1,356 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use app\common\library\Ems;
+use app\common\library\Sms;
+use fast\Random;
+use think\Config;
+use think\Validate;
+
+use app\common\library\Token;
+use think\Db;
+use app\common\model\UserDeviceInfo;
+use onlogin\onlogin;
+
+use addons\epay\library\Service;
+//use addons\epay\library\Wechat;
+use app\common\library\Wechat;
+
+/**
+ * 实名认证,真人认证相关
+ */
+class Userauth extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = '*';
+
+
+
+
+    //申请真人认证
+    public function apply_real_confirm(){
+
+        Db::startTrans();
+
+        //tag任务赠送金币
+        //完成本人基本资料 +15金币《所有资料完善,包括真人认证和实名认证》
+        $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,5);
+        if($task_rs === false){
+            Db::rollback();
+            $this->error('完成任务赠送奖励失败');
+        }
+        //完成真人头像 +5金币
+        $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,7);
+        if($task_rs === false){
+            Db::rollback();
+            $this->error('完成任务赠送奖励失败');
+        }
+        //邀请人拿奖励,男性3元
+        $intro_money = $this->auth->gender == 1 ? config('site.intro_man_money') : config('site.intro_woman_money');
+        if($this->auth->idcard_status == 1 && !empty($this->auth->intro_uid) && $intro_money > 0){
+            $task_rs = model('wallet')->lockChangeAccountRemain($this->auth->intro_uid,'money',$intro_money,63,$remark='');
+            if($task_rs['status'] === false){
+                Db::rollback();
+                $this->error($task_rs['msg']);
+            }
+        }
+        //系统消息
+        $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证已经审核通过');
+
+        Db::commit();
+        $this->success();
+    }
+
+
+
+    //申请实名认证
+    public function apply_idcard_confirm(){
+        $truename = input('truename','');
+        $idcard   = input('idcard'  ,'');
+
+        if(empty($truename) || empty($idcard)){
+            $this->error('实名认证信息必填');
+        }
+
+        if($this->auth->idcard_status == 1){
+            $this->error('您已经完成实名认证');
+        }
+
+        if($this->auth->idcard_status == 0){
+            $this->error('您已经提交实名认证,请等待审核');
+        }
+
+        Db::startTrans();
+        $check = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->lock(true)->find();
+        if(!empty($check)){
+            if($check['status'] == 0){
+                Db::rollback();
+                $this->error('您已经提交实名认证,请等待审核');
+            }
+            if($check['status'] == 1){
+                Db::rollback();
+                $this->error('您已经完成实名认证');
+            }
+        }
+
+        $data = [
+            'user_id' => $this->auth->id,
+            'truename' => $truename,
+            'idcard' => $idcard,
+            'status' => 0,
+            'createtime' => time(),
+            'updatetime' => time(),
+        ];
+
+        //更新
+        $update_rs = Db::name('user')->where('id',$this->auth->id)->update(['idcard_status'=>0]);
+        if(!empty($check)){
+            $rs = Db::name('user_idconfirm')->where('id',$check['id'])->update($data);
+        }else{
+            $rs = Db::name('user_idconfirm')->insertGetId($data);
+        }
+
+        if(!$rs || !$update_rs){
+            Db::rollback();
+            $this->error('提交失败');
+        }
+
+        Db::commit();
+        $this->success('提交成功,请等待审核');
+
+    }
+
+
+    //申请真人认证
+    public function realauth() {
+        if ($this->auth->real_status == 1) {
+            $this->error('您已经真人认证过了~');
+        }
+        if ($this->auth->avatar == config('avatar_boy') || $this->auth->avatar == config('avatar_girl')) {
+            $this->error('请先上传真人头像~');
+        }
+
+        //获取token
+        $token_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id='.config('tencent_yun')['secret_id'].'&secret='.config('tencent_yun')['secret_key'].'&grant_type=client_credential&version=1.0.0';
+        $token_result = file_get_contents($token_url);
+        if (!$token_result) {
+            $this->error('您的网络开小差啦1~');
+        }
+        $token_result = json_decode($token_result, true);
+        if ($token_result['code'] != 0) {
+            $this->error('您的网络开小差啦2~');
+        }
+        $token = $token_result['access_token'];
+
+        //获取签名鉴权参数ticket
+        $ticket_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id='.config('tencent_yun')['secret_id'].'&access_token='.$token.'&type=SIGN&version=1.0.0';
+        $ticket_result = file_get_contents($ticket_url);
+        if (!$ticket_result) {
+            $this->error('您的网络开小差啦3~');
+        }
+        $ticket_result = json_decode($ticket_result, true);
+        if ($ticket_result['code'] != 0) {
+            $this->error('您的网络开小差啦4~');
+        }
+        $ticket = $ticket_result['tickets'][0]['value'];
+
+        //获取签名
+        $sign_data = [
+            'wbappid' => config('tencent_yun')['secret_id'],
+            'userId'  => (string)$this->auth->id,
+            'version' => '1.0.0',
+            'ticket'  => $ticket,
+            'nonce'   => Random::alnum(32)
+        ];//p($sign_data);
+        asort($sign_data); //p($sign_data);//排序
+        $sign_string = join('', $sign_data);//p($sign_string);
+        $sign = sha1($sign_string);//p($sign);
+
+        //上传身份信息
+//        $orderNo = getMillisecond() . $this->auth->id . mt_rand(1, 1000); //商户请求的唯一标识
+        $orderNo = createUniqueNo('A',$this->auth->id);
+        $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/server/getAdvFaceId?orderNo=' . $orderNo;
+
+        $avatar = one_domain_image($this->auth->avatar);
+        $avatar = str_replace('https', 'http', $avatar);
+        $img = file_get_contents($avatar);
+        $img = str_replace('data:image/jpg;base64', '', $img);
+        $img = str_replace('\n', '', $img);
+        $sourcePhotoStr = base64_encode($img);
+
+        $data = [
+            'webankAppId' => config('tencent_yun')['secret_id'],
+            'orderNo' => $orderNo,
+            'userId' => (string)$this->auth->id,
+            'sourcePhotoStr' => $sourcePhotoStr,
+            'sourcePhotoType' => 2,
+            'version' => '1.0.0',
+            'sign' => $sign,
+            'nonce' => $sign_data['nonce']
+        ];
+
+        $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
+        if (!$rs) {
+            $this->error('您的网络开小差啦5~');
+        }
+        $rs = json_decode($rs, true);
+        if (!$rs || $rs['code'] != 0) {
+            $this->error('您的网络开小差啦6~');
+        }
+
+        $user_auth = [
+            'user_id' => $this->auth->id,
+            'certify_id' => $rs['result']['faceId'],
+            'out_trade_no' => $data['orderNo'],
+            'status' => 0,
+            'createtime' => time(),
+            'updatetime' => time()
+        ];
+
+        //开启事务
+        Db::startTrans();
+        //查询是否认证过
+        $info = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
+        if ($info) {
+            $auth_rs = Db::name('user_auth')->where(['id' => $info['id']])->setField($user_auth);
+        } else {
+            $auth_rs = Db::name('user_auth')->insertGetId($user_auth);
+        }
+        if (!$auth_rs) {
+            Db::rollback();
+            $this->error('您的网络开小差啦7~');
+        }
+        //修改用户表认证状态
+        $user_rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', 0);
+        if ($user_rs === false) {
+            Db::rollback();
+            $this->error('您的网络开小差啦8~');
+        }
+
+        Db::commit();
+
+        $return_data = [
+            'face_id' => $user_auth['certify_id'],
+            'order_no' => $user_auth['out_trade_no'],
+            'user_id' => (string)$this->auth->id,
+            'nonce' => $sign_data['nonce'],
+            'sign' => $sign
+        ];
+        $this->success('success', $return_data);
+    }
+
+    //查询真人认证结果
+    public function getrealauthresult() {
+        $user_auth = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
+        if (!$user_auth) {
+            $this->success('尚未认证');
+        }
+        if ($user_auth['status'] == 1) {
+            $this->success('真人认证通过');
+        }
+        if (!$user_auth['certify_id']) {
+            $this->success('请先进行真人认证');
+        }
+
+        //获取token
+        $token_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id='.config('tencent_yun')['secret_id'].'&secret='.config('tencent_yun')['secret_key'].'&grant_type=client_credential&version=1.0.0';
+        $token_result = file_get_contents($token_url);
+        if (!$token_result) {
+            $this->error('您的网络开小差啦1~');
+        }
+        $token_result = json_decode($token_result, true);
+        if ($token_result['code'] != 0) {
+            $this->error('您的网络开小差啦2~');
+        }
+        $token = $token_result['access_token'];
+
+        //获取签名鉴权参数ticket
+        $ticket_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id='.config('tencent_yun')['secret_id'].'&access_token='.$token.'&type=SIGN&version=1.0.0';
+        $ticket_result = file_get_contents($ticket_url);
+        if (!$ticket_result) {
+            $this->error('您的网络开小差啦3~');
+        }
+        $ticket_result = json_decode($ticket_result, true);
+        if ($ticket_result['code'] != 0) {
+            $this->error('您的网络开小差啦4~');
+        }
+        $ticket = $ticket_result['tickets'][0]['value'];
+
+        //获取签名
+        $sign_data = [
+            'wbappid' => config('tencent_yun')['secret_id'],
+            'orderNo'  => $user_auth['out_trade_no'],
+            'version' => '1.0.0',
+            'ticket'  => $ticket,
+            'nonce'   => Random::alnum(32)
+        ];//p($sign_data);
+        asort($sign_data); //p($sign_data);//排序
+        $sign_string = join('', $sign_data);//p($sign_string);
+        $sign = sha1($sign_string);//p($sign);
+
+        //人脸核身结果查询
+        $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/v2/base/queryfacerecord?orderNo=' . $user_auth['out_trade_no'];
+        $data = [
+            'appId' => config('tencent_yun')['secret_id'],
+            'version' => '1.0.0',
+            'nonce' => $sign_data['nonce'],
+            'orderNo' => $user_auth['out_trade_no'],
+            'sign' => $sign
+        ];
+
+        $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
+        if (!$rs) {
+            $this->error('您的网络开小差啦5~');
+        }
+        $rs = json_decode($rs, true);
+        if (!$rs || $rs['code'] != 0) {
+            $this->error($rs['msg']);
+        }
+        if ($rs['result']['liveRate'] >= 90 && $rs['result']['similarity'] >= 90) {
+            $edit_data['status'] = 1;
+            $msg = '真人认证成功';
+        } else {
+            $edit_data['status'] = 2;
+            $edit_data['certify_id'] = '';
+            $edit_data['out_trade_no'] = '';
+            $msg = '真人认证失败';
+        }
+
+        $edit_data['updatetime'] = time();
+        //开启事务
+        Db::startTrans();
+        //修改认证信息
+        $result = Db::name('user_auth')->where(['user_id' => $this->auth->id, 'status' => $user_auth['status']])->setField($edit_data);
+        if (!$result) {
+            Db::rollback();
+            $this->error('查询认证结果失败2');
+        }
+        //修改用户信息
+        $rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', $edit_data['status']);
+        if (!$rs) {
+            Db::rollback();
+            $this->error('查询认证结果失败3');
+        }
+        if ($edit_data['status'] == 1) { //通过
+            //tag任务赠送金币
+            //真人认证奖励
+            $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,20);
+            if($task_rs === false){
+                Db::rollback();
+                $this->error('完成任务赠送奖励失败');
+            }
+            //系统消息
+            $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证已经审核通过');
+        } else {
+            //系统消息
+            $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证审核不通过');
+        }
+
+        Db::commit();
+        $this->success($msg);
+    }
+
+
+}

+ 1 - 0
application/extra/site.php

@@ -59,4 +59,5 @@ return array (
   'introsite_introrule' => '1、所有用户可以参加邀请好友活动。
 2、通过自己分享的活动页面地址下载注册成功,即发放注册奖励,邀请新用户达100人,奖励额外增加20%。',
   'kefu_user_ids' => '1,2,3',
+  'user_auth_switch' => '1',
 );