Explorar o código

家族创建调整

zhangxiaobin hai 1 ano
pai
achega
96fca4e595

+ 11 - 9
application/api/controller/Guild.php

@@ -141,22 +141,24 @@ class Guild extends Api
         $guild_image = $this->request->request("guild_image"); //公会简介
         $guild_desc = $this->request->request("guild_desc"); //公会简介
         $guild_notice = $this->request->request("guild_notice"); //公会公告
-        if(!$guild_id) $this->error("参数错误!");
-        if(!$guild_name && !$guild_image && !$guild_desc && !$guild_notice) $this->error("请输入要修改的内容!");
-        $user_id = $this->auth->id;
-
-        // 获取公会信息
-        $guildInfo = \app\common\model\Guild::where(["id"=>$guild_id])->find();
-        // 验证更新条件
-        if($user_id !== $guildInfo->user_id) $this->error("身份验证失败!您不是公会长,无权限更改!");
 
+        if(!$guild_name && !$guild_image && !$guild_desc && !$guild_notice) $this->error("请输入要修改的内容!");
+        if (empty($guild_id)) {
+            $guildInfo = new \app\common\model\Guild();
+        } else {
+            $user_id = $this->auth->id;
+            // 获取公会信息
+            $guildInfo = \app\common\model\Guild::where(["id"=>$guild_id])->find();
+            // 验证更新条件
+            if($user_id !== $guildInfo->user_id) $this->error("身份验证失败!您不是公会长,无权限更改!");
+        }
         $guild_name && $guildInfo->name = $guild_name;
         $guild_image && $guildInfo->image = $guild_image;
         $guild_desc && $guildInfo->desc = $guild_desc;
         $guild_notice && $guildInfo->notice = $guild_notice;
         $res = $guildInfo->save();
         if($res !== false) {
-            $this->success("更新成功!");
+            $this->success("操作成功!");
         } else {
             $this->error("网络错误,请稍后重试!");
         }

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

@@ -5,6 +5,7 @@ namespace app\api\controller;
 use app\common\controller\Api;
 use app\common\library\Ems;
 use app\common\library\Sms;
+use app\common\service\UserService;
 use fast\Random;
 use think\Validate;
 use miniprogram\wxBizDataCrypt;
@@ -910,4 +911,190 @@ class User extends Api
 //        $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;
         return $httpStr.'/' . $imgurl;
     }
+
+    //申请真人认证
+    public function realauth()
+    {
+        try {
+            $realName = $this->request->param('real_name',0);
+            $idCard   = $this->request->param('id_card',0);
+            if ($this->auth->is_auth == 2) {
+                $this->error('您已经真人认证过了~');
+            }
+            if (empty($realName)) {
+                throw new Exception('请输入姓名');
+            }
+            if (empty($idCard)) {
+                throw new Exception('请输入身份证号');
+            }
+            $userService = new UserService();
+            $faceParams = [
+                'real_name' => $realName,
+                'id_card' => $idCard,
+            ];
+            $res = $userService->faceAuth($faceParams);
+            if (!$res['status']) {
+                $this->error('您的网络开小差啦5~');
+            }
+            $rs = json_decode($res['data'], true);
+            if (!$rs || $rs['code'] != 0) {
+                $this->error('您的网络开小差啦6~');
+            }
+
+            $user_auth = [
+                'user_id' => $this->auth->id,
+                'realname' => $realName,
+                'idcard' => $idCard,
+                '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);
+        } catch (Exception $e) {
+            $this->error($e->getMessage());
+        }
+    }
+
+    //查询真人认证结果
+    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);
+    }
 }

+ 11 - 0
application/common.php

@@ -605,3 +605,14 @@ if(!function_exists('mk_dir')) {
         }
     }
 }
+
+if (!function_exists('getMillisecond')) {
+    /**
+     * [getMillisecond 获取毫秒级时间戳]
+     * @return [type] [description]
+     */
+    function getMillisecond() {
+        list($t1, $t2) = explode(' ', microtime());
+        return (float)sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000);
+    }
+}

+ 86 - 0
application/common/service/UserService.php

@@ -0,0 +1,86 @@
+<?php
+
+namespace app\common\service;
+
+use fast\Random;
+use think\Exception;
+
+class UserService
+{
+
+    /**
+     * 获取请求参数
+     * @return void
+     */
+    public function faceAuth($params=[])
+    {
+        $result = [
+            'status' => 1,
+            'msg' => '获取成功',
+            'data' => [],
+        ];
+        try {
+            $idCard = isset($params['id_card']) ? $params['id_card'] : '';
+            $realName = isset($params['real_name']) ? $params['real_name'] : '';
+            $tencentConfig = config('tencent_im');
+            $sercrtId = isset($tencentConfig['secret_id']) ? $tencentConfig['secret_id'] : '';
+            $sercrtKey = isset($tencentConfig['secret_key']) ? $tencentConfig['secret_key'] : '';
+            //获取token
+            $token_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id='.$sercrtId.'&secret='.$sercrtKey.'&grant_type=client_credential&version=1.0.0';
+            $token_result = file_get_contents($token_url);
+            if (!$token_result) {
+                throw new Exception('您的网络开小差啦1~');
+            }
+            $token_result = json_decode($token_result, true);
+            if ($token_result['code'] != 0) {
+                throw new Exception('您的网络开小差啦2~');
+            }
+            $token = $token_result['access_token'];
+
+            //获取签名鉴权参数ticket
+            $ticket_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id='.$sercrtId.'&access_token='.$token.'&type=SIGN&version=1.0.0';
+            $ticket_result = file_get_contents($ticket_url);
+            if (!$ticket_result) {
+                throw new Exception('您的网络开小差啦3~');
+            }
+            $ticket_result = json_decode($ticket_result, true);
+            if ($ticket_result['code'] != 0) {
+                throw new Exception('您的网络开小差啦4~');
+            }
+            $ticket = $ticket_result['tickets'][0]['value'];
+
+            //获取签名
+            $sign_data = [
+                'wbappid' => $sercrtId,
+                'userId'  => (string)$this->auth->id,
+                'version' => '1.0.0',
+                'ticket'  => $ticket,
+                'nonce'   => Random::alnum(32)
+            ];
+            asort($sign_data);//排序
+            $sign_string = join('', $sign_data);
+            $sign = sha1($sign_string);
+
+            //上传身份信息
+            $orderNo = getMillisecond() . $this->auth->id . mt_rand(1, 1000); //商户请求的唯一标识
+            $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/server/getAdvFaceId?orderNo='.$orderNo;
+            $data = [
+                'webankAppId' => $sercrtId,
+                'orderNo' => $orderNo,
+                'userId' => (string)$this->auth->id,
+                'name' => $realName,//姓名
+                'idNo' => $idCard,//证件号
+                'version' => '1.0.0',
+                'sign' => $sign,
+                'nonce' => $sign_data['nonce']
+            ];
+            $res = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
+            echo '<pre>';var_dump($res);exit;
+            $result['data'] = $res;
+        } catch (Exception $e) {
+            $result['status'] = 0;
+            $result['msg'] = $e->getMessage();
+        }
+        return $result;
+    }
+}