|
|
@@ -17,16 +17,15 @@ namespace app\adminapi\logic\group_activity;
|
|
|
|
|
|
use think\facade\Db;
|
|
|
use app\common\logic\BaseLogic;
|
|
|
-use app\common\service\wechat\WeChatMnpService;
|
|
|
use app\common\model\group_activity\GroupActivity;
|
|
|
-
|
|
|
-
|
|
|
-use Endroid\QrCode\Color\Color;
|
|
|
-use Endroid\QrCode\Encoding\Encoding;
|
|
|
-use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelHigh;
|
|
|
use Endroid\QrCode\QrCode;
|
|
|
+use Endroid\QrCode\Logo\Logo;
|
|
|
+use Endroid\QrCode\Color\Color;
|
|
|
use Endroid\QrCode\Writer\PngWriter;
|
|
|
-
|
|
|
+use Endroid\QrCode\Encoding\Encoding;
|
|
|
+use Endroid\QrCode\Label\Font\NotoSans;
|
|
|
+use Endroid\QrCode\Label\LabelAlignment;
|
|
|
+use Endroid\QrCode\ErrorCorrectionLevel;
|
|
|
/**
|
|
|
* 拼团活动逻辑
|
|
|
* Class GroupActivityLogic
|
|
|
@@ -167,9 +166,16 @@ class GroupActivityLogic extends BaseLogic
|
|
|
* 获取活动二维码
|
|
|
* @return string|void
|
|
|
*/
|
|
|
- public static function getQRCode($params)
|
|
|
+ public static function getQRCode($params,$url)
|
|
|
{
|
|
|
try {
|
|
|
+ $savePath = './uploads/group_activity';
|
|
|
+ $file_name = $savePath.'/123456789'.$params['id'].'.png';
|
|
|
+
|
|
|
+ //判断二维码是否存在
|
|
|
+ if (file_exists($file_name)) {
|
|
|
+ return $url.'/'.$file_name;
|
|
|
+ }
|
|
|
|
|
|
// 要生成二维码的 H5 链接
|
|
|
$h5Url = 'https://weixiuadmin.kyjlkj.com?id=' . $params['id'];
|
|
|
@@ -180,41 +186,29 @@ class GroupActivityLogic extends BaseLogic
|
|
|
// 创建二维码实例
|
|
|
$qrCode = QrCode::create($h5Url)
|
|
|
->setEncoding(new Encoding('UTF-8'))
|
|
|
- ->setErrorCorrectionLevel(new ErrorCorrectionLevelHigh())
|
|
|
+ ->setErrorCorrectionLevel(ErrorCorrectionLevel::High)
|
|
|
->setSize(300)
|
|
|
->setMargin(10)
|
|
|
->setForegroundColor(new Color(0, 0, 0))
|
|
|
->setBackgroundColor(new Color(255, 255, 255));
|
|
|
-
|
|
|
+ // 添加文字标签
|
|
|
+ $label = \Endroid\QrCode\Label\Label::create('众盾闪修拼团活动')
|
|
|
+ ->setFont(new NotoSans(20))
|
|
|
+ ->setAlignment(LabelAlignment::Center);
|
|
|
+
|
|
|
+ // 添加 logo
|
|
|
+ $logoPath = './uploads/group_activity/logo.png';
|
|
|
+ $logo = Logo::create($logoPath)->setResizeToWidth(80);
|
|
|
// 生成二维码图像
|
|
|
- $result = $writer->write($qrCode);
|
|
|
+ $result = $writer->write($qrCode, $logo, $label);
|
|
|
|
|
|
// 定义保存二维码的文件路径
|
|
|
- $filename = '123456789'.$params['id'].'png';
|
|
|
- $savePath = __DIR__. '/uploads/group_activity/'.$filename;
|
|
|
-
|
|
|
- // 将二维码保存到本地文件
|
|
|
- $result->saveToFile($savePath);
|
|
|
- echo $savePath;;die;
|
|
|
-return $savePath;
|
|
|
- // 设置响应头,告知浏览器输出的是图片
|
|
|
- header('Content-Type: '. $result->getMimeType());
|
|
|
-
|
|
|
- // 输出二维码图片内容
|
|
|
- return $result->getString();
|
|
|
- $response = (new WeChatMnpService())->getUnlimitedQRCode(
|
|
|
- '&id='.$params['id'],
|
|
|
- "pages/group/activity",
|
|
|
- 'release',
|
|
|
- false
|
|
|
- );
|
|
|
- $qrcode = $response->getContent();
|
|
|
- if(!is_dir('./uploads/wx_qrcode/'.date('Ymd'))){
|
|
|
- mkdir('./uploads/wx_qrcode/'.date('Ymd'));
|
|
|
+ if(!is_dir($savePath)){
|
|
|
+ mkdir($savePath);
|
|
|
}
|
|
|
- $file_name = 'uploads/wx_qrcode/'.date('Ymd').'/'.time().rand(1000,9999).'.png';
|
|
|
- file_put_contents($file_name, $qrcode);
|
|
|
- return $file_name;
|
|
|
+ // 将二维码保存到本地文件
|
|
|
+ $result->saveToFile($file_name);
|
|
|
+ return $url.'/'.$file_name;
|
|
|
} catch (\Throwable $e) {
|
|
|
// 失败
|
|
|
echo $e->getMessage();
|