|
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
import com.aliyun.oss.OSS; |
|
|
import com.aliyun.oss.OSS; |
|
|
import com.aliyun.oss.OSSClientBuilder; |
|
|
import com.aliyun.oss.OSSClientBuilder; |
|
|
|
|
|
import com.aliyun.oss.model.PutObjectResult; |
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
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 org.springframework.web.multipart.commons.CommonsMultipartFile; |
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
|
|
|
import javax.imageio.ImageIO; |
|
|
import javax.transaction.Transactional; |
|
|
import javax.transaction.Transactional; |
|
|
|
|
|
import java.awt.*; |
|
|
|
|
|
import java.awt.image.BufferedImage; |
|
|
import java.io.*; |
|
|
import java.io.*; |
|
|
import java.math.BigDecimal; |
|
|
import java.math.BigDecimal; |
|
|
|
|
|
import java.net.URL; |
|
|
import java.time.LocalDateTime; |
|
|
import java.time.LocalDateTime; |
|
|
import java.time.ZoneId; |
|
|
import java.time.ZoneId; |
|
|
import java.time.temporal.ChronoUnit; |
|
|
import java.time.temporal.ChronoUnit; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
|
|
|
import java.util.List; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
@Slf4j |
|
|
@Slf4j |
|
@ -1058,7 +1064,10 @@ public class AppletIndexServiceImpl implements AppletIndexService { |
|
|
.eq(CommonConfig::getKeyName, "codeImg") |
|
|
.eq(CommonConfig::getKeyName, "codeImg") |
|
|
.one(); |
|
|
.one(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取二维码背景图 |
|
|
|
|
|
CommonConfig qr_code = commonConfigService.lambdaQuery() |
|
|
|
|
|
.eq(CommonConfig::getKeyName, "qr_code") |
|
|
|
|
|
.one(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String codeImg = oneImage.getKeyContent(); |
|
|
String codeImg = oneImage.getKeyContent(); |
|
@ -1073,6 +1082,9 @@ public class AppletIndexServiceImpl implements AppletIndexService { |
|
|
line_color.put("g", 0); |
|
|
line_color.put("g", 0); |
|
|
line_color.put("b", 0); |
|
|
line_color.put("b", 0); |
|
|
param.put("line_color", line_color); |
|
|
param.put("line_color", line_color); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); |
|
|
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); |
|
|
org.springframework.http.HttpEntity requestEntity = new org.springframework.http.HttpEntity(JSON.toJSONString(param), headers); |
|
|
org.springframework.http.HttpEntity requestEntity = new org.springframework.http.HttpEntity(JSON.toJSONString(param), headers); |
|
|
ResponseEntity<byte[]> entity = rest.exchange(url, HttpMethod.POST, requestEntity, byte[].class, new Object[0]); |
|
|
ResponseEntity<byte[]> 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); |
|
|
MultipartFile mf = new CommonsMultipartFile(item); |
|
|
//返回图片下载地址 |
|
|
//返回图片下载地址 |
|
|
WxQrCodeVo wxCodeVo = new WxQrCodeVo(); |
|
|
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("陌美人珠宝欢迎您"); |
|
|
wxCodeVo.setName("陌美人珠宝欢迎您"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// redisUtil.set("CodeImage::"+trial+member.getId(),wxCodeVo); |
|
|
// redisUtil.set("CodeImage::"+trial+member.getId(),wxCodeVo); |
|
|
return Result.OK(wxCodeVo); |
|
|
return Result.OK(wxCodeVo); |
|
|
|
|
|
|
|
@ -1150,6 +1170,94 @@ public class AppletIndexServiceImpl implements AppletIndexService { |
|
|
return null; |
|
|
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 |
|
|
@Override |
|
|
public Result<?> getInfoIntroduce(String type) { |
|
|
public Result<?> getInfoIntroduce(String type) { |
|
|
return null; |
|
|
return null; |
|
|