用户信息包括3个部分:
基本信息、用户属性和所在部门。
新增用户(add)和修改用户(update)时,需列式该用户下的全量属性和所在部门。
接口根据报文的用户所在部门对用户的身份进行增删改。
组织信息包括3个部分:
基本信息、组织属性和组织职务。
新增组织(add)和修改组织(update)时,需列式该组织下的全量组织属性和组织职务。
接口同时根据报文对组织属性和组织职务进行增删改
1、同步创建组织:
第一步:单点登入
第二步:创建顶层部门
第三步:获取创建的部门id
第四步:创建二级部门
public static void main(String[] args) throws IOException, Exception {
String token = "";
// 第一步:单点登入
String path = "http://172.16.99.20:20020/x_organization_assemble_authentication/jaxrs/sso";
long time = new Date().getTime();
String login_uid = "test";
String sso_key = "12345678";
String xtoken = null;
try {
xtoken = Crypto.encrypt(login_uid + "#" + time, sso_key);
System.out.println(xtoken);
} catch (Exception e1) {
e1.printStackTrace();
}
String string = "{"token": " + xtoken + ", "client": "unicom"}";
String str = HttpClientUtilsUnitSycn.getInstance().sendPost(path, string);
try {
JSONObject jsonObj = (JSONObject) (new JSONParser().parse(str));
JSONObject data = (JSONObject) jsonObj.get("data");
System.out.println(data.get("token"));
token = (String) data.get("token");
} catch (ParseException e) {
e.printStackTrace();
}
// 第二步:创建顶层部门
path = "http://172.16.99.20:20020/x_organization_assemble_control/jaxrs/unit";
JSONArray array = new JSONArray();
array.add("company");
JSONObject dep1 = new JSONObject();
dep1.put("name", "测试组织");
dep1.put("unique", "test001");
dep1.put("distinguishedName", "测试组织@test001@U");
dep1.put("typeList", array);
dep1.put("description", "测试");
dep1.put("shortName", "test");
dep1.put("orderNumber", "1");
String strResult = HttpClientUtilsUnitSycn.getInstance().sendPost2(path, token, dep1.toJSONString());
String id = "";
System.out.println("strResult=" + strResult);
//第三步:获取部门id
JsonParser parser = new JsonParser();
JsonObject object = null;
object = (JsonObject) parser.parse(strResult);
object = object.getAsJsonObject("data");
id = object.get("id").getAsString();
System.out.println("id=" + id);
//第四步:创建二级部门
path = "http://172.16.99.20:20020/x_organization_assemble_control/jaxrs/unit";
JSONArray array2 = new JSONArray();
array2.add("dept");
JSONObject dep2 = new JSONObject();
dep2.put("name", "测试部门");
dep2.put("unique", "dep001");
dep2.put("distinguishedName", "测试部门@dep001@U");
dep2.put("typeList", array2);
dep2.put("description", "测试部门");
dep2.put("shortName", "testdetp");
dep2.put("orderNumber", "1");
dep2.put("superior", id); // 上级部门id
String strResult2 = HttpClientUtilsUnitSycn.getInstance().sendPost2(path, token, dep2.toJSONString());
String id2 = "";
System.out.println("strResult2=" + strResult2);
//获取二级部门id
object = (JsonObject) parser.parse(strResult2);
object = object.getAsJsonObject("data");
id2 = object.get("id").getAsString();
System.out.println("id2=" + id2);
}2、同步创建个人:
第一步: 单点登入
第二步:创建个人信息
第三步:获取个人id
第四步:创建个人身份信息
public static void main(String[] args) throws IOException, Exception {
String token = "";
// 第一步:单点登入
String path = "http://172.16.99.20:20020/x_organization_assemble_authentication/jaxrs/sso";
long time = new Date().getTime();
String login_uid = "test";
String sso_key = "12345678";
String xtoken = null;
try {
xtoken = Crypto.encrypt(login_uid + "#" + time, sso_key);
System.out.println(xtoken);
} catch (Exception e1) {
e1.printStackTrace();
}
String string = "{"token": " + xtoken + ", "client": "unicom"}";
String str = HttpClientUtilsUnitSycn.getInstance().sendPost(path, string);
try {
JSONObject jsonObj = (JSONObject) (new JSONParser().parse(str));
JSONObject data = (JSONObject) jsonObj.get("data");
System.out.println(data.get("token"));
token = (String) data.get("token");
} catch (ParseException e) {
e.printStackTrace();
}
// 第二步:创建个人信息
path = "http://172.16.99.20:20020/x_organization_assemble_control/jaxrs/person";
JSONObject dep1 = new JSONObject();
dep1.put("genderType", "m");
dep1.put("name", "王文雄2");
dep1.put("employee", "12345678222");
dep1.put("unique", "wwx2");
dep1.put("orderNumber", "4");
dep1.put("mail", "955237612@qq.com");
dep1.put("mobile", "13456929932");
String strResult = HttpClientUtilsUnitSycn.getInstance().sendPost2(path, token, dep1.toJSONString());
String id = "";
System.out.println("strResult=" + strResult);
//第三步:获取个人id
JsonParser parser = new JsonParser();
JsonObject object = null;
object = (JsonObject) parser.parse(strResult);
object = object.getAsJsonObject("data");
id = object.get("id").getAsString();
System.out.println("id=" + id);
//第四步:创建个人身份信息
path = "http://172.16.99.20:20020/x_organization_assemble_control/jaxrs/identity";
JSONObject identity1 = new JSONObject();
identity1.put("name", "王文雄2");
identity1.put("person", id);
identity1.put("unit", "e32434b2-6071-4f7d-8858-d7ee3811e8f4");
strResult = HttpClientUtilsUnitSycn.getInstance().sendPost2(path, token, identity1.toJSONString());
System.out.println("strResult=" + strResult);
}sendPost2函数:
public static String sendPost2(String url, String token, String paramsStr) throws IOException, Exception {
// POST请求
CloseableHttpClient httpclient = HttpClients.createDefault();
// 请求参数
StringEntity postingString = new StringEntity(paramsStr, "utf-8");
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(postingString);
// 请求头设置
httpPost.addHeader("Cookie", "x-token=" + token);
httpPost.addHeader("accept", "*/*");
httpPost.addHeader("connection", "Keep-Alive");
httpPost.addHeader("Content-Type", "application/json; charset=utf-8");
httpPost.addHeader("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
// 执行请求
CloseableHttpResponse execute = httpclient.execute(httpPost);
// 处理返回结果
String restStr = IOUtils.toString(execute.getEntity().getContent(), "utf-8");
return restStr;
}

浙公网安备 33010602009829号