|
@@ -1,6 +1,7 @@
|
|
|
package com.izouma.jiashanxia.service;
|
|
package com.izouma.jiashanxia.service;
|
|
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
|
|
+import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
|
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
|
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
|
@@ -27,11 +28,14 @@ import com.izouma.jiashanxia.service.storage.StorageService;
|
|
|
import com.izouma.jiashanxia.utils.JpaUtils;
|
|
import com.izouma.jiashanxia.utils.JpaUtils;
|
|
|
import com.izouma.jiashanxia.utils.SecurityUtils;
|
|
import com.izouma.jiashanxia.utils.SecurityUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
+import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import me.chanjar.weixin.mp.api.WxMpService;
|
|
import me.chanjar.weixin.mp.api.WxMpService;
|
|
|
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
|
|
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
|
|
|
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
|
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
|
|
|
|
+import net.coobird.thumbnailator.Thumbnails;
|
|
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -39,11 +43,16 @@ import org.springframework.data.domain.Page;
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import javax.imageio.ImageIO;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
|
+import java.awt.*;
|
|
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
|
|
+import java.io.*;
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -473,4 +482,41 @@ public class UserService {
|
|
|
return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
}), JpaUtils.toPageRequest(pageQuery));
|
|
}), JpaUtils.toPageRequest(pageQuery));
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public String shareImg(Long userId) throws IOException, WxErrorException {
|
|
|
|
|
+ User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
|
|
|
|
|
+ if (!(StringUtils.isNotEmpty(user.getShareImg()) && user.getShareImg().contains("/v1/"))) {
|
|
|
|
|
+ String url = createShareImg(userId);
|
|
|
|
|
+ user.setShareImg(url);
|
|
|
|
|
+ userRepo.save(user);
|
|
|
|
|
+ }
|
|
|
|
|
+ return user.getShareImg();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public String createShareImg(Long userId) throws IOException, WxErrorException {
|
|
|
|
|
+ BufferedImage shareImg = ImageIO.read(this.getClass().getResourceAsStream("/static/shareImg.png"));
|
|
|
|
|
+ BufferedImage result = new BufferedImage(shareImg.getWidth(), shareImg.getHeight(), BufferedImage.TYPE_INT_RGB);
|
|
|
|
|
+ Graphics2D g = result.createGraphics();
|
|
|
|
|
+ g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
|
|
|
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
|
|
+ g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
|
|
|
|
+ g.setComposite(AlphaComposite.SrcOver);
|
|
|
|
|
+ g.drawImage(shareImg, 0, 0, null);
|
|
|
|
|
+
|
|
|
|
|
+ byte[] bytes = wxMaService.getQrcodeService()
|
|
|
|
|
+ .createWxaCodeUnlimitBytes("invitor=" + userId, "pages/home", 94 * 2, false, new WxMaCodeLineColor("0", "0", "0"), true);
|
|
|
|
|
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
|
|
|
|
|
+ BufferedImage codeImg = ImageIO.read(byteArrayInputStream);
|
|
|
|
|
+
|
|
|
|
|
+ g.drawImage(codeImg, 251 * 2, 543 * 2, 94 * 2, 94 * 2, null);
|
|
|
|
|
+
|
|
|
|
|
+ ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
|
|
|
|
|
+ Thumbnails.of(result)
|
|
|
|
|
+ .scale(1)
|
|
|
|
|
+ .outputQuality(.9f)
|
|
|
|
|
+ .outputFormat("jpg")
|
|
|
|
|
+ .toOutputStream(out);
|
|
|
|
|
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
|
|
|
|
+ return storageService.uploadFromInputStream(in, "share_img/v1/" + userId + ".jpg");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|