泛微oa java .net_第三方系统向泛微OA系统推送消息
/// ///调用泛微OA系统接口/// public classEcologyManager{ILog log= log4net.LogManager.GetLogger("EcologyManager");static String basePushUrl = ConfigurationManager.AppSettings["EcologyMobilePushUrl"];static Str
///
///调用泛微OA系统接口///
public classEcologyManager
{
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"];///
///向泛微移动端推送消息///
/// 消息
/// 接收者的loginid,多用户使用英文半角逗号分开
///
public void PushMobileMessage(string message, stringreceiverId)
{try{//url = url ?? messageUrl + "?account=" + receiverId;
string badge = "1"; //消息数量+1
HttpClient httpClient = newHttpClient();
httpClient.DefaultRequestHeaders.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1");
Dictionary para = new Dictionary();
para.Add("messagetypeid", messageTypeId);//在mobile后台注册的消息类型id
para.Add("module", "-2"); //标示属于自定义消息
para.Add("url", messageUrl);string paraJson =Sheng.Kernal.JsonHelper.Serializer(para);
StringBuilder sendMsg= newStringBuilder();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> paramList = new List>();
paramList.Add(new KeyValuePair("userid", receiverId));
paramList.Add(new KeyValuePair("msg", message));
paramList.Add(new KeyValuePair("badge", badge));
paramList.Add(new KeyValuePair("para", paraJson));
paramList.Add(new KeyValuePair("hash", hash));
HttpResponseMessage response= httpClient.PostAsync(new Uri(basePushUrl), newFormUrlEncodedContent(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}");
}
}///
///向泛微电脑端推送消息///
/// 消息标题
/// 消息接收人
public void PushPCMessage(string title, intecoloryUserId)
{try{//主字段
WorkflowRequestTableField[] wrti = new WorkflowRequestTableField[1]; //字段信息
wrti[0] = newWorkflowRequestTableField();
WorkflowRequestTableRecord[] wrtri= new WorkflowRequestTableRecord[1];//主字段只有一行数据
wrtri[0] = newWorkflowRequestTableRecord();
wrtri[0].workflowRequestTableFields =wrti;
WorkflowMainTableInfo wmi= newWorkflowMainTableInfo();
wmi.requestRecords=wrtri;
WorkflowBaseInfo wbi= newWorkflowBaseInfo();
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 = newWorkflowService();
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}");
}
}///
///根据工号获取泛微用户信息///
/// 工号
///
public EcologyUser GetEcologyUserByWorkCode(stringworkCode)
{
EcologyUser ecologyUser= newEcologyUser();try{//调用泛微OA系统人力资源接口//需要在泛微OA系统的安装目录 /Ecology/WEB-INF/prop/HrmWebserviceIP.properties 配置文件中配置调用接口客户端的IP(=hrmIpAddress),否则无法调用人力资源相关接口
HrmService hrmService = newHrmService();
hrmService.Url=hrmServiceUrl;//获取泛微所有用户
string resultXml = hrmService.getHrmUserInfoXML(hrmIpAddress, "", "", "", "", "");
log.Info("调用泛微OA人力资源getHrmUserInfoXML接口,接口返回数据:" +resultXml);if (string.IsNullOrWhiteSpace(resultXml)|| resultXml == "")
{returnecologyUser;
}//xml转成List
List userBeanList = Sheng.Kernal.JsonHelper.XmlToList(resultXml, "UserBean-array");if (userBeanList.Any() == false)
{returnecologyUser;
}
ecologyUser= userBeanList.FirstOrDefault(x => x.WorkCode ==workCode);
}catch(Exception ex)
{
log.Error("调用泛微OA人力资源getHrmUserInfoXML接口异常,异常信息:" + ex.Message + Environment.NewLine +ex.StackTrace);
}returnecologyUser;
}private static string Md5Hex(stringdata)
{
MD5CryptoServiceProvider md5= newMD5CryptoServiceProvider();byte[] dataHash =md5.ComputeHash(Encoding.UTF8.GetBytes(data));
StringBuilder sb= newStringBuilder();foreach (byte b indataHash)
{
sb.Append(b.ToString("x2").ToLower());
}returnsb.ToString();
}
}
更多推荐
所有评论(0)