This commit is contained in:
mkm 2024-01-21 16:31:23 +08:00
parent 58c27d36cd
commit 222e8b19ba
2 changed files with 11 additions and 3 deletions

View File

@ -644,7 +644,7 @@ class Common extends BaseController
public function Qrcode($data) public function Qrcode($data)
{ {
$siteUrl = systemConfig('site_url'); $siteUrl = systemConfig('site_url');
$name = md5('orcode' . date('Ymd')) . '.jpg'; $name = md5('orcode' . date('Ymd')) . '.png';
$attachmentRepository = app()->make(AttachmentRepository::class); $attachmentRepository = app()->make(AttachmentRepository::class);
$imageInfo = $attachmentRepository->getWhere(['attachment_name' => $name]); $imageInfo = $attachmentRepository->getWhere(['attachment_name' => $name]);
@ -653,7 +653,12 @@ class Common extends BaseController
$imageInfo = null; $imageInfo = null;
} }
if (!$imageInfo) { if (!$imageInfo) {
$imageInfo = app()->make(QrcodeService::class)->getQRCodePath($data['code'], $name); $imageInfo = app()->make(QrcodeService::class)->getQRCodePath($data['code'], $name,['code'=>[
'r' => 255,
'g' => 221,
'b' => 167,
'a' => 0,
]]);
if (is_string($imageInfo)) throw new ValidateException('二维码生成失败'); if (is_string($imageInfo)) throw new ValidateException('二维码生成失败');
$imageInfo['dir'] = tidy_url($imageInfo['dir'], null, $siteUrl); $imageInfo['dir'] = tidy_url($imageInfo['dir'], null, $siteUrl);

View File

@ -29,7 +29,7 @@ class QrcodeService
* @param $name * @param $name
* @return array|bool|string * @return array|bool|string
*/ */
public function getQRCodePath($url, $name) public function getQRCodePath($url, $name,$data)
{ {
if (!strlen(trim($url)) || !strlen(trim($name))) return false; if (!strlen(trim($url)) || !strlen(trim($name))) return false;
try { try {
@ -42,6 +42,9 @@ class QrcodeService
$info = []; $info = [];
$outfile = Config::get('qrcode.cache_dir'); $outfile = Config::get('qrcode.cache_dir');
$code = new QrCode($url); $code = new QrCode($url);
if(isset($data['code'])){
$code->setForegroundColor($data['code']);
}
if ($uploadType === 1) { if ($uploadType === 1) {
if (!is_dir('./public/' . $outfile)) if (!is_dir('./public/' . $outfile))
mkdir('./public/' . $outfile, 0777, true); mkdir('./public/' . $outfile, 0777, true);