puzhibing
2023-05-18 c54be562403989ae722ce4e12b640d4a44b5dcb3
UserZYTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/JuHeUtil.java
@@ -1,44 +1,44 @@
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;
    }
}
//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;
//    }
//}