的代码 如下 :请教高手指点。为什么不能接收到消息
public partial class Default : System.Web.UI.Page,IHttpHandler
{
const string Token = "1005sunyafen"; //与那边填写的token一致
protected void Page_Load(object sender, EventArgs e)
{
string postStr = "";
if (Request.HttpMethod.ToLower() == "post") //post方式
{
Stream s = Request.InputStream;
byte[] b = new byte[s.Length];
s.Read(b, 0, (int)s.Length);
postStr = Encoding.UTF8.GetString(b);
if (!string.IsNullOrEmpty(postStr))
{
//封装请求类
XmlDocument doc = new XmlDocument();
doc.LoadXml(postStr);
XmlElement rootElement = doc.DocumentElement;
XmlNode MsgType = rootElement.SelectSingleNode("MsgType");
RequestXML requestXML = new RequestXML();
requestXML.ToUserName = rootElement.SelectSingleNode("ToUserName").InnerText;
requestXML.FromUserName = rootElement.SelectSingleNode("FromUserName").InnerText;
requestXML.CreateTime = rootElement.SelectSingleNode("CreateTime").InnerText;
requestXML.MsgType = MsgType.InnerText;
if (requestXML.MsgType == "text")
{
requestXML.Content = rootElement.SelectSingleNode("Content").InnerText;
this.con.InnerText += requestXML.Content; }
else if (requestXML.MsgType == "location")
{
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;
}
else if (requestXML.MsgType == "image")
{
requestXML.PicUrl = rootElement.SelectSingleNode("PicUrl").InnerText;
}
//回复消息
ResponseMsg(requestXML);
}
}
else
{
Valid();
}
}
我前几天刚开通的,亲测是没有问题的,重点是你填写了URL,通过验证之后,你要启用服务器配置,否则微信是不会向你服务器推送信息的,这也就是为什么你接收不到的原因。有问题的都试试看是不是这个原因吧。
我知道了 如果直接使用$_POST是接收不到xml数据的,对php不能识别的格式,可以使 $GLOBALS["HTTP_RAW_POST_DATA"] 来接收