Step By Step
1、 开通人脸人体服务,具体可参考链接
2、获取您的真实AK信息,具体可参考链接
3、pom.xml
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.4.8</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>facebody20200910</artifactId>
<version>2.0.0</version>
</dependency>
4.金融人脸检测SDK Code Sample
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import sun.misc.BASE64Encoder;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
public class FaceMoney {
public static void main(String[] args) {
DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", "<AccessKey ID>", "<AccessKey Secret>");
/** use STS Token
DefaultProfile profile = DefaultProfile.getProfile(
"<your-region-id>", // The region ID
"<your-access-key-id>", // The AccessKey ID of the RAM account
"<your-access-key-secret>", // The AccessKey Secret of the RAM account
"<your-sts-token>"); // STS Token
**/
IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
request.setSysUriPattern("/viapi/thirdparty/realperson/execServerSideVerification");
request.setSysMethod(MethodType.POST);
request.setSysDomain("facebody.cn-shanghai.aliyuncs.com");
request.setSysVersion("2020-09-10");
// request.putHeadParameter("Content-Type", "application/json");
request.putQueryParameter("CertificateName","姓名");
request.putQueryParameter("CertificateNumber","身份证");
File fileA = new File("本地图片");
String A = null;
try {
A = encodeImageToBase64(fileA);
} catch (Exception e) {
e.printStackTrace();
}
request.putBodyParameter("FacialPictureData",A);
request.putQueryParameter("SceneType","server");
try {
CommonResponse response = client.getCommonResponse(request);
System.out.println(response.getData());
} catch (ClientException e) {
e.printStackTrace();
}
}
public static String encodeImageToBase64(File file) throws Exception {
//将图片文件转化为字节数组字符串,并对其进行Base64编码处理
// loggerger.info("图片的路径为:" + file.getAbsolutePath());
InputStream in = null;
byte[] data = null;
//读取图片字节数组
try {
in = new FileInputStream(file);
data = new byte[in.available()];
in.read(data);
in.close();
} catch (IOException e) {
e.printStackTrace();
throw new Exception("图片上传失败,请联系客服!");
}
//对字节数组Base64编码
BASE64Encoder encoder = new BASE64Encoder();
String base64 = encoder.encode(data);
return base64;//返回Base64编码过的字节数组字符串
}
}
5、运行结果: