jiangqs
2023-08-03 b95715d5cdc806cbb15cc7f49c538e61f5ab5dc6
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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;
    }
}