package com.huimv.admin.analyse;

import com.baidu.aip.face.AipFace;
import com.baidu.aip.http.AipRequest;
import com.baidu.aip.util.Base64Util;
import com.baidu.aip.util.Util;
import org.json.JSONObject;

import java.io.IOException;
import java.util.Base64;
import java.util.HashMap;

/**
 * @Project : huimv.shiwan
 * @Package : com.huimv.admin.analyse
 * @Description : TODO
 * @Author : yuxuexuan
 * @Create : 2020/12/27 0027 13:21
 **/

public class Sample {

    public static final String APP_ID = "23396383";
    public static final String API_KEY = "EiCulalmXcwLlxqicQrlYdxe";
    public static final String SECRET_KEY = "YYWBzZqyx6CTtzA9ldmfMME85AXMNTlx";
    public static void main(String[] args) throws IOException {
        //初始化一个FaceClient
        AipFace face = new AipFace(APP_ID,API_KEY ,SECRET_KEY);
      /*  //可选：设置网络连接参数
        face.setConnectionTimeoutInMillis(60000);
        face.setSocketTimeoutInMillis(60000);
        //调用API
        HashMap map = new HashMap();
        //
        map.put("face_fields", "age,beauty,expression,gender,glasses,race,qualities");
        String path = "G:/BaiduNetdiskDownload/pc/wallhaven-9mxjqk.png";
        AipRequest aipRequest = new AipRequest();
        aipRequest.setBody(map);
        String image = Base64Util.encode(Util.readFileByBytes(path));

        String groupId = "shiwan";
        String userId = "yxx";


        JSONObject result = face.addUser(image,"BASE64",groupId,userId,map);
        System.out.println(result.toString(2));*/
      sample(face);
    }

    public static void sample(AipFace client) throws IOException {
        // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("quality_control", "NORMAL");
        options.put("liveness_control", "LOW");

        //String path = "G:/BaiduNetdiskDownload/pc/wallhaven-39mdmy.jpg";
       String path = "C:/Users/Administrator/Desktop/1.jpg";
        String image = Base64Util.encode(Util.readFileByBytes(path));
        String imageType = "BASE64";
        String groupIdList = "shiwan";
       /* String idCardNumber = "yxx";
        String name = "shiwan";*/


        // 身份验证
        JSONObject res =  client.search(image, imageType, groupIdList , options);
        System.out.println(res.toString(2));

    }
}
