DESKTOP-71BH0QO\L、ming
2021-04-26 43c69b2a7ee65a2664b5749cd33cdd3afe50d791
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.panzhihua.common.utlis;
 
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
 
import java.util.Base64;
 
/**
 * @program: springcloud_k8s_panzhihuazhihuishequ
 * @description: 实名认证工具
 * @author: huang.hongfa weixin hhf9596 qq 959656820
 * @create: 2021-01-08 09:45
 **/
@Slf4j
public class RealNameUtil {
    private static final String CLIENT_ID="2092261934651932672";
    private static final String SECRET="de1c0dbb-9197-4724-9cc2-aa94e30a072f";
    private static final String URL="http://118.121.56.56:18080/users/auth/policeMatch";
 
 
    /**
     * 实名认证
     * @param idcard 身份证
     * @param name 名字
     * @return 认证结果 true false
     */
    public static boolean authentication(String idcard,String name){
        boolean result=false;
        String headerkey="Authorization";
        String headervalue="Basic ";
        String basicStr = CLIENT_ID + ":" + SECRET + ":" + System.currentTimeMillis();
        String encodeToString = Base64.getEncoder().encodeToString(basicStr.getBytes());
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("idNumber",idcard);
        jsonObject.put("realName",name);
        String param=jsonObject.toJSONString();
        log.info("请求公安实名认证接口,请求地址:" + URL);
        log.info("请求公安实名认证接口,请求参数:" + param);
        log.info("请求公安实名认证接口,请求头参数:" + headervalue + encodeToString);
        String postByJson = HttpClientUtil.sendPostByJson(URL, param, 0, headerkey, "Basic MjA5MjI2MTkzNDY1MTkzMjY3MjpkZTFjMGRiYi05MTk3LTQ3MjQtOWNjMi1hYTk0ZTMwYTA3MmY6MTYxOTQyMTMyMzgxMg==");
        log.info("请求公安实名认证接口,返回参数:" + postByJson);
        int code = JSONObject.parseObject(postByJson).getIntValue("code");
        if (0==code) {
            result =true;
        }
        return result;
    }
 
    public static void main(String[] args) {
        boolean b = RealNameUtil.authentication("340823199112282557", "黄宏发");
        System.out.println(b);
    }
 
}