WeChat public service platform development (. Net implementation) 7 ------- send text message

Source: Internet
Author: User

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 ;}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.