| package doumeemes.core.utils.edpg; | 
|   | 
| import com.alibaba.fastjson.JSONArray; | 
| import com.alibaba.fastjson.JSONObject; | 
| import com.iflytek.antelope.other.client.dto.resp.UserDTO; | 
| import doumeemes.core.utils.HttpsUtil; | 
| import doumeemes.core.utils.edpg.bean.AccessTokenModel; | 
| import doumeemes.core.utils.edpg.bean.AppDepartListModel; | 
| import doumeemes.core.utils.edpg.bean.AppUserInfoModel; | 
| import lombok.Data; | 
| import lombok.extern.slf4j.Slf4j; | 
|   | 
| import java.util.ArrayList; | 
| import java.util.List; | 
|   | 
|   | 
| @Slf4j | 
| @Data | 
| public class EdgpServerUtil { | 
|   | 
|     public static void main(String[] args) { | 
|     } | 
|     private String appKey; | 
|     private String appSecret; | 
|     private String aesToken; | 
|     private String url; | 
|     public static final String GET_ACCESSTOKEN_URL = "/apps/web/accessToken"; | 
|     public static final String GET_USERINFO_URL = "/apps/web/user/infoById"; | 
|     public static final String GET_USERINFO_TOKEN_URL = "/apps/web//user/infoByToken"; | 
|     public static final String GET_ALL_DEPARTMENT_TREE_URL = "/apps/web/department/tree"; | 
|     public EdgpServerUtil(String url,String appKey,String appSecret){ | 
|         this.appKey = appKey; | 
|         this.url=url; | 
|         this.appSecret=appSecret; | 
|     } | 
|   | 
|     public   String getAccessToken()   { | 
|         try { | 
|             String acturl = url+GET_ACCESSTOKEN_URL+"?accessKey="+appKey+"&secret="+appSecret; | 
|             String result = HttpsUtil.sendGetByHttps(acturl,null); | 
|             log.error("EDGP:===============获取accessToken:"+acturl+"\n返回:"+result); | 
|             JSONObject jsonObject = JSONObject.parseObject(result); | 
|             if(jsonObject !=null && jsonObject.getBoolean("success")){ | 
|                 AccessTokenModel model = JSONObject.toJavaObject(jsonObject.getJSONObject("data"), AccessTokenModel.class); | 
|                 if(model != null){ | 
|                     return  model.getAccessToken(); | 
|                 } | 
|             } | 
|         }catch (Exception e){ | 
|             log.error("EDGP:===============获取accessToken失败!"+e.getMessage()); | 
|         } | 
|         return  null; | 
|     } | 
|     public AppUserInfoModel getUserInfoById(String acccessToken, String userid )   { | 
|         try { | 
|             String acturl  =url+GET_ALL_DEPARTMENT_TREE_URL+"?accessToken="+acccessToken+"&userId="+userid; | 
|             String result = HttpsUtil.sendGetByHttps(acturl,null); | 
|             log.error("EDGP:===============获取用户编码获取用户信息:"+acturl+"\n返回:"+result); | 
|             JSONObject jsonObject = JSONObject.parseObject(result); | 
|             if(jsonObject !=null && jsonObject.getBoolean("success")){ | 
|                 AppUserInfoModel model = JSONObject.toJavaObject(jsonObject.getJSONObject("data"), AppUserInfoModel.class); | 
|                 if(model != null){ | 
|                     return model; | 
|                 } | 
|             } | 
|         }catch (Exception e){ | 
|             log.error("EDGP:===============获取用户编码获取用户信息失败!"+e.getMessage()); | 
|         } | 
|         return  null; | 
|     } | 
|     public List<AppDepartListModel> getAllDepartList(String acccessToken ,String companyId)   { | 
|         List<AppDepartListModel> list = null; | 
|         try { | 
|             String acturl  =url+GET_USERINFO_URL+"?accessToken="+acccessToken+"&companyId="+companyId; | 
|             String result = HttpsUtil.sendGetByHttps(acturl,null); | 
|             log.error("EDGP:===============获取企业部门树形信息失败:"+acturl+"\n返回:"+result); | 
|             JSONObject jsonObject = JSONObject.parseObject(result); | 
|             if(jsonObject !=null && jsonObject.getBoolean("success")){ | 
|               JSONArray model =  jsonObject.getJSONArray("data") ; | 
|                 if(model != null && model.size()>0){ | 
|                     list = new ArrayList<>(); | 
|                     for (int i = 0; i < model.size(); i++) { | 
|                         list.add(JSONObject.toJavaObject(model.getJSONObject(i),AppDepartListModel.class)); | 
|                     } | 
|                 } | 
|             } | 
|         }catch (Exception e){ | 
|             log.error("EDGP:===============获取企业部门树形信息失败!"+e.getMessage()); | 
|         } | 
|         return  list; | 
|     } | 
|     public AppUserInfoModel getUserInfoByToken(String token  )   { | 
|         try { | 
|             String acturl = url+GET_USERINFO_TOKEN_URL+"?token="+token; | 
|             String result = HttpsUtil.sendGetByHttps(acturl,null); | 
|             log.error("EDGP:===============根据授权登录码获取用户信息:"+acturl+"\n返回:"+result); | 
|             JSONObject jsonObject = JSONObject.parseObject(result); | 
|             if(jsonObject !=null && jsonObject.getBoolean("success")){ | 
|                 AppUserInfoModel model = JSONObject.toJavaObject(jsonObject.getJSONObject("data"), AppUserInfoModel.class); | 
|                 if(model != null){ | 
|                     return model; | 
|                 } | 
|             } | 
|         }catch (Exception e){ | 
|             log.error("EDGP:===============根据授权登录码获取用户信息失败!"+e.getMessage()); | 
|         } | 
|         return  null; | 
|     } | 
| } |