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.stereotype.Component; import java.util.HashMap; import java.util.Map; /** * 阿里云API接口工具类 */ @Component public class ALiApiUtil { @Autowired private HttpClientUtil httpClientUtil; /** * 身份认证接口 * @param name 姓名 * @param code 身份证号 * @return */ public boolean authentication(String name, String code){ String url = "http://apis.juhe.cn/telecom2Cucc/query"; Map header = new HashMap<>(); Map param = new HashMap<>(); param.put("key", "1"); param.put("mobile", name); param.put("idcard", code); String get = null; try { get = httpClientUtil.pushHttpRequset("GET", url, param, header, "form").getData(); } catch (Exception e) { e.printStackTrace(); } JSONObject jsonObject = JSON.parseObject(get); if(jsonObject.getIntValue("error_code") == 0){ JSONObject value = jsonObject.getJSONObject("result"); if(value.getString("res").equals("1")){ return true; }else{ return false; } }else{ System.err.println(jsonObject.getString("message")); } return false; } }