puzhibing
2023-03-15 79962435853baf5a28e08461f46a831fffa1a4b0
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
65
66
67
68
69
70
71
72
73
74
75
package com.stylefeng.guns.modular.system.util;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * 聚合数据工具类
 */
@Component
public class JuHeUtil {
 
    @Value("${juhe.appKey}")
    private String key;
 
    @Autowired
    private HttpClientUtil httpClientUtil;
 
    /**
     * 身份证号码实名认证
     * @param name
     * @param idcard
     * @return
     */
    public boolean idcard(String name, String idcard){
        Map<String, Object> map = new HashMap<>();
        map.put("key", key);
        map.put("idcard", idcard);
        map.put("realname", name);
        String content = httpClientUtil.pushHttpRequset("GET", "http://op.juhe.cn/idcard/query", map, new HashMap<>(), "form");
        System.err.println(content);
        JSONObject jsonObject = JSON.parseObject(content);
        if(jsonObject.getIntValue("error_code") == 0){
            int res = jsonObject.getJSONObject("result").getIntValue("res");
            return res == 1 ? true : false;
        }
        return false;
    }
 
 
    /**
     * 根据银行卡号获取银行数据
     * @param code
     * @return
     */
    public Map<String, String> queryBank(String code){
        String url = "http://apis.juhe.cn/interbank/query?key=" + key + "&bankcard=" + code;
        String get = httpClientUtil.pushHttpRequset("GET", url, null, null, "form");
        JSONObject jsonObject = JSON.parseObject(get);
        Map<String, String> map = new HashMap<>();
        if(jsonObject.getIntValue("error_code") == 0){
            JSONObject result = jsonObject.getJSONObject("result");
            JSONObject data = result.getJSONObject("data");
            JSONObject record = data.getJSONArray("record").getJSONObject(0);
 
            String province = record.getString("province");
            String city = record.getString("city");
            String district = record.getString("district");
            String address = record.getString("addr");
            map.put("msg", "success");
            map.put("address", province + city + district);
            map.put("bank_name", record.getString("lname"));
            map.put("bank", record.getString("bank"));
            map.put("bank_code", record.getString("bankcode"));//联行号
        }else{
            map.put("msg", jsonObject.getString("reason"));
        }
        return map;
    }
}