<?php
/**
* @author Abin
*/
defined('BASEPATH') or exit('No direct script access allowed');
require './application/libraries/Medoo.php';
use Firebase\JWT\JWT;
use Medoo\Medoo;
function jsonExit($status = '', $desc = '', $content = null, $more = null)
{
$data['status'] = $status;
$data['desc'] = $desc;
if (isset($content) && $content !== null && $content !== 'undefined') {
$data['content'] = $content;
}
if (isset($more) && $more !== null && $more !== 'undefined') {
$data += $more;
}
echo json_encode($data);
exit;
}
function secretKey()
{
return 'v2ILfnbsxgULEWBdAACa';
}
function setJWT($content)
{
$key = secretKey();
$prop = [
'iat' => 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常用类
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...