


When an ordinary WeChat user sends a message to a public account, the WeChat server will POST the XML data packet of the message to the URL filled in by the developer.
Please note:
1、关于重试的消息排重,推荐使用msgid排重。 2、微信服务器在五秒内收不到响应会断掉连接,并且重新发起请求,总共重试三次。假如服务器无法保证在五秒内处理并回复,可以直接回复空串,微信服务器不会对此作任何处理,并且不会发起重试。详情请见“发送消息-被动回复消息”。 3、为了保证更高的安全保障,开发者可以在公众平台官网的开发者中心处设置消息加密。开启加密后,用户发来的消息会被加密,公众号被动回复用户的消息也需要加密(但开发者通过客服接口等API调用形式向用户发送消息,则不受影响)。关于消息加解密的详细说明,请见“消息加解密说明”。
The push XML data packet structure of each message type is as follows:
Text message
<xml> <tousername></tousername> <fromusername></fromusername> <createtime>1348831860</createtime> <msgtype></msgtype> <content></content> <msgid>1234567890123456</msgid> </xml>
Parameters | Description |
---|---|
ToUserName | DeveloperWeChat ID |
FromUserName | Sender account (an OpenID) |
CreateTime | Message creation time (integer) |
text | |
Text message content | |
Message id, 64-bit integer |
Picture message <xml>
<tousername></tousername>
<fromusername></fromusername>
<createtime>1348831860</createtime>
<msgtype></msgtype>
<picurl></picurl>
<mediaid></mediaid>
<msgid>1234567890123456</msgid>
</xml>
Description | |
---|---|
DeveloperWeChat ID | |
Sender account (an OpenID) | |
Message creation time (integer) | |
image | |
Picture link | |
Picture message media id, you can call the multimedia file download interface to pull data. | |
Message id, 64-bit integer |
Voice message<xml>
<tousername></tousername>
<fromusername></fromusername>
<createtime>1357290913</createtime>
<msgtype></msgtype>
<mediaid></mediaid>
<format></format>
<msgid>1234567890123456</msgid>
</xml>
Description | |
---|---|
Developer WeChat ID | |
Sender account (an OpenID) | |
Message creation time (Integer type) | |
Voice is voice | |
Voice message media id, You can call the multimedia file download interface to pull data. | |
Voice format, such as amr, speex, etc. | |
Message id, 64 Bit integer |
<xml> <tousername></tousername> <fromusername></fromusername> <createtime>1357290913</createtime> <msgtype></msgtype> <mediaid></mediaid> <format></format> <recognition></recognition> <msgid>1234567890123456</msgid> </xml>In the extra fields, Format is the voice format, usually amr, and Recognition is the voice recognition result, using UTF8 encoding.
Video Message<xml>
<tousername></tousername>
<fromusername></fromusername>
<createtime>1357290913</createtime>
<msgtype></msgtype>
<mediaid></mediaid>
<thumbmediaid></thumbmediaid>
<msgid>1234567890123456</msgid>
</xml>
Description | |
---|---|
DeveloperWeChat ID | |
Sender account (an OpenID) | |
Message creation time (integer) | |
The video is video | |
Video message media id, you can call the multimedia file download interface to pull data. | |
The media id of the video message thumbnail, you can call the multimedia file download interface to pull the data. | |
Message id, 64-bit integer type |
Small video message <xml>
<tousername></tousername>
<fromusername></fromusername>
<createtime>1357290913</createtime>
<msgtype></msgtype>
<mediaid></mediaid>
<thumbmediaid></thumbmediaid>
<msgid>1234567890123456</msgid>
</xml>
Description | |
---|---|
Developer微信 | |
Sender account (an OpenID) | |
Message creation Time (integer type) | |
The short video is shortvideo | |
Video message media id, you can call the multimedia file download interface to pull data. | |
The media id of the video message thumbnail, you can call the multimedia file download interface to pull the data. | |
Message id, 64-bit integer |
参数 | 描述 |
---|---|
ToUserName | 开发者微信号 |
FromUserName | 发送方帐号(一个OpenID) |
CreateTime | 消息创建时间 (整型) |
MsgType | location |
Location_X | 地理位置维度 |
Location_Y | 地理位置经度 |
Scale | 地图缩放大小 |
Label | 地理位置信息 |
MsgId | 消息id,64位整型 |
链接消息
<xml> <tousername></tousername> <fromusername></fromusername> <createtime>1351776360</createtime> <msgtype></msgtype> <title></title> <description></description> <url></url> <msgid>1234567890123456</msgid> </xml>
参数 | 描述 |
---|---|
ToUserName | 接收方微信号 |
FromUserName | 发送方微信号,若为普通用户,则是一个OpenID |
CreateTime | 消息创建时间 |
MsgType | 消息类型,link |
Title | 消息标题 |
Description | 消息描述 |
Url | 消息链接 |
MsgId | 消息id,64位整型 |
Continued from the previous article, see ResponseXML(postString); the method is as follows
/// ///
/// Get Messages sent by users
’’’’’’’’’’’’’’’’’’’’ out out out through out through out out through out out through out together’’’psy out out out out out out out out out out out out out out's's's's's's' out''‐''‑'''‑'''‐By''‐By‐‐‐‐ paths to to be a Message to to be to the user to to be to account to the user to to be to the user to to to to itself to to to to to to itself to to up to a whirlwind pace to be as high as 10%?
Element rootElement = xmlDoc.DocumentElement;//Get the root of the document
XmlNode MsgType = rootElement.SelectSingleNode("MsgType"); //Get the text type of the message
RequestXML requestXML = new RequestXML();//Declare the instance, get each attribute and assign a value
requestXML.ToUserName = rootElement.SelectSingleNode ("ToUserName").InnerText;//Public account
requestXML.FromUserName = rootElement.SelectSingleNode("FromUserName").InnerText;//User
requestXML.CreateTime = rootElement.SelectSingleNode("CreateTime").InnerText ;//Creation time
requestXML.MsgType = MsgType.InnerText;//Message type
tent = rootElement.SelectSingleNode("Content").InnerText;
rootElement. Map zoom ratio, geographical location description
requestXML.Location_X = rootElement.SelectSingleNode("Location_X").InnerText;
requestXML.Location_Y = rootElement.SelectSingleNode("Location_Y").InnerText;
requestXML.Scale = rootElement.SelectSingleNode("Scale").InnerText;
requestXML.Label = rootElement.SelectSingleNode("Label").InnerText;
}
if (requestXML.MsgType.Trim().ToLower() = = "event")
= rootElement.SelectSingleNode ("EventKey").InnerText;
if (requestXML.MsgType.Trim().ToLower() == "voice") As a result, you must remember to turn on the voice recognition function in the developer mode before assigning, otherwise you will not get
Requestxml.RCOGNITION = rootlement.SelectsingLende ("Recognition"). Innertext;
} SEMSG ( requestXML);
}
The speech recognition function is turned on as follows:
requestXML is one I created separately Class, which declares the commonly used attribute fields in messages, as follows:
/// The entity class that receives the message
///
public class RequestXML
{
private String toUserName = String .Empty;
/// & lt; summary & gt;
/// Ben public account
/// & lt;/summary & gt;
PUBLIC String Tousername {get;} ##// /
; /// User WeChat ID
; ///
/ //
; # public String Content{get;set;}
/*The following are the properties unique to event type messages*/
/
; string EventKey { get; set; }
using use using it ’ ’ ’ ’ out’s ’ out’s out’s out’s out’s out out out out out way out out way out out out out out out out out out out out out out out out out out back out past ’ s ’ ’s out off out’s’ out out out out out out out out out out out out out out out out out out out out outO s , , , , , , , , , , - , / / summary>
public string Title { get; set; }
’’’’’’’’’’’’’’’’’’’’’’’’’’ out out’’ out out out out out out’’ out out out out out out out out out out out out out out out out of's to'’’’’ ‑ ‐‐'‐'‐‐‐‐‐ and to ? String description {get; set;}
/// & lt; summary & gt;
/// The link address of graphic message pictures
/// & lt;/summary & gt;
Public string picurl {get ; set; }
///
## /// & lt; Summary & gt;
/// 图 图
/// & lt;/Summary & GT;
Public list; requestxml & gt; Articles {get;}
/ * The following are the properties unique to messages of geographical location type*/
’’’’’’’’’’’’’’’’’’’’’’’’’’ out out out out Throughmb Through Outceps out right out right out out out out out out out out out out out out out out out out out out out outs’s ; set; }
///
/// Geographical Location
/// & LT;/Summary & GT;
Public String Location_y {get;}
/// & lt;
/// map zoom ratio
;
public String Label { get; set; } use using using using ‐ out out out through ’’s ’ ’’s ’ ’’s ’ ’ ’s ’ through out through out through out through out through through through over over through through through through through through through through‐ through through through through through through through through through through through through through through through‐ through‐over through through right through right through outthrough through through out through through out through through through out through out out through out out out out through Through out through over over over over over''s to come through through's toward's'‐''‐'‐‐‐‐‐ light to be pass be a t; public String Recognition { get; set; }
Continue to follow ResponseMsg(requestXML);The method is as follows,
private void ResponseMsg(RequestXML requestXML )
Case "text":
SendtextCase (Requestxml); // Send text messages
Break;
if (! String.isnullWhitespace (Requestxml. EventName ) && requestXML.EventName.ToString().Trim().Equals("subscribe"))
} if (!string.IsNullOrWhiteSpace(requestXML.EventName) && requestXML.EventName.ToString().Trim().Equals("CLICK"))
);//Send event message
case "voice":
SendVoiceMsg(requestXML);//Send a voice message SendMapMsg(requestXML);
break;
break; {
HttpContext.Current.Response.Write(ex.ToString());
Send text
# string responseContent = FormatTextXML(requestXML.FromUserName, requestXML.ToUserName, requestXML.Content); HttpContext.Current.Response.ContentEncoding = Encoding.UTF8 ;
HttpContext.Current.Response.Write(responseContent);
///
’’'' ’' to be returned to the formatted Public account
; /// User account
; /// Reply content
‐ ;
In this way, the response to the message can be realized. If the user clicks the button, the following code:
case "event"://Send event message
If
(!string.IsNullOrWhiteSpace(requestXML.EventName) &&
requestXML.EventName.ToString().Trim().Equals("subscribe"))
}
///
’’’’’’’’’ ‐ ’ parameter case "mypay":
SendPayDetails(requestXML);//Send salary bill
//Send weather forecast
:
SendKaiXinMessage(requestXML);//Send a happy smile result set XML);//Send modification information link
# case "yuangonghuodong":
SendYuanGongHuoDong(requestXML);//Send student activities
## SendYuanGongTongZhi(requestXML);//Send employee notification
SendYuanGongTongZhi(requestXML);//Send employee notification
case "youwenbida":
SendWenti(requestXML);//Send employee submission link
SendWentiList(requestXML);//Send question list link
break; defaultresponseContent = FormatTextXML(requestXML.FromUserName, requestXML.ToUserName,"This feature is not available yet! Please stay tuned!"); current. Response.ContentEncoding = Encoding.UTF8;
break;
}
}
SendWelComeMsg(requestXML);//The graphic message returned when paying attention
///
///
string newdate = DateTime.Now.Subtract(new DateTime(1970, 1, 1, 8, 0, 0)).TotalSeconds.ToString(); string PUrlfileName = "http://www.deqiaohr. com.cn/weixin/welcome.jpg";
responseContent = string.Format(Message_News_Main, requestXML.FromUserName, requestXML.ToUserName, newdate, "1",
string.Format((Message_News_Item, "Welcome to Deqiao) Employee Service Center", "Suzhou Deqiao Human Resources was founded in 2002...", PUrlfileName, "http://www.deqiaohr.com.cn/weixin/WxGsjianjie.aspx"));
HttpContext.Current .Response.ContentType = "text/xml";
current.Response.End ();
}
Message_News_Main and Message_News_Item are graphic and text message formats
///
/// 返回图文消息主体
///
public static string Message_News_Main
{
get
{
return @"
{4}
}
}
///
/// 返回图文消息项
///
public static string Message_News_Item
{
get
{
return @"
}
}
///
/param> ToString());
HttpContext.Current.Response.ContentType = "text/xml";
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
HttpContext.Current.Response.Write( responseContent) ;
Web page, regarding the issue of adaptive web page images, just set the width of the image to 100%. If you want the web page to adapt to the screen, remember to add
The above is the detailed content of Detailed explanation of asp.net WeChat development message response method. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Notepad++7.3.1
Easy-to-use and free code editor