|
|
@ -11,8 +11,10 @@ import org.jeecg.common.system.util.AppletUserUtil; |
|
|
import org.jeecg.common.system.vo.AppletUser; |
|
|
import org.jeecg.common.system.vo.AppletUser; |
|
|
import org.jeecg.common.util.RedisUtil; |
|
|
import org.jeecg.common.util.RedisUtil; |
|
|
import org.jeecg.common.util.oss.OssBootUtil; |
|
|
import org.jeecg.common.util.oss.OssBootUtil; |
|
|
|
|
|
import org.jeecg.modules.applet.Final.LoginType; |
|
|
import org.jeecg.modules.applet.entity.StatisticsVo; |
|
|
import org.jeecg.modules.applet.entity.StatisticsVo; |
|
|
import org.jeecg.modules.applet.service.AppletApiWaterService; |
|
|
import org.jeecg.modules.applet.service.AppletApiWaterService; |
|
|
|
|
|
import org.jeecg.modules.applet.util.QRCodeUtil; |
|
|
import org.jeecg.modules.common.IdUtils; |
|
|
import org.jeecg.modules.common.IdUtils; |
|
|
import org.jeecg.modules.common.wxUtils.WxHttpUtils; |
|
|
import org.jeecg.modules.common.wxUtils.WxHttpUtils; |
|
|
import org.jeecg.modules.demo.appletConfig.service.IAppletConfigService; |
|
|
import org.jeecg.modules.demo.appletConfig.service.IAppletConfigService; |
|
|
@ -67,7 +69,7 @@ public class AppletApiWaterServiceImpl implements AppletApiWaterService { |
|
|
private final ExecutorService asyncExecutor = Executors.newFixedThreadPool(5); |
|
|
private final ExecutorService asyncExecutor = Executors.newFixedThreadPool(5); |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public byte[] getInviteCode(){ |
|
|
|
|
|
|
|
|
public byte[] getInviteCode(String type){ |
|
|
AppletUser user = AppletUserUtil.getCurrentAppletUser(); |
|
|
AppletUser user = AppletUserUtil.getCurrentAppletUser(); |
|
|
|
|
|
|
|
|
// 获取环境配置 |
|
|
// 获取环境配置 |
|
|
@ -84,21 +86,23 @@ public class AppletApiWaterServiceImpl implements AppletApiWaterService { |
|
|
// 获取必要的配置信息 |
|
|
// 获取必要的配置信息 |
|
|
String xcxSharePage = appletConfigService.getContentByCode("xcxSharePage"); |
|
|
String xcxSharePage = appletConfigService.getContentByCode("xcxSharePage"); |
|
|
String backgroundImageUrl = appletConfigService.getContentByCode("qr_code_bg"); |
|
|
String backgroundImageUrl = appletConfigService.getContentByCode("qr_code_bg"); |
|
|
|
|
|
|
|
|
|
|
|
String webUrl = appletConfigService.getContentByCode("webUrl"); |
|
|
|
|
|
int webUrlCode = (webUrl != null && LoginType.OFFICIAL.equals(type)) ? webUrl.hashCode() : 0; |
|
|
|
|
|
|
|
|
// 获取二维码位置配置参数 |
|
|
// 获取二维码位置配置参数 |
|
|
int qrCodeX = appletConfigService.getContentByCodeAsInt("qr_code_x"); |
|
|
int qrCodeX = appletConfigService.getContentByCodeAsInt("qr_code_x"); |
|
|
int qrCodeY = appletConfigService.getContentByCodeAsInt("qr_code_y"); |
|
|
int qrCodeY = appletConfigService.getContentByCodeAsInt("qr_code_y"); |
|
|
|
|
|
|
|
|
// 优化缓存策略:使用更精确的缓存key,包含所有影响因素(包括背景图片URL和二维码位置配置) |
|
|
// 优化缓存策略:使用更精确的缓存key,包含所有影响因素(包括背景图片URL和二维码位置配置) |
|
|
String cacheKey = String.format("inviteCode:final:%s:%s:%s:%s:%s:%s", |
|
|
|
|
|
user.getId(), trial, xcxSharePage.hashCode(), backgroundImageUrl.hashCode(), qrCodeX, qrCodeY); |
|
|
|
|
|
|
|
|
// String cacheKey = String.format("inviteCode:final:%s:%s:%s:%s:%s:%s", |
|
|
|
|
|
// user.getId(), trial, xcxSharePage.hashCode(), backgroundImageUrl.hashCode(), qrCodeX, qrCodeY); |
|
|
|
|
|
|
|
|
// 移除图片数据的Redis缓存,避免类型转换错误 |
|
|
// 移除图片数据的Redis缓存,避免类型转换错误 |
|
|
// 直接检查OSS中是否已存在最终图片 |
|
|
// 直接检查OSS中是否已存在最终图片 |
|
|
|
|
|
|
|
|
// 检查OSS中是否已存在最终图片 |
|
|
// 检查OSS中是否已存在最终图片 |
|
|
String finalPath = String.format("invite/final/%s_%s_%s_%s_%s_%s.jpg", |
|
|
|
|
|
user.getId(), trial, xcxSharePage.hashCode(), backgroundImageUrl.hashCode(), qrCodeX, qrCodeY); |
|
|
|
|
|
|
|
|
String finalPath = String.format("invite/final/%s_%s_%s_%s_%s_%s_%s_%s.jpg", |
|
|
|
|
|
user.getId(), trial, xcxSharePage.hashCode(), backgroundImageUrl.hashCode(), qrCodeX, qrCodeY, type, webUrlCode); |
|
|
try { |
|
|
try { |
|
|
InputStream ossFile = OssBootUtil.getOssFile(finalPath, null); |
|
|
InputStream ossFile = OssBootUtil.getOssFile(finalPath, null); |
|
|
if (ossFile != null) { |
|
|
if (ossFile != null) { |
|
|
@ -112,7 +116,7 @@ public class AppletApiWaterServiceImpl implements AppletApiWaterService { |
|
|
} |
|
|
} |
|
|
buffer.flush(); |
|
|
buffer.flush(); |
|
|
byte[] ossImageBytes = buffer.toByteArray(); |
|
|
byte[] ossImageBytes = buffer.toByteArray(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 直接返回OSS中的图片,不再缓存到Redis |
|
|
// 直接返回OSS中的图片,不再缓存到Redis |
|
|
log.info("从OSS返回邀请码图片,用户ID: {}", user.getId()); |
|
|
log.info("从OSS返回邀请码图片,用户ID: {}", user.getId()); |
|
|
return ossImageBytes; |
|
|
return ossImageBytes; |
|
|
@ -127,10 +131,18 @@ public class AppletApiWaterServiceImpl implements AppletApiWaterService { |
|
|
try { |
|
|
try { |
|
|
// 直接生成小程序码,移除Redis缓存避免类型转换错误 |
|
|
// 直接生成小程序码,移除Redis缓存避免类型转换错误 |
|
|
log.info("生成小程序码,用户ID: {}", user.getId()); |
|
|
log.info("生成小程序码,用户ID: {}", user.getId()); |
|
|
byte[] qrCodeBytes = generateWxQrCode(user, xcxSharePage, trial); |
|
|
|
|
|
|
|
|
// byte[] qrCodeBytes = null; |
|
|
|
|
|
BufferedImage qrCodeImage = null; |
|
|
|
|
|
|
|
|
|
|
|
if (LoginType.APPLET.equals(type)){ |
|
|
|
|
|
qrCodeImage = ImageIO.read(new ByteArrayInputStream(generateWxQrCode(user, xcxSharePage, trial))); |
|
|
|
|
|
}else { |
|
|
|
|
|
qrCodeImage = QRCodeUtil.getBufferedImage(webUrl + "?inviter=" + user.getId()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 生成最终合成图片,传递已获取的配置参数避免重复调用 |
|
|
// 生成最终合成图片,传递已获取的配置参数避免重复调用 |
|
|
byte[] finalImage = this.generateAndCombineImagesFromUrl2(qrCodeBytes, backgroundImageUrl, qrCodeX, qrCodeY); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
byte[] finalImage = this.generateAndCombineImagesFromUrl2(qrCodeImage, backgroundImageUrl, qrCodeX, qrCodeY); |
|
|
|
|
|
|
|
|
// 异步上传到OSS(移除Redis缓存) |
|
|
// 异步上传到OSS(移除Redis缓存) |
|
|
uploadToOssAsync(finalImage, finalPath); |
|
|
uploadToOssAsync(finalImage, finalPath); |
|
|
@ -192,7 +204,7 @@ public class AppletApiWaterServiceImpl implements AppletApiWaterService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public byte[] generateAndCombineImagesFromUrl2(byte[] qrCodeImageByte, String backgroundUrl, int qr_code_x, int qr_code_y) { |
|
|
|
|
|
|
|
|
public byte[] generateAndCombineImagesFromUrl2(BufferedImage qrCodeImage, String backgroundUrl, int qr_code_x, int qr_code_y) { |
|
|
File file = null; |
|
|
File file = null; |
|
|
try { |
|
|
try { |
|
|
// 直接从URL加载背景图像,移除Redis缓存避免类型转换问题 |
|
|
// 直接从URL加载背景图像,移除Redis缓存避免类型转换问题 |
|
|
@ -201,7 +213,7 @@ public class AppletApiWaterServiceImpl implements AppletApiWaterService { |
|
|
log.debug("从URL加载背景图片: {}", backgroundUrl); |
|
|
log.debug("从URL加载背景图片: {}", backgroundUrl); |
|
|
|
|
|
|
|
|
// 从字节数组加载小程序码图像 |
|
|
// 从字节数组加载小程序码图像 |
|
|
BufferedImage qrCodeImage = ImageIO.read(new ByteArrayInputStream(qrCodeImageByte)); |
|
|
|
|
|
|
|
|
// BufferedImage qrCodeImage = ImageIO.read(new ByteArrayInputStream(qrCodeImageByte)); |
|
|
|
|
|
|
|
|
// 使用传入的配置参数,避免重复调用配置服务 |
|
|
// 使用传入的配置参数,避免重复调用配置服务 |
|
|
|
|
|
|
|
|
|