| | |
| | | import cn.hutool.core.img.ImgUtil; |
| | | import cn.hutool.extra.qrcode.QrCodeUtil; |
| | | import com.ruoyi.file.utils.OBSUploadUtils; |
| | | import me.chanjar.weixin.common.error.WxErrorException; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | |
| | | |
| | | /** |
| | | * @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, 300, 300, qrCodeFile); |
| | | InputStream codeStream = new FileInputStream(qrCodeFile); |
| | | String fileUrl = OBSUploadUtils.uploadInputStream(codeStream,fileName); |
| | | codeStream.close(); |
| | | return fileUrl; |
| | | } |
| | | |
| | | /** |
| | | * @description 生成活动二维码 |
| | | * @author jqs |
| | | * @date 2023/7/26 19:09 |
| | |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public String createActivityCode(String activityId){ |
| | | public String createActivityWxCode(String activityId){ |
| | | |
| | | WxMaQrcodeService wxMaQrcodeService = wxMaService.getQrcodeService(); |
| | | String scene = activityId; |
| | |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public String createActivityCode(String activityId,String backImageUrl) throws WxErrorException, FileNotFoundException { |
| | | |
| | | |
| | | public String createActivityPoster(String activityId,String backImageUrl) throws Exception { |
| | | String fileUrl = null; |
| | | File qrCodeFile = new File("/home/image/qrcode.png"); |
| | | // 二维码内容 |
| | | String text = ""+activityId; |
| | | String text = "https://wxapp.hhhrt.cn/mini/activity?id="+activityId; |
| | | // 生成二维码 |
| | | QrCodeUtil.generate(text, 100, 100, qrCodeFile); |
| | | File backFile ; |
| | | QrCodeUtil.generate(text, 200, 200, qrCodeFile); |
| | | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| | | InputStream codeStream = new FileInputStream(qrCodeFile); |
| | | InputStream backStream = 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(516, 516, Image.SCALE_DEFAULT), //水印图片 |
| | | ImgUtil.read(codeStream).getScaledInstance(200, 200, Image.SCALE_DEFAULT), //水印图片 |
| | | 0, //x坐标修正值。 默认在中间,偏移量相对于中间偏移 |
| | | 0, //y坐标修正值。 默认在中间,偏移量相对于中间偏移 |
| | | 350, //y坐标修正值。 默认在中间,偏移量相对于中间偏移 |
| | | 1.0f |
| | | ); |
| | | InputStream inputStream = new ByteArrayInputStream(out.toByteArray()); |
| | | fileUrl = OBSUploadUtils.uploadInputStream(inputStream,activityId); |
| | | codeStream.close(); |
| | | inputStream.close(); |
| | | return fileUrl; |
| | | } |
| | | } |