在文章【微信hook二次开发C#Demo之获取消息代码】中说到,获取微信消息的方法,这次详细说一下怎么 在获取到的消息中获取微信公众号推送的文章。
在获取到的消息中根据消息类型id来区分消息
var msgType=nmHeler.Json_GetIntEx(RecvJson, “Type”);
其中 msgType== 49的才是公众号文章
通过解析消息内容获得消息的实例
var MsgInfo = new NMHelper.nmMsgInfo
{
RecvWxid = nmHeler.Json_GetString(RecvJson, "RecvWxid", true),
Wxid_1 = Wxid_1,
Nick_1 = Nick_1,
Msg = nmHeler.Json_GetString(RecvJson, "Msg", true),
Type = msgType,
State = nmHeler.Json_GetIntEx(RecvJson, "State"),
Time = nmHeler.Json_GetIntEx(RecvJson, "Time"),
IsSend = nmHeler.Json_GetIntEx(RecvJson, "Sender"),
LocalMsgID = nmHeler.Json_GetIntEx(RecvJson, "LocalID"),
ServerMsgID = nmHeler.Json_GetString(RecvJson, "ServerID", false),
//Wxid_1 = nmHeler.Json_GetString(RecvJson, "Wxid_1", true),
//Nick_1 = nmHeler.Json_GetString(RecvJson, "Nick_1", true),
Wxid_2 = nmHeler.Json_GetString(RecvJson, "Wxid_2", true),
Nick_2 = nmHeler.Json_GetString(RecvJson, "Nick_2", true),
//Msg = nmHeler.Json_GetString(RecvJson, "Msg", true),
Source = nmHeler.Json_GetString(RecvJson, "Source", true)
};
其中 msgInfo.Msg 是消息的具体内容,是个xml结构的字符串,内容如下
<msg>
<appmsg appid=”” sdkver=”0″>
<title><![CDATA[百度全员涨薪,那你的薪资呢?]]></title>
<des><![CDATA[据每日经济新闻,3月18日,需要此c#的源代码请+微信weixinhook,年终奖可能还要多半个月,实习生也会涨工资。]]></des>
<action></action>
<type>5</type>
<showtype>1</showtype