From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 25 二月 2025 16:41:22 +0800
Subject: [PATCH] 淘宝转链接口更新

---
 fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java |  663 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 660 insertions(+), 3 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java
index ef5a634..46b6546 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java
@@ -31,18 +31,259 @@
 
 import org.yeshi.utils.DateLunarUtil;
 import org.yeshi.utils.HttpUtil;
+import org.yeshi.utils.MoneyBigDecimalUtil;
+import org.yeshi.utils.TimeUtil;
 import org.yeshi.utils.entity.DateInfo;
 
 import com.yeshi.fanli.entity.bus.activity.RecommendActivityTaoBaoGoods;
 import com.yeshi.fanli.entity.bus.user.UserInfo;
 import com.yeshi.fanli.entity.goods.CommonGoods;
-import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
+import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
 import com.yeshi.fanli.log.LogHelper;
 import com.yeshi.fanli.util.taobao.TaoBaoUtil;
 import com.yeshi.fanli.vo.goods.GoodsDetailVO;
+import com.yeshi.fanli.vo.user.PullNewRuleNumVO;
+import com.yeshi.fanli.vo.user.PullNewRuleVO;
 
 public class ImageUtil {
 
+	
+	/**
+	 * 鍒嗘瀽娴锋姤鍥�
+	 * @param qrcode
+	 * @param portraitStream
+	 * @param goods
+	 * @return
+	 */
+	public static InputStream drawGoodsQuickhShare(InputStream qrcode, InputStream portraitStream, String inviteCode,
+			String mainPic, GoodsDetailVO goods) {
+		try {
+			String fontPath = "/usr/share/fonts/PingFang_Medium.ttf";
+			String os = System.getProperty("os.name");
+			if (os.toLowerCase().startsWith("win")) {
+				fontPath = "D:/PingFang_Medium.ttf";
+			}
+
+			String fontBoldPath = "/usr/share/fonts/PingFang_Heavy_0.ttf";
+			if (os.toLowerCase().startsWith("win")) {
+				fontBoldPath = "D:/PingFang_Heavy_0.ttf";
+			}
+			Font font24 = Font.createFont(Font.PLAIN, new File(fontPath)).deriveFont(24.0f);
+			Font font26 = Font.createFont(Font.PLAIN, new File(fontPath)).deriveFont(26.0f);
+			Font boldFont36 = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(36.0f);
+
+			int px = 640; // 鍥剧墖瀹藉害
+			// int py = 1154; // 鍥剧墖楂樺害 鏄剧ず閭�璇风爜
+			int py = 1060; // 鍥剧墖楂樺害
+			final BufferedImage targetImg = new BufferedImage(px, py, BufferedImage.TYPE_INT_RGB);
+			HashMap<Key, Object> mapH = new HashMap<Key, Object>();
+			mapH.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);// 鎶楅敮榻柯狅紙鎶楅敮榻挎�诲紑鍏筹級聽聽
+			mapH.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);// 鏂囧瓧鎶楅敮榻柯�
+
+			final Graphics2D g2d = (Graphics2D) targetImg.getGraphics();
+			g2d.setRenderingHints(mapH);
+			g2d.setColor(Color.WHITE);
+			g2d.fillRect(0, 0, px, py);
+
+			int x = 640;
+			int y = 640;
+			int spacing = 20; // 鍙宠竟璺�
+
+			// 1銆佺敾鍟嗗搧涓诲浘
+			InputStream picStream = HttpUtil.getAsInputStream(mainPic);
+			// InputStream picStream =
+			// ImageUtil.class.getClassLoader().getResourceAsStream("image/share/test_pic1.jpg");
+			g2d.drawImage(ImageIO.read(picStream), 0, 0, x, y, null);
+
+			// 2銆佺敾鏉ユ簮鍥炬爣
+			int length = 10;
+			int row1 = 450;
+			int iconWidth = 72;
+			String source = "";
+			InputStream icon = null;
+			int goodsType = goods.getGoodsType();
+			if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
+				source = "娣樺疂";
+				if (goods.getShopType() == 10) {
+					icon = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_tb.png");
+				} else {
+					icon = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_tm.png");
+				}
+			} else if (goodsType == Constant.SOURCE_TYPE_JD) {
+				source = "浜笢";
+				icon = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_jd.png");
+			} else if (goodsType == Constant.SOURCE_TYPE_PDD) {
+				source = "鎷煎澶�";
+				length = 9;
+				row1 = row1 - 26;
+				iconWidth = iconWidth + 28;
+				icon = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_pdd.png");
+			} else {
+				return null;
+			}
+			g2d.drawImage(ImageIO.read(icon), spacing, y + 20, iconWidth, 34, null);
+
+			// 3銆佸晢鍝佹爣棰樺唴瀹�
+			int row = 0;
+			String title = goods.getTitle();
+			length = ImageUtil.getTextLengthByWidth(g2d, font26, title, row1, length);
+			g2d.setFont(font26);
+			g2d.setColor(new Color(0, 0, 0));
+			g2d.drawString(title.substring(0, length), spacing + iconWidth + 5, y + 45 + row * 36);
+
+			row++;
+			title = title.substring(length);
+			int length2 = ImageUtil.getTextLengthByWidth(g2d, font26, title, 600, 11);
+			if (length2 > 24) {
+				g2d.drawString(title.substring(0, 21) + "...", spacing, y + 45 + row * 36);
+			} else {
+				g2d.drawString(title.substring(0, length2), spacing, y + 45 + row * 36);
+			}
+
+			int baoYouLength = spacing;
+			if (!goods.isHasCoupon()) {
+				// 鏃犲埜
+				g2d.setColor(new Color(229, 0, 92));
+				g2d.drawString("楼 ", spacing, y + 125);
+				g2d.setFont(boldFont36);
+				g2d.drawString(MoneyBigDecimalUtil.getWithNoZera(goods.getZkPrice()).toString(), spacing + 21, y + 125);
+			} else {
+				// 鍒稿悗浠�
+				g2d.setFont(font26);
+				g2d.setColor(new Color(229, 0, 92));
+				g2d.drawString("鍒稿悗浠�  楼 ", spacing, y + 125);
+
+				g2d.setFont(boldFont36);
+				String couponPrice = MoneyBigDecimalUtil.getWithNoZera(goods.getCouponPrice()).toString();
+				g2d.drawString(couponPrice, spacing + 116, y + 125);
+
+				FontMetrics fm2 = g2d.getFontMetrics(boldFont36);
+				int textLength1 = 116 + fm2.stringWidth(couponPrice);
+
+				// 娓犻亾鍘熶环
+				g2d.setColor(new Color(153, 153, 153));
+				g2d.setFont(font24);
+				g2d.drawString(goods.getPriceName() + " 楼 " + MoneyBigDecimalUtil.getWithNoZera(goods.getZkPrice()),
+						spacing + textLength1 + 10, y + 125);
+
+				// 鍒稿瓧
+				InputStream quan = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_quan.png");
+				g2d.drawImage(ImageIO.read(quan), spacing, y + 140, 47, 40, null);
+				// 鍒搁潰棰�
+				String quanAmount = "楼 " + goods.getCouponInfo().getAmount();
+				FontMetrics fm = g2d.getFontMetrics(font26);
+				int textLength = fm.stringWidth(quanAmount);
+
+				g2d.setFont(font26);
+				g2d.setColor(new Color(229, 0, 92));
+				g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+				g2d.drawRoundRect(spacing + 42, y + 140, textLength + 20, 39, 10, 10);
+				g2d.drawString(quanAmount, spacing + 55, y + 170);
+
+				baoYouLength = spacing + 42 + textLength + 20 + 20;
+			}
+
+			// 鑷惀 銆佸寘閭�
+			InputStream ziying = null;
+			if (goods.getShopType() == 21) {
+				ziying = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_ziying.png");
+				g2d.drawImage(ImageIO.read(ziying), baoYouLength, y + 150, 60, 30, null);
+			} else if (goods.isBaoyou()) {
+				ziying = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_baoyou.png");
+				g2d.drawImage(ImageIO.read(ziying), baoYouLength, y + 150, 60, 30, null);
+			}
+
+			// 閿�閲�
+			String sale = null;
+			int salesType = goods.getSalesType();
+			if (salesType == 1) {
+				sale = "鏈堥攢";
+			} else if (salesType == 2) {
+				sale = "2灏忔椂閿�閲�";
+			} else if (salesType == 3) {
+				sale = "浠婃棩閿�閲�";
+			} else if (salesType == 4) {
+				sale = "鎬婚攢閲�";
+			} else {
+				sale = "鏈堥攢";
+			}
+			sale = sale + " " + goods.getSalesCount();
+			FontMetrics fm = g2d.getFontMetrics(font24);
+			int textLength = fm.stringWidth(sale);
+			g2d.setFont(font24);
+			g2d.setColor(new Color(153, 153, 153));
+			g2d.drawString(sale, spacing + 605 - textLength, y + 125);
+
+			// 涓嬪崟鎻愮ず
+			InputStream downTip = null;
+			if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
+				downTip = ImageUtil.class.getClassLoader().getResourceAsStream("image/share/down_tip_tb.png");
+			} else {
+				downTip = ImageUtil.class.getClassLoader().getResourceAsStream("image/share/down_tip_jd_pdd.png");
+			}
+			g2d.drawImage(ImageIO.read(downTip), spacing, y + 200, 382, 203, null);
+
+			// 浜岀淮鐮佸浘妗�
+			InputStream codeFrame = ImageUtil.class.getClassLoader()
+					.getResourceAsStream("image/share/qr_code_frame01.png");
+			g2d.drawImage(ImageIO.read(codeFrame), spacing + 405, y + 200, 200, 203, null);
+
+			// 鐢讳簩缁寸爜
+			int codeSize = 170;
+			int pX = spacing + 422;
+			int pY = y + 217;
+			g2d.drawImage(ImageIO.read(qrcode), pX, pY, codeSize, codeSize, null);
+
+			int portraitSize = 200 * 5 / 23;
+			int pPX = pX + codeSize / 2 - portraitSize / 2;
+			int pPY = pY + codeSize / 2 - portraitSize / 2;
+			// 澶村儚鐧借壊杈规
+			g2d.setColor(Color.WHITE);
+			g2d.fillRoundRect(pPX - 4, pPY - 4, portraitSize + 8, portraitSize + 8, 5, 5);
+			g2d.setRenderingHints(mapH);
+			// 鐢诲ご鍍�
+			BufferedImage portraitImg = ImageIO.read(portraitStream);
+			portraitImg = ImageUtil.zoomInImage(portraitImg, portraitSize, portraitSize);
+			portraitImg = ImageUtil.roundImage(portraitImg, 10);
+			g2d.drawImage(portraitImg, pPX, pPY, portraitSize, portraitSize, null);
+
+			g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+			g2d.setColor(new Color(255, 231, 224));
+			g2d.fillRoundRect(spacing, y + 420, 607, 79, 10, 10);
+
+			InputStream banliStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/banlikuaisheng.png");
+			g2d.drawImage(ImageIO.read(banliStream), spacing + 20, y + 440, 170, 38, null);
+
+			inviteCode = "閭�璇风爜:" + inviteCode;
+			Font font26d28 = Font.createFont(Font.PLAIN, new File(fontPath)).deriveFont(26.28f);
+			FontMetrics fmcode = g2d.getFontMetrics(font26d28);
+			int codeLength = fmcode.stringWidth(inviteCode);
+			// 閭�璇风爜鑳屾櫙
+			g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+			g2d.setColor(new Color(229, 71, 27));
+			g2d.fillRoundRect(spacing + (600 - (int) (codeLength * 1.1)), y + 440, 10 + codeLength, 37, 10, 10);
+			// 閭�璇风爜鏂囧瓧
+			g2d.setFont(font26d28);
+			g2d.setColor(new Color(255, 255, 255));
+			g2d.drawString(inviteCode, spacing + (600 - (int) (codeLength * 1.1) + 5), y + 468);
+
+			g2d.dispose();
+
+			ByteArrayOutputStream aos = new ByteArrayOutputStream();
+			ImageIO.write(targetImg, "JPEG", aos);
+			return new ByteArrayInputStream(aos.toByteArray());
+		} catch (Exception e) {
+			e.printStackTrace();
+			try {
+				LogHelper.errorDetailInfo(e);
+			} catch (Exception e1) {
+				e1.printStackTrace();
+			}
+		}
+		return null;
+
+	}
+	
 	// 鐢诲晢鍝佸垎浜浘
 	public static InputStream drawGoodsShareXCX(InputStream qrcode, UserInfo user, GoodsDetailVO goods) {
 		try {
@@ -1179,7 +1420,7 @@
 			// 鐢荤涓�寮�
 			for (int i = 0; i < goodsList.size(); i++) {
 				TaoBaoGoodsBrief goods = goodsList.get(i);
-				BigDecimal couplePrice = TaoBaoUtil.getAfterUseCouplePrice(goods);
+				BigDecimal couplePrice = TaoBaoUtil.getCouponPrice(goods);
 				// 绗竴寮犲浘闇�瑕佹湁浠锋牸淇℃伅
 				if (i == 0) {
 					int topX = 50;
@@ -1717,7 +1958,7 @@
 		g2d.drawImage(picImage, 50, 207, null);
 
 		// 鐢讳环鏍�
-		BigDecimal money = TaoBaoUtil.getAfterUseCouplePrice(goods);
+		BigDecimal money = TaoBaoUtil.getCouponPrice(goods);
 		money = MoneyBigDecimalUtil.getWithNoZera(money);
 		g2d.setColor(new Color(240, 66, 66));
 
@@ -2572,7 +2813,423 @@
 			}
 		}
 		return null;
+	}
+	
+	
+	
+	/**
+	 * 瀹夊崜-鏀粯瀹濈敾鍥�
+	 * @param money
+	 * @param orderNo
+	 * @param time
+	 * @param targetPath
+	 * @return
+	 * @throws IOException
+	 */
+	public static InputStream drawAlipayAndroid(BigDecimal money, String orderNo, String time) throws IOException {
+		String bgpic = "image/alipay/android.png";
+		BufferedImage bgImage = ImageIO.read(ImageUtil.class.getClassLoader().getResourceAsStream(bgpic));
+		
+		final BufferedImage targetImg = new BufferedImage(bgImage.getWidth(), bgImage.getHeight(), BufferedImage.TYPE_INT_RGB);
+		HashMap<Key, Object> mapH = new HashMap<Key, Object>();
+		mapH.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);// 鎶楅敮榻柯狅紙鎶楅敮榻挎�诲紑鍏筹級聽聽
+		mapH.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);// 鏂囧瓧鎶楅敮榻柯�
 
+		// 鐢� 鑳屾櫙鍥剧墖
+		final Graphics2D g2d = targetImg.createGraphics();
+		g2d.setRenderingHints(mapH);
+		g2d.drawImage(bgImage, 0, 0, bgImage.getWidth(), bgImage.getHeight(), null);
+		g2d.setBackground(Color.BLACK);
+		
+		// 瀛椾綋
+		String os = System.getProperty("os.name");
+		String fontRob0to = "/usr/share/fonts/ROBOTO-REGULAR.TTF";
+		String fontBahnschrift = "/usr/share/fonts/BAHNSCHRIFT.TTF";
+		if (os.toLowerCase().startsWith("win")) {
+			fontRob0to = "D:/ROBOTO-REGULAR.TTF";
+			fontBahnschrift = "D:/BAHNSCHRIFT.TTF";
+		}
+		
+		// 瀛椾綋澶у皬
+		Font font40 = null;
+		Font font42 = null;
+		Font font86 = null;
+		try {
+			font40 = Font.createFont(Font.PLAIN, new File(fontRob0to)).deriveFont(40.00f);
+			font42 = Font.createFont(Font.PLAIN, new File(fontBahnschrift)).deriveFont(42.00f);
+			font86 = Font.createFont(Font.PLAIN, new File(fontRob0to)).deriveFont(86.68f);
+		} catch (FontFormatException e) {
+			e.printStackTrace();
+		}
+		
+		
+		/*  鏃堕棿淇℃伅   */
+		g2d.setFont(font42);
+		g2d.setColor(new Color(247, 247, 247));
+		g2d.drawString(TimeUtil.formatHHMM_12H(new Date()), 134, 67);
+		
+		
+		/*  璧勯噾淇℃伅   */
+		String moneyInfo = "+" + money.setScale(2);
+		// 璁$畻闀垮害
+		FontMetrics fm = g2d.getFontMetrics(font86);
+		int textLength = fm.stringWidth(moneyInfo);
+		// 灞呬腑浣嶇疆
+		int x_money =  (bgImage.getWidth() - textLength) / 2 ;
+		// 鐢婚噾棰�
+		g2d.setFont(font86);
+		g2d.setColor(new Color(51, 51, 51));
+		g2d.drawString(moneyInfo, x_money, 420);
+
+		
+		/*  鍒涘缓鏃堕棿淇℃伅   */
+		FontMetrics fm2 = g2d.getFontMetrics(font40);
+		int l_time = fm2.stringWidth(time);
+		int x_time =  bgImage.getWidth() - l_time -41  ;
+		g2d.setFont(font40);
+		g2d.setColor(new Color(51, 51, 51));
+		g2d.drawString(time, x_time, 972);
+
+		/*  鍒涘缓鏃堕棿淇℃伅   */
+		int l_order = fm2.stringWidth(orderNo);
+		int x_order =  bgImage.getWidth() - l_order -41  ;
+		g2d.setFont(font40);
+		g2d.setColor(new Color(51, 51, 51));
+		g2d.drawString(orderNo, x_order, 1072);
+		g2d.dispose();
+
+		ByteArrayOutputStream aos = new ByteArrayOutputStream();
+		ImageIO.write(targetImg, "png", aos);
+		
+		return new ByteArrayInputStream(aos.toByteArray());
 	}
 
+	
+	
+	/**
+	 * IOS 鏀粯瀹濈敾鍥�
+	 * @param money
+	 * @param orderNo
+	 * @param time
+	 * @param targetPath
+	 * @return
+	 * @throws IOException
+	 */
+	public static InputStream drawAlipayIOS(BigDecimal money, String orderNo, String time)
+			throws IOException {
+		String bgpic = "image/alipay/ios.png";
+		BufferedImage bgImage = ImageIO.read(ImageUtil.class.getClassLoader().getResourceAsStream(bgpic));
+
+		final BufferedImage targetImg = new BufferedImage(bgImage.getWidth(), bgImage.getHeight(),
+				BufferedImage.TYPE_INT_RGB);
+		HashMap<Key, Object> mapH = new HashMap<Key, Object>();
+		mapH.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);// 鎶楅敮榻柯狅紙鎶楅敮榻挎�诲紑鍏筹級聽聽
+		mapH.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);// 鏂囧瓧鎶楅敮榻柯�
+
+		// 鐢� 鑳屾櫙鍥剧墖
+		final Graphics2D g2d = targetImg.createGraphics();
+		g2d.setRenderingHints(mapH);
+		g2d.drawImage(bgImage, 0, 0, bgImage.getWidth(), bgImage.getHeight(), null);
+		g2d.setBackground(Color.BLACK);
+
+		// 瀛椾綋
+		String os = System.getProperty("os.name");
+		String fontHeiTi = "/usr/share/fonts/AdobeHeiTiStd.otf";
+		String fontSquare = "/usr/share/fonts/SquareHeitiStd.TTF";
+		if (os.toLowerCase().startsWith("win")) {
+			fontHeiTi = "D:/AdobeHeiTiStd.otf";
+			fontSquare = "D:/SquareHeitiStd.TTF";
+		}
+		
+		// 瀛椾綋澶у皬
+		Font font40 = null;
+		Font font44 = null;
+		Font font92 = null;
+		try {
+			font44 = Font.createFont(Font.PLAIN, new File(fontHeiTi)).deriveFont(44.18f);
+			font40 = Font.createFont(Font.PLAIN, new File(fontSquare)).deriveFont(40.00f);
+			font92 = Font.createFont(Font.PLAIN, new File(fontSquare)).deriveFont(92.03f);
+		} catch (FontFormatException e) {
+			e.printStackTrace();
+		}
+		/* 鏃堕棿淇℃伅 */
+		g2d.setFont(font44);
+		g2d.setColor(new Color(16, 16, 16));
+		MyDrawString(TimeUtil.formatHHMM_12H(new Date()), 82, 82, font44, g2d);
+ 
+	        
+		/* 璧勯噾淇℃伅 */
+		String moneyInfo = "+" + money.setScale(2);
+		// 璁$畻闀垮害
+		FontMetrics fm = g2d.getFontMetrics(font92);
+		int textLength = fm.stringWidth(moneyInfo);
+		// 灞呬腑浣嶇疆
+		int x_money = (bgImage.getWidth() - textLength) / 2;
+		// 鐢婚噾棰�
+		g2d.setFont(font92);
+		g2d.setColor(new Color(51, 51, 51));
+		g2d.drawString(moneyInfo, x_money, 480);
+
+		/* 鍒涘缓鏃堕棿淇℃伅 */
+		FontMetrics fm2 = g2d.getFontMetrics(font40);
+		int l_time = fm2.stringWidth(time);
+		int x_time = bgImage.getWidth() - l_time - 41;
+		g2d.setFont(font40);
+		g2d.setColor(new Color(51, 51, 51));
+		g2d.drawString(time, x_time, 1052);
+		
+		/* 鍒涘缓鏃堕棿淇℃伅 */
+		int l_order = fm2.stringWidth(orderNo);
+		int x_order = bgImage.getWidth() - l_order - 41;
+		g2d.setFont(font40);
+		g2d.setColor(new Color(51, 51, 51));
+		g2d.drawString(orderNo, x_order, 1160);
+
+		g2d.dispose();
+
+		ByteArrayOutputStream aos = new ByteArrayOutputStream();
+		ImageIO.write(targetImg, "png", aos);
+		return new ByteArrayInputStream(aos.toByteArray());
+	}
+
+	public static void MyDrawString(String str,int x,int y, Font font40, Graphics2D g2d){
+		int i = 0;
+		int x_next = x;
+		String tempStr= null;
+		while(str.length()>0)
+		{
+			tempStr=str.substring(0, 1);
+			str=str.substring(1, str.length());
+			g2d.drawString(tempStr, x_next, y);
+			
+			if (i == 1) {
+				x_next += 3 +  22;
+			} else if (i == 2) {
+				x_next += 10;
+			} else {
+				x_next += 0 + 22;
+			}
+			i++;
+		}
+	}
+
+	
+	/**
+	 * 鎷夋柊娴锋姤
+	 * @param qrcode
+	 * @param portraitStream
+	 * @param code
+	 * @param rule
+	 * @return
+	 */
+	public static InputStream drawPullNewPoster(InputStream qrcode, InputStream portraitStream, String code, PullNewRuleVO rule) {
+		try {
+			String fontPath = "/usr/share/fonts/yahei.ttf";
+			String fontBoldPath = "/usr/share/fonts/yahei_bold.ttf";
+			String os = System.getProperty("os.name");
+			if (os.toLowerCase().startsWith("win")) {
+				fontPath = "D:/yahei.ttf";
+				fontBoldPath = "D:/yahei_bold.ttf";
+			}
+			Font font24 = Font.createFont(Font.PLAIN, new File(fontPath)).deriveFont(24.0f);
+			Font font34 = Font.createFont(Font.PLAIN, new File(fontPath)).deriveFont(34.0f);
+			Font boldFont24 = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(24.0f);
+
+			int px = 750; // 鍥剧墖瀹藉害
+			int topPicH = 529;
+			int ruleheight = getRuleHeight(boldFont24, rule);
+			int py = topPicH + ruleheight + +226 + 27 * 2;
+
+			final BufferedImage targetImg = new BufferedImage(px, py, BufferedImage.TYPE_INT_RGB);
+
+			HashMap<Key, Object> mapH = new HashMap<Key, Object>();
+			mapH.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);// 鎶楅敮榻柯狅紙鎶楅敮榻挎�诲紑鍏筹級聽聽
+			mapH.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);// 鏂囧瓧鎶楅敮榻柯�
+
+			final Graphics2D g2d = (Graphics2D) targetImg.getGraphics();
+			g2d.setRenderingHints(mapH);
+			g2d.setColor(new Color(255, 54, 104));
+			g2d.fillRect(0, 0, px, py);
+
+			// 椤堕儴鍥剧墖
+			InputStream headStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/invite/pull_new.png");
+			g2d.drawImage(ImageIO.read(headStream), 0, 0, px, 529, null);
+
+			// 瑙勫垯鐧借壊鑳屾櫙 562
+			g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+			g2d.setColor(new Color(255, 255, 255));
+			g2d.fillRoundRect(20, 529, 710, ruleheight, 50, 50);
+
+			// 鍏湀娲诲姩瑙勫垯
+			g2d.setFont(font34);
+			g2d.setColor(new Color(51, 51, 51));
+			g2d.drawString(rule.getRuleName(), 306 - 20, topPicH + 56);
+
+			int y_line = topPicH + 86;
+			g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+			g2d.setColor(new Color(224, 224, 224));
+			// 绗旂敾鐨勮疆寤擄紙鐢荤瑪瀹藉害/绾垮涓�1px锛�
+			BasicStroke bs1 = new BasicStroke(1);
+			g2d.setStroke(bs1);
+			g2d.drawLine(22, y_line, 728, y_line);
+
+			// 鍙宠竟璺�
+			int spacing = 43 + 20;
+			// 鏂囧瓧闂磋窛
+			int fontH = 24;
+			int spacingH = 14;
+			int y_temp = topPicH + 110 + fontH;
+			int fontNum = 10;
+			int maxWidth = 590;
+			
+			// 鏂颁汉濂栧姳绾㈣壊鏂囧瓧
+			String newTitle = rule.getNewTitle();
+			if (!StringUtil.isNullOrEmpty(newTitle)) {
+				g2d.setFont(boldFont24);
+				g2d.setColor(new Color(229, 0, 92));
+				g2d.drawString(rule.getNewRule(), spacing, y_temp);
+
+				g2d.setFont(font24);
+				g2d.setColor(new Color(51, 51, 51));
+				while (newTitle.length() > 0) {
+					y_temp += spacingH + fontH;
+					int lengthNew = ImageUtil.getTextLengthByWidth(g2d, font24, newTitle, maxWidth, fontNum);
+					g2d.drawString(newTitle.substring(0, lengthNew), spacing, y_temp);
+					newTitle = newTitle.substring(lengthNew);
+			   }
+				y_temp = y_temp + fontH +  50;
+			}
+			
+			
+			g2d.setFont(boldFont24);
+			g2d.setColor(new Color(229, 0, 92));
+			g2d.drawString(rule.getInviterRule(), spacing, y_temp);
+
+			g2d.setFont(font24);
+			g2d.setColor(new Color(51, 51, 51));
+			String inviterTitle = rule.getInviterTitle();
+			while (inviterTitle.length() > 0) {
+				y_temp += spacingH + fontH;
+				int lengthNew = ImageUtil.getTextLengthByWidth(g2d, font24, inviterTitle, maxWidth, fontNum);
+				g2d.drawString(inviterTitle.substring(0, lengthNew), spacing, y_temp);
+				inviterTitle = inviterTitle.substring(lengthNew);
+			}
+
+			FontMetrics fm = g2d.getFontMetrics(font24);
+			List<PullNewRuleNumVO> list = rule.getList();
+			for (int i = 0; i < list.size(); i++) {
+				if (i == 0) {
+					y_temp += fontH + 38;
+				} else {
+					y_temp += fontH + spacingH;
+				}
+
+				PullNewRuleNumVO numVO = list.get(i);
+				int codeLength = fm.stringWidth(numVO.getRewardDesc());
+				g2d.drawString(numVO.getNumRange(), 75, y_temp);
+				g2d.drawString(numVO.getRewardDesc(), px - 78 - codeLength, y_temp);
+			}
+
+			// 搴曢儴鍐呭
+			y_temp += 27 + 27;
+			g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+			g2d.setColor(new Color(255, 255, 255));
+			g2d.fillRoundRect(20, y_temp, 710, 226, 50, 50);
+
+			InputStream bottomStream = ImageUtil.class.getClassLoader()
+					.getResourceAsStream("image/invite/blks_ico.png");
+			g2d.drawImage(ImageIO.read(bottomStream), 98, y_temp + 53, 315, 71, null);
+
+			Font font26 = Font.createFont(Font.PLAIN, new File(fontPath)).deriveFont(26.28f);
+			FontMetrics fmcode = g2d.getFontMetrics(font26);
+			String inviteCode = "閭�璇风爜锛�" + code;
+			int codeLength = fmcode.stringWidth(inviteCode);
+			// 鑳屾櫙鑹�
+			g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+			g2d.setColor(new Color(229, 0, 92));
+			g2d.fillRoundRect(98 + 157 - codeLength / 2, y_temp + 138, codeLength + 10, 37, 10, 10);
+			// 閭�璇风爜
+			g2d.setColor(new Color(255, 255, 255));
+			g2d.drawString(inviteCode, 98 + 157 - codeLength / 2 + 10, y_temp + 138 + 27);
+
+			// 浜岀淮鐮佸浘妗�
+			InputStream codeFrame = ImageUtil.class.getClassLoader()
+					.getResourceAsStream("image/invite/qr_code_frame.png");
+			g2d.drawImage(ImageIO.read(codeFrame), 497 + 20, y_temp + 15, 200, 203, null);
+			// 鐢讳簩缁寸爜
+			int codeSize = 175;
+			int pX = 497 + 26;
+			int pY = y_temp + 20;
+			g2d.drawImage(ImageIO.read(qrcode), pX + 8, pY + 8, codeSize, codeSize, null);
+
+			int portraitSize = 200 * 5 / 23 - 5;
+			int pPX = pX + codeSize / 2 - portraitSize / 2 + 10;
+			int pPY = pY + codeSize / 2 - portraitSize / 2;
+			// 澶村儚鐧借壊杈规
+			g2d.setColor(Color.WHITE);
+			g2d.fillRoundRect(pPX - 2, pPY - 2, portraitSize + 4, portraitSize + 4, 5, 5);
+			g2d.setRenderingHints(mapH);
+			// 鐢诲ご鍍�
+			BufferedImage portraitImg = ImageIO.read(portraitStream);
+			portraitImg = ImageUtil.zoomInImage(portraitImg, portraitSize, portraitSize);
+			portraitImg = ImageUtil.roundImage(portraitImg, 10);
+			g2d.drawImage(portraitImg, pPX, pPY, portraitSize, portraitSize, null);
+
+			// 缁撴潫鐢诲浘
+			g2d.dispose();
+			
+			ByteArrayOutputStream aos = new ByteArrayOutputStream();
+			ImageIO.write(targetImg, "JPEG", aos);
+			return new ByteArrayInputStream(aos.toByteArray());
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+		}
+		return null;
+	}
+	
+	private static int getRuleHeight(Font font24, PullNewRuleVO rule) {
+		int px = 200; // 鍥剧墖瀹藉害
+		int py = 200; // 鍥剧墖楂樺害
+		BufferedImage targetImg = new BufferedImage(px, py, BufferedImage.TYPE_INT_RGB);
+		final Graphics2D g2d = (Graphics2D) targetImg.getGraphics();
+		// 鏂囧瓧闂磋窛
+		int fontH = 24;
+		int spacingH = 14;
+		int height = 110 + fontH;
+		
+		int fontNum = 10;
+		int maxWidth = 590;
+		// 鏂颁汉濂栧姳瑙勫垯
+		String newTitle = rule.getNewTitle();
+		if (!StringUtil.isNullOrEmpty(newTitle)) {
+			while (newTitle.length() > 0) {
+				height += spacingH + fontH;
+				int lengthNew = ImageUtil.getTextLengthByWidth(g2d, font24, newTitle, maxWidth, fontNum);
+				newTitle = newTitle.substring(lengthNew);
+		   }
+			height = height + fontH+ 50;
+		}
+		// 閭�璇蜂汉濂栧姳绾㈠瓧
+		String inviterTitle = rule.getInviterTitle();
+		while (inviterTitle.length() > 0) {
+			height += spacingH + fontH;
+			int lengthNew = ImageUtil.getTextLengthByWidth(g2d, font24, inviterTitle, maxWidth, fontNum);
+			inviterTitle = inviterTitle.substring(lengthNew);
+	   }
+		
+		// 濂栧姳鏂瑰紡
+		List<PullNewRuleNumVO> list = rule.getList();
+		for (int i = 0; i < list.size();i ++) {
+			if (i == 0) {
+				height += fontH + 38;
+			} else {
+				height += fontH + spacingH;
+			}
+		}
+		
+		// 搴曢儴绌虹櫧
+		height += 25;
+		return height;
+	}
+	
 }

--
Gitblit v1.8.0