国产成人卡2卡3卡4乱码_国产婷婷色一区二区三区在线_亚洲VA久久久噜噜噜久久天堂_漂亮人妻被中出中文字幕久久

java如何生成微商授權(quán)圖片

行業(yè)動(dòng)態(tài) 公司新聞 案例分享 技術(shù)百科

java如何生成微商授權(quán)圖片

來源:奇站網(wǎng)絡(luò) 瀏覽量:1,643 發(fā)布日期: 2017-12-17

微信公眾號(hào)開發(fā)中,微商商城系統(tǒng)經(jīng)常會(huì)碰到要求系統(tǒng)自動(dòng)生成授權(quán)圖片,試想如果會(huì)員較多,一個(gè)個(gè)手工處理費(fèi)時(shí)費(fèi)力。

一般會(huì)有如下要求:
自定義背景圖
附帶二維碼
附帶文字信息

  1. public String genQrcode(TMember member) throws Exception {
  2. /** 生成二維碼,用于圖片合并 */
  3. String url = WebConstants.PATH + "ucenter/member/inviteScan.do?inviteId=" + member.getId();
  4. String logo = ContextUtil.getRealPath() + "/theme/wd/images/qrcode_logo.png";
  5. String desDir = WebConstants.WEB_ROOT + "upload/code/";
  6. String fileName = "code_" + member.getId() + ".jpg";
  7. QRCodeUtil.encode(url, logo, desDir, fileName, true);
  8. /** 生成推廣圖 */
  9. String shareName = "share_" + member.getId() + ".jpg";
  10. String qrcodeBg = ContextUtil.getRealPath() + "/theme/wd/images/qrcode_bg.png";
  11. BufferedImage image1 = ImageIO.read(new File(qrcodeBg));
  12. BufferedImage image2 = ImageIO.read(new File(WebConstants.WEB_ROOT + "upload/code/" + fileName));
  13. BufferedImage combined = new BufferedImage(image1.getWidth(), image1.getHeight(), BufferedImage.TYPE_INT_RGB);
  14. // paint both images, preserving the alpha channels
  15. Graphics g = combined.getGraphics();
  16. g.drawImage(image1, 0, 0, null);
  17. g.drawImage(image2, 95, 600, 150, 150, null);
  18. // paint both images, preserving the alpha channels
  19. String uname = member.getUname();
  20. Calendar cal = Calendar.getInstance();
  21. cal.setTime(member.getInputDate());
  22. cal.add(Calendar.YEAR, 3);
  23. Font font = new Font("微軟雅黑", Font.BOLD, 16);
  24. Color color = new Color(0, 0, 0);
  25. g.drawImage(image1, 0, 0, null);
  26. g.setFont(font);
  27. g.setColor(color);
  28. g.drawString(uname, 200, 385);
  29. g.drawString(DateUtils.formatShortDate(cal.getTime()), 191, 495);
  30. g.drawString(member.getOpenid(), 191, 525);
  31. // Save as new image
  32. ImageIO.write(combined, "JPG", new File(desDir, shareName));
  33. return "upload/code/" + shareName;
  34. }
標(biāo)簽:

廈門奇站網(wǎng)絡(luò)科技有限公司

電話:13313868605

QQ:3413772931

地址:廈門集美區(qū)軟件園三期

網(wǎng)站地圖


                    掃一掃加我咨詢