如下操做案例中關於第三方系統向泛微OA系統的移動端和電腦端版本推送消息說明:後端
• 移動端使用的是泛微系統登陸帳號(工號)來最終實現消息的推送服務器
• 電腦端使用的是泛微系統用戶表中的id字段來最終實現消息的推送jsp
配置完成後,會自動生成消息標識Id;而後根據外部系統推送示例,實現移動端消息推送。ide
實現移動端消息推送,必需要消息標識Id和e-mobile消息推送密鑰ui
消息標識Id:新建消息類型成功後,會自動生成消息標識Idurl
消息推送密鑰:「服務器管理」—「系統狀態」—服務器屬性:e-mobile消息推送密鑰spa
請勿必保證license值是有效可用的,不然會致使調用接口失敗.net
以上都配置完成後,修改調用程序中對應的相關參數,可能首次調用接口沒法接收到消息,請先屢次調用後。code
頁面右上角更多,點擊 後端應用中心orm
須要在OA的/Ecology/WEB-INF/prop/HrmWebserviceIP.properties配置文件中配置調用接口客戶端的IP,調用接口時傳入的參數ip包涵在此配置文件才能調用人力資源WebService服務的全部接口。
附.net代碼
/// <summary> /// 調用泛微OA系統接口 /// </summary> public class EcologyManager { ILog log = log4net.LogManager.GetLogger("EcologyManager"); static String basePushUrl = ConfigurationManager.AppSettings["EcologyMobilePushUrl"]; static String key = ConfigurationManager.AppSettings["EcologyMobilePushKey"];//emobile後臺的推送祕鑰 static String messageUrl = ConfigurationManager.AppSettings["EcologyMobileMessageUrl"]; static String messageTypeId = ConfigurationManager.AppSettings["EcologyMobileMessageTypeId"]; static String workflowServiceUrl = ConfigurationManager.AppSettings["EcologyWorkflowServiceUrl"]; static String hrmServiceUrl = ConfigurationManager.AppSettings["EcologyHrmServiceUrl"]; static String workflowId = ConfigurationManager.AppSettings["EcologyWorkflowId"]; static String workflowLevel = ConfigurationManager.AppSettings["EcologyWorkflowLevel"]; static String hrmIpAddress = ConfigurationManager.AppSettings["EcologyHrmIpAddress"]; /// <summary> /// 向泛微移動端推送消息 /// </summary> /// <param name="message">消息</param> /// <param name="receiverId">接收者的loginid,多用戶使用英文半角逗號分開</param> /// <returns></returns> public void PushMobileMessage(string message, string receiverId) { try { //url = url ?? messageUrl + "?account=" + receiverId; string badge = "1"; //消息數量+1 HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1"); Dictionary<string, string> para = new Dictionary<string, string>(); para.Add("messagetypeid", messageTypeId);//在mobile後臺註冊的消息類型id para.Add("module", "-2"); //標示屬於自定義消息 para.Add("url", messageUrl); string paraJson = Sheng.Kernal.JsonHelper.Serializer(para); StringBuilder sendMsg = new StringBuilder(); if (message.Length > 100) message = message.Substring(0, 100) + "..."; sendMsg.Append(receiverId); sendMsg.Append(message); sendMsg.Append(badge); sendMsg.Append(paraJson); sendMsg.Append(key); string hash = Md5Hex(sendMsg.ToString()); List<KeyValuePair<String, String>> paramList = new List<KeyValuePair<String, String>>(); paramList.Add(new KeyValuePair<string, string>("userid", receiverId)); paramList.Add(new KeyValuePair<string, string>("msg", message)); paramList.Add(new KeyValuePair<string, string>("badge", badge)); paramList.Add(new KeyValuePair<string, string>("para", paraJson)); paramList.Add(new KeyValuePair<string, string>("hash", hash)); HttpResponseMessage response = httpClient.PostAsync(new Uri(basePushUrl), new FormUrlEncodedContent(paramList)).Result; log.Info($"Ecology移動端消息推送:{Environment.NewLine}用戶工號:{receiverId },消息內容:{message };{Environment.NewLine}接口響應結果:{Sheng.Kernal.JsonHelper.Serializer(response)}"); } catch (Exception ex) { log.Error($"Ecology移動端消息推送:{Environment.NewLine}用戶工號:{receiverId },消息內容:{message };{Environment.NewLine}接口異常,異常信息:{ex.Message},異常堆棧信息:{ex.StackTrace}"); } } /// <summary> /// 向泛微電腦端推送消息 /// </summary> /// <param name="title">消息標題</param> /// <param name="ecoloryUserId">消息接收人</param> public void PushPCMessage(string title, int ecoloryUserId) { try { //主字段 WorkflowRequestTableField[] wrti = new WorkflowRequestTableField[1]; //字段信息 wrti[0] = new WorkflowRequestTableField(); WorkflowRequestTableRecord[] wrtri = new WorkflowRequestTableRecord[1];//主字段只有一行數據 wrtri[0] = new WorkflowRequestTableRecord(); wrtri[0].workflowRequestTableFields = wrti; WorkflowMainTableInfo wmi = new WorkflowMainTableInfo(); wmi.requestRecords = wrtri; WorkflowBaseInfo wbi = new WorkflowBaseInfo(); wbi.workflowId = workflowId; WorkflowRequestInfo wri = new WorkflowRequestInfo();//流程基本信息 wri.creatorId = ecoloryUserId.ToString();//接收人 wri.requestLevel = workflowLevel; //0 正常,1重要,2緊急 wri.requestName = title;//流程標題 wri.workflowMainTableInfo = wmi;//添加主字段數據 wri.workflowBaseInfo = wbi; //執行建立流程接口 WorkflowService workflowService = new WorkflowService(); workflowService.Url = workflowServiceUrl; String requestid = workflowService.doCreateWorkflowRequest(wri, ecoloryUserId);//接收人 log.Info($"Ecology電腦端消息推送;{Environment.NewLine}泛微USERID:{ecoloryUserId },消息內容:{title }{Environment.NewLine}接口響應結果:{requestid}"); } catch (Exception ex) { log.Error($"Ecology電腦端消息推送;{Environment.NewLine}泛微USERID:{ecoloryUserId },消息內容:{title }{Environment.NewLine}接口異常,異常信息:{ex.Message},異常堆棧信息:{ex.StackTrace}"); } } /// <summary> /// 根據工號獲取泛微用戶信息 /// </summary> /// <param name="workCode">工號</param> /// <returns></returns> public EcologyUser GetEcologyUserByWorkCode(string workCode) { EcologyUser ecologyUser = new EcologyUser(); try { //調用泛微OA系統人力資源接口 //須要在泛微OA系統的安裝目錄 /Ecology/WEB-INF/prop/HrmWebserviceIP.properties 配置文件中配置調用接口客戶端的IP(=hrmIpAddress),不然沒法調用人力資源相關接口 HrmService hrmService = new HrmService(); hrmService.Url = hrmServiceUrl; //獲取泛微全部用戶 string resultXml = hrmService.getHrmUserInfoXML(hrmIpAddress, "", "", "", "", ""); log.Info("調用泛微OA人力資源getHrmUserInfoXML接口,接口返回數據:" + resultXml); if (string.IsNullOrWhiteSpace(resultXml) || resultXml == "<UserBean-array/>") { return ecologyUser; } //xml轉成List List<EcologyUser> userBeanList = Sheng.Kernal.JsonHelper.XmlToList<EcologyUser>(resultXml, "UserBean-array"); if (userBeanList.Any() == false) { return ecologyUser; } ecologyUser = userBeanList.FirstOrDefault(x => x.WorkCode == workCode); } catch (Exception ex) { log.Error("調用泛微OA人力資源getHrmUserInfoXML接口異常,異常信息:" + ex.Message + Environment.NewLine + ex.StackTrace); } return ecologyUser; } private static string Md5Hex(string data) { MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); byte[] dataHash = md5.ComputeHash(Encoding.UTF8.GetBytes(data)); StringBuilder sb = new StringBuilder(); foreach (byte b in dataHash) { sb.Append(b.ToString("x2").ToLower()); } return sb.ToString(); } }