import org.apache.commons.io.IOUtils; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; /** * 类说明:企业黑名单接口 * 网站接口地址:https://www.juhe.cn/docs/api/id/242 * 需要用到的jar包,通过maven导入 * <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpmime</artifactId> <version>4.3.6</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.4.1</version> </dependency> */ public class BalckEntDemo { //接口KEY,需要在线申请 private static String key=""; //请求接口的地址 private static String url="http://v.juhe.cn/blackEnt/index.php"; public static void main(String[] args) { String name ="苏州新科兰德科技有限公司"; String result = query(name); //后续根据需要处理逻辑。。。 } /** * * @param name 企业名称 * @return 查询结果 * 返回JSON示例 : * { * "reason": "成功的返回", // 原因 * "result": "NO", //结果,NO表示不是黑名单,YES表示是黑名单 * "error_code": 0 // 错误码 * } * */ public static String query(String name) { CloseableHttpClient client = HttpClients.createDefault(); CloseableHttpResponse response=null; String result = null; try { HttpGet httpGet = new HttpGet(url); response = client.execute(httpGet); result =IOUtils.toString(response.getEntity().getContent(),"UTF-8"); } catch (Exception e) { e.printStackTrace(); }finally{ try { response.close(); client.close(); } catch (Exception e2) { } } return result; } }