Before that, let's talk about sending common text information to us. Next, let's take a look at how to send text information. What we need to note here is: Let's send it to us, instead of sending an image for processing, we will upload the image in a later section. the following is a function for sending text and text messages, which involves the following key parameters: title, description, picurl, and url:
protected string sendPicTextMessage(Msg _mode,string title,string description,string picurl,string url) { string res = string.Format(@"
{0}
{1}
{2}
news
1
<![CDATA[{3}]]>
{4}
{5}
{6}
", _mode.FromUserName, _mode.ToUserName, DateTime.Now,title, description, picurl, url); return res; }
Directly call the function:
Protected void Page_Load (object sender, EventArgs e) {MyMenu (); wxmessage wx = GetWxMessage (); string res = ""; if (! String. isNullOrEmpty (wx. eventName) & wx. eventName. trim () = "subscribe") {string content = ""; content = "/: rose Welcome Beijing Yongjie youxin Technology Co., Ltd /: rose \ n directly replies "hello" "; res = sendTextMessage (wx, content);} else if (! String. isNullOrEmpty (wx. eventName) & wx. eventName. trim () = "CLICK") {if (wx. eventKey = "Hello") res = sendTextMessage (wx, "Hello, welcome to Beijing Yongjie youxin Technology Co., Ltd. public platform! "); If (wx. eventKey = "P1") res = sendTextMessage (wx, "Hello, click product 1"); if (wx. eventKey = "P2") res = sendTextMessage (wx, "Hello, click product 2");} else {if (wx. msgType = "text" & wx. content = "hello") {res = sendTextMessage (wx, "Hello, welcome to Beijing Yongjie youxin Technology Co., Ltd. public platform! ");} If (wx. msgType = "text" & wx. content = "文"") {res = sendPicTextMessage (wx, "This is a title", "this is a summary "," http://mp.weixin.qq.com/wiki/skins/common/images/weixin_wiki_logo.png "," http://www.4ugood.net ");} Else if (wx. msgType = "voice") {res = sendTextMessage (wx, wx. recognition);} else {res = sendTextMessage (wx, "Hello, failed to recognize the message! ") ;}} Response. write (res);} private wxmessage GetWxMessage () {wxmessage wx = new wxmessage (); StreamReader str = new StreamReader (Request. inputStream, System. text. encoding. UTF8); XmlDocument xml = new XmlDocument (); xml. load (str); wx. toUserName = xml. selectSingleNode ("xml "). selectSingleNode ("ToUserName "). innerText; wx. fromUserName = xml. selectSingleNode ("xml "). selectSingleNode ("FromUserName "). innerText; wx. msgType = xml. selectSingleNode ("xml "). selectSingleNode ("MsgType "). innerText; if (wx. msgType. trim () = "text") {wx. content = xml. selectSingleNode ("xml "). selectSingleNode ("Content "). innerText;} if (wx. msgType. trim () = "event") {wx. eventName = xml. selectSingleNode ("xml "). selectSingleNode ("Event "). innerText; wx. eventKey = xml. selectSingleNode ("xml "). selectSingleNode ("EventKey "). innerText;} if (wx. msgType. trim () = "voice") {wx. recognition = xml. selectSingleNode ("xml "). selectSingleNode ("Recognition "). innerText;} return wx ;}