| package com.zy.crm.manager.utils; | 
|   | 
| import com.alibaba.fastjson.JSON; | 
| import com.alibaba.fastjson.JSONObject; | 
| import com.core.common.Cools; | 
| import com.core.exception.CoolException; | 
|   | 
| import java.util.ArrayList; | 
| import java.util.HashMap; | 
| import java.util.List; | 
| import java.util.Map; | 
|   | 
| /** | 
|  * 第三方API接口搜索企业信息 | 
|  */ | 
| public class CompanySearchUtils { | 
|   | 
|     /** | 
|      * 对外暴露搜索接口 | 
|      * @param company 企业名(模糊) | 
|      * @param api 调用的第三方接口 | 
|      */ | 
|     public static List<Map<String, Object>> search(String company, Integer api) { | 
|         List<Map<String, Object>> list = new ArrayList<>(); | 
|         switch (api) { | 
|             case 1: | 
|                 List<Map<String, Object>> maps = aliyun_1(company); | 
|                 if (Cools.isEmpty(maps)){ | 
|                     break; | 
|                 } | 
|                 list.addAll(maps); | 
|                 break; | 
|         } | 
|         return list; | 
|     } | 
|   | 
|     /** | 
|      * 阿里云市场API | 
|      */ | 
|     private static List<Map<String, Object>> aliyun_1(String company) { | 
|         if (Cools.isEmpty(company) || company.length()<=3){ | 
|             return null; | 
|         } | 
|         ArrayList<Map<String, Object>> list = new ArrayList<>(); | 
|         try { | 
|             HashMap<String, Object> headers = new HashMap<>(); | 
|             HashMap<String, Object> param = new HashMap<>(); | 
|   | 
|             headers.put("Authorization", "APPCODE 15ce5d8be5e348c7b680dfd7cfb8307e"); | 
|   | 
|             param.put("com", company); | 
|             param.put("method", "企业名称"); | 
|             param.put("page", "1"); | 
|   | 
|             String response = new HttpHandler.Builder() | 
|                     .setUri("https://orgs.market.alicloudapi.com") | 
|                     .setPath("/searchCompany") | 
|                     .setHeaders(headers) | 
|                     .setParams(param) | 
|                     .build() | 
|                     .doPost(); | 
|             JSONObject jsonObject = JSON.parseObject(response); | 
|             if (Cools.isEmpty(jsonObject)){ | 
|                 throw new CoolException("无返回结果"); | 
|             } | 
|             if (Integer.parseInt(jsonObject.get("error_code").toString()) == 0) { | 
|                 JSONObject result = JSON.parseObject(jsonObject.get("result").toString()); | 
|                 List<JSONObject> data = JSON.parseArray(result.get("data").toString(), JSONObject.class); | 
|                 for (JSONObject object : data) { | 
|                     //将API接口数据转换成系统定义的数据 | 
|                     HashMap<String, Object> objData = new HashMap<>(); | 
|                     objData.put("creditCode", object.get("creditCode"));//企业信用代码 | 
|                     objData.put("issueTime", object.get("issueTime"));//企业创建时间 | 
|                     objData.put("companyType", object.get("companyType"));//企业类型 | 
|                     objData.put("companyPerson", object.get("faRen"));//法人 | 
|                     objData.put("companyStatus", object.get("businessStatus"));//企业状态 | 
|                     objData.put("regMoney", object.get("regMoney"));//注册资金 | 
|   | 
|   | 
|                     HashMap<String, Object> map = new HashMap<>(); | 
|                     map.put("value", objData); | 
|                     map.put("name", object.get("companyName")); | 
|                     list.add(map); | 
|                 } | 
|             } | 
|         } catch (Exception e) { | 
|             if (e.getMessage().equals("无返回结果")){ | 
|                 throw new CoolException("无返回结果"); | 
|             } | 
|             e.printStackTrace(); | 
|         } | 
|         return list; | 
|     } | 
|   | 
| } |