. NET to realize the function of sending text message in the development of micro-credit public service platform, the specific contents are as follows
First, create a micro-mail 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 of the first attention, used to welcome the word string content = "";
Content = "/:rose welcome Beijing Yong Jie Friend Letter Technology Co., Ltd./:rose\n directly reply" Hello ";
res = sendtextmessage (wx, content); else {if (WX. Msgtype = = "Text" && wx.
Content = = "Hello") {res = Sendtextmessage (wx, "Hello, Welcome to use Beijing Yong Jie Xin Technology Co., Ltd. Public micro-letter platform!");
else {res = Sendtextmessage (wx, "Hello, failed to recognize 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 messages//////obtain sender information///content///private string sendtextmessage (Wxmessage wx, String conten T) {string res = string. Format (@ ", WX.) Fromusername, WX.
Tousername, DateTime.Now, content);
return res;
}
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.