代码示例如下:

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.http.ProtocolType;
import com.aliyuncs.profile.DefaultProfile;

public class FaceVerifyTest {
    public static void main(String[] args) throws IOException {
        // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
        // 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
        // 本示例通过阿里云Credentials工具从环境变量中读取AccessKey,来实现API访问的身份验证。
        com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client();
        String accesssKey = credentialClient.getAccessKeyId();
        String accessKeySecret = credentialClient.getAccessKeySecret();
      
        DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai",accesssKey,accessKeySecret);
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);

        request.setSysDomain("saf.cn-shanghai.aliyuncs.com");
        request.setSysVersion("2017-03-31");
        request.setSysAction("ExecuteRequest");
        request.setSysProtocol(ProtocolType.HTTPS);

        // 业务详细参数。
        Map<String, Object> serviceParams = new HashMap<String, Object>();

        // 发起认证请求。
        serviceParams.put("method",  "init");
        serviceParams.put("sceneId",  "1000000006");    
        serviceParams.put("outerOrderNo",  "e0c34a77f5ac40a5aa5e6ed20c353888");
        serviceParams.put("bizCode", "FACE");  // 当用户在iOS或安卓平台发起认证时,认证场景码是FACE_SDK;在小程序中,认证场景码则为FACE。
        serviceParams.put("identityType", "CERT_INFO");
        serviceParams.put("certType", "IDENTITY_CARD");        
        serviceParams.put("certNo", "330103xxxxxxxxxxxx");
        serviceParams.put("certName", "张三");
        serviceParams.put("returnUrl", "https://www.aliyun.com");
        serviceParams.put("callbackUrl", "https://www.aliyun.com");
        serviceParams.put("callbackToken", "NMjvQanQgplBSaEI0sL86WnQplB");

        /*
        // 如需开启个人信息加密传输。
        serviceParams.put("encryptType", "SM2");
        serviceParams.put("certNo", "BMjsstxK3S4b1YH*****Pet8ECObfxmLN92SLsNg==");
        serviceParams.put("certName", "BCRD/7ZkNy7Q*****M1BMBezZe8GaYHrLwyJv558w==");
        */

        /*
        // 查询认证结果。
        serviceParams.put("method",  "query");
        serviceParams.put("certifyId", "7eff3ad26a9c7b68c511b9f35eb1a354");
        serviceParams.put("sceneId", "100000000");
        */

        request.putBodyParameter("ServiceParameters", JSON.toJSONString(serviceParams));
        // 固定值,Service = fin_face_verify。
        request.putBodyParameter("Service", "fin_face_verify");

        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}