by su vor 3 Jahren
Ursprung
Commit
77da602d45

+ 12 - 0
4dkankan-common-utils/pom.xml

@@ -105,6 +105,12 @@
         </dependency>
 
         <dependency>
+            <groupId>com.aliyun</groupId>
+            <artifactId>aliyun-java-sdk-dysmsapi</artifactId>
+            <version>1.1.0</version>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-lang3</artifactId>
         </dependency>
@@ -127,6 +133,12 @@
         </dependency>
 
         <dependency>
+            <groupId>com.google.zxing</groupId>
+            <artifactId>javase</artifactId>
+            <version>2.1</version>
+        </dependency>
+
+        <dependency>
             <groupId>joda-time</groupId>
             <artifactId>joda-time</artifactId>
             <version>2.9.9</version>

+ 15 - 0
4dkankan-common-utils/src/main/java/com/fdkankan/common/request/RequestBase.java

@@ -0,0 +1,15 @@
+package com.fdkankan.common.request;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class RequestBase implements Serializable {
+
+    private int pageNum = 1;
+
+    private int pageSize = 10;
+
+    private int start;
+}

+ 152 - 0
4dkankan-common-utils/src/main/java/com/fdkankan/common/validation/SensitiveWord.java

@@ -0,0 +1,152 @@
+package com.fdkankan.common.validation;
+
+import com.fdkankan.common.constant.ConstantFileName;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ *  敏感词过滤
+ */
+public class SensitiveWord {
+    @SuppressWarnings("rawtypes")
+    public Map sensitiveWordMap = null;
+    public static int minMatchTYpe = 1;      //最小匹配规则
+    public static int maxMatchType = 2;      //最大匹配规则
+
+    /**
+     * 构造函数,初始化敏感词库
+     */
+    public SensitiveWord(){
+        if (sensitiveWordMap == null){
+            String txtPath = this.getClass().getResource("/static/txt/"+ ConstantFileName.BBS_SENSITIVE).getPath();
+            sensitiveWordMap = new SensitiveWordConfig().initKeyWord(txtPath);
+        }
+    }
+
+    /**
+     * 判断文字是否包含敏感字符
+     * @author chenming
+     * @date 2014年4月20日 下午4:28:30
+     * @param txt  文字
+     * @param matchType  匹配规则&nbsp;1:最小匹配规则,2:最大匹配规则
+     * @return 若包含返回true,否则返回false
+     * @version 1.0
+     */
+    public boolean isContaintSensitiveWord(String txt,int matchType){
+        boolean flag = false;
+        for(int i = 0 ; i < txt.length() ; i++){
+            int matchFlag = this.CheckSensitiveWord(txt, i, matchType); //判断是否包含敏感字符
+            if(matchFlag > 0){    //大于0存在,返回true
+                flag = true;
+            }
+        }
+        return flag;
+    }
+
+    /**
+     * 获取文字中的敏感词
+     * @author chenming
+     * @date 2014年4月20日 下午5:10:52
+     * @param txt 文字
+     * @param matchType 匹配规则&nbsp;1:最小匹配规则,2:最大匹配规则
+     * @return
+     * @version 1.0
+     */
+    public Set<String> getSensitiveWord(String txt , int matchType){
+        Set<String> sensitiveWordList = new HashSet<String>();
+
+        for(int i = 0 ; i < txt.length() ; i++){
+            int length = CheckSensitiveWord(txt, i, matchType);    //判断是否包含敏感字符
+            if(length > 0){    //存在,加入list中
+                sensitiveWordList.add(txt.substring(i, i+length));
+                i = i + length - 1;    //减1的原因,是因为for会自增
+            }
+        }
+
+        return sensitiveWordList;
+    }
+
+    /**
+     * 替换敏感字字符
+     * @author chenming
+     * @date 2014年4月20日 下午5:12:07
+     * @param txt
+     * @param matchType
+     * @param replaceChar 替换字符,默认*
+     * @version 1.0
+     */
+    public String replaceSensitiveWord(String txt,int matchType,String replaceChar){
+        String resultTxt = txt;
+        Set<String> set = getSensitiveWord(txt, matchType);     //获取所有的敏感词
+        Iterator<String> iterator = set.iterator();
+        String word = null;
+        String replaceString = null;
+        while (iterator.hasNext()) {
+            word = iterator.next();
+            replaceString = getReplaceChars(replaceChar, word.length());
+            resultTxt = resultTxt.replaceAll(word, replaceString);
+        }
+
+        return resultTxt;
+    }
+
+    /**
+     * 获取替换字符串
+     * @author chenming
+     * @date 2014年4月20日 下午5:21:19
+     * @param replaceChar
+     * @param length
+     * @return
+     * @version 1.0
+     */
+    private String getReplaceChars(String replaceChar,int length){
+        String resultReplace = replaceChar;
+        for(int i = 1 ; i < length ; i++){
+            resultReplace += replaceChar;
+        }
+
+        return resultReplace;
+    }
+
+    /**
+     * 检查文字中是否包含敏感字符,检查规则如下:<br>
+     * @author chenming
+     * @date 2014年4月20日 下午4:31:03
+     * @param txt
+     * @param beginIndex
+     * @param matchType
+     * @return,如果存在,则返回敏感词字符的长度,不存在返回0
+     * @version 1.0
+     */
+    @SuppressWarnings({ "rawtypes"})
+    public int CheckSensitiveWord(String txt,int beginIndex,int matchType){
+        boolean  flag = false;    //敏感词结束标识位:用于敏感词只有1位的情况
+        int matchFlag = 0;     //匹配标识数默认为0
+        char word = 0;
+
+        Map nowMap = sensitiveWordMap;
+        for(int i = beginIndex; i < txt.length() ; i++){
+            word = txt.charAt(i);
+            nowMap = (Map) nowMap.get(word);     //获取指定key
+            if(nowMap != null){     //存在,则判断是否为最后一个
+                matchFlag++;     //找到相应key,匹配标识+1
+                if("1".equals(nowMap.get("isEnd"))){       //如果为最后一个匹配规则,结束循环,返回匹配标识数
+                    flag = true;       //结束标志位为true
+                    if(SensitiveWord.minMatchTYpe == matchType){    //最小规则,直接返回,最大规则还需继续查找
+                        break;
+                    }
+                }
+            }
+            else{     //不存在,直接返回
+                break;
+            }
+        }
+        if(matchFlag < 2 || !flag){        //长度必须大于等于1,为词
+            matchFlag = 0;
+        }
+        return matchFlag;
+    }
+}

+ 131 - 0
4dkankan-common-utils/src/main/java/com/fdkankan/common/validation/SensitiveWordConfig.java

@@ -0,0 +1,131 @@
+package com.fdkankan.common.validation;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.util.*;
+
+/**
+ * 初始化敏感词库,将敏感词加入到HashMap中,构建DFA算法模型
+ */
+public class SensitiveWordConfig {
+    private String ENCODING = "utf-8";    //字符编码
+    @SuppressWarnings("rawtypes")
+    public HashMap sensitiveWordMap;
+
+    public SensitiveWordConfig(){
+        super();
+    }
+
+    /**
+     * @date 2014年4月20日 下午2:28:32
+     * @version 1.0
+     */
+    @SuppressWarnings("rawtypes")
+    public Map initKeyWord(String filePath){
+        try {
+            //读取敏感词库
+            Set<String> keyWordSet = readSensitiveWordFile(filePath);
+            //将敏感词库加入到HashMap中
+            addSensitiveWordToHashMap(keyWordSet);
+            //spring获取application,然后application.setAttribute("sensitiveWordMap",sensitiveWordMap);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return sensitiveWordMap;
+    }
+
+    /**
+     * 读取敏感词库,将敏感词放入HashSet中,构建一个DFA算法模型:<br>
+     * 中 = {
+     *      isEnd = 0
+     *      国 = {<br>
+     *      	 isEnd = 1
+     *           人 = {isEnd = 0
+     *                民 = {isEnd = 1}
+     *                }
+     *           男  = {
+     *           	   isEnd = 0
+     *           		人 = {
+     *           			 isEnd = 1
+     *           			}
+     *           	}
+     *           }
+     *      }
+     *  五 = {
+     *      isEnd = 0
+     *      星 = {
+     *      	isEnd = 0
+     *      	红 = {
+     *              isEnd = 0
+     *              旗 = {
+     *                   isEnd = 1
+     *                  }
+     *              }
+     *      	}
+     *      }
+     * @param keyWordSet  敏感词库
+     */
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    private void addSensitiveWordToHashMap(Set<String> keyWordSet) {
+        sensitiveWordMap = new HashMap(keyWordSet.size());     //初始化敏感词容器,减少扩容操作
+        String key = null;
+        Map nowMap = null;
+        Map<String, String> newWorMap = null;
+        //迭代keyWordSet
+        Iterator<String> iterator = keyWordSet.iterator();
+        while(iterator.hasNext()){
+            key = iterator.next();    //关键字
+            nowMap = sensitiveWordMap;
+            for(int i = 0 ; i < key.length() ; i++){
+                char keyChar = key.charAt(i);       //转换成char型
+                Object wordMap = nowMap.get(keyChar);       //获取
+
+                if(wordMap != null){        //如果存在该key,直接赋值
+                    nowMap = (Map) wordMap;
+                }
+                else{     //不存在则,则构建一个map,同时将isEnd设置为0,因为他不是最后一个
+                    newWorMap = new HashMap<String,String>();
+                    newWorMap.put("isEnd", "0");     //不是最后一个
+                    nowMap.put(keyChar, newWorMap);
+                    nowMap = newWorMap;
+                }
+
+                if(i == key.length() - 1){
+                    nowMap.put("isEnd", "1");    //最后一个
+                }
+            }
+        }
+    }
+
+    /**
+     * 读取敏感词库中的内容,将内容添加到set集合中
+     */
+    @SuppressWarnings("resource")
+    private Set<String> readSensitiveWordFile(String path) throws Exception{
+        Set<String> set = null;
+        //File file = new File("E:\\2017\\4Dweb\\bug汇总\\过滤敏感词\\敏感词库\\敏感词库\\2012年最新敏感词列表\\论坛需要过滤的不良词语大全.txt");    //读取文件
+        //File file = new File("D:\\SensitiveWord.txt");    //读取文件
+        File file = new File(path);
+        InputStreamReader read = new InputStreamReader(new FileInputStream(file),ENCODING);
+        try {
+            if(file.isFile() && file.exists()){      //文件流是否存在
+                set = new HashSet<String>();
+                BufferedReader bufferedReader = new BufferedReader(read);
+                String txt = null;
+                while((txt = bufferedReader.readLine()) != null){    //读取文件,将文件内容放入到set中
+                    set.add(txt);
+                }
+            }
+            else{         //不存在抛出异常信息
+                throw new Exception("敏感词库文件不存在");
+            }
+        } catch (Exception e) {
+            throw e;
+        }finally{
+            read.close();     //关闭文件流
+        }
+        return set;
+    }
+}

+ 208 - 0
4dkankan-common-utils/src/main/java/com/fdkankan/common/validation/ValidationUtils.java

@@ -0,0 +1,208 @@
+package com.fdkankan.common.validation;
+
+import org.springframework.util.StringUtils;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+public class ValidationUtils {
+
+    /** Email */
+    public static final String EMAIL_PATTERN = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z0-9]{2,40}$" ;
+
+    /** Age 1-120  */
+    public static final String AGE_PATTERN="^(?:[1-9][0-9]?|1[01][0-9]|120)$";
+
+    /** URL、http、www、ftp */
+    public static final String URL_PATTERN = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?" ;
+
+    /** No. */
+    public static final String INTEGER_PATTERN = "^([+-]?)\\d*\\.?\\d+$" ;
+
+    /** String. */
+    public static final String STRING_PATTERN = "^[\\u4E00-\\u9FFF\\sA-za-z]+$";
+//    public static final String STRING_PATTERN = "^[\\u4E00-\\u9FFF\\sA-za-z\\d*]+$";
+
+    /** Chinese. */
+    public static final String CHINESE_NAME = "^[\\u4E00-\\u9FFF\\W]+$";
+
+    /** PhoenNo. */
+    public static final String PHONE_NO = "^[0-9 ]{1,20}$";
+
+    /** PhoneCountry. */
+    public static final String PHONE_COUNTRY = "^[0-9\\ \\+\\-\\(\\)]{1,22}$";
+
+    /** HkID. */
+    public static final String HK_ID = "[a-zA-Z]{1}[0-9a-zA-Z]{6}\\([0-9]{1}\\)";
+
+    /** Only String and space */
+    public static final String ONLY_STRING_SPACE="^[A-Za-z\\s\\u4E00-\\u9FFF\\W]+$";
+
+
+
+    /** RecStatus */
+    public static boolean validateRecStatus(String str){
+        if(StringUtils.isEmpty(str)){
+            return Boolean.FALSE ;
+        }
+        if ("A".equals(str) || "I".equals(str)){
+            return Boolean.TRUE;
+        }
+        return Boolean.FALSE;
+    }
+
+
+
+    /**
+     * plan、marital
+     */
+    public static boolean validateInteger(int i){
+        if(i == 1 || i == 2 || i == 3 || i == 4 || i == 5){
+            return Boolean.TRUE ;
+        }
+        return Boolean.FALSE;
+    }
+
+    public static boolean validateString(String i){
+        if("1".equals(i) || "2".equals(i)){
+            return Boolean.TRUE ;
+        }
+        return Boolean.FALSE;
+    }
+
+
+
+
+    /**  Email */
+    public static boolean validateEamil(final String email){
+        if(StringUtils.isEmpty(email)){
+            return Boolean.FALSE ;
+        }
+        return email.matches(EMAIL_PATTERN) ;
+    }
+
+
+    /**  URL */
+    public static boolean validateUrl(final String url){
+        if(StringUtils.isEmpty(url)){
+            return Boolean.FALSE ;
+        }
+        return url.matches(URL_PATTERN) ;
+    }
+
+    /**
+     * Date
+     * str to Date check
+     */
+    public static boolean validateDate(String date){
+        if(StringUtils.isEmpty(date)){
+            return Boolean.FALSE ;
+        }
+        try {
+            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+            dateFormat.parse(date);
+        }   catch (ParseException e) {
+            return Boolean.FALSE;
+        }
+        return Boolean.TRUE;
+    }
+
+    /**
+     * Date
+     * date check
+     */
+    public static boolean validateDate(Date date){
+        try {
+            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
+            formatter.format(date);
+            if(date.after(new Date())){
+                return Boolean.FALSE;
+            }
+        }   catch (Exception e) {
+            return Boolean.FALSE;
+        }
+        return Boolean.TRUE;
+    }
+
+
+
+
+    /**  Message */
+    public static boolean validateMsg(String name, int start , int end){
+        if(StringUtils.isEmpty(name)){
+            return Boolean.FALSE ;
+        }
+        if (name.length() >= start && name.length() <= end){
+            return Boolean.TRUE ;
+        }
+        return Boolean.FALSE;
+    }
+
+
+    /**  PhoenNo */
+    public static boolean validatePhoenNo(String str){
+        if(StringUtils.isEmpty(str)){
+            return Boolean.FALSE ;
+        }
+        return str.matches(PHONE_NO) ;
+    }
+
+
+    /**  PhoneCountry */
+    public static boolean validatePhoneCountry(String str){
+        if(StringUtils.isEmpty(str)){
+            return Boolean.FALSE ;
+        }
+        return str.matches(PHONE_COUNTRY) ;
+    }
+
+
+
+
+
+    /**  check Float */
+    public static boolean validateFloat(String str){
+        if(StringUtils.isEmpty(str)){
+            return Boolean.FALSE ;
+        }
+        String key = "[+]?[0-9]*\\.?[0-9]{2}+";
+        return str.matches(key) ;
+    }
+
+
+
+    /**  compareDate */
+    public static boolean compareDate(String str){
+        if(StringUtils.isEmpty(str)){
+            return Boolean.FALSE ;
+        }
+        try {
+            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+            Date date = dateFormat.parse(str);
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(new Date());
+            calendar.add(Calendar.DAY_OF_MONTH, -15);
+            Date nowDate = dateFormat.parse(dateFormat.format(calendar.getTime()));
+            if (date.before(nowDate)){
+                return Boolean.TRUE;
+            } else {
+                return Boolean.FALSE;
+            }
+        }   catch (ParseException e) {
+            return Boolean.FALSE;
+        }
+    }
+
+
+
+
+    public static boolean validateState(int i){
+        if(i == 0 || i == 1 ){
+            return Boolean.TRUE ;
+        }
+        return Boolean.FALSE;
+    }
+
+}

+ 26 - 0
4dkankan-common-utils/src/main/java/com/fdkankan/common/validation/Variable.java

@@ -0,0 +1,26 @@
+package com.fdkankan.common.validation;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+public class Variable {
+
+    //public static Map<String,String> gl_AppSession = new HashMap<String,String>();
+
+    //二维码登录
+    public static Map<String,String> globalCodeLogin = new HashMap<String,String>();
+
+    public static ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<String>();
+    //论坛过滤
+    public static SensitiveWord sensitiveWord = new SensitiveWord();
+
+    //更新浏览大场景次数
+    public static Map<String, Integer> globalViewCount = new ConcurrentHashMap<String, Integer>();
+
+    //微信支付,原始订单对应后面添加了随机数的订单
+    public static Map<String, String> globalOrders = new ConcurrentHashMap<String, String>();
+
+//	public static ComputerModel[] thread_computers = null;
+}