php常用类


 time(),
        'exp' => time() + 60,
    ];

    $array = array_merge($prop, $content);
    $data = JWT::encode($array, $key);

    return $data;
}

//得到jwt里面id的方法
function getJWT($data)
{
    $key = secretKey();
    $decoded = JWT::decode($data, $key, array('HS256'));

    return $decoded;
}

function getInput()
{
    return json_decode(trim(file_get_contents('php://input')), true);
}

function filtInput($str)
{
    return trim(htmlspecialchars($str));
}

function getCaptcha()
{
    // error_reporting(E_ALL);
    putenv('GDFONTPATH='.realpath('.'));
    $font = './application/helpers/Arial-Black.ttf';
    $string = 'abcdefghijkLmnpqrstuvwxyz123456789';
    $str = '';
    for ($i = 0; $i < 4; ++$i) {
        $pos = rand(0, 33);
        $str .= $string[$pos];
    }
    if (!session_id()) {
        session_start();
    }
    $_SESSION['captcha'] = strtolower($str);
    $img_handle = imagecreate(90, 28);
    $back_color = imagecolorallocate($img_handle, 45, 140, 240);
    $txt_color = imagecolorallocate($img_handle, 255, 255, 255);
    // 加入干扰线
    for ($i = 0; $i < 3; ++$i) {
        $line = imagecolorallocate($img_handle, rand(200, 255), rand(200, 255), rand(200, 255));
        imageline($img_handle, 0, rand(0, 28), 130, rand(0, 28), $line);
    }
    // 加入干扰象素
    for ($i = 0; $i < 400; ++$i) {
        $randcolor = imagecolorallocate($img_handle, 29, 55, 110);
        imagesetpixel($img_handle, rand() % 130, rand() % 30, $randcolor);
    }
    imagefill($img_handle, 0, 0, $back_color);
    imagettftext($img_handle, 20, 0, 4, 21, $txt_color, $font, $str);
    ob_clean();
    header('Content-Type: image/png;');
    imagepng($img_handle);
    imagedestroy($img_handle);
}

function initMedoo($dbname)
{
    return new Medoo([
        // required
        'database_type' => 'mysql',
        'database_name' => $dbname,
        'server' => 'localhost',
        'username' => 'root',
        'password' => 'root',
        // 'port' => 3306,
    ]);
}

你可能感兴趣的:(php常用类)