From b12ea7f2ed4755719592ba68244229af4982c548 Mon Sep 17 00:00:00 2001 From: lzx_win <2602107437@qq.com> Date: Thu, 20 Feb 2025 15:23:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin-pc/.env.development | 2 +- admin-pc/.env.production | 2 +- .../api/service/impl/AppletIndexServiceImpl.java | 114 ++++++++++++++++++++- .../src/main/resources/application-dev.yml | 2 +- 4 files changed, 114 insertions(+), 6 deletions(-) diff --git a/admin-pc/.env.development b/admin-pc/.env.development index 0aa32f0..9d58881 100644 --- a/admin-pc/.env.development +++ b/admin-pc/.env.development @@ -1,5 +1,5 @@ NODE_ENV=development -VUE_APP_API_BASE_URL=https://jewelry-admin.hhlm1688.com/jewelry-admin/ +VUE_APP_API_BASE_URL=http://localhost:8001/jewelry-admin/ VUE_APP_CAS_BASE_URL=http://cas.example.org:8443/cas VUE_APP_ONLINE_BASE_URL=http://fileview.jeecg.com/onlinePreview diff --git a/admin-pc/.env.production b/admin-pc/.env.production index 9a476f5..2bdc95e 100644 --- a/admin-pc/.env.production +++ b/admin-pc/.env.production @@ -1,4 +1,4 @@ NODE_ENV=production -VUE_APP_API_BASE_URL=https://jewelry-admin.hhlm1688.com/jewelry-admin/ +VUE_APP_API_BASE_URL=http://localhost:8001/jewelry-admin/ VUE_APP_CAS_BASE_URL=http://localhost:8888/cas VUE_APP_ONLINE_BASE_URL=http://fileview.jeecg.com/onlinePreview \ No newline at end of file diff --git a/module-common/src/main/java/org/jeecg/api/service/impl/AppletIndexServiceImpl.java b/module-common/src/main/java/org/jeecg/api/service/impl/AppletIndexServiceImpl.java index 4135527..558d946 100644 --- a/module-common/src/main/java/org/jeecg/api/service/impl/AppletIndexServiceImpl.java +++ b/module-common/src/main/java/org/jeecg/api/service/impl/AppletIndexServiceImpl.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.TypeReference; import com.aliyun.oss.OSS; import com.aliyun.oss.OSSClientBuilder; +import com.aliyun.oss.model.PutObjectResult; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -74,13 +75,18 @@ import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.commons.CommonsMultipartFile; import javax.annotation.Resource; +import javax.imageio.ImageIO; import javax.transaction.Transactional; +import java.awt.*; +import java.awt.image.BufferedImage; import java.io.*; import java.math.BigDecimal; +import java.net.URL; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.temporal.ChronoUnit; import java.util.*; +import java.util.List; import java.util.stream.Collectors; @Slf4j @@ -1058,7 +1064,10 @@ public class AppletIndexServiceImpl implements AppletIndexService { .eq(CommonConfig::getKeyName, "codeImg") .one(); - + //获取二维码背景图 + CommonConfig qr_code = commonConfigService.lambdaQuery() + .eq(CommonConfig::getKeyName, "qr_code") + .one(); String codeImg = oneImage.getKeyContent(); @@ -1073,6 +1082,9 @@ public class AppletIndexServiceImpl implements AppletIndexService { line_color.put("g", 0); line_color.put("b", 0); param.put("line_color", line_color); + + + MultiValueMap headers = new LinkedMultiValueMap<>(); org.springframework.http.HttpEntity requestEntity = new org.springframework.http.HttpEntity(JSON.toJSONString(param), headers); ResponseEntity entity = rest.exchange(url, HttpMethod.POST, requestEntity, byte[].class, new Object[0]); @@ -1114,13 +1126,21 @@ public class AppletIndexServiceImpl implements AppletIndexService { MultipartFile mf = new CommonsMultipartFile(item); //返回图片下载地址 WxQrCodeVo wxCodeVo = new WxQrCodeVo(); - wxCodeVo.setUrl(this.uploadAliYunOss(mf)); - + this.uploadAliYunOss(mf); + CommonConfig image_go_url = commonConfigService.lambdaQuery() + .eq(CommonConfig::getKeyName, "image_go_url") + .one(); + String qrCodeImageUrl = image_go_url.getKeyContent()+this.uploadAliYunOss(mf); + String backgroundImageUrl = qr_code.getKeyContent(); + String outputFilePath = "combined_image.png"; + String s = this.generateAndCombineImagesFromUrl(qrCodeImageUrl, backgroundImageUrl, outputFilePath); + wxCodeVo.setUrl(s); wxCodeVo.setName("陌美人珠宝欢迎您"); + // redisUtil.set("CodeImage::"+trial+member.getId(),wxCodeVo); return Result.OK(wxCodeVo); @@ -1150,6 +1170,94 @@ public class AppletIndexServiceImpl implements AppletIndexService { return null; } + + + + public String generateAndCombineImagesFromUrl(String qrCodeImageUrl, String backgroundUrl, String outputFilePath) { + File file = null; + try { + // 从URL加载小程序码图像 + URL qrCodeUrl = new URL(qrCodeImageUrl); + BufferedImage qrCodeImage = ImageIO.read(qrCodeUrl); + + // 从URL加载背景图像 + URL backgroundImageUrl = new URL(backgroundUrl); + BufferedImage backgroundImage = ImageIO.read(backgroundImageUrl); + + // 创建一个新的BufferedImage来保存合并后的图像 + BufferedImage combinedImage = new BufferedImage(backgroundImage.getWidth(), backgroundImage.getHeight(), BufferedImage.TYPE_INT_ARGB); + Graphics2D g2d = combinedImage.createGraphics(); + + // 绘制背景图像 + g2d.drawImage(backgroundImage, 0, 0, null); + + // 计算小程序码放置的位置(这里以中心位置为例) + int qrCodeX = (backgroundImage.getWidth() - qrCodeImage.getWidth()) / 2; + int qrCodeY = (backgroundImage.getHeight() - qrCodeImage.getHeight()) / 2; +// +// int backgroundHeight = backgroundImage.getHeight(); +// int qrCodeHeight = qrCodeImage.getHeight(); +// int qrCodeY = (int) (backgroundHeight - qrCodeHeight / 2); + + // 绘制小程序码图像 + g2d.drawImage(qrCodeImage, qrCodeX, 1100, null); + + // 释放Graphics2D资源 + g2d.dispose(); + + // 将合并后的图像保存到文件(或根据需要执行其他操作) + file = new java.io.File(outputFilePath); + ImageIO.write(combinedImage, "png", file); + + String tempSave = outputFilePath; + String filePath = tempSave; + + file = new File(filePath); + if (!file.exists()) { + file.createNewFile(); + } + // 上传到阿里云 + DiskFileItemFactory factory = new DiskFileItemFactory(16, null); + FileItem item = factory.createItem("File", "text/plain", true, file.getName()); + int bytesRead = 0; + byte[] buffer = new byte[8192]; + try { + FileInputStream fis = new FileInputStream(file); + OutputStream os = item.getOutputStream(); + while ((bytesRead = fis.read(buffer, 0, 8192)) != -1) { + os.write(buffer, 0, bytesRead); + } + os.close(); + fis.close(); + } catch (IOException e) { + e.printStackTrace(); + } + MultipartFile mf = new CommonsMultipartFile(item); + String rul = this.uploadAliYunOss(mf); + + System.out.println("合并后的图像已保存到" + this.uploadAliYunOss(mf)); + + return rul; + + } catch (Exception e) { + e.printStackTrace(); + } finally { + //删除文件 + if (file.exists()) { + file.delete(); + } + } + return null; + } + + + + + + + + + @Override public Result getInfoIntroduce(String type) { return null; diff --git a/module-system/src/main/resources/application-dev.yml b/module-system/src/main/resources/application-dev.yml index 62c33b6..62fb3d3 100644 --- a/module-system/src/main/resources/application-dev.yml +++ b/module-system/src/main/resources/application-dev.yml @@ -196,7 +196,7 @@ jeecg : secretKey: qHI7C3PaXYZySr84HTToviC71AYlFq endpoint: oss-cn-shenzhen.aliyuncs.com bucketName: hanhaiimage - staticDomain: https://image.hhlm1688.com/ + staticDomain: https://image.hhlm1688.com # ElasticSearch 6设置 elasticsearch: cluster-name: jeecg-ES