对接开发身份验证程序的流程

来源:互联网 发布:mac口红最值得买的色号 编辑:程序博客网 时间:2024/05/01 21:32
private Map<String, Object> checkIdCardAuth(Map<String, String> params) {        Map<String, Object> resultMap = new HashMap<String, Object>();        // 1.校验传入参数        String[] keys = { "code", "name", "path" };        String check_1 = CommUtil.checkMapParams(params, keys);        if (check_1.length() > 0) {            resultMap.put(CommUtil.STATUS, CommUtil.FAIL);            resultMap.put(CommUtil.MESSAGE, check_1);            return resultMap;        }        check_1 = CommUtil.checkMapParamsIsNotNull(params, keys);        if (check_1.length() > 0) {            resultMap.put(CommUtil.STATUS, CommUtil.FAIL);            resultMap.put(CommUtil.MESSAGE, check_1);            return resultMap;        }        // 2.获取参数        String code = params.get("code");        String name = params.get("name");        String path = params.get("path");        // 3.校验身份证号 code 的合法性        if (!IdCardUtil.isIDCard(code)) {            resultMap.put(CommUtil.STATUS, CommUtil.FAIL);            resultMap.put(CommUtil.MESSAGE, "身份证信息不合法");            return resultMap;        }        // 4.本地数据库查询是否已经验证过 包括名字的校验        Map<String, String> request_Temp = new HashMap<String, String>();        request_Temp.put("code", code);        Map<String, String> response_Temp = authService.getAuthInfo(params);        // 5.验证过了,就直接返回正确与否 没验证过,就进行下一步        if (response_Temp != null) {            if (name.equals(response_Temp.get("name"))) {                resultMap.put(CommUtil.STATUS, CommUtil.SUCCESS);                resultMap.put(CommUtil.MESSAGE, "身份证信息合法");                return resultMap;            } else {                resultMap.put(CommUtil.STATUS, CommUtil.FAIL);                resultMap.put(CommUtil.MESSAGE, "身份证信息不合法");                return resultMap;            }        }        // 6.组织校验关系,进行发送校验请求        String result = "";        try {            result = authOperate(code, name, path);        } catch (Exception e) {            e.printStackTrace();            resultMap.put(CommUtil.STATUS, CommUtil.FAIL);            resultMap.put(CommUtil.MESSAGE, "身份证验证过程失败");            return resultMap;        }        System.out.println("----->" + result + "<-----");        // 7.校验为成功则记录本地数据库 校验失败则不记录        // TODO 看看是否成功        boolean bl = true;        if (!bl) {            request_Temp.clear();            Map<String, Object> add_Request_Temp = new HashMap<String, Object>();            add_Request_Temp.put("code", code);            add_Request_Temp.put("name", name);            add_Request_Temp.put("createtime", new Date());            authService.addAuthInfo(params);            resultMap.put(CommUtil.STATUS, CommUtil.SUCCESS);            resultMap.put(CommUtil.MESSAGE, "身份证信息合法");        } else {            resultMap.put(CommUtil.STATUS, CommUtil.FAIL);            resultMap.put(CommUtil.MESSAGE, "身份证验证过程失败");        }        // 8.返回校验结果        return resultMap;    }

//程序中调用的部分方法为对接服务商提供的接口,暂不提供出来。如果碰到对接任务的话,可以向对接上获取

//只提供一个截取返回值的公用方法

/**     * XML解析     *      * @param result     * @return     * @throws DocumentException     */    public static Map<String, Object> xmlParseMethod(String result) throws DocumentException {        Map<String, Object> resultMap = new HashMap<String, Object>();        if (result == null || result.length() == 0) {            resultMap.put(CommUtil.STATUS, CommUtil.FAIL);            resultMap.put(CommUtil.MESSAGE, "未知错误");            return resultMap;        }        Document document = DocumentHelper.parseText(result);        Element root = document.getRootElement();        if (root != null) {            // 判断是否包含ErrorCode 和 ErrorMsg            Element ErrorCode = (Element) root.selectSingleNode("//ErrorCode");            Element ErrorMsg = (Element) root.selectSingleNode("//ErrorMsg");            if (ErrorCode != null || ErrorMsg != null) {                resultMap.put(CommUtil.STATUS, CommUtil.FAIL);                resultMap.put(CommUtil.MESSAGE, ErrorMsg.getTextTrim());                return resultMap;            }            // 其他错误            Element errormesage = (Element) root.selectSingleNode("//errormesage");            Element errormesagecol = (Element) root.selectSingleNode("//errormesagecol");            if (errormesage != null || errormesagecol != null) {                resultMap.put(CommUtil.STATUS, CommUtil.FAIL);                resultMap.put(CommUtil.MESSAGE, errormesage.getTextTrim() + "-" + errormesagecol.getTextTrim());                return resultMap;            }            // 校验结果            Element result_gmsfhm = (Element) root.selectSingleNode("//result_gmsfhm");            Element result_xm = (Element) root.selectSingleNode("//result_xm");            if (result_gmsfhm != null || result_xm != null) {                String result_gmsfhmText = result_gmsfhm.getTextTrim();                String result_xmText = result_xm.getTextTrim();                if ("一致".equals(result_gmsfhmText) && "一致".equals(result_xmText)) {                    resultMap.put(CommUtil.STATUS, CommUtil.SUCCESS);                    resultMap.put(CommUtil.MESSAGE, "校验通过");                    return resultMap;                }            }        }        resultMap.put(CommUtil.STATUS, CommUtil.FAIL);        resultMap.put(CommUtil.MESSAGE, "验证未通过");        return resultMap;    }
0 0