<?php

namespace app\api\controller;

use app\api\model\BrowserVerify;
use app\api\model\User;

class Verify
{
    /**
     * @description: 验证浏览器指纹 判断是否允许访问
     * @param {*}
     * @return {*}
     */
    public function index()
    {
        $browser_code = json_decode(file_get_contents("php://input"), true)['code'];
        $verify = new BrowserVerify;
        if ($verify->getOne(['code' => $browser_code])) {
            result([], '', 30000);
        } else {
            result([], 'false', 30000);
        }
    }

    //验证用户是否实名
    public function userverify() {
        $post = $_POST;

        if (empty($post)) {
            $post = json_decode(file_get_contents("php://input"), true);
        }

        $username = $post['phone'];

        if (empty($username)) {
            $return_data = [
                'code' => -1,
                'msg' => '身份证号或手机号不能为空',
            ];
            echo json_encode($return_data);
            die;
        }

        $user_model = new User;

        $userinfo = $user_model->getOne(['LoginCode'=>$username], 'is_verify');

        if ($userinfo['is_verify']) {
            $return_data = [
                'code' => 1,
                'msg' => '实名认证成功',
            ];
            echo json_encode($return_data);
            die;
        } else {
            $return_data = [
                'code' => -1,
                'msg' => '实名认证失败',
            ];
            echo json_encode($return_data);
            die;
        }

    }

    public function openlimit() { 

        $data = $_POST;
        if (empty($data)) {
            $data = json_decode(file_get_contents("php://input"), true);
        }

        if (empty($data)) {
            $data = $_GET;
        }
        $url = "http://124.236.113.166:18702/api/agent/openIM/apikey/80cf4f64e990b78a9fc5eb/account/".$data['account'];
        linkcurl($url,'GET',[],[],0);
        echo  json_encode(['code'=>1,]);
    }
}
