| | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | | import org.json.JSONObject; |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.InputStreamReader; |
| | |
| | | map2.put("image_type","URL"); |
| | | list.add(map); |
| | | list.add(map2); |
| | | String s = JSONObject.valueToString(list); |
| | | String s = JSONUtil.toJsonStr(list); |
| | | return face(s); |
| | | } |
| | | |
| | | public static int face(String jsonBody) { |
| | | String result = HttpUtil.jsonPost2(jsonBody, "https://aip.baidubce.com/rest/2.0/face/v3/match?access_token=" + getAuth()); |
| | | try { |
| | | JSONObject jsonObject = new JSONObject(result); |
| | | String access_token = jsonObject.getString("error_msg"); |
| | | JSONObject jsonObject = JSONUtil.parseObj(result); |
| | | String access_token = jsonObject.getStr("error_msg"); |
| | | if(access_token.equals("SUCCESS")){ |
| | | String result2 = jsonObject.get("result").toString(); |
| | | JSONObject jsonObject2 = new JSONObject(result2); |
| | | JSONObject jsonObject2 = JSONUtil.parseObj(result2); |
| | | int score = jsonObject2.getInt("score"); |
| | | return score; |
| | | } |
| | |
| | | * 返回结果示例 |
| | | */ |
| | | //System.err.println("result:" + result); |
| | | JSONObject jsonObject = new JSONObject(result); |
| | | String access_token = jsonObject.getString("access_token"); |
| | | JSONObject jsonObject = JSONUtil.parseObj(result); |
| | | String access_token = jsonObject.getStr("access_token"); |
| | | return access_token; |
| | | } catch (Exception e) { |
| | | System.err.printf("获取token失败!"); |