xy_jx / utils
utils🛠一个工具箱
0.8.9
2024-03-21 02:57 UTC
Requires
- php: >=7.3.0
- ext-openssl: *
- dev-master
- 0.8.9
- 0.8.8
- 0.8.7
- 0.8.6
- 0.8.5
- 0.8.4
- 0.8.3
- 0.8.2
- 0.8.1
- 0.8.0
- 0.7.2
- 0.7.1
- 0.7.0
- 0.6.8
- 0.6.7
- 0.6.6
- 0.6.5
- 0.6.4
- 0.6.3
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.7
- 0.5.6
- 0.5.5
- 0.5.4
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5
- 0.4.1
- 0.4.0
- 0.3.28
- 0.3.27
- 0.3.26
- 0.3.25
- 0.3.24
- 0.3.23
- 0.3.22
- 0.3.21
- 0.3.20
- 0.3.19
- 0.3.18
- 0.3.17
- 0.3.16
- 0.3.15
- 0.3.14
- 0.3.13
- 0.3.12
- 0.3.11
- 0.3.10
- 0.3.9
- 0.3.8
- 0.3.7
- 0.3.6
- 0.3.5
- 0.3.4
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.10
- 0.2.9
- 0.2.8
- 0.2.7
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.17
- 0.1.16
- 0.1.15
- 0.1.14
- 0.1.13
- 0.1.12
- 0.1.11
- 0.1.10
- 0.1.9
- 0.1.8
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1
This package is auto-updated.
Last update: 2024-12-21 04:30:35 UTC
README
1.生成二维码 2.xml与数组转换 3.生成范围经纬度 4.经纬度换算距离 5.人民币转大写 6.MurmurHash 7.GoogleAuth 8.对称加密和证书加密 9.访问限制 10.生成证书 11.验证码 12.Excel导出 13.jwt
第一步:composer安装
composer require xy_jx/utils
第二步使用:
获取随机字符串
echo rand_string();//KPV1
获取UUID
echo UUID();//0b90f8b2-dca8-4ee8-86a1-f2a990605912
数字人民币转汉字大写
echo rmb_capital(159622);//壹拾伍万玖仟陆佰贰拾贰圆
验证码
use xy_jx\Utils\Captcha;
class xy
{
// 初始化验证码类
$Captcha = new Captcha();
// 生成验证码和key (密钥没有存储到session或Cookie)可自己存储 防止用户重复使用
$cap = $Captcha->create();
//echo $cap['img'];//data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAAA+CAMAAABZTaSoAAAAclBMVEXOvPAKZhygpcukoLrfprXhuaOenLe+n8ianayatMa...
// 验证是否正确
var_dump($Captcha->check($cap['code'], $cap['key']));// true
}
jwt
use xy_jx\Utils\Jwt;
class xy
{
//设置额外的密钥
Jwt::set('iv', '@user@token@jwt*');
Jwt::set('key', '@user@token@jwt*');//默认key 0.8+
$user = [
'id' => 5,
'tel' => '188888888888',
'name' => 'xy',
'email' => 'xy@email.com',
'sex' => 2,
'login_num' => 12,
];
//获取token
$token = Jwt::getToken($user);
//通过token获取用户数据
$user = Jwt::getUser($token['token']);
var_dump($user);
}
加解密数据
use xy_jx\Utils\Encryption;
class xy
{
$data = [
'id' => 5,
'tel' => '188888888888',
'name' => 'xy',
'email' => 'xy@email.com',
'sex' => 2,
'login_num' => 12,
];
//加密数据
$encrypt = Encryption::Encrypt($data);
//解密数据
var_dump(Encryption::Decrypt($encrypt));
}
谷歌验证码GoogleAuthenticator
use xy_jx\Utils\GoogleAuthenticator;
class xy
{
//创建一个密钥
$secret = GoogleAuthenticator::createSecret();//WQI5IOGD6WSRHDIFNFHYJCHANUJZDMAG
//通过密钥获取一个验证码
$code = GoogleAuthenticator::getCode($secret);//273079
//通过密钥验证code
var_dump(GoogleAuthenticator::verifyCode($secret, $code));// true
//获取第3方绑定二维码(从google图表中获取图像的QR码URL)
echo GoogleAuthenticator::getQRCodeGoogleUrl(
$name = 'xy',
$secret,
$title = '绑定密钥'
);//https://api.qrserver.com/v1/create-qr-code/?data=otpauth%3A%2F%2Ftotp%2Fxy%3Fsecret%3DG3HVLCM5OCO6GTLCVNTD35UFIO4L6GB3%26issuer%3D%25E7%25BB%2591%25E5%25AE%259A%25E5%25AF%2586%25E9%2592%25A5&size=200x200&ecc=M
}
Excel导出
额外安装phpspreadsheet
composer require phpoffice/phpspreadsheet
use xy_jx\Utils\Excel;
class xy
{
$userAll = [
[
'id' => 1,
'name' => '张三',
'cd' => date('Y-m-d'),
],
[
'id' => 2,
'name' => '李四',
'cd' => date('Y-m-d'),
],
[
'id' => 3,
'name' => '王五',
'cd' => date('Y-m-d'),
],
];
Excel::header('用户导出', ['id' => 'ID', 'name' => '名字', 'cd' => '时间'])
->content($userAll)->save('Xlsx', true, '用户.Xlsx');
}