欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java检测身份证号是否符合18岁

程序员文章站 2023-12-27 15:56:09
...
      private Integer yzIdcard(String name , String idcard){
            String host = "http://checkone.market.alicloudapi.com";
            String path = "/chinadatapay/1882";
            String method = "POST";
//            String appcode = "c20ddc9f3116423ab8edaf9f98bcc09e";
            Map<String, String> headers = new HashMap<String, String>();
            //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
            headers.put("Authorization", "APPCODE " + appCode);
            //根据API的要求,定义相对应的Content-Type
            headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
            Map<String, String> querys = new HashMap<String, String>();
            Map<String, String> bodys = new HashMap<String, String>();
            bodys.put("idcard", idcard);
            bodys.put("name", name);


            try {
                  /**
                   * 重要提示如下:
                   * HttpUtils请从
                   * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
                   * 下载
                   *
                   * 相应的依赖请参照
                   * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
                   */
//                  官方的请求
                  HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);

//                  官方
                  JSONObject jsonObject = JSONObject.parseObject(EntityUtils.toString(response.getEntity()));
               logger.info("code的数据类型 {}" ,code);

                  Object o = jsonObject.get("data");
                  logger.info("o的数据类型 {}" ,o);
                  if (o == null) {
                        return 2;
                  } else {
                        Object o1 = jsonObject.getJSONObject("data").get("result");
                        String s11 = o1.toString();
                        if (s11.equals("1")) {
                           return 1;
                        } else {
                           return 2;
                        }
                  }

            } catch (Exception e) {
                  e.printStackTrace();

            }
            return 2;
      }
            String name = param.getName();
            String idCard = param.getIdCard();
         Integer last = yzIdcard(name , idCard);
           Msg.S2c_REGISTER_RESULT.Builder builder = Msg.S2c_REGISTER_RESULT.newBuilder();
            if (last != 1) {
                  builder.setResultCode(1);
                  builder.setResultMsg("身份认证失败");
                  session.writeResponse(new ResponseMsg(MsgType.Enums.S2C_REGISTER_RESULT_VALUE, builder.build()));
                  return;
            }
相关标签: JAVA 新星计划

上一篇:

下一篇: