From 31a142ac391b474faa04d82971105cc608a0f973 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期日, 17 五月 2020 19:29:44 +0800
Subject: [PATCH] 新版饿了么相关接口添加

---
 fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java |  201 +++++++++++++++++++++++++++++++++++++------------
 1 files changed, 150 insertions(+), 51 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 8f5f1b8..aed7789 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java
@@ -195,7 +195,8 @@
 
 			// 浜岀淮鐮佸浘妗�
 			g2d.setColor(Color.WHITE);
-			InputStream codeFrame = ImageUtil.class.getClassLoader().getResourceAsStream("image/share/qr_code_frame_xcx.png");
+			InputStream codeFrame = ImageUtil.class.getClassLoader()
+					.getResourceAsStream("image/share/qr_code_frame_xcx.png");
 			g2d.drawImage(ImageIO.read(codeFrame), spacing + 405, y + 20, 200, 220, null);
 			// 鐢讳簩缁寸爜
 			int codeSize = 170;
@@ -208,9 +209,10 @@
 			} catch (Exception e) {
 				e.printStackTrace();
 			}
-			
+
 			if (portraitStream == null) {
-				portraitStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/official_default_head.jpg");
+				portraitStream = ImageUtil.class.getClassLoader()
+						.getResourceAsStream("image/official_default_head.jpg");
 			}
 			BufferedImage portraitImg = ImageIO.read(portraitStream);
 			BufferedImage zoomInImage = ImageUtil.zoomInImage(portraitImg, 84, 84);
@@ -240,7 +242,7 @@
 		}
 		return null;
 	}
-	
+
 	/**
 	 * 鍒嗘瀽娴锋姤鍥�
 	 * @param qrcode
@@ -248,7 +250,7 @@
 	 * @param goods
 	 * @return
 	 */
-	public static InputStream drawGoodsPoster(InputStream qrcode, InputStream portraitStream, String inviteCode, 
+	public static InputStream drawGoodsPoster(InputStream qrcode, InputStream portraitStream, String inviteCode,
 			String mainPic, GoodsDetailVO goods) {
 		try {
 			String fontPath = "/usr/share/fonts/PingFang_Medium.ttf";
@@ -266,7 +268,7 @@
 			Font boldFont36 = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(36.0f);
 
 			int px = 640; // 鍥剧墖瀹藉害
-//			int py = 1154; // 鍥剧墖楂樺害 鏄剧ず閭�璇风爜
+			// 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>();
@@ -284,9 +286,10 @@
 
 			// 1銆佺敾鍟嗗搧涓诲浘
 			InputStream picStream = HttpUtil.getAsInputStream(mainPic);
-//			InputStream picStream  = ImageUtil.class.getClassLoader().getResourceAsStream("image/share/test_pic1.jpg");
+			// 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;
@@ -331,8 +334,7 @@
 			} else {
 				g2d.drawString(title.substring(0, length2), spacing, y + 45 + row * 36);
 			}
-			
-			
+
 			int baoYouLength = spacing;
 			if (!goods.isHasCoupon()) {
 				// 鏃犲埜
@@ -345,14 +347,14 @@
 				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);
+				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);
@@ -372,8 +374,8 @@
 				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;
+
+				baoYouLength = spacing + 42 + textLength + 20 + 20;
 			}
 
 			// 鑷惀 銆佸寘閭�
@@ -385,7 +387,6 @@
 				ziying = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_baoyou.png");
 				g2d.drawImage(ImageIO.read(ziying), baoYouLength, y + 150, 60, 30, null);
 			}
-			
 
 			// 閿�閲�
 			String sale = null;
@@ -407,26 +408,25 @@
 			g2d.setFont(font24);
 			g2d.setColor(new Color(153, 153, 153));
 			g2d.drawString(sale, spacing + 605 - textLength, y + 125);
-			
-			
+
 			// 涓嬪崟鎻愮ず
-			InputStream downTip = null;	
+			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");
+			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;
+			int pX = spacing + 422;
+			int pY = y + 217;
 			g2d.drawImage(ImageIO.read(qrcode), pX, pY, codeSize, codeSize, null);
 
 			int portraitSize = 200 * 5 / 23;
@@ -441,28 +441,34 @@
 			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.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();
@@ -477,7 +483,7 @@
 			}
 		}
 		return null;
-	
+
 	}
 
 	/**
@@ -1566,9 +1572,9 @@
 					// 鐢诲埜
 					BigDecimal withNoZera = MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount());
 					if (withNoZera != null && withNoZera.compareTo(new BigDecimal(0)) > 0) {
-//						// 鐢婚�忔槑鑳屾櫙
-//						g2d.setColor(new Color(255, 255, 255, 210));
-//						g2d.fillRect(topX + 8, topY + 240, 300, 65);
+						// // 鐢婚�忔槑鑳屾櫙
+						// g2d.setColor(new Color(255, 255, 255, 210));
+						// g2d.fillRect(topX + 8, topY + 240, 300, 65);
 
 						g2d.setRenderingHints(mapH);
 
@@ -1576,7 +1582,7 @@
 						int size = withNoZera.toString().length() * 22;
 						int place = withNoZera.toString().length() * 22;
 
-//						// 鍒哥孩鑹插簳閮�
+						// // 鍒哥孩鑹插簳閮�
 						int quanBGWidht = topX + 170 - place;
 						int quanBGHeight = topY + 220;
 						g2d.setColor(new Color(229, 0, 92));
@@ -2385,4 +2391,97 @@
 		out.close();
 	}
 
+	public static InputStream drawAlipayImage(InputStream bg, String recieveTime, String money, String orderNo,
+			String ttf) {
+		try {
+			String fontPath = "/usr/share/fonts/PingFang_Medium.ttf";
+			String os = System.getProperty("os.name");
+			if (os.toLowerCase().startsWith("win")) {
+				fontPath = ttf;
+			}
+
+			String fontBoldPath = "/usr/share/fonts/PingFang_Heavy_0.ttf";
+			if (os.toLowerCase().startsWith("win")) {
+				fontBoldPath = "D:/PingFang_Heavy_0.ttf";
+			}
+			int px = 1080; // 鍥剧墖瀹藉害
+			int py = 2340; // 鍥剧墖楂樺害
+			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.decode("#333333"));
+			g2d.fillRect(0, 0, px, py);
+
+			BufferedImage bgImage = ImageIO.read(bg);
+			g2d.drawImage(bgImage, null, 0, 0);
+
+			Font font = Font.createFont(Font.PLAIN, new File(fontPath)).deriveFont(87.0f);
+			g2d.setFont(font);
+
+			// 鐢婚噾棰�
+			FontMetrics fm = g2d.getFontMetrics(font);
+			fm.stringWidth(money);
+
+			g2d.drawString(money, (px - fm.stringWidth(money)) / 2, 359 + 65);
+
+			// 鐢诲垱寤烘椂闂�
+
+			// 鐢昏鍗�
+
+			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 drawSimpleImage(InputStream bg, int width, int height, InputStream imgStream,
+			int imgWidth, int imgHeight, int px, int py) {
+		try {
+			final BufferedImage targetImg = new BufferedImage(width, height, 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.decode("#333333"));
+			g2d.fillRect(0, 0, px, py);
+
+			BufferedImage bgImage = ImageIO.read(bg);
+			g2d.drawImage(bgImage, null, 0, 0);
+
+			BufferedImage img = zoomInImage(ImageIO.read(imgStream), imgWidth, imgHeight);
+
+			g2d.drawImage(img, px, py, null);
+
+			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;
+	}
+
 }

--
Gitblit v1.8.0