package com.ruoyi.file.service;
|
|
import cn.binarywang.wx.miniapp.api.WxMaQrcodeService;
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
import cn.hutool.core.img.ImgUtil;
|
import cn.hutool.extra.qrcode.QrCodeUtil;
|
import com.ruoyi.file.utils.OBSUploadUtils;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.awt.*;
|
import java.io.*;
|
|
/**
|
* @ClassName ActivityCodeServiceImpl
|
* @Description TODO
|
* @Author jqs
|
* @Date 2023/7/26 19:12
|
* @Version 1.0
|
*/
|
@Service
|
public class ActivityCodeServiceImpl implements ActivityCodeService{
|
|
@Resource
|
private WxMaService wxMaService;
|
|
|
/**
|
* @description 生成二维码
|
* @author jqs
|
* @date 2023/8/3 12:44
|
* @param url
|
* @return String
|
*/
|
@Override
|
public String createActivityCode(String url, String fileName) throws Exception {
|
File qrCodeFile = new File("/home/image/qrcode.png");// 生成二维码
|
QrCodeUtil.generate(url, 100, 100, qrCodeFile);
|
InputStream codeStream = new FileInputStream(qrCodeFile);
|
String fileUrl = OBSUploadUtils.uploadInputStream(codeStream,fileName);
|
return fileUrl;
|
}
|
|
/**
|
* @description 生成活动二维码
|
* @author jqs
|
* @date 2023/7/26 19:09
|
* @param activityId
|
* @return void
|
*/
|
@Override
|
public String createActivityWxCode(String activityId){
|
|
WxMaQrcodeService wxMaQrcodeService = wxMaService.getQrcodeService();
|
String scene = activityId;
|
String page = "";
|
String filePath = "";
|
String fileUrl = null;
|
try {
|
File file = wxMaQrcodeService.createWxaCodeUnlimit(scene,page,filePath);
|
fileUrl = OBSUploadUtils.uploadLocalFile(file);
|
} catch (Exception e) {
|
throw new RuntimeException(e);
|
}
|
return fileUrl;
|
}
|
/**
|
* @description 生成活动二维码
|
* @author jqs
|
* @date 2023/7/26 19:09
|
* @param activityId
|
* @return void
|
*/
|
@Override
|
public String createActivityPoster(String activityId,String backImageUrl) throws Exception {
|
String fileUrl = null;
|
File qrCodeFile = new File("/home/image/qrcode.png");
|
// 二维码内容
|
String text = "https://wxapp.hhhrt.cn/mini/activity?"+activityId;
|
// 生成二维码
|
QrCodeUtil.generate(text, 200, 200, qrCodeFile);
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
InputStream codeStream = new FileInputStream(qrCodeFile);
|
backImageUrl = backImageUrl.replace("https://hongruitang.oss-cn-beijing.aliyuncs.com/","");
|
InputStream backStream = OBSUploadUtils.getOSSInputStream(backImageUrl);
|
// 将图片合成在一起
|
ImgUtil.pressImage(
|
backStream, // 主图片
|
out, // 输出图片
|
ImgUtil.read(codeStream).getScaledInstance(200, 200, Image.SCALE_DEFAULT), //水印图片
|
0, //x坐标修正值。 默认在中间,偏移量相对于中间偏移
|
350, //y坐标修正值。 默认在中间,偏移量相对于中间偏移
|
1.0f
|
);
|
InputStream inputStream = new ByteArrayInputStream(out.toByteArray());
|
fileUrl = OBSUploadUtils.uploadInputStream(inputStream,activityId);
|
return fileUrl;
|
}
|
}
|