DESKTOP-71BH0QO\L、ming
2021-04-20 26cd8c7b2bc7a725a3de28d3ed883a6f54da84f1
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
package com.panzhihua.common.utlis;
 
import com.alibaba.fastjson.JSONObject;
 
import java.util.Base64;
 
/**
 * @program: springcloud_k8s_panzhihuazhihuishequ
 * @description: 实名认证工具
 * @author: huang.hongfa weixin hhf9596 qq 959656820
 * @create: 2021-01-08 09:45
 **/
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();
        String postByJson = HttpClientUtil.sendPostByJson(URL, param, 0, headerkey, headervalue + encodeToString);
        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", "黄宏发f");
        System.out.println(b);
    }
 
}