好像是face++,又好像不是,具体的忘记了,为了以后自己可以好找代码:
package com.common.face;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import javax.net.ssl.SSLException;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
/**
* 得到pic的face_token
*/
public class FacePlus {
public static void main(String[] args) throws Exception{
File file = new File("C:\\Users\\Administrator\\Desktop\\abc\\erwa.jpg");
byte[] buff = getBytesFromFile(file);
String url = "https://api-cn.faceplusplus.com/facepp/v3/detect";
HashMap map = new HashMap<>();
HashMap byteMap = new HashMap<>();
map.put("api_key", "NCZxjJtNcTsQJLNc_zhEp6OeWyC3OgW6");
map.put("api_secret", "X8ymk7AKMFWrWJP6RHr_NZOO9eZmAvzw");
map.put("return_landmark", "1");
map.put("return_attributes", "gender,age,smiling,headpose,facequality,blur,eyestatus,emotion,ethnicity,beauty,mouthstatus,eyegaze,skinstatus");
byteMap.put("image_file", buff);
try{
byte[] bacd = post(url, map, byteMap);
String str = new String(bacd);
System.out.println(str);
JSONObject jsonObject = JSONObject.parseObject(str);
JSONArray jsonArray = (JSONArray) jsonObject.get("faces");
JSONObject jsonfac = (JSONObject) jsonArray.get(jsonArray.size()-1);
String face_token = (String) jsonfac.get("face_token");
System.out.println(face_token);
}catch (Exception e) {
e.printStackTrace();
}
}
public static String getFaceId(byte[] buff){
String url = "https://api-cn.faceplusplus.com/facepp/v3/detect";
HashMap map = new HashMap<>();
HashMap byteMap = new HashMap<>();
map.put("api_key", "NCZxjJtNcTsQJLNc_zhEp6OeWyC3OgW6");
map.put("api_secret", "X8ymk7AKMFWrWJP6RHr_NZOO9eZmAvzw");
map.put("return_landmark", "1");
map.put("return_attributes", "gender,age,smiling,headpose,facequality,blur,eyestatus,emotion,ethnicity,beauty,mouthstatus,eyegaze,skinstatus");
byteMap.put("image_file", buff);
String face_token = "";
try{
byte[] bacd = post(url, map, byteMap);
String str = new String(bacd);
System.out.println("str:"+str);
JSONObject jsonObject = JSONObject.parseObject(str);
JSONArray jsonArray = (JSONArray) jsonObject.get("faces");
int size = jsonArray.size();
System.out.println("size:"+size);
if(size == 0){
return "-1";
}
JSONObject jsonfac = (JSONObject) jsonArray.get(size-1);
face_token = (String) jsonfac.get("face_token");
}catch (Exception e) {
e.printStackTrace();
}
return face_token;
}
private final static int CONNECT_TI