From 74328e2638ce3b09a126e8343af651256250b8ab Mon Sep 17 00:00:00 2001
From: whyclj <1525436766@qq.com>
Date: 星期二, 28 四月 2020 11:02:48 +0800
Subject: [PATCH] 添加各种方法

---
 webSockTest/src/com/fgkj/services/FaceDetect.java |  390 ++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 296 insertions(+), 94 deletions(-)

diff --git a/webSockTest/src/com/fgkj/services/FaceDetect.java b/webSockTest/src/com/fgkj/services/FaceDetect.java
index 2122c09..88d87ca 100644
--- a/webSockTest/src/com/fgkj/services/FaceDetect.java
+++ b/webSockTest/src/com/fgkj/services/FaceDetect.java
@@ -1,6 +1,5 @@
 package com.fgkj.services;
 
-
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
@@ -11,100 +10,301 @@
 import com.fgkj.actions.ActionUtil;
 
 /**
-* 浜鸿劯妫�娴嬩笌灞炴�у垎鏋�
-*/
+ * 浜鸿劯妫�娴嬩笌灞炴�у垎鏋�
+ */
 public class FaceDetect {
 
-    /**
-    * 閲嶈鎻愮ず浠g爜涓墍闇�宸ュ叿绫�
-    * FileUtil,Base64Util,HttpUtil,GsonUtils璇蜂粠
-    * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
-    * https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2
-    * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
-    * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
-    * 涓嬭浇
-    */
-    public static String faceDetect(String json) {
-        // 璇锋眰url
-        String url = "https://aip.baidubce.com/rest/2.0/face/v3/detect";
-        try {
-            //Map<String, Object> map = new HashMap<>();
-        	//map.put("image", "027d8308a2ec665acb1bdf63e513bcb9");
-            //map.put("face_field", "faceshape,facetype");
-            //map.put("image_type", "FACE_TOKEN");
-        	//map.put("accessToken", "************");
-        	Map<String, Object> map = ActionUtil.getGson().fromJson(json, HashMap.class);
-        	
-            String param = GsonUtils.toJson(map);
+	/**
+	 * 閲嶈鎻愮ず浠g爜涓墍闇�宸ュ叿绫� FileUtil,Base64Util,HttpUtil,GsonUtils璇蜂粠
+	 * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
+	 * https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2
+	 * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
+	 * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3 涓嬭浇
+	 */
+	public static String faceDetect(String json) {
+		// 璇锋眰url
+		String url = "https://aip.baidubce.com/rest/2.0/face/v3/detect";
+		try {
+			// Map<String, Object> map = new HashMap<>();
+			// map.put("image", "027d8308a2ec665acb1bdf63e513bcb9");
+			// map.put("face_field", "faceshape,facetype");
+			// map.put("image_type", "FACE_TOKEN");
+			// map.put("accessToken", "************");
+			Map<String, Object> map = ActionUtil.getGson().fromJson(json,
+					HashMap.class);
 
-            // 娉ㄦ剰杩欓噷浠呬负浜嗙畝鍖栫紪鐮佹瘡涓�娆¤姹傞兘鍘昏幏鍙朼ccess_token锛岀嚎涓婄幆澧僡ccess_token鏈夎繃鏈熸椂闂达紝 瀹㈡埛绔彲鑷缂撳瓨锛岃繃鏈熷悗閲嶆柊鑾峰彇銆�
-            //String accessToken = "[璋冪敤閴存潈鎺ュ彛鑾峰彇鐨則oken]";
-            String msg = HttpUtil.post(url, map.get("accessToken").toString(), "application/json", param);
-            
-            return msg;
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-    
-    
-    /**
-     * 	浜鸿劯鎼滅储
-     * FileUtil,Base64Util,HttpUtil,GsonUtils璇蜂粠
-     * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
-     * https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2
-     * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
-     * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
-     * 涓嬭浇
-     */
-     public static String faceSearch(String json) {
-         // 璇锋眰url
-         String url = "https://aip.baidubce.com/rest/2.0/face/v3/search";
-         try {
-             /*Map<String, Object> map = new HashMap<>();
-             map.put("image", "027d8308a2ec665acb1bdf63e513bcb9");
-             map.put("liveness_control", "NORMAL");
-             map.put("group_id_list", "group_repeat,group_233");
-             map.put("image_type", "FACE_TOKEN");
-             map.put("quality_control", "LOW");*/
+			String param = GsonUtils.toJson(map);
 
-             Map<String, Object> map = ActionUtil.getGson().fromJson(json, HashMap.class);
-         	
-             String param = GsonUtils.toJson(map);
+			// 娉ㄦ剰杩欓噷浠呬负浜嗙畝鍖栫紪鐮佹瘡涓�娆¤姹傞兘鍘昏幏鍙朼ccess_token锛岀嚎涓婄幆澧僡ccess_token鏈夎繃鏈熸椂闂达紝
+			// 瀹㈡埛绔彲鑷缂撳瓨锛岃繃鏈熷悗閲嶆柊鑾峰彇銆�
+			// String accessToken = "[璋冪敤閴存潈鎺ュ彛鑾峰彇鐨則oken]";
+			String msg = HttpUtil.post(url, map.get("accessToken").toString(),
+					"application/json", param);
 
-             // 娉ㄦ剰杩欓噷浠呬负浜嗙畝鍖栫紪鐮佹瘡涓�娆¤姹傞兘鍘昏幏鍙朼ccess_token锛岀嚎涓婄幆澧僡ccess_token鏈夎繃鏈熸椂闂达紝 瀹㈡埛绔彲鑷缂撳瓨锛岃繃鏈熷悗閲嶆柊鑾峰彇銆�
-             //String accessToken = "[璋冪敤閴存潈鎺ュ彛鑾峰彇鐨則oken]";
+			return msg;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
 
-             String result = HttpUtil.post(url, map.get("accessToken").toString(), "application/json", param);
-             System.out.println(result);
-             return result;
-         } catch (Exception e) {
-             e.printStackTrace();
-         }
-         return null;
-     }
+	/**
+	 * 浜鸿劯鎼滅储 FileUtil,Base64Util,HttpUtil,GsonUtils璇蜂粠
+	 * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
+	 * https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2
+	 * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
+	 * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3 涓嬭浇
+	 */
+	public static String faceSearch(String json) {
+		// 璇锋眰url
+		String url = "https://aip.baidubce.com/rest/2.0/face/v3/search";
+		try {
+			/*
+			 * Map<String, Object> map = new HashMap<>(); map.put("image",
+			 * "027d8308a2ec665acb1bdf63e513bcb9"); map.put("liveness_control",
+			 * "NORMAL"); map.put("group_id_list", "group_repeat,group_233");
+			 * map.put("image_type", "FACE_TOKEN"); map.put("quality_control",
+			 * "LOW");
+			 */
 
-    public static void main(String[] args) {
-    	
-    	//map.put("image", "027d8308a2ec665acb1bdf63e513bcb9");
-        //map.put("face_field", "faceshape,facetype");
-        //map.put("image_type", "FACE_TOKEN");
-    	//map.put("accessToken", "************");
-//    	String json = "{'accessToken':'24.0363955052d87d6558e635ce1990a0ae.2592000.1590564753.282335-19585027',"
-//    			+ "'image_type':'BASE64',"
-//    			+ "'face_field':'age,beauty,expression,face_shape,gender,glasses,landmark,landmark150,race,quality,eye_status,emotion,face_type,mask,spoofing',"
-//    			+ "}";
-    	String imgstr = "";
-    	File file = new File("src/img.txt");
-        String courseFile = file.getAbsolutePath();
-        System.out.println(courseFile);
-    	try {
+			Map<String, Object> map = ActionUtil.getGson().fromJson(json,
+					HashMap.class);
+
+			String param = GsonUtils.toJson(map);
+
+			// 娉ㄦ剰杩欓噷浠呬负浜嗙畝鍖栫紪鐮佹瘡涓�娆¤姹傞兘鍘昏幏鍙朼ccess_token锛岀嚎涓婄幆澧僡ccess_token鏈夎繃鏈熸椂闂达紝
+			// 瀹㈡埛绔彲鑷缂撳瓨锛岃繃鏈熷悗閲嶆柊鑾峰彇銆�
+			// String accessToken = "[璋冪敤閴存潈鎺ュ彛鑾峰彇鐨則oken]";
+
+			String result = HttpUtil.post(url, map.get("accessToken")
+					.toString(), "application/json", param);
+			//System.out.println(result);
+			return result;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	/**
+	 * 娣诲姞浜鸿劯
+	 * 
+	 * @param json
+	 * @return
+	 */
+	public static String faceAdd(String json) {
+		// 璇锋眰url
+		String url = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/add";
+		try {
+			// Map<String, Object> map = new HashMap<>();
+			// map.put("image", "027d8308a2ec665acb1bdf63e513bcb9");
+			// map.put("group_id", "group_repeat");
+			// map.put("user_id", "user1");
+			// map.put("user_info", "abc");
+			// map.put("liveness_control", "NORMAL");
+			// map.put("image_type", "FACE_TOKEN");
+			// map.put("quality_control", "LOW");
+			// map.put("accessToken", "*********************");
+
+			String param = GsonUtils.toJson(json);
+			Map map = ActionUtil.getGson().fromJson(json, HashMap.class);
+			// 娉ㄦ剰杩欓噷浠呬负浜嗙畝鍖栫紪鐮佹瘡涓�娆¤姹傞兘鍘昏幏鍙朼ccess_token锛岀嚎涓婄幆澧僡ccess_token鏈夎繃鏈熸椂闂达紝
+			// 瀹㈡埛绔彲鑷缂撳瓨锛岃繃鏈熷悗閲嶆柊鑾峰彇銆�
+			// String accessToken = "[璋冪敤閴存潈鎺ュ彛鑾峰彇鐨則oken]";
+
+			String result = HttpUtil.post(url, map.get("accessToken")
+					.toString(), "application/json", param);
+			//System.out.println(result);
+			return result;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	/**
+	 * 鍒犻櫎浜鸿劯
+	 * 
+	 * @param json
+	 * @return
+	 */
+	public static String faceDelete(String json) {
+		// 璇锋眰url
+		String url = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/face/delete";
+		try {
+			// Map<String, Object> map = new HashMap<>();
+			// map.put("user_id", "user1");
+			// map.put("group_id", "group1");
+			// map.put("face_token", "*************");
+			// map.put("accessToken", "*************");
+
+			String param = json;
+			Map map = ActionUtil.getGson().fromJson(json, HashMap.class);
+			// 娉ㄦ剰杩欓噷浠呬负浜嗙畝鍖栫紪鐮佹瘡涓�娆¤姹傞兘鍘昏幏鍙朼ccess_token锛岀嚎涓婄幆澧僡ccess_token鏈夎繃鏈熸椂闂达紝
+			// 瀹㈡埛绔彲鑷缂撳瓨锛岃繃鏈熷悗閲嶆柊鑾峰彇銆�
+			// String accessToken = "[璋冪敤閴存潈鎺ュ彛鑾峰彇鐨則oken]";
+
+			String result = HttpUtil.post(url, map.get("accessToken")
+					.toString(), "application/json", param);
+			//System.out.println(result);
+			return result;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	/**
+	 * 鏇存柊浜鸿劯
+	 * 
+	 * @param json
+	 * @return
+	 */
+	public static String faceUpdate(String json) {
+		// 璇锋眰url
+		String url = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/update";
+		try {
+			// Map<String, Object> map = new HashMap<>();
+			// map.put("image", "027d8308a2ec665acb1bdf63e513bcb9");
+			// map.put("group_id", "group_repeat");
+			// map.put("user_id", "user1");
+			// map.put("user_info", "cba");
+			// map.put("liveness_control", "NORMAL");
+			// map.put("image_type", "FACE_TOKEN");
+			// map.put("quality_control", "LOW");
+			// map.put("accessToken", "*************");
+
+			String param = json;
+			Map map = ActionUtil.getGson().fromJson(json, HashMap.class);
+			// 娉ㄦ剰杩欓噷浠呬负浜嗙畝鍖栫紪鐮佹瘡涓�娆¤姹傞兘鍘昏幏鍙朼ccess_token锛岀嚎涓婄幆澧僡ccess_token鏈夎繃鏈熸椂闂达紝
+			// 瀹㈡埛绔彲鑷缂撳瓨锛岃繃鏈熷悗閲嶆柊鑾峰彇銆�
+			// String accessToken = "[璋冪敤閴存潈鎺ュ彛鑾峰彇鐨則oken]";
+
+			String result = HttpUtil.post(url, map.get("accessToken")
+					.toString(), "application/json", param);
+			//System.out.println(result);
+			return result;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	/**
+	 * 鑾峰彇鐢ㄦ埛浜鸿劯鍒楄〃
+	 * 
+	 * @param json
+	 * @return
+	 */
+	public static String faceGetList(String json) {
+		// 璇锋眰url
+		String url = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/face/getlist";
+		try {
+			// Map<String, Object> map = new HashMap<>();
+			// map.put("user_id", "user1");
+			// map.put("group_id", "group1");
+			// map.put("accessToken", "*************");
+
+			String param = json;
+			Map map = ActionUtil.getGson().fromJson(json, HashMap.class);
+			// 娉ㄦ剰杩欓噷浠呬负浜嗙畝鍖栫紪鐮佹瘡涓�娆¤姹傞兘鍘昏幏鍙朼ccess_token锛岀嚎涓婄幆澧僡ccess_token鏈夎繃鏈熸椂闂达紝
+			// 瀹㈡埛绔彲鑷缂撳瓨锛岃繃鏈熷悗閲嶆柊鑾峰彇銆�
+			// String accessToken = "[璋冪敤閴存潈鎺ュ彛鑾峰彇鐨則oken]";
+
+			String result = HttpUtil.post(url, map.get("accessToken")
+					.toString(), "application/json", param);
+			//System.out.println(result);
+			return result;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	/**
+	 * 鑾峰彇鐢ㄦ埛鍒楄〃
+	 * 
+	 * @param json
+	 * @return
+	 */
+	public static String groupGetusers(String json) {
+		// 璇锋眰url
+		String url = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/group/getusers";
+		try {
+			// Map<String, Object> map = new HashMap<>();
+			// map.put("group_id", "group1");
+			// map.put("accessToken", "**********");
+
+			String param = json;
+			Map map = ActionUtil.getGson().fromJson(json, HashMap.class);
+			// 娉ㄦ剰杩欓噷浠呬负浜嗙畝鍖栫紪鐮佹瘡涓�娆¤姹傞兘鍘昏幏鍙朼ccess_token锛岀嚎涓婄幆澧僡ccess_token鏈夎繃鏈熸椂闂达紝
+			// 瀹㈡埛绔彲鑷缂撳瓨锛岃繃鏈熷悗閲嶆柊鑾峰彇銆�
+			// String accessToken = "[璋冪敤閴存潈鎺ュ彛鑾峰彇鐨則oken]";
+
+			String result = HttpUtil.post(url, map.get("accessToken")
+					.toString(), "application/json", param);
+			//System.out.println(result);
+			return result;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	/**
+	 * 浜鸿劯澶嶅埗
+	 * @param json
+	 * @return
+	 */
+	public static String faceCopy(String json) {
+		// 璇锋眰url
+		String url = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/copy";
+		try {
+			// Map<String, Object> map = new HashMap<>();
+			// map.put("user_id", "group1");
+			// map.put("src_group_id", "**********");		婧愮粍鍙�
+			// map.put("dst_group_id", "**********");		鐩爣缁勫彿
+			// map.put("accessToken", "**********");		鐩爣缁勫彿
+
+			String param = json;
+			Map map = ActionUtil.getGson().fromJson(json, HashMap.class);
+			// 娉ㄦ剰杩欓噷浠呬负浜嗙畝鍖栫紪鐮佹瘡涓�娆¤姹傞兘鍘昏幏鍙朼ccess_token锛岀嚎涓婄幆澧僡ccess_token鏈夎繃鏈熸椂闂达紝
+			// 瀹㈡埛绔彲鑷缂撳瓨锛岃繃鏈熷悗閲嶆柊鑾峰彇銆�
+			// String accessToken = "[璋冪敤閴存潈鎺ュ彛鑾峰彇鐨則oken]";
+
+			String result = HttpUtil.post(url, map.get("accessToken").toString(), "application/json", param);
+			//System.out.println(result);
+			return result;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+	
+	
+
+	public static void main(String[] args) {
+
+		// map.put("image", "027d8308a2ec665acb1bdf63e513bcb9");
+		// map.put("face_field", "faceshape,facetype");
+		// map.put("image_type", "FACE_TOKEN");
+		// map.put("accessToken", "************");
+		// String json =
+		// "{'accessToken':'24.0363955052d87d6558e635ce1990a0ae.2592000.1590564753.282335-19585027',"
+		// + "'image_type':'BASE64',"
+		// +
+		// "'face_field':'age,beauty,expression,face_shape,gender,glasses,landmark,landmark150,race,quality,eye_status,emotion,face_type,mask,spoofing',"
+		// + "}";
+		String imgstr = "";
+		File file = new File("src/img.txt");
+		String courseFile = file.getAbsolutePath();
+		//System.out.println(courseFile);
+		try {
 			FileInputStream fis = new FileInputStream(file);
 			byte[] b = new byte[1024];
 			int len = 0;
 			try {
-				while((len = fis.read(b))!=-1){
+				while ((len = fis.read(b)) != -1) {
 					imgstr += new String(b);
 				}
 			} catch (IOException e) {
@@ -112,14 +312,16 @@
 			}
 		} catch (FileNotFoundException e) {
 			e.printStackTrace();
-		} 
-    	Map map = new HashMap<String, String>();
-    	map.put("accessToken", "24.0363955052d87d6558e635ce1990a0ae.2592000.1590564753.282335-19585027");
-    	map.put("image_type", "BASE64");
-    	map.put("face_field", "age,beauty,expression,face_shape,gender,glasses,landmark,landmark150,race,quality,eye_status,emotion,face_type,mask,spoofing");
-    	map.put("image", imgstr);
-    	
-    	//System.out.println(json);
-    	System.out.println( FaceDetect.faceDetect(ActionUtil.tojson(map)));
-    }
+		}
+		Map map = new HashMap<String, String>();
+		map.put("accessToken",
+				"24.0363955052d87d6558e635ce1990a0ae.2592000.1590564753.282335-19585027");
+		map.put("image_type", "BASE64");
+		map.put("face_field",
+				"age,beauty,expression,face_shape,gender,glasses,landmark,landmark150,race,quality,eye_status,emotion,face_type,mask,spoofing");
+		map.put("image", imgstr);
+
+		// System.out.println(json);
+		System.out.println(FaceDetect.faceDetect(ActionUtil.tojson(map)));
+	}
 }
\ No newline at end of file

--
Gitblit v1.9.1