1. 在微信公众号中,开发 --> 基本配置
2. post的服务器地址
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.HttpMethod.ToLower() == "post")
{
string postStr = "";
postStr = PostInput();//获取xml数据
string weixin = "";
weixin = postStr;//获取xml数据
if (!string.IsNullOrEmpty(postStr) && !string.IsNullOrEmpty(weixin))
{
try
{//注册
XmlDocument doc1 = new XmlDocument();
doc1.LoadXml(weixin);//读取xml字符串
XmlNodeList list = doc1.GetElementsByTagName("xml");
XmlNode xn = list[0];
string Event = xn.SelectSingleNode("//Event").InnerText;
string FromUserName = xn.SelectSingleNode("//FromUserName").InnerText;
string EventKey = xn.SelectSingleNode("//EventKey").InnerText;
}
catch
{
}
XmlDocument doc = new XmlDocument();
doc.LoadXml(postStr);//读取xml字符串
//公众号发消息
XmlElement root = doc.DocumentElement;
ExmlMsg xmlMsg = GetExmlMsg(root);
ResponseMsg(xmlMsg);调用消息适配器
}