package shkd.utils; import com.alibaba.fastjson.JSONObject; import kd.bos.logging.Log; import kd.bos.logging.LogFactory; import kd.bos.util.HttpClientUtils; import kd.bos.util.StringUtils; import java.util.Date; /** * @author :weiyunlong * @date :Created 2024/9/11 16:02 * @description:致远OA集成工具类 */ public class OAUtils { private static final Log logger = LogFactory.getLog(OAUtils.class); //致远服务前获取token接口 public static String getOaToken(){ //String url = System.getProperty("efms.infcompany.url.ip"); //logger.info("url"); //致远服务前获取token接口 String userName = "ICSTest"; String password = "8f72e360-268e-41ba-9886-af9a802e4de3"; String linkUrl = "http://172.31.254.240:9090/seeyon/rest/token"; //接口请求体 JSONObject linkBody = new JSONObject(); linkBody.put("userName", userName); linkBody.put("password", password); String token = ""; try { String linkPostjson = HttpClientUtils.postjson(linkUrl, null, linkBody.toJSONString()); logger.info("获取OaToken接口返回结果:\n{}", linkPostjson); if (StringUtils.isNotEmpty(linkPostjson)) { JSONObject jsonObject = JSONObject.parseObject(linkPostjson); token = jsonObject.getString("id"); } return token; } catch (Exception e) { logger.info(String.format("获取OaToken接口异常:%s", e.getMessage())); throw new RuntimeException(e); } } /** * model值转Long */ public static long l(Object value) { if (value == null) { return 0L; } else if (value instanceof Long) { return (Long)value; } else if (value instanceof Number) { return ((Number)value).longValue(); } else if (value instanceof Boolean) { return ((Boolean)value).booleanValue() ? 1L : 0L; } else if (value instanceof Date) { return ((Date)value).getTime(); } else { String s = value.toString().trim(); if (s.length() == 0) { return 0L; } else { return Long.parseLong(s); } } } }