企业微信后台关闭微信邮件提醒企业状态提醒

企业微信运营意义是什么? - 知乎有问题,上知乎。知乎作为中文互联网最大的知识分享平台,以「知识连接一切」为愿景,致力于构建一个人人都可以便捷接入的知识分享网络,让人们便捷地与世界分享知识、经验和见解,发现更大的世界。91被浏览<strong class="NumberBoard-itemValue" title="分享邀请回答138 条评论分享收藏感谢收起0添加评论分享收藏感谢收起企业微信后台
可以记录推荐数据哦!
收录收藏夹
企业微信后台B/S
添加到收藏
没有新消息
创建收藏夹
公开(受欢迎的收藏夹将有可能选入站酷精选)
私密(仅自己可见)
分享给微信好友Zabbix企业微信告警最新版
Zabbix企业微信告警最新版
最近企业微信公众号和企业微信合并了,导致了原先使用微信发送告警的用户无法正常使用,为了方便广大用户能够正常使用,oneoaas给出了解决方案。
下面来详述操作步骤
登录企业微信管理后台https://work.weixin.qq.com
企业应用-添加应用
返回到企业应用,找到刚才创建的”Zabbix告警”应用
AgentId:1111111
Secret:88888
记住这两个数据,后面会用到
找到企业CorpID,我的企业
好了,现在微信发送的三个必要参数已经找到。
cp -rf weixin_linux_amd64 /usr/local/zabbix/share/zabbix/alertscripts/weixin
chown 755 /usr/local/zabbix/share/zabbix/alertscripts/weixin
chown zabbix:zabbix /etc/zabbix/alertscripts/weixin
修改zabbix.conf:
grep alertscripts /usr/local/zabbix/etc/zabbix_server.conf
AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts
/usr/local/zabbix/share/zabbix/alertscriptsweixin –corpid=66
corpsecret=8 –msg=”您好告警测试” –user=L –agentid=
{“errcode”:0,”errmsg”:”ok”,”invaliduser”:”“}
web界面配置
增加微信报警媒介:
增加动作:
具体内容如下:
名称:Report problems to Zabbix administrators
默认接收人:{TRIGGER.STATUS}: {TRIGGER.NAME}
默认信息:
{TRIGGER.STATUS}: {TRIGGER.NAME}
告警主机:{HOSTNAME1}
告警时间:{EVENT.DATE} {EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息:{TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}
恢复信息:打钩
恢复主旨:{TRIGGER.STATUS}: {TRIGGER.NAME}{TRIGGER.NAME}
恢复信息:
{TRIGGER.STATUS}: {TRIGGER.NAME}
告警主机:{HOSTNAME1}
告警时间:{EVENT.DATE} {EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息:{TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}
修改动作操作:
查看告警发送记录:
企业微信收到的消息格式如下:
注意本文中所用的方法仅适用于Zabbix 版本&=3.0
没有更多推荐了,
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!微信企业号开发:接收消息和事件
接收到的消息和事件,其实都是微信post到我们配置的URL的消息。接收普通消息就是用户给公众号发送的消息,事件是由于用户的特定操作,微信post给我们的消息。被动响应消息是我们收到微信post过来的普通消息或者是事件时,企业号通过Response.Write这种方式回复的消息。核心代码:把微信post过来的数据先解密,转为能处理的XML,再把XML转为对象 #region 将POST过来的数据转化成实体对象
/// &summary&
/// 将微信POST过来的数据转化成实体对象
/// &/summary&
/// &param name="token"&&/param&
/// &returns&&/returns&
public static ReceiveMessageBase ConvertMsgToObject(string msgBody = "")
if (string.IsNullOrWhiteSpace(msgBody))
Stream s = System.Web.HttpContext.Current.Request.InputS
byte[] b = new byte[s.Length];
s.Read(b, 0, (int)s.Length);
msgBody = Encoding.UTF8.GetString(b);
string CorpToken = AppIdInfo.GetToken();
string corpId = AppIdInfo.GetCorpId();
string encodingAESKey = AppIdInfo.GetEncodingAESKey();
WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(CorpToken, encodingAESKey, corpId);
string msg_signature = HttpContext.Current.Request.QueryString["msg_signature"];
string timestamp = HttpContext.Current.Request.QueryString["timestamp"];
string nonce = HttpContext.Current.Request.QueryString["nonce"];
string sMsg = "";
// 解析之后的明文
int flag = wxcpt.DecryptMsg(msg_signature, timestamp, nonce, msgBody, ref sMsg);
if (flag == 0)
msgBody = sM
LogInfo.Info("解密后的消息为" + sMsg);
LogInfo.Error("解密消息失败!flag=" + flag);
if (string.IsNullOrWhiteSpace(msgBody))
XmlDocument doc =
MsgType msgType = MsgType.UnK
EventType eventType = EventType.UnK
ReceiveMessageBase msg = new ReceiveMessageBase();
msg.MsgType = msgT
msg.MessageBody = msgB
XmlNode node =
XmlNode tmpNode =
doc = new XmlDocument();
doc.LoadXml(msgBody);//解密后才是需要处理的XML数据,读取XML字符串
XmlElement rootElement = doc.DocumentE
XmlNode msgTypeNode = rootElement.SelectSingleNode("MsgType");//获取字符串中的消息类型
node = rootElement.SelectSingleNode("FromUserName");
if (node != null)
msg.FromUserName = node.InnerT
node = rootElement.SelectSingleNode("AgentID");
if (node != null)
msg.AgentID = Convert.ToInt32(node.InnerText);
node = rootElement.SelectSingleNode("ToUserName");
if (node != null)
msg.ToUserName = node.InnerT
node = rootElement.SelectSingleNode("CreateTime");
if (node != null)
msg.CreateTime = Convert.ToInt64(node.InnerText);
#region 获取具体的消息对象
string strMsgType = msgTypeNode.InnerT
string msgId = string.E
string content = string.E
tmpNode = rootElement.SelectSingleNode("MsgId");
if (tmpNode != null)
msgId = tmpNode.InnerText.Trim();
string strMsgType2 = strMsgType.Trim().ToLower();
switch (strMsgType2)
case "text"://接收普通消息 text消息
msgType = MsgType.T
tmpNode = rootElement.SelectSingleNode("Content");
if (tmpNode != null)
content = tmpNode.InnerText.Trim();
TextReceiveMessage txtMsg = new TextReceiveMessage(msg)
MsgType = msgType,
MsgId = Convert.ToInt64(msgId),
Content = content
txtMsg.AfterRead();
return txtM
case "image"://接收普通消息 image消息
msgType = MsgType.I
ImageReceiveMessage imgMsg = new ImageReceiveMessage(msg)
MsgId = Convert.ToInt64(msgId),
MsgType = msgType,
MediaId = rootElement.SelectSingleNode("MediaId").InnerText,
PicUrl = rootElement.SelectSingleNode("PicUrl").InnerText
imgMsg.AfterRead();
return imgM
case "voice"://接收普通消息 voice消息
msgType = MsgType.V
XmlNode node1 = rootElement.SelectSingleNode("Recognition");
if (node1 != null)
msgType = MsgType.VoiceR
VoiceReceiveMessage voiceMsg = new VoiceReceiveMessage(msg)
MsgId = Convert.ToInt64(msgId),
MsgType = msgType,
Recognition = node1 == null ? string.Empty : node1.InnerText.Trim(),
Format = rootElement.SelectSingleNode("Format").InnerText,
MediaId = rootElement.SelectSingleNode("MediaId").InnerText
voiceMsg.AfterRead();
return voiceM
case "video"://接收普通消息 video消息
msgType = MsgType.V
VideoReceiveMessage videoMsg = new VideoReceiveMessage(msg)
MediaId = rootElement.SelectSingleNode("MediaId").InnerText,
MsgId = Convert.ToInt64(msgId),
MsgType = msgType,
ThumbMediaId = rootElement.SelectSingleNode("ThumbMediaId").InnerText
videoMsg.AfterRead();
return videoM
case "location"://接收普通消息 location消息
msgType = MsgType.L
LocationReceiveMessage locationMsg = new LocationReceiveMessage(msg)
MsgId = Convert.ToInt64(msgId),
MsgType = msgType,
Label = rootElement.SelectSingleNode("Label").InnerText,
Location_X = rootElement.SelectSingleNode("Location_X").InnerText,
Location_Y = rootElement.SelectSingleNode("Location_Y ").InnerText,
Scale = rootElement.SelectSingleNode("Scale").InnerText
locationMsg.AfterRead();
return locationM
case "event":// 接收事件
msgType = MsgType.E
eventType = EventType.UnK
msg.MsgType = msgT
XmlNode eventNode = rootElement.SelectSingleNode("Event");
if (eventNode != null)
string eventtype = eventNode.InnerText.Trim().ToLower();
switch (eventtype)
case "subscribe": //接收事件 成员关注
eventType = EventType.S
SubscribeEventMessage subEvt = new SubscribeEventMessage(msg)
EventType = EventType.Subscribe,
MsgType = msgType,
subEvt.AfterRead();
return subE
case "unsubscribe": //接收事件 取消关注事件
eventType = EventType.UnS
UnSubscribeEventMessage unSubEvt = new UnSubscribeEventMessage(msg)
EventType = eventType,
MsgType = msgType,
unSubEvt.AfterRead();
return unSubE
case "location"://接收事件 上报地理位置事件
eventType = EventType.L
UploadLocationEventMessage locationEvt = new UploadLocationEventMessage(msg)
EventType = eventType,
Latitude = rootElement.SelectSingleNode("Latitude").InnerText,
Longitude = rootElement.SelectSingleNode("Longitude").InnerText,
MsgType = msgType,
Precision = rootElement.SelectSingleNode("Precision").InnerText,
locationEvt.AfterRead();
return locationE
case "click": //接收事件 上报菜单事件 点击菜单拉取消息的事件推送
eventType = EventType.C
MenuEventMessage menuEvt = new MenuEventMessage(msg)
EventKey = rootElement.SelectSingleNode("EventKey").InnerText,
EventType = eventType,
MsgType = msgType,
menuEvt.AfterRead();
return menuE
case "view": //接收事件 上报菜单事件 点击菜单跳转链接的事件推送
eventType = EventType.VIEW;
MenuEventVIEWEventMessage menuVIEWEvt = new MenuEventVIEWEventMessage(msg)
EventKey = rootElement.SelectSingleNode("EventKey").InnerText,
EventType = eventType,
MsgType = msgType,
menuVIEWEvt.AfterRead();
return menuVIEWE
case "scancode_push"://接收事件 上报菜单事件 扫码推事件的事件推送
eventType = EventType.scancode_
ScanCodePushEventMessage scanCodePushEventMessage = new ScanCodePushEventMessage(msg)
EventKey = rootElement.SelectSingleNode("EventKey").InnerText,
EventType = eventType,
MsgType = msgType,
ScanCodeInfo = new ScanCodeInfo(rootElement.SelectSingleNode("ScanCodeInfo"))
scanCodePushEventMessage.AfterRead();
return scanCodePushEventM
case "scancode_waitmsg"://接收事件 上报菜单事件 扫码推事件且弹出“消息接收中”提示框的事件推送
eventType = EventType.scancode_
ScanCodeWaitMsgEventMessage scanCodeWaitMsgEventMessage = new ScanCodeWaitMsgEventMessage(msg)
EventKey = rootElement.SelectSingleNode("EventKey").InnerText,
EventType = eventType,
MsgType = msgType,
ScanCodeInfo = new ScanCodeInfo(rootElement.SelectSingleNode("ScanCodeInfo"))
scanCodeWaitMsgEventMessage.AfterRead();
return scanCodeWaitMsgEventM
case "pic_sysphoto"://接收事件 上报菜单事件 弹出系统拍照发图的事件推送
eventType = EventType.pic_
PicSysPhotoEventMessage picSysPhotoEventMessage = new PicSysPhotoEventMessage(msg)
EventKey = rootElement.SelectSingleNode("EventKey").InnerText,
MsgType = msgType,
SendPicsInfo = new SendPicsInfo(rootElement.SelectSingleNode("SendPicsInfo"))
picSysPhotoEventMessage.AfterRead();
return picSysPhotoEventM
case "pic_photo_or_album"://接收事件 上报菜单事件 弹出拍照或者相册发图的事件推送
eventType = EventType.pic_photo_or_
PicPhotoOrAlbumEventMessage picPhotoOrAlbumEventMessage = new PicPhotoOrAlbumEventMessage(msg)
EventType = eventType,
EventKey = rootElement.SelectSingleNode("EventKey").InnerText,
MsgType = msgType,
SendPicsInfo = new SendPicsInfo(rootElement.SelectSingleNode("SendPicsInfo"))
picPhotoOrAlbumEventMessage.AfterRead();
return picPhotoOrAlbumEventM
case "pic_weixin"://接收事件 上报菜单事件 弹出微信相册发图器的事件推送
eventType = EventType.pic_
PicWeiXinEventMessage picWeiXinEventMessage = new PicWeiXinEventMessage(msg)
EventType = eventType,
EventKey = rootElement.SelectSingleNode("EventKey").InnerText,
MsgType = msgType,
SendPicsInfo = new SendPicsInfo(rootElement.SelectSingleNode("SendPicsInfo"))
picWeiXinEventMessage.AfterRead();
return picWeiXinEventM
case "location_select"://接收事件 上报菜单事件 弹出地理位置选择器的事件推送
eventType = EventType.location_
LocationSelectEventMessage locationSelectEventMessage = new LocationSelectEventMessage(msg)
EventType = eventType,
EventKey = rootElement.SelectSingleNode("EventKey").InnerText,
MsgType = msgType,
SendLocationInfo = new SendLocationInfo(rootElement.SelectSingleNode("SendLocationInfo"))
locationSelectEventMessage.AfterRead();
return locationSelectEventM
case "enter_agent": //接收事件 成员进入应用的事件推送
eventType = EventType.enter_
EnterAgentEventMessage EnterAgentEventMessage = new EnterAgentEventMessage(msg)
MsgType = msgType,
EnterAgentEventMessage.AfterRead();
return EnterAgentEventM
LogInfo.Error("事件类型" + eventtype + "未处理");
LogInfo.Error("消息类型" + strMsgType2 + "未处理");
msg.MsgType = msgT
#endregion
catch (Exception ex)
LogInfo.Error("处理消息异常:" + msgBody, ex);
if (doc != null)
msg.MsgType = msgT
}发送被动响应文本消息:
/// &summary&
/// 发送被动响应文本消息,需要先加密在发送
/// &/summary&
/// &param name="fromUserName"&发送方&/param&
/// &param name="toUserName"&接收方&/param&
/// &param name="content"&文本内容&/param&
public static void SendTextReplyMessage(string fromUserName, string toUserName, string content)
TextReplyMessage msg = new TextReplyMessage()
CreateTime = Tools.ConvertDateTimeInt(DateTime.Now),
FromUserName = fromUserName,
ToUserName = toUserName,
Content = content
LogInfo.Info("发送信息2sMsg=" + content);//也可以使用微信的接口发送消息
TextMsg data = new TextMsg(content);
data.agentid = "7";
data.safe = "0";
// data.toparty = "@all";
data.totag = "@all";
data.touser = toUserN
BLLMsg.SendMessage(data);*/
string CorpToken = AppIdInfo.GetToken();
string corpId = AppIdInfo.GetCorpId();
string encodingAESKey = AppIdInfo.GetEncodingAESKey();
WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(CorpToken, encodingAESKey, corpId);
string msg_signature = HttpContext.Current.Request.QueryString["msg_signature"];
string timestamp = HttpContext.Current.Request.QueryString["timestamp"];
string nonce = HttpContext.Current.Request.QueryString["nonce"];
string encryptResponse = "";//加密后的文字
string sMsg = msg.ToXmlString();//加密前的文字
int isok = wxcpt.EncryptMsg(sMsg, timestamp, nonce, ref encryptResponse);//
LogInfo.Info("发送信息sMsg=" + sMsg);
LogInfo.Info("发送信息encryptResponse=" + encryptResponse);
if (isok == 0 && !string.IsNullOrEmpty(encryptResponse))
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
HttpContext.Current.Response.Write(encryptResponse);//被动相应消息不需要调用微信接口
LogInfo.Info("发送信息失败isok=" + isok);
}注释掉的代码就是主动发送消息,具体可参考使用注释掉的代码也可以给用户发送消息,但这种方式不叫被动响应消息被动响应消息实体 /// &summary&
/// 被动响应消息类
/// &/summary&
public abstract class ReplyMessage
public string ToUserName { }
public string FromUserName { }
public long CreateTime { }
/// &summary&
/// 将对象转化为Xml消息
/// &/summary&
/// &returns&&/returns&
public abstract
string ToXmlString();
/// &summary&
/// 被动响应文本消息
/// &/summary&
public class TextReplyMessage : ReplyMessage
/// &summary&
/// 回复的消息内容(换行:在content中能够换行,微信客户端就支持换行显示)
/// &/summary&
public string Content { }
/// &summary&
/// 将对象转化为Xml消息
/// &/summary&
/// &returns&&/returns&
public override string ToXmlString()
string s = "&xml&&ToUserName&&![CDATA[{0}]]&&/ToUserName&&FromUserName&&![CDATA[{1}]]&&/FromUserName&&CreateTime&{2}&/CreateTime&&MsgType&&![CDATA[{3}]]&&/MsgType&&Content&&![CDATA[{4}]]&&/Content&&/xml&";
s = string.Format(s,
ToUserName ?? string.Empty,
FromUserName ?? string.Empty,
CreateTime.ToString(),
Content ?? string.Empty
}配置的URL网页的代码:public class TestWeixin : IHttpHandler {
public void ProcessRequest (HttpContext context) {
if (context.Request.HttpMethod.ToLower() == "post")
System.IO.Stream s = context.Request.InputS
byte[] b = new byte[s.Length];
s.Read(b, 0, (int)s.Length);
string postStr = System.Text.Encoding.UTF8.GetString(b);
if (!string.IsNullOrEmpty(postStr))
Execute(postStr);
}catch(Exception e)
new AppException("收到信息异常" + e.Message);
else //开启应用的回调模式调用 ,代码省略
private void Execute(string postStr)
ReceiveMessageBase basemsg = ConvertMsgToObject(postStr);
if (basemsg.MsgType ==.MsgType.Text)
TextReceiveMessage txtMsg = basemsg as TextReceiveM
if (txtMsg != null)
SendTextReplyMessage(txtMsg.ToUserName, txtMsg.FromUserName, "收到文本消息:" + txtMsg.Content);//发送被动消息
public bool IsReusable {
}开启应用的回调模式调用使用的代码参考这样修改之后呢,用户给企业号发送文本消息时,企业号就可以把用户发送的消息主动回复给用户。效果如下:其他的类型的普通消息,也都相似。但我个人发现,收到事件时,发送被动响应消息,似乎不保证用户能收到,似乎有很大的概率收不到,不知道是我人的原因,还是微信的原因。但奇怪的是,事件都能收到,发送被动响应消息,很大的概率收不到。其实收到普通的消息时,也可以通过主动发送消息,也就是调用微信的相关接口,也可以达到回复用户的目的,这个我测试过,但比发送被动响应消息慢,也能实现和上边类似的效果。
没有更多推荐了,
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!

我要回帖

更多关于 关闭微信邮件提醒 的文章

 

随机推荐