派生自 projectDept/qhighschool

EricsHu
2022-12-05 068fc7f2e81178e55fa191a13709af64b1a163f6
src/main/java/com/qxueyou/scc/base/util/QrCodeUtils.java
@@ -32,9 +32,9 @@
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
/**
 * 二维码生成工具类
 * 二维码生成工具类
 * 
 * @author 德虎
 * @author 德虎
 * 
 */
public final class QrCodeUtils {
@@ -42,29 +42,29 @@
   private static Logger log = LogManager.getLogger(QrCodeUtils.class);
   /**
    * 生成二维码图片并输出到流
    * @param msg 需要生成的二维码信息
    * @param os 二维码图片输出流,输出后会自动关闭
    * @param logoFlag 是否添加logo
    * 生成二维码图片并输出到流
    * @param msg 需要生成的二维码信息
    * @param os 二维码图片输出流,输出后会自动关闭
    * @param logoFlag 是否添加logo
    * 
    */
   public static void createQRCodeImgAndSend(String msg, OutputStream os, boolean logoFlag) {
      try {
         //如果是网址,则转换为短网址
         //如果是网址,则转换为短网址
         /*if(ShortUrlUtils.IsUrl(msg)){
            IShortUrlService shortUrlService = SpringUtil.getBean(IShortUrlService.class);
            ShortUrl oldShortUrl = shortUrlService.queryShortUrl(msg);
            if(oldShortUrl != null){//判断是否已经存在数据
            if(oldShortUrl != null){//判断是否已经存在数据
               msg = oldShortUrl.getShortUrl();
            }else{
               //获取域
               //获取域
               String domain = SpringUtil.getBean(IConfigService.class).getConfigByEnv("domain-name");
               //获取短链接编码
               //获取短链接编码
               String strShortUrlCode = ShortUrlUtils.shortUrl(msg);
               //拼接成短链接
               //拼接成短链接
               String shortUrl = domain+(domain.indexOf("/qxueyou", 10)>=0?"/s/":"/qxueyou/s/")+strShortUrlCode;
               ShortUrl objShortUrl = new ShortUrl();
               //保存短链接的值
               //保存短链接的值
               objShortUrl.setShortUrl(shortUrl);
               objShortUrl.setLongUrl(msg);
               objShortUrl.setShortUrlCode(strShortUrlCode);
@@ -85,7 +85,7 @@
               msg,
               BarcodeFormat.QR_CODE, 300, 300, hints);
         MatrixToImageConfig config = new MatrixToImageConfig(0xFF000000, -1);
         //添加机构图标
         //添加机构图标
         if(StringUtils.isNoneBlank(ClientUtils.getOrgLogoPath()) && ShortUrlUtils.IsUrl(msg) && logoFlag){
             int width = bitMatrix.getWidth();  
              int height = bitMatrix.getHeight();  
@@ -113,9 +113,9 @@
   }
   
   /**
    * 添加机构logo
    * 添加机构logo
    * 
    * @param buf 生成的二维码
    * @param buf 生成的二维码
    * @return
    * @throws IOException 
    */
@@ -126,25 +126,25 @@
//         String domain = SpringUtil.getBean(IConfigService.class).getConfigByEnv("oss-domain");
         String domain =null;
         httpClient = HttpClients.createDefault();
         //获取机构logo
         //获取机构logo
         httpget = new HttpGet(domain+ClientUtils.getOrgLogoPath());  
         HttpResponse response = httpClient.execute(httpget);
         HttpEntity entity = response.getEntity();
         /**
         * 读取Logo图片
         * 读取Logo图片
         */
         BufferedImage logo = ImageIO.read(entity.getContent());
         /**
         * 读取二维码图片,并构建绘图对象
         * 读取二维码图片,并构建绘图对象
         */
         Graphics2D g = buf.createGraphics();
         int widthLogo = 65, heightLogo = 65;
      
         // 计算图片放置位置
         // 计算图片放置位置
         int x = (buf.getWidth() - widthLogo) / 2;
         int y = (buf.getHeight() - heightLogo) / 2;
      
         //开始绘制图片
         //开始绘制图片
         g.setColor(Color.WHITE);
         g.drawImage(logo, x, y, widthLogo, heightLogo, null);
           g.setStroke(new BasicStroke(1));  
@@ -152,7 +152,7 @@
         ImageIO.write(buf, "PNG", os);
      }catch (Exception e) {
         ImageIO.write(buf, "PNG", os);
         log.error("二维码添加logo失败"+e);
         log.error("二维码添加logo失败"+e);
      }finally {
         httpClient.close();
      }