前端-胡立永 1 month ago
parent
commit
883e87324e
6 changed files with 149 additions and 6 deletions
  1. +3
    -3
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiPromotionController.java
  2. +1
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiWaterService.java
  3. +2
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiCouponServiceImpl.java
  4. +128
    -3
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiWaterServiceImpl.java
  5. +2
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletConfig/service/IAppletConfigService.java
  6. +13
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletConfig/service/impl/AppletConfigServiceImpl.java

+ 3
- 3
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiPromotionController.java View File

@ -28,10 +28,10 @@ public class AppletApiPromotionController {
@Autowired
private AppletApiWaterService appletApiWaterService;
@Operation(summary = "获取推广二维码【待开发】", description = "获取推广二维码")
@Operation(summary = "获取推广二维码", description = "获取推广二维码")
@GetMapping(value = "/qrCode")
public Result<?> qrCode() {
return Result.OK();
public byte[] getInviteCode() {
return appletApiWaterService.getInviteCode();
}
@Operation(summary = "我的团队", description = "我的团队")


+ 1
- 0
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiWaterService.java View File

@ -11,6 +11,7 @@ import java.util.List;
public interface AppletApiWaterService {
byte[] getInviteCode();
/**
* 流水列表


+ 2
- 0
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiCouponServiceImpl.java View File

@ -36,4 +36,6 @@ public class AppletApiCouponServiceImpl implements AppletApiCouponService {
.eq(AppletCouponRecord::getStatus, status)
.page(page);
}
}

+ 128
- 3
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiWaterServiceImpl.java View File

@ -1,7 +1,9 @@
package org.jeecg.modules.applet.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.api.IAppletUserService;
import org.jeecg.common.exception.JeecgBootException;
@ -10,17 +12,33 @@ import org.jeecg.common.system.vo.AppletUser;
import org.jeecg.modules.applet.entity.StatisticsVo;
import org.jeecg.modules.applet.service.AppletApiWaterService;
import org.jeecg.modules.common.IdUtils;
import org.jeecg.modules.common.wxUtils.WxHttpUtils;
import org.jeecg.modules.demo.appletConfig.service.IAppletConfigService;
import org.jeecg.modules.demo.appletWater.entity.AppletWater;
import org.jeecg.modules.demo.appletWater.service.IAppletWaterService;
import org.jeecg.modules.demo.appletWithdrawal.entity.AppletWithdrawal;
import org.jeecg.modules.demo.appletWithdrawal.service.IAppletWithdrawalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.math.BigDecimal;
import java.util.List;
import java.util.UUID;
import java.net.URL;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
@Log4j2
@Service
public class AppletApiWaterServiceImpl implements AppletApiWaterService {
@Autowired
@ -29,6 +47,113 @@ public class AppletApiWaterServiceImpl implements AppletApiWaterService {
private IAppletUserService appletUserService;
@Autowired
private IAppletWithdrawalService appletWithdrawalService;
@Autowired
private IAppletConfigService appletConfigService;
@Autowired
private WxHttpUtils wxHttpUtils;
@Override
public byte[] getInviteCode(){
AppletUser user = AppletUserUtil.getCurrentAppletUser();
// 获取环境配置
String vsion = appletConfigService.getContentByCode("invite_env_version");
Integer vsionStr = Integer.parseInt(vsion);
String trial = "release";
if(vsionStr == 0){
trial= "release";
}else if(vsionStr == 1){
trial= "trial";
}else{
trial= "develop";
}
// 获取必要的配置信息
String xcxSharePage = appletConfigService.getContentByCode("xcxSharePage");
try {
// 准备微信API请求参数
String key = "shareId=" + user.getId();
Map<String, Object> param = new HashMap<>();
param.put("path", xcxSharePage + "?" + key);
param.put("scene", user.getId());
param.put("width", 150);
param.put("auto_color", false);
param.put("env_version", trial);
Map<String, Object> line_color = new HashMap<>();
line_color.put("r", 0);
line_color.put("g", 0);
line_color.put("b", 0);
param.put("line_color", line_color);
// param.put("is_hyaline", true);
// 获取微信小程序码
String accessToken = wxHttpUtils.getAccessToken();
String url = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + accessToken;
// 请求微信API获取二维码图片数据
RestTemplate rest = new RestTemplate();
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
HttpEntity requestEntity = new HttpEntity(JSON.toJSONString(param), headers);
ResponseEntity<byte[]> entity = rest.exchange(url, HttpMethod.POST, requestEntity, byte[].class, new Object[0]);
byte[] qrCodeBytes = entity.getBody();
return qrCodeBytes;
// return this.generateAndCombineImagesFromUrl2(qrCodeBytes, backgroundImageUrl);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public byte[] generateAndCombineImagesFromUrl2(byte[] qrCodeImageByte, String backgroundUrl) {
File file = null;
try {
// 从字节数组加载小程序码图像
BufferedImage qrCodeImage = ImageIO.read(new ByteArrayInputStream(qrCodeImageByte));
// 从URL加载背景图像
URL backgroundImageUrl = new URL(backgroundUrl);
BufferedImage backgroundImage = ImageIO.read(backgroundImageUrl);
// 创建一个新的BufferedImage来保存合并后的图像
Graphics2D g2d = backgroundImage.createGraphics();
int wh = backgroundImage.getWidth() / 3;
// 计算小程序码放置的位置这里以中心位置为例
int qrCodeX = (backgroundImage.getWidth() - wh) / 2;
int qrCodeY = (int) ((backgroundImage.getHeight() - wh) * 0.6);
// 绘制小程序码图像
g2d.drawImage(qrCodeImage, qrCodeX, qrCodeY, wh, wh, null);
// 释放Graphics2D资源
g2d.dispose();
// 将合并后的图像保存到临时文件
file = File.createTempFile("combined_", ".png");
ImageIO.write(backgroundImage, "png", file);
// 上传到阿里云OSS
// return this.uploadAliYunOss(Files.readAllBytes(file.toPath()), file.getName());
return Files.readAllBytes(file.toPath());
} catch (Exception e) {
log.error("生成合并图片失败", e);
throw new RuntimeException("生成合并图片失败", e);
} finally {
// 删除临时文件
if (file != null && file.exists()) {
file.delete();
}
}
}
/**


+ 2
- 0
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletConfig/service/IAppletConfigService.java View File

@ -11,4 +11,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface IAppletConfigService extends IService<AppletConfig> {
String getContentByCode(String code);
}

+ 13
- 0
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletConfig/service/impl/AppletConfigServiceImpl.java View File

@ -7,6 +7,8 @@ import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
/**
* @Description: 小程序配置
* @Author: jeecg-boot
@ -16,4 +18,15 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@Service
public class AppletConfigServiceImpl extends ServiceImpl<AppletConfigMapper, AppletConfig> implements IAppletConfigService {
@Override
public String getContentByCode(String code) {
List<AppletConfig> configs = lambdaQuery()
.eq(AppletConfig::getCode, code)
.list();
if (configs.size() > 0){
configs.get(0).getContent();
}
return null;
}
}

Loading…
Cancel
Save