From ff33cdfa1bd3a89ad9f5a72067b1c9b47376ef22 Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期二, 21 五月 2019 14:05:15 +0800
Subject: [PATCH] 动态邀请素材优化

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/QrCodeServiceImpl.java |   83 ++++++++++++++++++++++++++++++++++++++---
 1 files changed, 76 insertions(+), 7 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/QrCodeServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/QrCodeServiceImpl.java
index 4cf39c9..119389b 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/QrCodeServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/QrCodeServiceImpl.java
@@ -5,6 +5,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Date;
+import java.util.UUID;
 
 import javax.annotation.Resource;
 
@@ -133,6 +134,75 @@
 	
 	
 	@Override
+	public String drawInviteQrCodeNew(String url, Long uid, String portrait, String inviteCode) throws IOException {
+		
+		if (StringUtil.isNullOrEmpty(url)) {
+			return null;
+		}
+		
+		String targetPath = null;
+		String erCodeTempPath = null;
+		InputStream erCodeInputStream  = null; // 浜岀淮鐮�
+		InputStream portraitInputStream = null; // 澶村儚
+		InputStream urlInputStream = HttpUtil.getAsInputStream(url); // 鑳屾櫙
+		
+		String uuid = UUID.randomUUID().toString().replace("-", "");
+		if (uid == null) {
+			targetPath = FileUtil.getCacheDir() + "/share_" + uuid + "_" + System.currentTimeMillis() + ".jpg";
+			// 瀹樻柟 閭�璇风爜锛堟棤鏁堢殑锛�
+			inviteCode = "FLQAPP";
+			// 瀹樻柟浜岀淮鐮�
+			erCodeInputStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/official.png");
+			// 瀹樻柟榛樿澶村儚
+			portraitInputStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/official_icon.png");
+		
+		} else {
+		
+			targetPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + System.currentTimeMillis() + ".jpg";
+			erCodeTempPath = FileUtil.getCacheDir() + "/" + uid + "_" + System.currentTimeMillis() + ".jpg";
+	
+			String erCode = HttpUtil.getShortLink("http://" + Constant.wxGZConfig.getLoginHost() + "/"
+					+ Constant.systemCommonConfig.getProjectName() + "/client/threeShareNew?uid=" + uid);
+			// 鐢熸垚
+			try {
+				QRCodeUtil.getInstance(250).encode(erCode, erCodeTempPath);
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+	
+			urlInputStream = HttpUtil.getAsInputStream(url); // 鑳屾櫙
+			portraitInputStream = HttpUtil.getAsInputStream(portrait); // 澶村儚
+			erCodeInputStream = new FileInputStream(new File(erCodeTempPath)); // 浜岀淮鐮�
+		}
+		// 寮�濮嬫牴鎹� url(鑳屾櫙鍥�), qrCode(浜岀淮鐮�), portrait(澶村儚) 鐢熸垚鍥剧墖
+		ImageUtil.inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, inviteCode);
+
+		if (new File(targetPath).exists() && new File(targetPath).length() > 0) {
+			
+			int index = url.lastIndexOf("/");
+			String newUrl = url.substring(index + 1);
+			String urlMd5 = newUrl.substring(0, newUrl.lastIndexOf("."));
+
+			String fileUrl= null;
+			if (uid == null) {
+				fileUrl= "ercode/" + "ercode_" + uuid + "_" + System.currentTimeMillis() + "_" + urlMd5 + ".jpg";
+			} else {
+				
+				fileUrl = "ercode/" + "ercode_" + uid + "_" + System.currentTimeMillis() + "_" + urlMd5 + ".jpg";
+				if (new File(erCodeTempPath).exists())
+					new File(erCodeTempPath).delete();
+			}
+			
+			String imgUrl = COSManager.getInstance().uploadFile(new File(targetPath), fileUrl).getUrl();
+			if (new File(targetPath).exists())
+				new File(targetPath).delete();
+
+			return imgUrl;
+		}
+		return null;
+	}
+	
+	@Override
 	public String drawInviteToGreet(String url, Long uid, String portrait, String inviteCode, String content, 
 			Date date) throws IOException {
 		
@@ -146,8 +216,9 @@
 		InputStream portraitInputStream = null; // 澶村儚
 		InputStream urlInputStream = HttpUtil.getAsInputStream(url); // 鑳屾櫙
 		
+		String uuid = UUID.randomUUID().toString().replace("-", "");
 		if (uid == null) {
-			targetPath = FileUtil.getCacheDir() + "/share_official" + System.currentTimeMillis() + ".jpg";
+			targetPath = FileUtil.getCacheDir() + "/share_" + uuid + "_" + System.currentTimeMillis() + ".jpg";
 			// 瀹樻柟 閭�璇风爜锛堟棤鏁堢殑锛�
 			inviteCode = "FLQAPP";
 			// 瀹樻柟浜岀淮鐮�
@@ -167,6 +238,7 @@
 				e.printStackTrace();
 			}
 			erCodeInputStream = new FileInputStream(new File(erCodeTempPath)); 
+			portraitInputStream = HttpUtil.getAsInputStream(portrait); // 澶村儚
 		}
 		
 		
@@ -175,7 +247,6 @@
 
 		// 涓婁紶鏂囦欢
 		if (new File(targetPath).exists() && new File(targetPath).length() > 0) {
-			// 灏唘rl 杞负 md5 璁╁埌涓嬮潰涓坊鍔� 鍦ㄦ瘮杈僲d5鐨勫��
 			int index = url.lastIndexOf("/");
 			String newUrl = url.substring(index + 1);
 			String urlMd5 = newUrl.substring(0, newUrl.lastIndexOf("."));
@@ -183,18 +254,16 @@
 			// 涓婁紶鏂囦欢鐩稿浣嶇疆
 			String fileUrl= null;
 			if (uid == null) {
-				fileUrl="ercode/" + "ercode_official" + "_" + urlMd5 + ".jpg";
+				fileUrl= "ercode/" + "ercode_" + uuid + "_" + System.currentTimeMillis() + "_" + urlMd5 + ".jpg";
 			} else {
-				fileUrl="ercode/" + "ercode_" + uid + "_" + urlMd5 + ".jpg";
 				
+				fileUrl = "ercode/" + "ercode_" + uid + "_" + System.currentTimeMillis() + "_" + urlMd5 + ".jpg";
 				if (new File(erCodeTempPath).exists())
 					new File(erCodeTempPath).delete();
 			}
-			
+
 			String imgUrl = COSManager.getInstance().uploadFile(new File(targetPath), fileUrl).getUrl();
 			
-			
-
 			if (new File(targetPath).exists())
 				new File(targetPath).delete();
 

--
Gitblit v1.8.0