فهرست منبع

登录获取验证码

lirong 3 سال پیش
والد
کامیت
bc1527cadf

+ 7 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RestApi.java

@@ -138,4 +138,11 @@ public class RestApi {
 		String result = RestUtil.login(param);
 		return result;
 	}
+
+	// 获取验证码
+	@PostMapping(path = { "/getCaptcha", "/zkt-sdk/getCaptcha" }, produces = "application/json;charset=UTF-8")
+	public String getCaptcha(@RequestBody String param, HttpServletRequest request) {
+		String result = RestUtil.getCaptcha();
+		return result;
+	}
 }

+ 20 - 1
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RestUtil.java

@@ -9,6 +9,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
 
 import javax.servlet.http.HttpServletRequest;
 
+import cn.hutool.core.lang.Tuple;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -478,7 +479,7 @@ public class RestUtil {
 		return JSONObject.toJSONString(result, SerializerFeature.WriteMapNullValue);
 	}
 
-	// 获取最近摄像头
+	// 登录
 	public static String login(String param) {
 		JSONObject result = new JSONObject();
 		try {
@@ -495,6 +496,24 @@ public class RestUtil {
 			result.put("ResultCode", 250);
 		}
 		return result.toJSONString();
+	}
+
+	// 获取验证码
+	public static String getCaptcha() {
+		JSONObject result = new JSONObject();
+		try {
+			Tuple object = PersonUtil.getCaptcha();
+			result.put("Content", object);
+			result.put("Result", "success");
+		} catch (Exception e) {
+			log.error(e.getMessage(), e);
+			String message = LogUtil.GetExceptionStackTrace(e);
+			log.error(message);
+			result.put("Result", "failure");
+			result.put("ResultMsg", message);
+			result.put("ResultCode", 250);
+		}
+		return result.toJSONString();
 
 	}
 }

+ 35 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/HttpClientUtil.java

@@ -5,6 +5,10 @@ import java.io.InputStream;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
+import cn.hutool.core.lang.Tuple;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.config.RequestConfig;
@@ -13,6 +17,8 @@ import org.apache.http.client.methods.HttpPost;
 import org.apache.http.client.methods.HttpPut;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import sun.misc.BASE64Encoder;
 
 public class HttpClientUtil {
 	private static Map<String, HttpClientUtil> instanceMap = new ConcurrentHashMap<String, HttpClientUtil>();
@@ -154,4 +160,33 @@ public class HttpClientUtil {
 		String result = baos.toString("UTF-8");
 		return result;
 	}
+
+	public synchronized Tuple postImg(String url, String content, Integer timeout, Map<String, String> headerMap) throws Exception {
+		HttpPost httpost = new HttpPost(url);
+		if (headerMap != null) {
+			for (String key : headerMap.keySet()) {
+				httpost.setHeader(key, headerMap.get(key));
+			}
+		}
+		if (timeout == null) {
+			timeout = 300000;
+		}
+		if (timeout != null) {
+			RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(timeout).setConnectionRequestTimeout(timeout)
+					.setSocketTimeout(timeout).build();
+			httpost.setConfig(requestConfig);
+		}
+		StringEntity entity = new StringEntity(content, "UTF-8");
+		httpost.setEntity(entity);
+		entity.setContentType("application/json");
+		HttpResponse httpResponse = client.execute(httpost);
+		String guid= httpResponse.getHeaders("guid")[0].getValue();
+		HttpEntity entity2 = httpResponse.getEntity();
+		byte[] data= EntityUtils.toByteArray(entity2);
+		BASE64Encoder encoder=new BASE64Encoder();
+		String imageBase64="data:image/png;base64,"+encoder.encodeBuffer(data).trim();
+		imageBase64=imageBase64.replaceAll("\n","").replaceAll("\r","").replaceAll(" ","");
+		Tuple tuple = new Tuple(guid, imageBase64);
+		return tuple;
+	}
 }

+ 10 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/PersonUtil.java

@@ -1,11 +1,14 @@
 package com.persagy.ibms.data.sdk.util;
 
+import cn.hutool.core.lang.Tuple;
+import cn.hutool.json.JSONString;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.persagy.ibms.core.data.SceneDataObject;
 import com.persagy.ibms.core.data.SceneDataSet;
 
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 
 public class PersonUtil {
@@ -17,4 +20,11 @@ public class PersonUtil {
         JSONObject resultJSON = JSON.parseObject(post_result).getJSONObject("content");
         return resultJSON;
     }
+
+    public static Tuple getCaptcha() throws Exception {
+        JSONObject queryCriteria=new JSONObject();
+        Tuple post_result = HttpClientUtil.instance("person_center").postImg(Constant.person_center_url + "/user/getCaptcha",queryCriteria.toJSONString(),300000, null);
+//        JSONObject resultJSON = JSON.parseObject(post_result).getJSONObject("content");
+        return post_result;
+    }
 }