AVRIL_START_JANCOKALIVEAVRIL_END_JANCOK
| Server IP : dzynews.com / Your IP : 216.73.217.105 Web Server : nginx/1.30.3 System : Linux cloud-tdkldl-avd6 5.15.0-91-generic #101-Ubuntu SMP Tue Nov 14 13:30:08 UTC 2023 x86_64 User : www ( 1000) PHP Version : 8.2.31 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/dzynews.com/wp-content/themes/archive-document/Modules/Common/ |
Upload File : |
<?php
namespace B2\Modules\Common;
use \Firebase\JWT\JWT;
use Gregwar\Captcha\CaptchaBuilder;
class Recaptcha
{
public static function code_letter($num, $width, $height){
// 1. 创建验证码实例
$builder = new CaptchaBuilder;
$builder->build(186, 50);
// 2. 获取验证码文本
$captchaPhrase = $builder->getPhrase();
// 3. 获取Base64编码的图片
$captchaImageBase64 = $builder->inline();
// 4. 如果需要纯Base64数据(不带data:image/jpeg;base64,前缀)
$pureBase64 = explode(',', $captchaImageBase64)[1];
//加密验证码
$issuedAt = time();
$expire = $issuedAt + 180;
$token = array(
"iss" => B2_HOME_URI,
"iat" => $issuedAt,
"nbf" => $issuedAt,
'exp' => $expire,
'data' => array(
'value' => md5(md5(AUTH_KEY . strtolower($captchaPhrase)))
)
);
try {
$jwt = JWT::encode($token, AUTH_KEY);
} catch (\Throwable $th) {
wp_die(__('请正确安装jwt插件', 'b2'));
}
return [
'token' => $jwt,
'base' => 'data:image/png;base64,' . $pureBase64
];
}
// public static function code_letter($num, $width, $height)
// {
// //字体路径
// $font_address = B2_THEME_DIR . DIRECTORY_SEPARATOR . 'Assets' . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . rand(1, 8) . '.ttf';//字体文件地址
// //生成背景
// $image = imagecreatetruecolor($width, $height);
// imagefill($image, 0, 0, imagecolorallocate($image, rand(200, 255), rand(200, 255), rand(200, 255)));//区域填充
// $value = '';
// $data = "ABCDEFGHJKMNPQRSTUVWXYZ1234567890";
// for ($i = 0; $i < $num; $i++) {
// $fontsize = $width > 300 ? 80 : 40;
// $fontcolor = imagecolorallocate($image, 132, 132, 132);//0,120是代表随机的深色颜色
// $fontcontent = substr($data, rand(0, strlen($data) - 1), 1);
// $value .= $fontcontent;
// $x = $i * $width / $num + ($width > 300 ? 20 : 10);//x坐标
// $y = ($height / 2) + ($fontsize / 2);
// $anger = 0;
// ImageTTFText($image, $fontsize, $anger, (int)$x, (int)$y, $fontcolor, $font_address, $fontcontent);
// }
// //转换成 base64
// ob_start();
// imagejpeg($image);
// $image_data = ob_get_contents();
// ob_end_clean();
// ob_end_flush();
// $image_data_base64 = base64_encode($image_data);
// //加密验证码
// $issuedAt = time();
// $expire = $issuedAt + 180;
// $token = array(
// "iss" => B2_HOME_URI,
// "iat" => $issuedAt,
// "nbf" => $issuedAt,
// 'exp' => $expire,
// 'data' => array(
// 'value' => md5(md5(AUTH_KEY . strtolower($value)))
// )
// );
// try {
// $jwt = JWT::encode($token, AUTH_KEY);
// } catch (\Throwable $th) {
// wp_die(__('请正确安装jwt插件', 'b2'));
// }
// return array(
// 'token' => $jwt,
// 'base' => 'data:image/png;base64,' . $image_data_base64
// );
// }
}