交互流程
支付宝身份核验的交互流程如下图所示:
接入指引
第一步:创建小程序
第二步:添加功能
第三步:签约功能
第四步:调用接口
其中前三步看 开发文档:https://opendocs.alipay.com/mini/introduce/alipay-verfify
接口代码:
@GetMapping("/shenfenrz")
@ResponseBody
public HashMap<String, String> shenfenrz(String sfzh, String xm, String appid) throws AlipayApiException {
HashMap<String, String> map = null;
map = new HashMap<>();
int i = sfrz.getapp_id(appid,sfzh,xm);
System.err.println(i);
if (i == 0) {
AlipayClient alipayClient = new DefaultAlipayClient(URL, APP_ID, APP_PRIVATE_KEY, FORMAT, CHARSET, ALIPAY_PUBLIC_KEY, SIGN_TYPE);
AlipayUserCertifyOpenInitializeRequest request = new AlipayUserCertifyOpenInitializeRequest();
// new AlipayUserCertifyInfoApplyRequest();
//构造身份信息json对象
JSONObject identityObj = new JSONObject();
//身份类型,必填,详细取值范围请参考接口文档说明
identityObj.put("identity_type", "CERT_INFO");
//证件类型,必填,详细取值范围请参考接口文档说明
identityObj.put("cert_type", "IDENTITY_CARD");
//真实姓名,必填
String regex = "\\d{15}(\\d{2}[0-9xX])?";
String id = sfzh;
if (id.matches(regex)) {
//证件号码,必填
identityObj.put("cert_no", sfzh);
} else {
map.put("message", "请认真核对身份证证件号码信息");
map.put("success", "false");
}
identityObj.put("cert_name", xm);
//证件号码,必填
// identityObj.put("cert_no", sfzh);
//构造商户配置json对象
JSONObject merchantConfigObj = new JSONObject();
// 设置回调地址,必填. 如果需要直接在支付宝APP里面打开回调地址使用alipay协议,参考下面的案例:appId用固定值 20000067,url替换为urlEncode后的业务回跳地址
// alipays://platformapi/startapp?appId=20000067&url=https%3A%2F%2Fapp.cqkqinfo.com%2Fcertify%2FzmxyBackNew.do
merchantConfigObj.put("return_url", "alipays://platformapi/startapp?appId=20000067&url=https%3A%2F%2Fapp.cqkqinfo.com%2Fcertify%2FzmxyBackNew.do");
//构造身份认证初始化服务业务参数数据
JSONObject bizContentObj = new JSONObject();
//商户请求的唯一标识,推荐为uuid,必填
String uuid = UUID.randomUUID().toString();
bizContentObj.put("outer_order_no", uuid);
bizContentObj.put("biz_code", "FACE");
bizContentObj.put("identity_param", identityObj);
bizContentObj.put("merchant_config", merchantConfigObj);
request.setBizContent(bizContentObj.toString());
//发起请求
AlipayUserCertifyOpenInitializeResponse response = alipayClient.execute(request);
String url = "";
if (response.isSuccess()) {
System.out.println("调用成功");
//接口调用成功,从返回对象中获取certify_id
String certifyId = response.getCertifyId();
url = url(certifyId);
//执行后续流程...
map.put("certifyId", certifyId);
map.put("url", url);
if (certifyId != null && url != null) {
map.put("success", "2");
} else {
map.put("success", "3");
}
} else {
System.out.println("调用失败");
}
return map;
} else {
map.put("success", "1");
NDShenPi ndShenPi = sfrz.getselect(sfzh, xm);
System.err.println("ndShenPi:" + ndShenPi);
if (ndShenPi != null) {
map.put("id", String.