PHP code example of xy_jx / utils
1. Go to this page and download the library: Download xy_jx/utils library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
xy_jx / utils example snippets
echo rand_string();//KPV1
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
}
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' => '[email protected] ',
'sex' => 2,
'login_num' => 12,
];
//获取token
$token = Jwt::getToken($user);
//通过token获取用户数据
$user = Jwt::getUser($token['token']);
var_dump($user);
}
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
}