Explanation of text message sending. Net code parsing method developed on WeChat public platform

Source: Internet
Author: User
This article describes how to send text messages. Net code parsing methods for public platform development. This article describes how to send text messages. Net code parsing methods for public platform development.

. Net implements the function of sending text messages in the development of the public service platform. the specific content is as follows:

First, create a message class.

class wxmessage {  public string FromUserName { get; set; }  public string ToUserName { get; set; }  public string MsgType { get; set; }  public string EventName { get; set; }  public string Content { get; set; } public string EventKey { get; set; } }

The background code is as follows:

Protected void Page_Load (object sender, EventArgs e) {wxmessage wx = GetWxMessage (); string res = ""; if (! String. isNullOrEmpty (wx. eventName) & wx. eventName. trim () = "subscribe") {// The time when you just followed, used for the welcome word string content = ""; content = "/: rose welcomes Beijing Yongjie Youxin Technology Co., Ltd./: rose \ n to directly reply "Hello"; res = sendTextMessage (wx, content);} else {if (wx. msgType = "text" & wx. content = "Hello") {res = sendTextMessage (wx, "Hello, welcome to Beijing Yongjie Youxin Technology Co., Ltd. public platform! ");} 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;} return wx ;} ////// send text message ///// obtain the recipient information /// content /// private string sendTextMessage (wxmessage wx, string content) {string res = string. format (@ "", wx. fromUserName, wx. toUserName, DateTime. now, content); return res ;}

The above is a detailed description of the text message. Net code parsing method developed by the public platform. 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.