mitao
2024-06-06 3d2b51ea4520533de5e78f88dddf5b5c7dce4247
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
55
56
57
58
59
60
61
62
63
64
package com.sinata.rest.core.aliyun.realname;
 
import com.alibaba.fastjson.JSONObject;
import com.sinata.common.keys.AliyunConfig;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * @author :liziming
 * @date :2020/9/21 12:27
 * @description:阿里云实名认证工具类
 * @version: 1.0
 */
@Slf4j
public class AliyunRealNameUtil {
 
    public static void main(String[] args) {
        //Map<String,Integer> map = getResult("*******", "**");
        //System.out.println(map);
    }
 
    public static Map<String, Integer> getResult(String idCard, String name) {
        //返回的结果
        Map<String, Integer> map = new HashMap<>();
        String host = "https://idcardcheck.shumaidata.com";
        String path = "/idcardcheck";
        String method = "GET";
        String appcode = AliyunConfig.shumaiDataCode;
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("idcard", idCard);
        querys.put("name", name);
        try {
            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            log.debug("实名认证请求报文:{}", response.toString());
            //获取response的body
            //返回结果数据
            JSONObject object = JSONObject.parseObject(EntityUtils.toString(response.getEntity()));
            log.debug("实名认证请求返回的参数:{}", object);
            Integer code = (Integer) object.get("code");
            map.put("code", code);
            JSONObject data = (JSONObject) object.get("data");
            Integer result = (Integer) data.get("result");
            map.put("result", result);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }
 
    public static Boolean checkRealName(String idCard, String name) {
        Map<String, Integer> resultAll = AliyunRealNameUtil.getResult(idCard, name);
        Integer code = resultAll.get("code");
        Integer result = resultAll.get("result");
        return code == 200 && result == 0;
    }
 
}