浏览代码

实名认证,绑定银行卡等,用户钱包,提现

lizhen_gitee 11 月之前
父节点
当前提交
2f41d51382

+ 173 - 0
application/api/controller/Takecash.php

@@ -0,0 +1,173 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 提现
+ */
+class Takecash extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = ['*'];
+
+    //提现
+    public function take_cash(){
+        $freemoney = input('freemoney',0);
+        $type = input('type',1);
+
+        if(!$freemoney){
+            $this->error('请填写金额');
+        }
+
+        if (!in_array($type,[1,2,3])) {
+            $this->error('未知的提现类型');
+        }
+
+        if(!$this->user_auth_limit()){
+            $this->error('请先完成实名认证');
+        }
+
+        //赋值money
+        /*if($rc_id){
+            $recharge_config = Db::name('take_cash_config')->where('id',$rc_id)->find();
+            $money = $recharge_config['money'] ?: 0;
+        }*/
+
+        //自由输入覆盖
+        if(!empty($freemoney)){
+            $rc_id = 0;
+            $money = floatval($freemoney);
+        }
+
+        //
+        if($money<=0)
+        {
+            $this->error('金额必须大于0');
+        }
+
+        $min = config('site.min_takecash_money');
+        $max = config('site.max_takecash_money');
+        if($money < $min){
+            $this->error('提现金额不能小于'.$min);
+        }
+        if($money > $max){
+            $this->error('提现金额不能大于'.$max);
+        }
+
+        $check = Db::name('user_take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
+        if($check){
+            $this->error('您已经申请了提现,请等待审核');
+        }
+
+        $user_money = model('wallet')->getwallet($this->auth->id,'money');
+        if($money > $user_money){
+            $this->error('提现金额不能大于可提现余额');
+        }
+
+        if($type == 1){
+            $table_name = 'user_alipay';
+            $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
+            if(empty($account_json)){
+                $this->error('未绑定对应的提现账号');
+            }
+        }elseif($type == 2){
+            $table_name = 'user_bank';
+            $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
+            if(empty($account_json)){
+                $this->error('未绑定对应的提现账号');
+            }
+        }elseif($type == 3){
+            //微信支付
+            $table_name = 'user_wechat';
+            $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
+            if(empty($account_json)){
+                $this->error('未绑定对应的提现账号');
+            }
+        }
+
+        //平台手续费
+        $plat_bilv = config('site.takecash_plat_bili');
+        $plat_money = bcdiv(bcmul($money,$plat_bilv,2),100,2);
+
+        //减去手续费,得实得金额
+        $get_money = bcsub($money,$plat_money,2);
+
+        $data = [
+            'user_id' => $this->auth->id,
+            'money' => $money,
+            'plat_bilv'  => $plat_bilv,
+            'plat_money' => $plat_money,
+            'get_money'  => $get_money,
+            'type' => $type,
+            'acount_json' => json_encode($account_json),
+            'createtime' => time(),
+            'updatetime' => time(),
+            'status' => 0,
+        ];
+        Db::startTrans();
+
+        $log_id = Db::name('user_take_cash')->insertGetId($data);
+        if(!$log_id){
+            Db::rollback();
+            $this->error('提现失败');
+        }
+
+        //扣除money
+        $rs_wallet = model('Wallet')->lockChangeAccountRemain($this->auth->id,'money',-$money,21,'提现(审核中)','user_take_cash',$log_id);
+        if($rs_wallet['status']===false)
+        {
+            Db::rollback();
+            $this->error($rs_wallet['msg']);
+        }
+
+        Db::commit();
+        $this->success('申请成功请等待审核');
+    }
+
+    //提现记录
+    public function take_cash_log(){
+        $list = Db::name('user_take_cash')->field('id,money,get_money,type,createtime,status')->where(['user_id'=>$this->auth->id])->autopage()->select();
+        foreach($list as $key => &$val){
+            $val['remark'] = '';
+
+            if($val['type'] == 1){
+                $val['remark'] = '支付宝提现';
+            }elseif($val['type'] == 2){
+                $val['remark'] = '银行卡提现';
+            }else{
+                $val['remark'] = '微信提现';
+            }
+        }
+
+        $this->success('success',$list);
+    }
+
+   //////////////////////////////////////////////
+
+    //提现配置
+    public function take_cash_config(){
+        $config = Db::name('take_cash_config')->order('weigh asc,id asc')->select();
+
+        $plat_bilv = config('site.takecash_plat_bili');
+        foreach($config as $key => &$val){
+            $val['get_money'] = bcdiv(bcmul($val['money'],(100-$plat_bilv),2),100,2);
+        }
+
+        $data = [
+            'config' => $config,
+            'wallet' => model('wallet')->getwallet($this->auth->id),
+            'min' => config('site.min_takecash_money'),
+            'max' => config('site.max_takecash_money'),
+            'plat_bilv' => $plat_bilv,
+            'user_bank' => Db::name('user_bank')->where('user_id',$this->auth->id)->find(),
+            'user_alipay' => Db::name('user_alipay')->where('user_id',$this->auth->id)->find(),
+            'remark' => config('site.take_cash_rule'),
+        ];
+
+        $this->success('success',$data);
+    }
+
+
+}

+ 0 - 4
application/api/controller/Upload.php

@@ -50,10 +50,6 @@ class Upload extends Api
 
         // 获取临时密钥,计算签名
         $tempKeys = $sts->getTempKeys($config);
-
-        $tempKeys['bucket'] = $cos_config['bucket'];
-        $tempKeys['endpoint'] = $cos_config['cdnurl'];
-
         $this->success("获取成功!",$tempKeys);
 
     }

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

@@ -0,0 +1,579 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+use think\Cache;
+
+use TencentCloud\Common\Credential;
+use TencentCloud\Common\Profile\ClientProfile;
+use TencentCloud\Common\Profile\HttpProfile;
+use TencentCloud\Common\Exception\TencentCloudSDKException;
+//use TencentCloud\Faceid\V20180301\FaceidClient;
+//use TencentCloud\Faceid\V20180301\Models\IdCardVerificationRequest;
+use TencentCloud\Iai\V20200303\IaiClient;
+use TencentCloud\Iai\V20200303\Models\CompareFaceRequest;
+use fast\Random;
+
+/**
+ * 实名认证,真人认证相关
+ */
+class Userauth extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = '*';
+
+
+
+
+    //实名认证信息
+    public function idcard_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(){
+        $realname = input('realname','');
+        $idcard   = input('idcard'  ,'');
+
+        if(empty($realname) || 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'] == 1){
+                Db::rollback();
+                $this->error('您已经完成实名认证');
+            }
+
+            if($check['status'] == 0){
+                Db::rollback();
+                $this->error('您已经提交实名认证,请等待审核');
+            }
+        }
+
+        $count = Db::name('user_idconfirm')->where(['idcard' => $idcard, 'user_id' => ['neq', $this->auth->id]])->count('id');
+        if ($count) {
+            $this->error('该身份证号已被他人使用');
+        }
+
+        //限制每日请求次数
+        $time = time();
+        $today_end = strtotime(date('Y-m-d 23:59:59', $time));
+        $cache_time = $today_end - $time; //缓存时间
+        $time_count = Cache::get('userauth' . $this->auth->id);
+        if (!$time_count) {
+            Cache::set('userauth' . $this->auth->id, 1, $cache_time);
+        } else {
+            Cache::set('userauth' . $this->auth->id, $time_count + 1, $cache_time);
+            if ($time_count > 5) {
+                $this->error('今日实名次数已到上限,明天再来吧');
+            }
+        }
+
+        //阿里云身份证二要素认证
+        $auth_restult = $this->userauth_aliyun_two($idcard, $realname);
+        if($auth_restult == false){
+            $this->error('身份证信息与姓名不符');
+        }
+
+        $data = [
+            'user_id' => $this->auth->id,
+            'realname' => $realname,
+            'idcard' => $idcard,
+            'status' => 1, //不需要人工刚审核了,直接过审
+            'createtime' => time(),
+            'updatetime' => time(),
+        ];
+
+        //更新
+        $update_rs = Db::name('user')->where('id',$this->auth->id)->update(['idcard_status'=>$data['status']]);
+        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('请先上传真人头像~');
+        }
+        $check = Db::name('user_audit')->where('user_id',$this->auth->id)->where('type','avatar')->where('status',0)->find();
+        if(!empty($check)){
+            $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 = 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,6);
+            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);
+    }
+
+
+
+    //真人认证后修改头像
+    public function editrealavatar() {
+        if ($this->auth->real_status != 1) {
+            $this->error('尚未通过真人认证');
+        }
+        $avatar = input('avatar', '', 'trim'); //头像地址
+        if ($avatar === '') {
+            $this->error('参数缺失');
+        }
+        $avatar = one_domain_image($avatar);
+        $now_avatar = one_domain_image($this->auth->avatar);
+        if ($avatar == $now_avatar) {
+            $this->error('头像未改变');
+        }
+        //腾讯云人脸识别
+        $auit_result = $this->face_tencent($now_avatar, $avatar); //1通过 0拒绝
+        if ($auit_result != 1) {
+            $this->success('提示', ['code' => 2]);
+        }
+
+        $data['avatar'] = $avatar;
+
+        $user_result = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
+        if (!$user_result) {
+            $this->error('修改失败');
+        }
+
+        $this->success('修改成功');
+    }
+
+    //真人认证后修改头像并取消真人认证
+    public function editrealavatarcancelauit() {
+        if ($this->auth->real_status != 1) {
+            $this->error('尚未通过真人认证');
+        }
+        $avatar = input('avatar', '', 'trim'); //头像地址
+        if ($avatar === '') {
+            $this->error('参数缺失');
+        }
+        $avatar = one_domain_image($avatar);
+        $now_avatar = one_domain_image($this->auth->avatar);
+        if ($avatar == $now_avatar) {
+            $this->error('头像未改变');
+        }
+
+        $data['avatar'] = $avatar;
+        $data['real_status'] = -1;
+
+        //开启事务
+        Db::startTrans();
+        $user_result = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
+        if (!$user_result) {
+            Db::rollback();
+            $this->error('修改失败');
+        }
+        $user_auth_result = Db::name('user_auth')->where(['user_id' => $this->auth->id])->delete();
+        if (!$user_auth_result) {
+            Db::rollback();
+            $this->error('修改失败');
+        }
+
+        Db::commit();
+        $this->success('修改成功');
+    }
+
+    //腾讯云人脸识别
+    public function face_tencent($urla = '', $urlb = '') {
+//        require_once 'vendor/autoload.php';
+        try {
+            // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
+            // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
+            $config = config('tencent_realauth');
+            $cred = new Credential($config['SecretId'], $config['SecretKey']);
+            // 实例化一个http选项,可选的,没有特殊需求可以跳过
+            $httpProfile = new HttpProfile();
+            $httpProfile->setEndpoint("iai.tencentcloudapi.com");
+
+            // 实例化一个client选项,可选的,没有特殊需求可以跳过
+            $clientProfile = new ClientProfile();
+            $clientProfile->setHttpProfile($httpProfile);
+            // 实例化要请求产品的client对象,clientProfile是可选的
+            $client = new IaiClient($cred, "ap-beijing", $clientProfile);
+
+            // 实例化一个请求对象,每个接口都会对应一个request对象
+            $req = new CompareFaceRequest();
+
+            $params = array(
+                "UrlA" => $urla,
+                "UrlB" => $urlb,
+                "FaceModelVersion" => "3.0"
+            );
+            $req->fromJsonString(json_encode($params));
+
+            // 返回的resp是一个CompareFaceResponse的实例,与请求对象对应
+            $resp = $client->CompareFace($req);
+
+            // 输出json格式的字符串回包
+//            print_r($resp->toJsonString());
+            $result = json_decode($resp->toJsonString(), true);
+            //3.0版本误识率千分之一对应分数为40分,误识率万分之一对应分数为50分,误识率十万分之一对应分数为60分。 一般超过50分则可认定为同一人。
+            if (isset($result['Score']) && $result['Score'] >= 60) {
+                return 1; //通过
+            } else {
+                return 0;
+            }
+        }
+        catch(TencentCloudSDKException $e) {
+//            echo $e;
+            return 0;
+        }
+    }
+
+
+////////////////////////////////////////////////////////////////////////////////////
+
+    //产品链接:https://market.aliyun.com/products/57000002/cmapi026109.html#sku=yuncode20109000025
+    //阿里云-数脉api
+    //姓名+身份证号
+    private function userauth_aliyun_two($cardNo = '',$realname = ''){
+        if(!$cardNo || !$realname){
+            return false;
+        }
+
+        $config = config('aliyun_auth_shumai_two');
+
+        $host = "https://eid.shumaidata.com";
+        $path = "/eid/check";
+        $method = "POST";
+        $appcode = $config['app_code'];
+        $headers = array();
+        array_push($headers, "Authorization:APPCODE " . $appcode);
+
+        $querys = "idcard=".$cardNo."&name=".urlencode($realname);
+        $bodys  = '';
+        $url = $host . $path . "?" . $querys;
+
+        $curl = curl_init();
+        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
+        curl_setopt($curl, CURLOPT_URL, $url);
+        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
+        curl_setopt($curl, CURLOPT_FAILONERROR, false);
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+        //设定返回信息中是否包含响应信息头,启用时会将头文件的信息作为数据流输出,true 表示输出信息头, false表示不输出信息头
+        //如果需要将字符串转成json,请将 CURLOPT_HEADER 设置成 false
+        curl_setopt($curl, CURLOPT_HEADER, false);
+        if (1 == strpos("$".$host, "https://"))
+        {
+            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+        }
+        $returnRes = curl_exec($curl);
+        //var_dump($returnRes);
+        curl_close($curl);
+        $result = json_decode($returnRes,true);
+        //dump($result);
+
+        if(is_array($result) && isset($result['code']) && $result['code'] == 0){
+            if(isset($result['result']) && isset($result['result']['res'])){
+                if($result['result']['res'] == 1){
+                    //实名过了
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+
+    //产品链接:https://market.aliyun.com/products/57000002/cmapi026100.html?spm=5176.730005.result.8.1dbc123e8ArY19&innerSource=search#sku=yuncode2010000006
+    //阿里云-数脉api
+    //姓名+手机号+身份证号
+    private function userauth_aliyun_three($cardNo = '',$realname = '',$mobile = ''){
+        if(!$cardNo || !$realname || !$mobile){
+            return false;
+        }
+
+        $config = config('aliyun_auth_shumai');
+
+        $host = "https://mobile3elements.shumaidata.com";
+        $path = "/mobile/verify_real_name";
+        $method = "POST";
+        $appcode = $config['app_code'];
+        $headers = array();
+        array_push($headers, "Authorization:APPCODE " . $appcode);
+        //根据API的要求,定义相对应的Content-Type
+        array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8");
+        $querys = "";
+        $bodys = "idcard=".$cardNo."&mobile=".$mobile."&name=".urlencode($realname);
+        $url = $host . $path;
+
+        $curl = curl_init();
+        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
+        curl_setopt($curl, CURLOPT_URL, $url);
+        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
+        curl_setopt($curl, CURLOPT_FAILONERROR, false);
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+        //设定返回信息中是否包含响应信息头,启用时会将头文件的信息作为数据流输出,true 表示输出信息头, false表示不输出信息头
+        //如果需要将字符串转成json,请将 CURLOPT_HEADER 设置成 false
+        curl_setopt($curl, CURLOPT_HEADER, false);
+        if (1 == strpos("$".$host, "https://"))
+        {
+            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+        }
+        curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
+        $returnRes = curl_exec($curl);
+        curl_close($curl);
+        $result = json_decode($returnRes,true);
+
+        if(is_array($result) && isset($result['code']) && $result['code'] == 0){
+            if(isset($result['result']) && isset($result['result']['res'])){
+                if($result['result']['res'] == 1){
+                    //实名过了
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+}

+ 206 - 0
application/api/controller/Userbank.php

@@ -0,0 +1,206 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+use app\common\library\Sms;
+
+/**
+ *
+ */
+class Userbank extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = ['*'];
+
+
+
+
+    /**
+     * 绑定银行卡
+     */
+    public function bindBank() {
+
+        $captcha = input('captcha');
+        if (!$captcha) {
+            $this->error(__('Invalid parameters'));
+        }
+        $result = Sms::check($this->auth->mobile, $captcha, 'changemobile');
+        if (!$result) {
+            $this->error(__('Captcha is incorrect'));
+        }
+
+        //
+        $bank_no = $this->request->request('bank_no');// 银行账号
+        $open_bank = $this->request->request('open_bank');// 开户行
+        if(!$bank_no || !$open_bank ) {
+            $this->error("请将信息填写完整");
+        }
+
+        $userId = $this->auth->id;
+
+        //检测实名认证
+        $userAuthWhere['user_id'] = $userId;
+        $userAuth = Db::name('user_idconfirm')->where($userAuthWhere)->find();
+        if (empty($userAuth)) {
+            $this->error('请先实名认证');
+        }
+        if ($userAuth['status'] != 1) {
+            $this->error('请先实名认证通过');
+        }
+        $realname = $userAuth['realname'];
+
+
+        // 查询是否有过绑定
+        $bankInfo = Db::name('user_bank')->where(["user_id"=>$userId])->find();
+        $data = [];
+        $data["realname"] = $realname;
+        $data["bank_no"] = $bank_no;
+        $data["open_bank"] = $open_bank;
+
+        if($bankInfo) {
+            $res = Db::name('user_bank')->where(["user_id"=>$userId])->update($data);
+        } else {
+            $data["user_id"] = $userId;
+            $res = Db::name('user_bank')->insertGetId($data);
+        }
+
+
+        $this->success("银行卡绑定成功!");
+
+    }
+
+    /**
+     * 获取绑定银行卡信息
+     */
+    public function getBankInfo() {
+        // 查询是否有过绑定
+        $bankInfo = Db::name('user_bank')->where(["user_id"=>$this->auth->id])->find();
+
+        $this->success("获取成功!",$bankInfo);
+    }
+
+    /**
+     * 绑定支付宝
+     */
+    public function bindAlipay() {
+
+        $captcha = input('captcha');
+        if (!$captcha) {
+            $this->error(__('Invalid parameters'));
+        }
+        $result = Sms::check($this->auth->mobile, $captcha, 'changemobile');
+        if (!$result) {
+            $this->error(__('Captcha is incorrect'));
+        }
+
+        //
+        $payNo = $this->request->request('pay_no');//支付宝账号
+        if(!$payNo) {
+            $this->error("请将信息填写完整");
+        }
+
+        $userId = $this->auth->id;
+
+        //检测实名认证
+        $userAuthWhere['user_id'] = $userId;
+        $userAuth = Db::name('user_idconfirm')->where($userAuthWhere)->find();
+        if (empty($userAuth)) {
+            $this->error('请先实名认证');
+        }
+        if ($userAuth['status'] != 1) {
+            $this->error('请先实名认证通过');
+        }
+
+
+        // 查询是否有过绑定
+        $bankInfo = Db::name('user_alipay')->where(["user_id"=>$userId])->find();
+        $data = [];
+        $data["realname"] = $userAuth['realname'];
+        $data["pay_no"] = $payNo;
+        if($bankInfo) {
+            $res = Db::name('user_alipay')->where(["user_id"=>$userId])->update($data);
+        } else {
+            $data["user_id"] = $userId;
+            $res = Db::name('user_alipay')->insertGetId($data);
+        }
+        if($res) {
+            $this->success("支付宝绑定成功!");
+        } else {
+            $this->error("网络异常,请稍后重试!");
+        }
+    }
+
+    /**
+     * 获取绑定银行卡信息
+     */
+    public function getAlipayInfo() {
+        // 查询是否有过绑定
+        $alipayInfo = Db::name('user_alipay')->where(["user_id"=>$this->auth->id])->find();
+        $this->success("获取成功!",$alipayInfo);
+    }
+
+
+    /**
+     * 绑定微信
+     */
+    public function bindWechat() {
+
+        $captcha = input('captcha');
+        if (!$captcha) {
+            $this->error(__('Invalid parameters'));
+        }
+        $result = Sms::check($this->auth->mobile, $captcha, 'changemobile');
+        if (!$result) {
+            $this->error(__('Captcha is incorrect'));
+        }
+
+        //
+        $payNo = $this->request->request('pay_no');//支付宝账号
+        if(!$payNo) {
+            $this->error("请将信息填写完整");
+        }
+
+        $userId = $this->auth->id;
+
+        //检测实名认证
+        $userAuthWhere['user_id'] = $userId;
+        $userAuth = Db::name('user_idconfirm')->where($userAuthWhere)->find();
+        if (empty($userAuth)) {
+            $this->error('请先实名认证');
+        }
+        if ($userAuth['status'] != 1) {
+            $this->error('请先实名认证通过');
+        }
+
+
+        // 查询是否有过绑定
+        $bankInfo = Db::name('user_wechat')->where(["user_id"=>$userId])->find();
+        $data = [];
+        $data["realname"] = $userAuth['realname'];
+        $data["pay_no"] = $payNo;
+        if($bankInfo) {
+            $res = Db::name('user_wechat')->where(["user_id"=>$userId])->update($data);
+        } else {
+            $data["user_id"] = $userId;
+            $res = Db::name('user_wechat')->insertGetId($data);
+        }
+        if($res) {
+            $this->success("绑定成功!");
+        } else {
+            $this->error("网络异常,请稍后重试!");
+        }
+    }
+
+    /**
+     * 获取绑定银行卡信息
+     */
+    public function getWechatInfo() {
+        // 查询是否有过绑定
+        $alipayInfo = Db::name('user_wechat')->where(["user_id"=>$this->auth->id])->find();
+        $this->success("获取成功!",$alipayInfo);
+    }
+
+
+}

+ 3 - 3
application/api/controller/Usermember.php

@@ -16,7 +16,7 @@ class Usermember extends Api
     //添加成员
     public function add_one(){
         $field = [
-            'truename',
+            'realname',
             'idcard',
             'relation',
             'mobile',
@@ -43,7 +43,7 @@ class Usermember extends Api
     //我的成员列表
     public function my_list(){
 
-        $list = Db::name('user_member')->field('id,truename,gender,birthday')->where('user_id',$this->auth->id)->order('id desc')->select();
+        $list = Db::name('user_member')->field('id,realname,gender,birthday')->where('user_id',$this->auth->id)->order('id desc')->select();
 
 
         if(!empty($list)){
@@ -76,7 +76,7 @@ class Usermember extends Api
         $id = input('id',0);
 
         $field = [
-            'truename',
+            'realname',
             'idcard',
             'relation',
             'mobile',

+ 57 - 0
application/api/controller/Userwallet.php

@@ -0,0 +1,57 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+//use app\common\model\wallet;
+/**
+ * 用户钱包
+ */
+class Userwallet extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = ['*'];
+
+    //我的钱包余额
+    public function my_wallet(){
+        $wallet = model('wallet')->getwallet($this->auth->id);
+        $this->success('success',$wallet);
+    }
+
+    //我的余额日志
+    public function my_money_log(){
+        $type = input('type',0);
+
+        $map = [
+           'user_id' => $this->auth->id,
+        ];
+
+        if($type == 1){
+            $map['change_value'] = ['gt',0];
+        }
+        if($type == 2){
+            $map['change_value'] = ['lt',0];
+        }
+
+        $list = Db::name('user_money_log')
+            ->field('id,log_type,before,change_value,remain,remark,createtime')
+            ->where($map)->order('id desc')->autopage()->select();
+        $list = $this->list_appen_logtext($list);
+
+        $this->success('success',$list);
+    }
+
+
+    //追加log_text
+    private function list_appen_logtext($list){
+        if(!empty($list)){
+            $conf = config('wallet.logtype');
+            foreach($list as $key => $val){
+                $list[$key]['log_text'] = isset($conf[$val['log_type']]) ? $conf[$val['log_type']] : '';
+            }
+        }
+        return $list;
+    }
+
+}