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 com.ruoyi.file.utils.OBSUploadUtils;
|
import me.chanjar.weixin.common.error.WxErrorException;
|
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/7/26 19:09
|
* @param activityId
|
* @return void
|
*/
|
@Override
|
public String createActivityCode(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 createActivityCode(String activityId,String backImageUrl) throws WxErrorException, FileNotFoundException {
|
|
WxMaQrcodeService wxMaQrcodeService = wxMaService.getQrcodeService();
|
String scene = activityId;
|
String page = "";
|
String filePath = "";
|
String fileUrl = null;
|
File file = wxMaQrcodeService.createWxaCodeUnlimit(scene,page,filePath);
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
InputStream codeStream = new FileInputStream(file);
|
InputStream backStream = new FileInputStream(file);
|
// 将图片合成在一起
|
ImgUtil.pressImage(
|
backStream, // 主图片
|
out, // 输出图片
|
ImgUtil.read(codeStream).getScaledInstance(516, 516, Image.SCALE_DEFAULT), //水印图片
|
0, //x坐标修正值。 默认在中间,偏移量相对于中间偏移
|
0, //y坐标修正值。 默认在中间,偏移量相对于中间偏移
|
1.0f
|
);
|
InputStream inputStream = new ByteArrayInputStream(out.toByteArray());
|
return fileUrl;
|
}
|
}
|