Browse Source

watero母亲节活动

wangxiaoming 6 years ago
parent
commit
8fbff21a31

+ 44 - 24
watero-common-tool/src/main/java/com/iamberry/wechat/tools/ImageUtils.java

@@ -2,6 +2,7 @@ package com.iamberry.wechat.tools;
 
 
 import com.mortennobel.imagescaling.ResampleFilters;
 import com.mortennobel.imagescaling.ResampleFilters;
 import com.mortennobel.imagescaling.ResampleOp;
 import com.mortennobel.imagescaling.ResampleOp;
+import org.apache.commons.lang3.StringUtils;
 
 
 import javax.imageio.ImageIO;
 import javax.imageio.ImageIO;
 import java.awt.*;
 import java.awt.*;
@@ -76,26 +77,32 @@ public final class ImageUtils {
 
 
 
 
         String newImg = "E:\\java-work\\iamberry-watero\\watero-wechat-web\\target\\watero-wechat-web-1.0.0\\common\\images\\movable\\1.jpg";
         String newImg = "E:\\java-work\\iamberry-watero\\watero-wechat-web\\target\\watero-wechat-web-1.0.0\\common\\images\\movable\\1.jpg";
-        String headImg = "E:\\java-work\\iamberry-watero\\watero-wechat-web\\target\\watero-wechat-web-1.0.0\\common\\images\\movable\\7a7620fb_head.jpg";
-        String codeImg = "E:\\java-work\\iamberry-watero\\watero-wechat-web\\target\\watero-wechat-web-1.0.0\\common\\images\\movable\\7a7620fb_code.jpg";
+        String headImg = "E:\\java-work\\iamberry-watero\\watero-wechat-web\\target\\watero-wechat-web-1.0.0\\common\\images\\movable\\ff18fcf3_head.jpg";
+        String codeImg = "E:\\java-work\\iamberry-watero\\watero-wechat-web\\target\\watero-wechat-web-1.0.0\\common\\images\\movable\\545e3eeb_code.jpg";
         String text = "小茗同学";
         String text = "小茗同学";
-        String alltext = "慈母手中线,\n游子身上衣。\n临行密密缝,\n意恐迟迟归。\n谁言寸草心,\n报得三春晖!";
-//        String alltext = "You are the best mom thatsdafsadasfsadsaf a son ever had.\nSometimes it may not seem like it, but I really do love you.God could not be everywhere and therefore he made mothers.";
+        String alltext = "慈母手中线,游子身上衣。临行密密缝,意恐迟迟归。谁言寸草心,报得三春晖!报得三春晖!报得三春晖!报得三春晖!!!";
+//        String alltext = "You are the best mom,th,asssx had.\nSometimes it may not seem like it, but";
 
 
 
 
+        PosterNumUtils pnu = new PosterNumUtils(0);
+
         try {
         try {
             ImageUtils.pressPost(newImg,
             ImageUtils.pressPost(newImg,
-                    headImg,PosterNumUtils.HEAD_X,PosterNumUtils.HEAD_Y,
-                    codeImg,PosterNumUtils.CODE_X,PosterNumUtils.CODE_Y,
-                    text,PosterNumUtils.TEXT_X,PosterNumUtils.TEXT_Y,new Color(221,106,140),PosterNumUtils.TEXT_FONT_SIZE,
-                    alltext,PosterNumUtils.TEXT_CONTENT_X,PosterNumUtils.TEXT_CONTENT_Y,new Color(0,0,0),PosterNumUtils.TEXT_CONTENT_FONT_SIZE
+                    headImg,pnu.HEAD_X,pnu.HEAD_Y,
+                    codeImg,pnu.CODE_X,pnu.CODE_Y,
+                    text,pnu.TEXT_X,pnu.TEXT_Y,new Color(0,0,0),pnu.TEXT_FONT_SIZE,
+                    alltext,pnu.TEXT_CONTENT_X,pnu.TEXT_CONTENT_Y,new Color(0,0,0),pnu.TEXT_CONTENT_FONT_SIZE,
+                    pnu.FONT_LINE_SPACING,pnu.FONT_NUMBER
             );
             );
         } catch (Exception e) {
         } catch (Exception e) {
             e.printStackTrace();
             e.printStackTrace();
         }
         }
+
+//        String newString = new String("三大将大".getBytes("GB2312"), "ISO-8859-1");
+//        System.out.println(newString.length());
+
 //        String ENCODE = "utf-8";
 //        String ENCODE = "utf-8";
 //        String name = java.net.URLDecoder.decode( "%E5%B0%8F%E8%8C%97%E5%90%8C%E5%AD%A6", ENCODE);
 //        String name = java.net.URLDecoder.decode( "%E5%B0%8F%E8%8C%97%E5%90%8C%E5%AD%A6", ENCODE);
-//
 //        System.out.println(name);
 //        System.out.println(name);
 
 
     }
     }
@@ -107,7 +114,7 @@ public final class ImageUtils {
                                  String srcImg1, int imgx1, int imgy1,
                                  String srcImg1, int imgx1, int imgy1,
                                  String srcImg2, int imgx2, int imgy2,
                                  String srcImg2, int imgx2, int imgy2,
                                  String headText, int x, int y,Color xyColorName,int xySizeNum,
                                  String headText, int x, int y,Color xyColorName,int xySizeNum,
-                                 String pressText, int m, int n,Color mnColorName,int mnSizeNum
+                                 String pressText, int m, int n,Color mnColorName,int mnSizeNum,int fontLineSpacing,int fontNumber
     ) throws Exception{
     ) throws Exception{
         float alpha = 1;
         float alpha = 1;
 
 
@@ -127,11 +134,11 @@ public final class ImageUtils {
         List<String> strList = new ArrayList<>();
         List<String> strList = new ArrayList<>();
         String strs[] = pressText.split("\n");
         String strs[] = pressText.split("\n");
         for (String s : strs) {
         for (String s : strs) {
-            strList.addAll(getStrArr(s));
+            strList.addAll(getStrArr(s,fontNumber));
         }
         }
         for (String strCon :  strList) {    //循环行生成文本
         for (String strCon :  strList) {    //循环行生成文本
             customText(g,width,height,strCon,"微软雅黑",mnSizeNum,mnColorName,Font.PLAIN,m,n);
             customText(g,width,height,strCon,"微软雅黑",mnSizeNum,mnColorName,Font.PLAIN,m,n);
-            n += PosterNumUtils.FONT_LINE_SPACING;
+            n += fontLineSpacing;
         }
         }
 
 
         Image tarImage = ImageIO.read(new File(srcImg1));
         Image tarImage = ImageIO.read(new File(srcImg1));
@@ -149,7 +156,7 @@ public final class ImageUtils {
      * @param text
      * @param text
      * @return
      * @return
      */
      */
-    public static List<String> getStrArr(String text){
+    public static List<String> getStrArr(String text,int fontNumber){
         if(text == null){
         if(text == null){
             return new ArrayList<>();
             return new ArrayList<>();
         }
         }
@@ -157,7 +164,7 @@ public final class ImageUtils {
         List<String> strList = new ArrayList<>();
         List<String> strList = new ArrayList<>();
         StringBuffer temp = new StringBuffer();
         StringBuffer temp = new StringBuffer();
         while (text.length() > num){
         while (text.length() > num){
-            if(i >= PosterNumUtils.FONT_NUMBER){
+            if(i >= fontNumber){
                 strList.add(temp.toString());
                 strList.add(temp.toString());
                 temp = new StringBuffer();
                 temp = new StringBuffer();
                 i = 0;
                 i = 0;
@@ -168,17 +175,28 @@ public final class ImageUtils {
             try {
             try {
                 String newString = new String(x.getBytes("GB2312"), "ISO-8859-1");
                 String newString = new String(x.getBytes("GB2312"), "ISO-8859-1");
                 i+=newString.length();
                 i+=newString.length();
-                if(32 == c){    //英文状态下,本行字母写不下,换行
-                    String later = text.substring(num,text.length());
-                    if(later.indexOf(" ") > -1 && later.indexOf(" ",later.indexOf(" ")+1) > 1){
-                        String a = later.substring(0,later.indexOf(" ",later.indexOf(" ")+1));   //str.indexOf("a", str.indexOf("a")+1)
-                        if((a.length()+i) >  PosterNumUtils.FONT_NUMBER){
-                            strList.add(temp.toString());
+                if(32 == c || 46 == c || 44 ==c){    //英文状态下,本行字母写不下,换行
+                    temp.append(c);
+                    isWarp = true;
+
+                    String later = text.substring(num+1,text.length());
+                    int shortest = text.length();   //下一个单词的长度
+                    if(later.indexOf(" ") > 0 &&  later.indexOf(" ") < shortest){
+                        shortest = later.indexOf(" ");
+                    }
+                    if(later.indexOf(",") > 0 &&  later.indexOf(",") < shortest){
+                        shortest = later.indexOf(",");
+                    }
+                    if(later.indexOf(".") > 0 &&  later.indexOf(".") < shortest){
+                        shortest = later.indexOf(".");
+                    }
+                   if(shortest > 0){
+                       if((i + shortest) > fontNumber){
+                           strList.add(temp.toString());
                             temp = new StringBuffer();
                             temp = new StringBuffer();
                             i = 0;
                             i = 0;
-                            isWarp = true;
-                        }
-                    }
+                       }
+                   }
                 }
                 }
             } catch (UnsupportedEncodingException e) {
             } catch (UnsupportedEncodingException e) {
                 e.printStackTrace();
                 e.printStackTrace();
@@ -188,7 +206,9 @@ public final class ImageUtils {
             }
             }
             num++;
             num++;
         }
         }
-        strList.add(temp.toString());
+        if(!StringUtils.isEmpty(temp.toString())){
+            strList.add(temp.toString());
+        }
         return strList;
         return strList;
     }
     }
 
 

+ 69 - 19
watero-common-tool/src/main/java/com/iamberry/wechat/tools/PosterNumUtils.java

@@ -10,43 +10,94 @@ import java.util.Map;
 
 
 @Component
 @Component
 public class PosterNumUtils {
 public class PosterNumUtils {
+
+    private PosterNumUtils(){
+    }
+
+    /**
+     * 构造
+     * @param type
+     */
+    public PosterNumUtils(Integer type){
+        PosterNumUtils pnu = new PosterNumUtils();
+        switch (type){
+            case 1://头像在中间
+                //二维码大小
+                pnu.CODE_WIDTH = 106;
+                pnu.CODE_HEIGHT = 106;
+                //头像大小
+                pnu.HEAD_WIDTH = 132;
+                pnu.HEAD_HEIGHT = 132;
+                pnu.HEAD_IS_CIRCLE = false;  //头像是否圆形
+
+                /*文字位置 -- 昵称*/
+                pnu.TEXT_X = -1; //居中
+                pnu.TEXT_Y = 208;
+                pnu.TEXT_FONT_SIZE = 30;
+
+                /*文字位置 -- 文本 - 起始位置*/
+                pnu.TEXT_CONTENT_X = 170; //居中
+                pnu.TEXT_CONTENT_Y = 270;
+                pnu.TEXT_CONTENT_FONT_SIZE = 26;
+
+                /*每行文字字符限制数量,中文算两个字符,所以只能是双数*/
+                pnu.FONT_NUMBER = 28;
+
+                //每行间距 - 行距
+                pnu.FONT_LINE_SPACING = 71;
+
+                /*头像位置*/
+                pnu.HEAD_X = 309;
+                pnu.HEAD_Y = 38;
+
+                /*二维码位置*/
+                pnu.CODE_X = 620;
+                pnu.CODE_Y = 1077;
+                break;
+            default://通用,传 0
+                break;
+        }
+    }
+
+
     //背景色集合
     //背景色集合
     private static Map<Integer,String> map = new HashMap<>();
     private static Map<Integer,String> map = new HashMap<>();
 
 
-    public static final String IMG_PATH = "common/images/movable/";
-    public static final String OLD_IMG_PATH = "common/images/movable/ditu.jpg";
+    public  String IMG_PATH = "common/images/movable/";
+    public  String OLD_IMG_PATH = "common/images/movable/ditu.jpg";
 
 
     /*二维码大小*/
     /*二维码大小*/
-    public static final int CODE_WIDTH = 106;
-    public static final int CODE_HEIGHT = 106;
+    public  int CODE_WIDTH = 144;
+    public  int CODE_HEIGHT = 144;
 
 
     /*头像大小*/
     /*头像大小*/
-    public static final int HEAD_WIDTH = 132;
-    public static final int HEAD_HEIGHT = 132;
+    public  int HEAD_WIDTH = 124;
+    public  int HEAD_HEIGHT = 124;
+    public  boolean HEAD_IS_CIRCLE = false;  //头像是否圆形
 
 
     /*文字位置 -- 昵称*/
     /*文字位置 -- 昵称*/
-    public static final int TEXT_X = -1; //居中
-    public static final int TEXT_Y = 208;
-    public static final int TEXT_FONT_SIZE = 30;
+    public  int TEXT_X = 107; //居中
+    public  int TEXT_Y = 243;
+    public  int TEXT_FONT_SIZE = 18;
 
 
     /*文字位置 -- 文本 - 起始位置*/
     /*文字位置 -- 文本 - 起始位置*/
-    public static final int TEXT_CONTENT_X = 170; //居中
-    public static final int TEXT_CONTENT_Y = 270;
-    public static final int TEXT_CONTENT_FONT_SIZE = 26;
+    public  int TEXT_CONTENT_X = 170; //居中
+    public  int TEXT_CONTENT_Y = 478;
+    public  int TEXT_CONTENT_FONT_SIZE = 27;
 
 
     /*每行文字字符限制数量,中文算两个字符,所以只能是双数*/
     /*每行文字字符限制数量,中文算两个字符,所以只能是双数*/
-    public static final int FONT_NUMBER = 28;
+    public  int FONT_NUMBER = 28;
 
 
     //每行间距 - 行距
     //每行间距 - 行距
-    public static final int FONT_LINE_SPACING = 71;
+    public  int FONT_LINE_SPACING = 48;
 
 
     /*头像位置*/
     /*头像位置*/
-    public static final int HEAD_X = 309;
-    public static final int HEAD_Y = 38;
+    public  int HEAD_X = 107;
+    public  int HEAD_Y = 94;
 
 
     /*二维码位置*/
     /*二维码位置*/
-    public static final int CODE_X = 620;
-    public static final int CODE_Y = 1077;
+    public  int CODE_X = 490;
+    public  int CODE_Y = 830;
 
 
     static {
     static {
         map.put(0,"head.jpg");  //默认头像
         map.put(0,"head.jpg");  //默认头像
@@ -56,7 +107,6 @@ public class PosterNumUtils {
         map.put(4,"4.jpg");  //4
         map.put(4,"4.jpg");  //4
         map.put(5,"5.jpg");  //5
         map.put(5,"5.jpg");  //5
     }
     }
-
     public static String  getBackPath(Integer type){
     public static String  getBackPath(Integer type){
         return "back/"+map.get(type);
         return "back/"+map.get(type);
     }
     }

+ 4 - 0
watero-common-tool/src/main/java/com/iamberry/wechat/tools/ResultInfo.java

@@ -69,6 +69,10 @@ public class ResultInfo {
 	 */
 	 */
 	public  static String messageIsNullResponseText = "";									// 用户发送信息为空时的回复文本
 	public  static String messageIsNullResponseText = "";									// 用户发送信息为空时的回复文本
 	/**
 	/**
+	 * 母亲节回复文本内容
+	 */
+	public  static String messageMothMsg = "";									// 母亲节回复文本内容
+	/**
 	 * 异常时回复信息
 	 * 异常时回复信息
 	 */
 	 */
 	public  static String tryCatchDefaultResponseText = "";									
 	public  static String tryCatchDefaultResponseText = "";									

+ 1 - 0
watero-common-tool/src/main/java/com/iamberry/wechat/tools/loadResultUtil.java

@@ -53,6 +53,7 @@ public class loadResultUtil {
 			ResultInfo.subDefaultResponseText=prop.getProperty("subDefaultResponseText");
 			ResultInfo.subDefaultResponseText=prop.getProperty("subDefaultResponseText");
 			ResultInfo.messageDefaultResponseText=prop.getProperty("messageDefaultResponseText");
 			ResultInfo.messageDefaultResponseText=prop.getProperty("messageDefaultResponseText");
 			ResultInfo.messageIsNullResponseText=prop.getProperty("messageIsNullResponseText");
 			ResultInfo.messageIsNullResponseText=prop.getProperty("messageIsNullResponseText");
+			ResultInfo.messageMothMsg=prop.getProperty("messageMothMsg");
 			ResultInfo.tryCatchDefaultResponseText=prop.getProperty("tryCatchDefaultResponseText");
 			ResultInfo.tryCatchDefaultResponseText=prop.getProperty("tryCatchDefaultResponseText");
 			ResultInfo.rebateOrderText=prop.getProperty("rebateOrderText");
 			ResultInfo.rebateOrderText=prop.getProperty("rebateOrderText");
 			
 			

+ 14 - 8
watero-wechat-service/src/main/java/com/iamberry/wechat/service/mothMovable/MothMovableServiceImpl.java

@@ -132,12 +132,17 @@ public class MothMovableServiceImpl  implements MothMovableService {
      * @return
      * @return
      */
      */
     private boolean geneImg(MothMovable mothMovable,String rootPath)throws Exception{
     private boolean geneImg(MothMovable mothMovable,String rootPath)throws Exception{
+        Integer type = 0;
+        if(mothMovable.getMothMovaBackType() == 5){
+            type = 1;   //头像放在中间
+        }
+        PosterNumUtils pnu = new PosterNumUtils(type);
         //  ****/common/images/movable/
         //  ****/common/images/movable/
         String uuid = UUID.randomUUID().toString().substring(0,8);
         String uuid = UUID.randomUUID().toString().substring(0,8);
         String codeName  = uuid + "_code.jpg";
         String codeName  = uuid + "_code.jpg";
         String headName  = uuid + "_head.jpg";
         String headName  = uuid + "_head.jpg";
         String imgName  = uuid + "_img.jpg";
         String imgName  = uuid + "_img.jpg";
-        String path  = rootPath + PosterNumUtils.IMG_PATH;
+        String path  = rootPath + pnu.IMG_PATH;
 
 
         File targetFile = new File(path);
         File targetFile = new File(path);
         if (!targetFile.exists()) {
         if (!targetFile.exists()) {
@@ -149,14 +154,14 @@ public class MothMovableServiceImpl  implements MothMovableService {
         QRCJson qrc = WeixinUtil.createQrcode(json);
         QRCJson qrc = WeixinUtil.createQrcode(json);
 
 
        /*下载二维码*/
        /*下载二维码*/
-        DownloadWXCodeUtil.downloadByNIO2(qrc.getUrl(),codeName,path,PosterNumUtils.CODE_WIDTH,PosterNumUtils.CODE_HEIGHT,false);
+        DownloadWXCodeUtil.downloadByNIO2(qrc.getUrl(),codeName,path,pnu.CODE_WIDTH,pnu.CODE_HEIGHT,false);
 
 
         if(mothMovable.getMothMovaHead() == null || "".equals(mothMovable.getMothMovaHead())){
         if(mothMovable.getMothMovaHead() == null || "".equals(mothMovable.getMothMovaHead())){
             String headImg = path+headName;
             String headImg = path+headName;
             String oldheadImg = path+PosterNumUtils.getBackPath(0);
             String oldheadImg = path+PosterNumUtils.getBackPath(0);
             FileUtils.copyFile(oldheadImg,headImg);
             FileUtils.copyFile(oldheadImg,headImg);
         }else{
         }else{
-            DownloadWXCodeUtil.downloadByNIO2(mothMovable.getMothMovaHead(),headName,path,PosterNumUtils.HEAD_WIDTH,PosterNumUtils.HEAD_HEIGHT,true);
+            DownloadWXCodeUtil.downloadByNIO2(mothMovable.getMothMovaHead(),headName,path,pnu.HEAD_WIDTH,pnu.HEAD_HEIGHT,pnu.HEAD_IS_CIRCLE);
         }
         }
 
 
 
 
@@ -171,15 +176,16 @@ public class MothMovableServiceImpl  implements MothMovableService {
         String oldImgPath = path + PosterNumUtils.getBackPath(mothMovable.getMothMovaBackType());
         String oldImgPath = path + PosterNumUtils.getBackPath(mothMovable.getMothMovaBackType());
         FileUtils.copyFile(oldImgPath,newImg);
         FileUtils.copyFile(oldImgPath,newImg);
 
 
-        mothMovable.setMothMovaImgUrl(PosterNumUtils.IMG_PATH + imgName);
+        mothMovable.setMothMovaImgUrl(pnu.IMG_PATH + imgName);
         mothMovable.setMothMovaShareUrl(qrc.getUrl());
         mothMovable.setMothMovaShareUrl(qrc.getUrl());
 
 
 			  /*添加文字*/
 			  /*添加文字*/
         ImageUtils.pressPost(newImg,
         ImageUtils.pressPost(newImg,
-                headImg,PosterNumUtils.HEAD_X,PosterNumUtils.HEAD_Y,
-                codeImg,PosterNumUtils.CODE_X,PosterNumUtils.CODE_Y,
-                mothMovable.getMothMovaName(),PosterNumUtils.TEXT_X,PosterNumUtils.TEXT_Y,new Color(221,106,140),PosterNumUtils.TEXT_FONT_SIZE,
-                mothMovable.getMothMovaText(),PosterNumUtils.TEXT_CONTENT_X,PosterNumUtils.TEXT_CONTENT_Y,new Color(0,0,0),PosterNumUtils.TEXT_CONTENT_FONT_SIZE
+                headImg,pnu.HEAD_X,pnu.HEAD_Y,
+                codeImg,pnu.CODE_X,pnu.CODE_Y,
+                mothMovable.getMothMovaName(),pnu.TEXT_X,pnu.TEXT_Y,new Color(221,106,140),pnu.TEXT_FONT_SIZE,
+                mothMovable.getMothMovaText(),pnu.TEXT_CONTENT_X,pnu.TEXT_CONTENT_Y,new Color(0,0,0),pnu.TEXT_CONTENT_FONT_SIZE,
+                pnu.FONT_LINE_SPACING,pnu.FONT_NUMBER
         );
         );
         return true;
         return true;
     }
     }

+ 1 - 1
watero-wechat-service/src/main/java/com/iamberry/wechat/service/wechat/WeChatServiceImpl.java

@@ -322,7 +322,7 @@ public class WeChatServiceImpl implements WeChatService {
 			senceid = senceid.replaceAll(ResultInfo.barCode,"");
 			senceid = senceid.replaceAll(ResultInfo.barCode,"");
 		}
 		}
 		Integer flag = mothMovableService.scanInfo(senceid,member.getUserOpenid());
 		Integer flag = mothMovableService.scanInfo(senceid,member.getUserOpenid());
-		status.setCountext("活动链接:");
+		status.setCountext(ResultInfo.messageMothMsg);
 		status.setFlag(false);
 		status.setFlag(false);
 		return status;
 		return status;
 	}
 	}

+ 4 - 2
watero-wechat-web/src/main/java/com/iamberry/wechat/handles/mothMovable/MothMovableHandler.java

@@ -70,8 +70,10 @@ public class MothMovableHandler {
         if(mothMovable.getMothMovaText() == null || "".equals(mothMovable.getMothMovaText())){
         if(mothMovable.getMothMovaText() == null || "".equals(mothMovable.getMothMovaText())){
             return new ResultMsg(false,  ResultMsg.ERROR, "未输入文字",null);
             return new ResultMsg(false,  ResultMsg.ERROR, "未输入文字",null);
         }
         }
-        if(mothMovable.getMothMovaText().length() > 200){
-            return new ResultMsg(false,  ResultMsg.ERROR, "文字超出限制",null);
+
+        String newString = new String(mothMovable.getMothMovaText().getBytes("GB2312"), "ISO-8859-1");
+        if(newString.length() > 112){
+            return new ResultMsg(false,  ResultMsg.ERROR, "文字超出限制,最大支持56个文字",null);
         }
         }
 
 
         MothMovable mothM = new MothMovable();
         MothMovable mothM = new MothMovable();

File diff suppressed because it is too large
+ 1 - 0
watero-wechat-web/src/main/resources/ResultInfo.properties