1>rtx二次开发操作类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; using System.Xml; using System.Xml.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.Configuration; using RTXServerApi; namespace RTXHelper { public class RTX { private RTXSAPILib.IRTXSAPIRootObj rootObj; /// <summary> /// 默认的RTX服务器的地址和端口是本机,如果夸服务器则从配置文件中读取 /// 默认值:IP(127.0.0.1) port(8006) /// </summary> public RTX() { rootObj = new RTXSAPILib.RTXSAPIRootObjClass(); WebConfigHelper webConfig = new WebConfigHelper(); rootObj.ServerIP = webConfig.RTXServerIP; rootObj.ServerPort = webConfig.RTXServerPort; } public RTX(String rtxServerIP, Int16 rtxServerPort) { rootObj = new RTXSAPILib.RTXSAPIRootObjClass(); rootObj.ServerIP = rtxServerIP; rootObj.ServerPort = rtxServerPort; } public bool SignatureAuth(string bstrUserName, string bstrSign) { RTXSAPILib.IRTXSAPIUserAuthObj2 AuthObj2 = (RTXSAPILib.IRTXSAPIUserAuthObj2)rootObj.UserAuthObj; return AuthObj2.SignatureAuth(bstrUserName, bstrSign); } public void SendIM(string bstrSender, string bstrPwd, string bstrReceivers, string bstrMsg, string bstrSessionID) { rootObj.SendIM(bstrSender, bstrPwd, bstrReceivers, bstrMsg, string.Format("{0}{1}{2}", "{", bstrSessionID, "}")); } public void SendIM(string bstrSender, string bstrReceivers, string bstrMsg) { rootObj.SendIM(bstrSender, "", bstrReceivers, bstrMsg, string.Format("{0}{1}{2}", "{", Guid.NewGuid().ToString(), "}")); } public void SendNotify(string bstrReceiver, string bstrTitle, int lDelayTime, string bstrMsg) { rootObj.SendNotify(bstrReceiver, bstrTitle, lDelayTime, bstrMsg); } public string GetDepartment(string userId) { short d = rootObj.Login("124065", "2"); rootObj.UserManager.SetUserPwd("124065", "2"); rootObj.UserManager.SetUserMd5Pwd("060637", "2"); return rootObj.GetBUinPwd(); } public short Login(string userId, string pwd) { return rootObj.Login(userId, pwd); } public void SendDisGroupIM(string bstrSender, string bstrpwd, int lDisGroupId, string bstrtitle, string bstrMsg, string bstrSessionId) { rootObj.SendDisGroupIM(bstrSender, bstrpwd, lDisGroupId, bstrtitle, bstrMsg, string.Format("{0}{1}{2}", "{", Guid.NewGuid().ToString(), "}")); } public void SendRCAIM(string bstrSender, string bstrpwd, string bstrReceivers, string bstrMsg, string bstrSessionId) { rootObj.SendRCAIM(bstrSender, bstrpwd, bstrReceivers, bstrMsg, string.Format("{0}{1}{2}", "{", bstrSessionId, "}")); } public string GetAllUsers() { XDocument xDoc = XDocument.Parse(rootObj.DeptManager.GetChildDepts("")); return rootObj.DisGroupManager.GetAllDisGroupIds(); } /// <summary> /// 查找部门下的所有用户 /// </summary> /// <param name="deptName">部门路径,比如:"生产技术部\信息中心"</param> /// <returns>返回部门下所有用户的账户,不包含子部门下的用户</returns> public string[] GetDeptUsers(string deptName) { List<string> result = new List<string>(); string users = rootObj.DeptManager.GetDeptUsers(deptName); XDocument xdoc = XDocument.Parse(users); foreach (var userItem in xdoc.Root.Elements("User")) { result.Add(userItem.Attribute("Name").Value); } return result.ToArray(); } /// <summary> /// 查找部门下的所有用户 /// </summary> /// <param name="deptName">部门路径,比如:"生产技术部\信息中心"</param> /// <returns>返回部门下所有用户的账户,不包含子部门下的用户</returns> public string GetDeptUsersJson(string deptName) { JArray jArray = new JArray(); string users = rootObj.DeptManager.GetDeptUsers(deptName); XDocument xdoc = XDocument.Parse(users); foreach (var userItem in xdoc.Root.Elements("User")) { string staffId = userItem.Attribute("Name").Value; string pbstrName = ""; int plGender = 0; string pbstrMobile = ""; string pbstrEMail = ""; string pbstrPhone = ""; int plAuthType = 0; try { rootObj.UserManager.GetUserBasicInfo(staffId, out pbstrName, out plGender, out pbstrMobile, out pbstrEMail, out pbstrPhone, out plAuthType); } catch (Exception) { pbstrName = "获取用户失败"; } finally { jArray.Add(new JObject( new JProperty("UserName", staffId), new JProperty("Name", pbstrName), new JProperty("Gender", plGender), new JProperty("Mobile", pbstrMobile), new JProperty("EMail", pbstrEMail), new JProperty("Phone", pbstrPhone), new JProperty("AuthType", plAuthType))); } } return jArray.ToString(); } /// <summary> /// 从rtx中获取所有部门和用户 /// </summary> /// <param name="serverIp">rtx服务器ip</param> /// <param name="serverPort">SDKServerPort,默认6000</param> public string GetALLDeptAndUserXml(string serverIp, int sdkServerPort) { JArray jArray = new JArray(); RTXServerApi.RTXObject RTXObj = new RTXServerApi.RTXObject(); RTXServerApi.RTXCollection RTXParams = new RTXServerApi.RTXCollection(); RTXObj.ServerIP = serverIp; RTXObj.ServerPort = sdkServerPort; RTXObj.Name = "USERSYNC"; RTXParams.Add("MODIFYMODE", 1); RTXParams.Add("XMLENCODE", @"<?xml version=" + """ + "1.0" + """ + " encoding=" + """ + "gb2312" + """ + " ?>"); string deptUsersXml = RTXObj.Call2( enumCommand_.PRO_SYNC_FROM_RTX, RTXParams).ToString(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(deptUsersXml); return xmlDoc.OuterXml; } /// <summary> /// 从rtx中获取所有部门和用户 /// </summary> /// <param name="serverIp">rtx服务器ip</param> /// <param name="serverPort">SDKServerPort,默认6000</param> /// <param name="deptName">部门路径,比如:"生产技术部\信息中心"</param> public string GetDeptAndUserXml(string serverIp, int sdkServerPort, string deptName) { JArray jArray = new JArray(); RTXServerApi.RTXObject RTXObj = new RTXServerApi.RTXObject(); RTXServerApi.RTXCollection RTXParams = new RTXServerApi.RTXCollection(); RTXObj.ServerIP = serverIp; RTXObj.ServerPort = sdkServerPort; RTXObj.Name = "USERSYNC"; RTXParams.Add("MODIFYMODE", 1); RTXParams.Add("XMLENCODE", @"<?xml version=" + """ + "1.0" + """ + " encoding=" + """ + "gb2312" + """ + " ?>"); string deptUsersXml = RTXObj.Call2( enumCommand_.PRO_SYNC_FROM_RTX, RTXParams).ToString(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(deptUsersXml); XmlNode xmlNode = xmlDoc.SelectSingleNode(GetXpath(deptName)); foreach (XmlNode item in xmlNode.SelectNodes("department")) { xmlNode.RemoveChild(item); } return xmlNode.OuterXml; } private string GetXpath(string pathName) { StringBuilder sb = new StringBuilder(); sb.Append("//departments"); string[] paths = pathName.Split( new string[] { "\" }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in paths) { sb.AppendFormat("/department[@name='{0}']", item); } return sb.ToString(); } } }
程序员的基础教程:菜鸟程序员