用户信息包括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; }