bug
jiangqs
2023-07-26 add86a49cc69b6882500c95dd67a2ac826c35526
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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;
    }
}