支付宝小程序身份认证(拉取人脸识别 认证功能 +详细案例)

本文介绍了支付宝小程序进行身份认证的交互流程,包括创建小程序、添加功能、签约及调用接口步骤。通过遵循开发文档,获取`certify_id`来拉取认证页面,实现身份验证功能。
摘要由CSDN通过智能技术生成

交互流程
支付宝身份核验的交互流程如下图所示:
在这里插入图片描述
接入指引
第一步:创建小程序
第二步:添加功能
第三步:签约功能
第四步:调用接口

其中前三步看 开发文档: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.
  • 8
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 30
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 30
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值