这里是对应java本地上传部分上面案例是银行卡,当时人脸识别是另外一个包,所以不能用银行卡的去跑人脸识别的,下面是测试样例,仅供参考
import com.aliyun.facebody20191230.Client;
import com.aliyun.facebody20191230.models.AddFaceAdvanceRequest;
import com.aliyun.facebody20191230.models.AddFaceResponse;
import com.aliyun.tearpc.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.google.gson.Gson;
import com.site.upload.config.MyInfo;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
/**
* @author lenyuqin
*/
public class AddFaceAdvance {
public static void main(String[] args) throws Exception {
//这里是个坑,注意别导错包了,如果采用官网的银行卡测试是会失效的
//银行卡的Client是在com.aliyun.ocr20191230下
//人脸识别是在com.aliyun.tearpc.models包下,
Config config = new Config();
config.setAccessKeyId(MyInfo.ACCESS_KEY_ID);//这里填写个人的ACCESSKEY_ID
config.setAccessKeySecret(MyInfo.ACCESS_KEY_SECRET);//这里填写个人的ACCESSKEY_SECRET
config.setRegionId("cn-shanghai");
Client client = new Client(config);
//填写本地文件的位置
File file = new File("D:\\Huawei Share\\OneHop\\IMG_20201215_141438.jpg");
InputStream inputStream = new FileInputStream(file);
//只有request有Advance才能进行本地上传
AddFaceAdvanceRequest addFaceAdvanceRequest = new AddFaceAdvanceRequest();
RuntimeOptions runtimeOptions = new RuntimeOptions();
//这些是基本信息,必填~
addFaceAdvanceRequest.setDbName("default");
addFaceAdvanceRequest.setImageUrlObject(inputStream);
addFaceAdvanceRequest.setEntityId("xxxxx");
addFaceAdvanceRequest.setExtraData("xxxx");
try {
AddFaceResponse response = client.addFaceAdvance(addFaceAdvanceRequest,runtimeOptions);
System.out.println(new Gson().toJson(response));
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
System.out.println("ErrCode:" + e.getErrCode());
System.out.println("ErrMsg:" + e.getErrMsg());
System.out.println("RequestId:" + e.getRequestId());
}
}
}
银行卡Client的包:
人脸识别的包:
由于官方导包太多了,很容易出错,建议选择自己需要的功能进行导包
依赖包
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.5.14</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>ocr20191230</artifactId>
<version>0.2.16</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>facebody20191230</artifactId>
<version>0.2.16</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-facebody</artifactId>
<version>1.2.7</version>
</dependency>