日期:2014-05-17 浏览次数:20712 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Net;
using System.Text;
using System.IO;
public partial class weixin_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//string postStr = "";
// WriteLog("postStr:" + content);
// Response.Write(strresponse);
if (Request.HttpMethod.ToLower() == "post")
{
Stream s = System.Web.HttpContext.Current.Request.InputStream;
byte[] b = new byte[s.Length];
s.Read(b, 0, (int)s.Length);
string apostStr = Encoding.UTF8.GetString(b);
if (!string.IsNullOrEmpty(apostStr))
{
ResponseMsg(apostStr);
}
}
}
/// <summary>
/// 返回信息结果(微信信息返回)
/// </summary>
/// <param name="weixinXML"></param>
private void ResponseMsg(string weixinXML)
{
//回复消息的部分:你的代码写在这里
XmlDocument doc = new XmlDocument();
doc.LoadXml(weixinXML);
XmlNodeList list = doc.GetElementsByTagName("xml");
XmlNode xn = list[0];
string FromUserName = xn.SelectSingleNode("//FromUserName").InnerText;
string ToUserName = xn.SelectSingleNode("//ToUserName").InnerText;
string content = "";
content = xn.SelectSingleNode("//Content").InnerText;
//调用翻译方法
content = Query(content);
//组织xml回复
&nbs