WeChat development sends text message instance resolution through. Net

Source: Internet
Author: User
This article mainly analyzes in detail the text message sent by the public platform development. net code, interested friends can refer to this article for detailed analysis of the public platform development to send text messages. net code. if you are interested, refer

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

The above is the detailed content of instance resolution for sending text and text messages through. Net. For more information, see other related articles on php Chinese network!

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.