| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public String drawInviteQrCode(String url, Long uid, String portrait) throws IOException {
|
| | | public String drawInviteQrCode(String url, Long uid, String portrait, String inviteCode) throws IOException {
|
| | | if (url != null && !url.equals("")) {
|
| | | String targetPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + System.currentTimeMillis() + ".jpg";
|
| | | String erCodeTempPath = FileUtil.getCacheDir() + "/" + uid + "_" + System.currentTimeMillis() + ".jpg";
|
| | |
| | | InputStream erCodeInputStream = new FileInputStream(new File(erCodeTempPath)); // 二维码
|
| | |
|
| | | // 开始根据 url(背景图), qrCode(二维码), portrait(头像) 生成图片
|
| | | ImageUtil.inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath);
|
| | | ImageUtil.inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, inviteCode);
|
| | |
|
| | | if (new File(targetPath).exists() && new File(targetPath).length() > 0) {
|
| | | // 上传文件
|
| | |
| | |
|
| | | @Override
|
| | | public String drawInviteQrCode(String url, Long uid, String portrait, int erCodePostionX, int erCodePostionY,
|
| | | int erCodeSize) throws IOException {
|
| | | int erCodeSize, String inviteCode) throws IOException {
|
| | | if (!StringUtil.isNullOrEmpty(url)) {
|
| | | String targetPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + System.currentTimeMillis() + ".jpg";
|
| | | String erCodeTempPath = FileUtil.getCacheDir() + "/" + uid + "_" + System.currentTimeMillis() + ".jpg";
|
| | |
| | |
|
| | | // 开始根据 url(背景图), qrCode(二维码), portrait(头像) 生成图片
|
| | | ImageUtil.inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath,
|
| | | erCodePostionX, erCodePostionY, erCodeSize);
|
| | | erCodePostionX, erCodePostionY, erCodeSize, inviteCode);
|
| | |
|
| | | if (new File(targetPath).exists() && new File(targetPath).length() > 0) {
|
| | | // 上传文件
|
| | |
| | | import com.yeshi.fanli.entity.bus.invite.SpreadImg;
|
| | | import com.yeshi.fanli.entity.bus.invite.SpreadUserImg;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
|
| | | import com.yeshi.fanli.service.inter.user.QrCodeService;
|
| | | import com.yeshi.fanli.service.inter.user.SpreadUserImgService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | |
| | |
|
| | | @Resource
|
| | | private UserInfoDao userInfoDao;
|
| | |
|
| | | @Resource
|
| | | private UserInfoExtraService userInfoExtraService;
|
| | |
|
| | | @Override
|
| | | public void addUserInviteImg(Long uid, String imgUrl) {
|
| | |
| | | UserInfo user = null;
|
| | | if (dlist != null && dlist.size() > 0)
|
| | | user = userInfoDao.find(UserInfo.class, uid);
|
| | |
|
| | | String inviteCode = null;
|
| | | UserInfoExtra extraInfo = userInfoExtraService.getUserInfoExtra(uid);
|
| | | if (extraInfo != null) {
|
| | | inviteCode = extraInfo.getInviteCode();
|
| | | }
|
| | | // 添加原来没有的
|
| | | for (String md5 : dlist) {
|
| | | for (SpreadImg img : spreadImgList)
|
| | | if (img.getMd5().equalsIgnoreCase(md5)) {
|
| | | // 画图
|
| | | try {
|
| | |
|
| | | String imgUrl = qrCodeService.drawInviteQrCode(img.getUrl(), uid,
|
| | | StringUtil.isNullOrEmpty(user.getPortrait())
|
| | | ? Constant.systemCommonConfig.getDefaultPortrait() : user.getPortrait());
|
| | | ? Constant.systemCommonConfig.getDefaultPortrait() : user.getPortrait(),
|
| | | inviteCode);
|
| | | if (!StringUtil.isNullOrEmpty(imgUrl)) {
|
| | | if (imgUrl != null) {
|
| | | addUserInviteImg(uid, imgUrl);
|
| | |
| | | // 生成
|
| | | UserInfo user = userInfoDao.find(UserInfo.class, uid);
|
| | | try {
|
| | | String imgUrl = qrCodeService.drawInviteQrCode(bgImg, uid, user.getPortrait());
|
| | | String imgUrl = qrCodeService.drawInviteQrCode(bgImg, uid, user.getPortrait(), null);
|
| | | return imgUrl;
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | |
| | | UserInfo user = userInfoDao.find(UserInfo.class, uid);
|
| | | try {
|
| | | String imgUrl = qrCodeService.drawInviteQrCode(bgImg, uid, user.getPortrait(), erCodePostionX,
|
| | | erCodePostionY, erCodeSize);
|
| | | erCodePostionY, erCodeSize, null);
|
| | | return imgUrl;
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | |
| | | * @return
|
| | | * @throws IOException
|
| | | */
|
| | | String drawInviteQrCode(String url, Long uid, String portrait) throws IOException;
|
| | | String drawInviteQrCode(String url, Long uid, String portrait,String inviteCode) throws IOException;
|
| | |
|
| | | /**
|
| | | * 绘制邀请二维码
|
| | |
| | | * @throws IOException
|
| | | */
|
| | | String drawInviteQrCode(String url, Long uid, String portrait, int erCodePostionX, int erCodePostionY,
|
| | | int erCodeSize) throws IOException;
|
| | | int erCodeSize,String inviteCode) throws IOException;
|
| | | }
|
| | |
| | |
|
| | | // 邀请好友图片
|
| | | public static void inviteFriendImg(InputStream urlInputStream, InputStream portraitInputStream,
|
| | | InputStream erCodeInputStream, String targetPath) throws IOException {
|
| | | inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, 260, 908, 230);
|
| | | InputStream erCodeInputStream, String targetPath,String inviteCode) throws IOException {
|
| | | inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, 260, 908, 230, inviteCode);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * -二维码的纵坐标
|
| | | * @param size
|
| | | * -二维码的尺寸
|
| | | * @param inviteCode
|
| | | * -邀请码
|
| | | * @throws IOException
|
| | | */
|
| | | // 邀请好友图片
|
| | | public static void inviteFriendImg(InputStream urlInputStream, InputStream portraitInputStream,
|
| | | InputStream erCodeInputStream, String targetPath, int pX, int pY, int size) throws IOException {
|
| | | InputStream erCodeInputStream, String targetPath, int pX, int pY, int size, String inviteCode)
|
| | | throws IOException {
|
| | | BufferedImage bgImage = ImageIO.read(urlInputStream);
|
| | | final BufferedImage targetImg = new BufferedImage(bgImage.getWidth(), bgImage.getHeight(),
|
| | | BufferedImage.TYPE_INT_RGB);
|
| | |
| | | int pPY = pY + size / 2 - portraitSize / 2;
|
| | | portraitImg = ImageUtil.portraitImg(g2d, portraitImg, pPX, pPY, portraitSize, portraitSize);// 头像长宽
|
| | |
|
| | | // 画邀请码(邀请码的大小与字体固定)
|
| | | if (!StringUtil.isNullOrEmpty(inviteCode)) {
|
| | | String st = "邀请码:" + inviteCode;
|
| | | int width = bgImage.getWidth();
|
| | | String os = System.getProperty("os.name");
|
| | | String fontBoldPath = "/usr/share/fonts/PingFang_Medium.ttf";
|
| | | if (os.toLowerCase().startsWith("win")) {
|
| | | fontBoldPath = "D:/PingFang_Medium.ttf";
|
| | | }
|
| | |
|
| | | Font boldFont = null;
|
| | | try {
|
| | | boldFont = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(36.0f);
|
| | | } catch (FontFormatException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | g2d.setFont(boldFont);
|
| | | g2d.setColor(new Color(0, 0, 0));
|
| | |
|
| | | FontMetrics fm = g2d.getFontMetrics(boldFont);
|
| | | int textLength = fm.stringWidth(st);
|
| | |
|
| | | int ax = (width - textLength) / 2;
|
| | | int ay = bgImage.getHeight() - 92 + boldFont.getSize() / 2 - 5;
|
| | |
|
| | | g2d.setColor(new Color(0, 0, 0));
|
| | | g2d.drawString(st, ax, ay);
|
| | |
|
| | | }
|
| | |
|
| | | OutputStream out = new FileOutputStream(new File(targetPath));
|
| | | ImageIO.write(targetImg, "JPEG", out);
|
| | | out.flush();
|