Browse Source

规范代码

syh 5 years ago
parent
commit
d6a83c733b

+ 4 - 0
jeecg-boot-base-common/src/main/java/org/jeecg/common/util/DateUtils.java

@@ -1201,6 +1201,7 @@ public class DateUtils extends PropertyEditorSupport {
     public static long getDiscrepantDays(String dateStart, String dateEnd){
         //设置转换的日期格式
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
         //结束时间
         Date startDate = null;
         Date endDate = null;
@@ -1214,6 +1215,9 @@ public class DateUtils extends PropertyEditorSupport {
 
         //得到相差的天数 betweenDate
         long betweenDate = (endDate.getTime() - startDate.getTime())/(60*60*24*1000);
+
+        //打印控制台相差的天数
+        System.out.println(betweenDate);
         return betweenDate;
     }
 

+ 14 - 14
jeecg-boot-base-common/src/main/java/org/jeecg/common/util/jsonschema/JsonschemaUtil.java

@@ -1,15 +1,13 @@
 package org.jeecg.common.util.jsonschema;
 
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+
 import java.io.*;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-
-import lombok.extern.slf4j.Slf4j;
-
 @Slf4j
 public class JsonschemaUtil {
 
@@ -74,26 +72,28 @@ public class JsonschemaUtil {
      * @param fileName
      * @return
      */
-    public static String readJsonFile(String fileName) {
+	public static String readJsonFile(String fileName) throws IOException {
         String jsonStr = "";
-        try {
+		FileReader fileReader = null;
+		Reader reader = null;
+		try {
             File jsonFile = new File(fileName);
-            FileReader fileReader = new FileReader(jsonFile);
-
-            Reader reader = new InputStreamReader(new FileInputStream(jsonFile), "utf-8");
+			fileReader = new FileReader(jsonFile);
+			reader = new InputStreamReader(new FileInputStream(jsonFile), "utf-8");
             int ch = 0;
             StringBuffer sb = new StringBuffer();
             while ((ch = reader.read()) != -1) {
                 sb.append((char) ch);
             }
-            fileReader.close();
-            reader.close();
             jsonStr = sb.toString();
             return jsonStr;
-        } catch (IOException e) {
+		} catch (Exception e) {
             e.printStackTrace();
             return null;
-        }
+		} finally {
+			fileReader.close();
+			reader.close();
+		}
     }
 
 }

+ 13 - 48
jeecg-boot-base-common/src/main/java/org/jeecg/common/util/oConvertUtils.java

@@ -3,7 +3,6 @@ package org.jeecg.common.util;
 import org.apache.commons.lang.StringEscapeUtils;
 
 import javax.servlet.http.HttpServletRequest;
-import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.math.BigInteger;
@@ -47,23 +46,11 @@ public class oConvertUtils {
 		return temp;
 	}
 
-    public static String strToUtf(String strIn, String sourceCode, String targetCode) {
-		strIn = "";
-		try {
-			strIn = new String(strIn.getBytes("ISO-8859-1"), "GBK");
-		} catch (UnsupportedEncodingException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		return strIn;
-
-	}
-
 	private static String code2code(String strIn, String sourceCode, String targetCode) {
-		String strOut = null;
         if (strIn == null || "".equals(strIn.trim())) {
 			return strIn;
 		}
+		String strOut = null;
 		try {
 			byte[] b = strIn.getBytes(sourceCode);
 			strOut = new String(b, targetCode);
@@ -75,7 +62,7 @@ public class oConvertUtils {
 	}
 
 	public static int getInt(String s, int defval) {
-		if (s == null || s == "") {
+		if (s == null || s.trim().equals("")) {
 			return (defval);
 		}
 		try {
@@ -86,7 +73,7 @@ public class oConvertUtils {
 	}
 
 	public static int getInt(String s) {
-		if (s == null || s == "") {
+		if (s == null || s.trim().equals("")) {
 			return 0;
 		}
 		try {
@@ -97,7 +84,7 @@ public class oConvertUtils {
 	}
 
 	public static int getInt(String s, Integer df) {
-		if (s == null || s == "") {
+		if (s == null || s.trim().equals("")) {
 			return df;
 		}
 		try {
@@ -108,10 +95,10 @@ public class oConvertUtils {
 	}
 
 	public static Integer[] getInts(String[] s) {
-		Integer[] integer = new Integer[s.length];
 		if (s == null) {
 			return null;
 		}
+		Integer[] integer = new Integer[s.length];
 		for (int i = 0; i < s.length; i++) {
 			integer[i] = Integer.parseInt(s[i]);
 		}
@@ -120,7 +107,7 @@ public class oConvertUtils {
 	}
 
 	public static double getDouble(String s, double defval) {
-		if (s == null || s == "") {
+		if (s == null || s.trim().equals("")) {
 			return (defval);
 		}
 		try {
@@ -137,14 +124,6 @@ public class oConvertUtils {
 		return s;
 	}
 
-	/*public static Short getShort(String s) {
-		if (StringUtil.isNotEmpty(s)) {
-			return (Short.parseShort(s));
-		} else {
-			return null;
-		}
-	}*/
-
 	public static int getInt(Object object, int defval) {
 		if (isEmpty(object)) {
 			return (defval);
@@ -174,7 +153,7 @@ public class oConvertUtils {
 		return s.intValue();
 	}
 
-	public static Integer[] getIntegerArry(String[] object) {
+	public static Integer[] getIntegerArray(String[] object) {
 		int len = object.length;
 		Integer[] result = new Integer[len];
 		try {
@@ -230,12 +209,7 @@ public class oConvertUtils {
 	}
 
 	public static long stringToLong(String str) {
-        Long test = 0L;
-		try {
-			test = Long.valueOf(str);
-		} catch (Exception e) {
-		}
-		return test.longValue();
+		return Long.valueOf(str);
 	}
 
 	/**
@@ -260,7 +234,7 @@ public class oConvertUtils {
 	 *            要判断的类。
 	 * @return true 表示为基本数据类型。
 	 */
-	private static boolean isBaseDataType(Class clazz) throws Exception {
+	private static boolean isBaseDataType(Class clazz) {
 		return (clazz.equals(String.class) || clazz.equals(Integer.class) || clazz.equals(Byte.class) || clazz.equals(Long.class) || clazz.equals(Double.class) || clazz.equals(Float.class) || clazz.equals(Character.class) || clazz.equals(Short.class) || clazz.equals(BigDecimal.class) || clazz.equals(BigInteger.class) || clazz.equals(Boolean.class) || clazz.equals(Date.class) || clazz.isPrimitive());
 	}
 
@@ -302,11 +276,11 @@ public class oConvertUtils {
 			Enumeration<InetAddress> address = ni.getInetAddresses();
 			while (address.hasMoreElements()) {
 				ip = address.nextElement();
-                if (!ip.isSiteLocalAddress() && !ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == -1) {
+				if (!ip.isSiteLocalAddress() && !ip.isLoopbackAddress() && ip.getHostAddress().indexOf(':') == -1) {
 					netip = ip.getHostAddress();
 					finded = true;
 					break;
-                } else if (ip.isSiteLocalAddress() && !ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == -1) {
+				} else if (ip.isSiteLocalAddress() && !ip.isLoopbackAddress() && ip.getHostAddress().indexOf(':') == -1) {
 					localip = ip.getHostAddress();
 				}
 			}
@@ -357,20 +331,13 @@ public class oConvertUtils {
 	}
 
 	/**
-	 * 获取Map对象
-	 */
-	public static Map<Object, Object> getHashMap() {
-		return new HashMap<Object, Object>();
-	}
-
-	/**
 	 * SET转换MAP
      *
 	 * @param setobj
 	 * @return
 	 */
     public static Map<Object, Object> setToMap(Set<Object> setobj) {
-		Map<Object, Object> map = getHashMap();
+		Map<Object, Object> map = new HashMap<>();
 		for (Iterator iterator = setobj.iterator(); iterator.hasNext();) {
 			Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>) iterator.next();
 			map.put(entry.getKey().toString(), entry.getValue() == null ? "" : entry.getValue().toString().trim());
@@ -401,9 +368,7 @@ public class oConvertUtils {
 		long b = Integer.parseInt(ip[1]);
 		long c = Integer.parseInt(ip[2]);
 		long d = Integer.parseInt(ip[3]);
-
-		long ipNum = a * 256 * 256 * 256 + b * 256 * 256 + c * 256 + d;
-		return ipNum;
+		return a * 256 * 256 * 256 + b * 256 * 256 + c * 256 + d;
 	}
 
 	private static boolean isInner(long userIp, long begin, long end) {

+ 3 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/OceanengineJob.java

@@ -316,13 +316,13 @@ public class OceanengineJob implements Job {
                 FateadmUtil fateadmUtil = new FateadmUtil();
                 fateadmUtil.init();
                 if (orderId != null) {
-                    fateadmUtil.Justice(orderId);
+                    fateadmUtil.justice(orderId);
                 }
                 String captcha = jsonNode.get("captcha").asText();
                 Base64.Decoder decoder = Base64.getDecoder();
                 FateadmHttpUtil.HttpResp resp = fateadmUtil.Predict("30400", decoder.decode(captcha));
-                param.put("captcha", resp.pred_resl);
-                orderId = resp.req_id;
+                param.put("captcha", resp.predResl);
+                orderId = resp.reqId;
                 res = HttpUtils2.httpPostParamRequest("https://sso.toutiao.com/account_login/", param, header);
                 jsonNode = mapper.readTree(res);
                 errorCode = jsonNode.get("error_code").asInt();

+ 0 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/AdvertiserServiceImpl.java

@@ -106,8 +106,6 @@ public class AdvertiserServiceImpl extends ServiceImpl<AdvertiserMapper, Adverti
             List<YdPlanAggregateEntity> planAggregateEntities = getYdPlanStatisticInfo(projectId, startDate, endDate);
             secondVo.setDetails(planAggregateEntities);
             sheetInfoVos.add(secondVo);
-            //3:获取每周素材统计
-
             return sheetInfoVos;
         } catch (ParseException e) {
             e.printStackTrace();

+ 3 - 5
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/CreateInternalServiceImpl.java

@@ -143,13 +143,13 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
                 FateadmUtil fateadmUtil = new FateadmUtil();
                 fateadmUtil.init();
                 if (orderId != null) {
-                    fateadmUtil.Justice(orderId);
+                    fateadmUtil.justice(orderId);
                 }
                 String captcha = jsonNode.get("captcha").asText();
                 Base64.Decoder decoder = Base64.getDecoder();
                 FateadmHttpUtil.HttpResp resp = fateadmUtil.Predict("30400", decoder.decode(captcha));
-                param.put("captcha", resp.pred_resl);
-                orderId = resp.req_id;
+                param.put("captcha", resp.predResl);
+                orderId = resp.reqId;
                 res = HttpUtils2.httpPostParamRequest("https://sso.toutiao.com/account_login/", param, header);
                 jsonNode = mapper.readTree(res);
                 errorCode = jsonNode.get("error_code").asInt();
@@ -178,8 +178,6 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
             e.printStackTrace();
             ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_SERVER_ERROR.getCode());
         } finally {
-            //获得cookie
-            Set<Cookie> coo = webDriver.manage().getCookies();
             //清除所有的缓存
             webDriver.manage().deleteAllCookies();
             webDriver.quit();

+ 40 - 185
module-crawler/src/main/java/cn/com/ctop/crawler/modules/core/util/FateadmHttpUtil.java

@@ -1,5 +1,6 @@
 package cn.com.ctop.crawler.modules.core.util;
 import java.io.*;
+import java.nio.charset.StandardCharsets;
 import java.security.MessageDigest;
 import java.net.HttpURLConnection;
 import java.net.URL;
@@ -8,159 +9,12 @@ import java.util.Base64;
 
 public class FateadmHttpUtil {
     public static class HttpResp {
-        public int      ret_code;
-        public double   cust_val;
-        public String   err_msg;
-        public String   req_id;
-        public String   rsp_data;
-        public String   pred_resl;
-    }
-
-    /**
-     * 为避免引入复杂的json包,这里简单实现一个,只用来能解析从网络的回包中的指定字段的内容
-     */
-    public static class JsonHelper{
-        public String json;
-        public int next_idx;
-        public JsonHelper(String json){
-            this.json       = json;
-            this.next_idx   = 0;
-        }
-
-        public void skip() {
-            while( next_idx < json.length()){
-                char c = json.charAt( next_idx);
-                if( (c<=32) || (c=='\\')){
-                    next_idx ++;
-                } else {
-                    break;
-                }
-            }
-        }
-        public String NextSToken( ) {
-            //int start = next_idx;
-            String ret = "";
-            while(next_idx < json.length()){
-                char c = json.charAt(next_idx);
-                if (c == '\"') {
-                    break;
-                }
-                if( (c=='\\') && (next_idx+1<json.length())){
-                    if(json.charAt(next_idx+1) == '\\')
-                    {
-                        ret += '\\';
-                        next_idx += 2;
-                        continue;
-                    }
-                    if( json.charAt(next_idx+1) == '\"'){
-                        ret += '\"';
-                        next_idx += 2;
-                        continue;
-                    }
-                }
-                ret += c;
-                next_idx ++;
-            }
-            return ret;
-        }
-        public String NextNToken(){
-            String ret = "";
-            while(next_idx < json.length()){
-                char c = json.charAt(next_idx);
-                if ( c == '\\'){
-                    next_idx++;
-                    continue;
-                }
-                if((c <'0' || c>'9')&& c != '.'){
-                    // not number
-                    break;
-                }
-                ret += c;
-                next_idx ++;
-            }
-            return ret;
-        }
-        public void Key2Val(HttpResp rsp, String key, String val){
-            if ("RetCode".equals(key)) {
-                rsp.ret_code    = Integer.parseInt( val);
-            } else if ("ErrMsg".equals(key)) {
-                rsp.err_msg     = val;
-            } else if ("RequestId".equals(key)) {
-                rsp.req_id      = val;
-            } else if ("RspData".equals(key)) {
-                rsp.rsp_data    = val;
-            } else if ("result".equals(key)) {
-                rsp.pred_resl   = val;
-            } else if ("cust_val".equals(key)) {
-                rsp.cust_val    = Double.parseDouble(val);
-            }
-        }
-        public void Parse(HttpResp rsp ){
-            //rsp.ret_code    = -1;
-            next_idx = 0;
-            String key = "";
-            String sval = "";
-            for( next_idx = 0; next_idx < json.length(); ){
-                skip();
-                char c = json.charAt(next_idx);
-                switch( c){
-                    case ':':
-                    case ',':
-                        break;
-                    case '[':
-                    case '{':
-                    case '}':
-                    case ']':
-                        // not support here
-                        break;
-                    case '\"':
-                        next_idx++;
-                        sval = NextSToken();
-                        skip();
-                        if (next_idx >= json.length()) {
-                            break;
-                        }
-                        if( json.charAt(next_idx+1) == ':'){
-                            key = sval;
-                            next_idx ++;
-                            continue;
-                        }
-                        // key to val
-                        Key2Val(rsp, key, sval);
-                        key     = "";
-                        break;
-                    case '+':
-                    case '-':
-                    case '.':
-                    case '0': case '1': case '2':
-                    case '3': case '4': case '5':
-                    case '6': case '7': case '8':
-                    case '9':
-                        // is number
-                        sval    = NextNToken();
-                        // key to val
-                        Key2Val(rsp, key, sval);
-                        key     = "";
-                        break;
-                    case 'n':
-                    case 'N':
-                        sval    = json.substring(next_idx, 4).toLowerCase();
-                        if (!"null".equals(sval)) {
-                            //error
-                            break;
-                        }
-                        sval = "";
-                        next_idx += 4;
-                        // key to val
-                        Key2Val(rsp, key, sval);
-                        key     = "";
-                        break;
-                    default:
-                        break;
-                }
-                next_idx ++;
-            }
-        }
+        public int retCode;
+        public double custVal;
+        public String errMsg;
+        public String reqId;
+        public String rspData;
+        public String predResl;
     }
 
     public static String toHex(byte[] arr) {
@@ -200,21 +54,22 @@ public class FateadmHttpUtil {
     }
     public static String CalcSign(String id, String key, String tm){
         String chk1 = calcMd5(tm + key);
-        String sum = calcMd5(id + tm + chk1);
-        return sum;
+        return calcMd5(id + tm + chk1);
     }
-    public static HttpResp ParseHttpResp(String resl){
+
+    public static HttpResp parseHttpResp(String resl) {
         HttpResp resp   = new HttpResp();
-        resp.ret_code   = -1;
+        resp.retCode = -1;
         JsonHelper json = new JsonHelper(resl);
         json.Parse(resp);
-        if( !resp.rsp_data.isEmpty() ){
-            JsonHelper rjson = new JsonHelper( resp.rsp_data);
+        if (!resp.rspData.isEmpty()) {
+            JsonHelper rjson = new JsonHelper(resp.rspData);
             rjson.Parse(resp);
         }
         return resp;
     }
-    public static byte[] ReadBinaryFile(String file_name) throws IOException{
+
+    public static byte[] readBinaryFile(String fileName) throws IOException {
         InputStream in = null;
         BufferedInputStream buffer = null;
         DataInputStream dataIn = null;
@@ -222,7 +77,7 @@ public class FateadmHttpUtil {
         DataOutputStream dos = null;
         byte[] bArray = null;
         try{
-            in = new FileInputStream(file_name);
+            in = new FileInputStream(fileName);
             buffer = new BufferedInputStream(in);
             dataIn = new DataInputStream(buffer);
             bos = new ByteArrayOutputStream();
@@ -257,9 +112,10 @@ public class FateadmHttpUtil {
         }
         return bArray;
     }
-    public static String MFPost(URL url,byte[] img_data,String stm,String pd_id,String sign,String app_id,String asign,String pred_type) throws Exception {
+
+    public static String mfPost(URL url, byte[] imgData, String stm, String pdId, String sign, String appId, String asign, String predType) throws Exception {
         String boundary = "--" + calcMd5(stm);
-        String boundarybytes_string = "--" + boundary + "\r\n";
+        String boundaryBytesString = "--" + boundary + "\r\n";
         HttpURLConnection con = (HttpURLConnection) url.openConnection();
         con.setRequestMethod("POST");
         con.setConnectTimeout(30000);
@@ -269,27 +125,27 @@ public class FateadmHttpUtil {
         con.setRequestProperty("Content-Type",
 				"multipart/form-data; boundary=" + boundary);
         OutputStream out    = con.getOutputStream();
-        String item_string  = boundarybytes_string + "Content-Disposition: form-data;name=\"";
-        String param_string = item_string + "user_id\"\r\n\r\n" + pd_id + "\r\n"
-                + item_string + "timestamp\"\r\n\r\n" + stm + "\r\n"
-        		+ item_string + "sign\"\r\n\r\n" + sign + "\r\n"
-        		+ item_string + "predict_type\"\r\n\r\n" + pred_type + "\r\n"
-        		+ item_string + "up_type\"\r\n\r\nmt\r\n";
-        if(!app_id.isEmpty()){
-            param_string  += item_string + "appid\"\r\n\r\n" + app_id + "\r\n"
-        		+ item_string + "asign\"\r\n\r\n" + asign + "\r\n";
+        String itemString = boundaryBytesString + "Content-Disposition: form-data;name=\"";
+        String paramString = itemString + "user_id\"\r\n\r\n" + pdId + "\r\n"
+                + itemString + "timestamp\"\r\n\r\n" + stm + "\r\n"
+                + itemString + "sign\"\r\n\r\n" + sign + "\r\n"
+                + itemString + "predict_type\"\r\n\r\n" + predType + "\r\n"
+                + itemString + "up_type\"\r\n\r\nmt\r\n";
+        if (!appId.isEmpty()) {
+            paramString += itemString + "appid\"\r\n\r\n" + appId + "\r\n"
+                    + itemString + "asign\"\r\n\r\n" + asign + "\r\n";
         }
-        String file_strig = item_string + "img_data\";filename=\"image.jpg\"\r\nContent-Type: image/jpg\r\n\r\n";
-        String end_string = "\r\n--" + boundary + "--\r\n";
-        out.write(param_string.getBytes("UTF-8"));
-        out.write(file_strig.getBytes("UTF-8"));
-        out.write(img_data);
-        out.write(end_string.getBytes("UTF-8"));
+        String fileStrig = itemString + "img_data\";filename=\"image.jpg\"\r\nContent-Type: image/jpg\r\n\r\n";
+        String endString = "\r\n--" + boundary + "--\r\n";
+        out.write(paramString.getBytes(StandardCharsets.UTF_8));
+        out.write(fileStrig.getBytes(StandardCharsets.UTF_8));
+        out.write(imgData);
+        out.write(endString.getBytes(StandardCharsets.UTF_8));
         out.flush();
         out.close();
 
-        StringBuffer buffer = new StringBuffer();
-        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
+        StringBuilder buffer = new StringBuilder();
+        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8));
         String temp;
         while((temp = br.readLine()) != null) {
         	buffer.append(temp);
@@ -309,14 +165,13 @@ public class FateadmHttpUtil {
 		while((rc = is.read(buff, 0, 128)) > 0 ) {
 			baos.write(buff,0,rc);
 		}
-        byte[] imgData = baos.toByteArray();
-        return imgData;
+        return baos.toByteArray();
     }
 
     public static String httpPost(String url, String params) {
         PrintWriter out = null;
         BufferedReader in = null;
-        String result = "";
+        StringBuilder result = new StringBuilder();
         try {
             URL realUrl = new URL(url);
             // 打开和URL之间的连接
@@ -339,7 +194,7 @@ public class FateadmHttpUtil {
                     new InputStreamReader(conn.getInputStream()));
             String line;
             while ((line = in.readLine()) != null) {
-                result += line;
+                result.append(line);
             }
         } catch (Exception e) {
             e.printStackTrace();
@@ -358,6 +213,6 @@ public class FateadmHttpUtil {
                 ex.printStackTrace();
             }
         }
-        return result;
+        return result.toString();
     }
 }

+ 15 - 15
module-crawler/src/main/java/cn/com/ctop/crawler/modules/core/util/FateadmUtil.java

@@ -44,7 +44,7 @@ public class FateadmUtil {
         String url = this.pred_url + "/api/custval";
         String params = "user_id=" + this.pd_id + "&timestamp=" + stm + "&sign=" + sign;
         String pres = FateadmHttpUtil.httpPost(url, params);
-        FateadmHttpUtil.HttpResp resp = FateadmHttpUtil.ParseHttpResp(pres);
+        FateadmHttpUtil.HttpResp resp = FateadmHttpUtil.parseHttpResp(pres);
         return resp;
     }
 
@@ -55,7 +55,7 @@ public class FateadmUtil {
      */
     public double QueryBalcExtend() throws Exception {
         FateadmHttpUtil.HttpResp resp = QueryBalc();
-        return resp.cust_val;
+        return resp.custVal;
     }
 
     /**
@@ -74,7 +74,7 @@ public class FateadmUtil {
         String url = this.pred_url + "/api/charge";
         String params = "user_id=" + pd_id + "&timestamp=" + stm + "&sign=" + sign + "&cardid=" + cardid + "&csign=" + csign;
         String pres = FateadmHttpUtil.httpPost(url, params);
-        FateadmHttpUtil.HttpResp resp = FateadmHttpUtil.ParseHttpResp(pres);
+        FateadmHttpUtil.HttpResp resp = FateadmHttpUtil.parseHttpResp(pres);
         return resp;
     }
 
@@ -85,7 +85,7 @@ public class FateadmUtil {
      */
     private int ChargeExtend(String cardid, String cardkey) throws Exception {
         FateadmHttpUtil.HttpResp resp = Charge(cardid, cardkey);
-        return resp.ret_code;
+        return resp.retCode;
     }
 
 
@@ -99,11 +99,11 @@ public class FateadmUtil {
      * resp.pred_resl:识别的结果
      */
     public FateadmHttpUtil.HttpResp PredictFromFile(String predType, String fileName) throws Exception {
-        byte[] fileData = FateadmHttpUtil.ReadBinaryFile(fileName);
+        byte[] fileData = FateadmHttpUtil.readBinaryFile(fileName);
         if (fileData == null) {
             FateadmHttpUtil.HttpResp resp = new FateadmHttpUtil.HttpResp();
-            resp.ret_code = -1;
-            resp.err_msg = "ERROR: read file failed! file_name: " + fileName;
+            resp.retCode = -1;
+            resp.errMsg = "ERROR: read file failed! file_name: " + fileName;
             return resp;
         }
         FateadmHttpUtil.HttpResp resp = Predict(predType, fileData);
@@ -117,7 +117,7 @@ public class FateadmUtil {
      */
     public String PredictFromFileExtend(String pred_type, String file_name) throws Exception {
         FateadmHttpUtil.HttpResp resp = PredictFromFile(pred_type, file_name);
-        return resp.pred_resl;
+        return resp.predResl;
     }
 
     /**
@@ -139,8 +139,8 @@ public class FateadmUtil {
         if (!app_id.isEmpty()) {
             asign = FateadmHttpUtil.CalcSign(app_id, app_key, stm);
         }
-        String pres = FateadmHttpUtil.MFPost(url, imgData, stm, pd_id, sign, app_id, asign, predType);
-        FateadmHttpUtil.HttpResp resp = FateadmHttpUtil.ParseHttpResp(pres);
+        String pres = FateadmHttpUtil.mfPost(url, imgData, stm, pd_id, sign, app_id, asign, predType);
+        FateadmHttpUtil.HttpResp resp = FateadmHttpUtil.parseHttpResp(pres);
         return resp;
     }
 
@@ -151,7 +151,7 @@ public class FateadmUtil {
      */
     public String PredictExtend(String pred_type, byte[] img_data) throws Exception {
         FateadmHttpUtil.HttpResp resp = Predict(pred_type, img_data);
-        return resp.pred_resl;
+        return resp.predResl;
     }
 
     /**
@@ -166,14 +166,14 @@ public class FateadmUtil {
      * 注意2:
      * 退款仅在正常识别出结果后,无法通过网站验证的情况,请勿非法或者滥用,否则可能进行封号处理
      */
-    public FateadmHttpUtil.HttpResp Justice(String reqId) throws Exception {
+    public FateadmHttpUtil.HttpResp justice(String reqId) throws Exception {
         long curTm = System.currentTimeMillis() / 1000;
         String stm = String.valueOf(curTm);
         String sign = FateadmHttpUtil.CalcSign(pd_id, pd_key, stm);
         String url = pred_url + "/api/capjust";
         String params = "user_id=" + pd_id + "&timestamp=" + stm + "&sign=" + sign + "&request_id=" + reqId;
         String pres = FateadmHttpUtil.httpPost(url, params);
-        FateadmHttpUtil.HttpResp resp = FateadmHttpUtil.ParseHttpResp(pres);
+        FateadmHttpUtil.HttpResp resp = FateadmHttpUtil.parseHttpResp(pres);
         return resp;
     }
 
@@ -183,8 +183,8 @@ public class FateadmUtil {
      * 返回值: 返回 0 代表成功
      */
     public int JusticeExtend(String req_id) throws Exception {
-        FateadmHttpUtil.HttpResp resp = Justice(req_id);
-        return resp.ret_code;
+        FateadmHttpUtil.HttpResp resp = justice(req_id);
+        return resp.retCode;
     }
 
     public static void main(String[] args) {

+ 153 - 0
module-crawler/src/main/java/cn/com/ctop/crawler/modules/core/util/JsonHelper.java

@@ -0,0 +1,153 @@
+package cn.com.ctop.crawler.modules.core.util;
+
+public class JsonHelper {
+    public String json;
+    public int nextIdx;
+
+    public JsonHelper(String json) {
+        this.json = json;
+        this.nextIdx = 0;
+    }
+
+    public void skip() {
+        while (nextIdx < json.length()) {
+            char c = json.charAt(nextIdx);
+            if ((c <= 32) || (c == '\\')) {
+                nextIdx++;
+            } else {
+                break;
+            }
+        }
+    }
+
+    public String NextSToken() {
+        StringBuilder ret = new StringBuilder();
+        while (nextIdx < json.length()) {
+            char c = json.charAt(nextIdx);
+            if (c == '\"') {
+                break;
+            }
+            if ((c == '\\') && (nextIdx + 1 < json.length())) {
+                if (json.charAt(nextIdx + 1) == '\\') {
+                    ret.append('\\');
+                    nextIdx += 2;
+                    continue;
+                }
+                if (json.charAt(nextIdx + 1) == '\"') {
+                    ret.append('\"');
+                    nextIdx += 2;
+                    continue;
+                }
+            }
+            ret.append(c);
+            nextIdx++;
+        }
+        return ret.toString();
+    }
+
+    public String NextNToken() {
+        String ret = "";
+        while (nextIdx < json.length()) {
+            char c = json.charAt(nextIdx);
+            if (c == '\\') {
+                nextIdx++;
+                continue;
+            }
+            if ((c < '0' || c > '9') && c != '.') {
+                // not number
+                break;
+            }
+            ret += c;
+            nextIdx++;
+        }
+        return ret;
+    }
+
+    public void Key2Val(FateadmHttpUtil.HttpResp rsp, String key, String val) {
+        if ("RetCode".equals(key)) {
+            rsp.retCode = Integer.parseInt(val);
+        } else if ("ErrMsg".equals(key)) {
+            rsp.errMsg = val;
+        } else if ("RequestId".equals(key)) {
+            rsp.reqId = val;
+        } else if ("RspData".equals(key)) {
+            rsp.rspData = val;
+        } else if ("result".equals(key)) {
+            rsp.predResl = val;
+        } else if ("cust_val".equals(key)) {
+            rsp.custVal = Double.parseDouble(val);
+        }
+    }
+
+    public void Parse(FateadmHttpUtil.HttpResp rsp) {
+        nextIdx = 0;
+        String key = "";
+        String sval = "";
+        for (nextIdx = 0; nextIdx < json.length(); ) {
+            skip();
+            char c = json.charAt(nextIdx);
+            switch (c) {
+                case ':':
+                case ',':
+                    break;
+                case '[':
+                case '{':
+                case '}':
+                case ']':
+                    // not support here
+                    break;
+                case '\"':
+                    nextIdx++;
+                    sval = NextSToken();
+                    skip();
+                    if (nextIdx >= json.length()) {
+                        break;
+                    }
+                    if (json.charAt(nextIdx + 1) == ':') {
+                        key = sval;
+                        nextIdx++;
+                        continue;
+                    }
+                    // key to val
+                    Key2Val(rsp, key, sval);
+                    key = "";
+                    break;
+                case '+':
+                case '-':
+                case '.':
+                case '0':
+                case '1':
+                case '2':
+                case '3':
+                case '4':
+                case '5':
+                case '6':
+                case '7':
+                case '8':
+                case '9':
+                    // is number
+                    sval = NextNToken();
+                    // key to val
+                    Key2Val(rsp, key, sval);
+                    key = "";
+                    break;
+                case 'n':
+                case 'N':
+                    sval = json.substring(nextIdx, 4).toLowerCase();
+                    if (!"null".equals(sval)) {
+                        //error
+                        break;
+                    }
+                    sval = "";
+                    nextIdx += 4;
+                    // key to val
+                    Key2Val(rsp, key, sval);
+                    key = "";
+                    break;
+                default:
+                    break;
+            }
+            nextIdx++;
+        }
+    }
+}

+ 1 - 1
xxl-job-executor/src/main/java/com/xxl/job/executor/handler/kuaishou/KuaishouCampaignJob.java

@@ -24,7 +24,7 @@ public class KuaishouCampaignJob {
     static ExecutorService executorService = null;
 
     @XxlJob("kuaishouCampaignJob")
-    public ReturnT<String> execute(String param) throws Exception {
+    public ReturnT<String> execute(String param) {
         List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
         executorService = Executors.newFixedThreadPool(5);
         tokens.forEach(token -> executorService.submit(() -> kuaishouInterfaceService.getCampaignList(token, null, null)));