C#????????????-?????????Demo??
???????????? ???????[ 2014/6/12 11:07:05 ] ????????C# ??? net
????access_token?????????????????????????????????json??????????????????????menu.txt??????????
??????????????????????{"errcode":0??"errmsg":"ok"}????????????????п??????
???????????
???????????????????????http://mp.weixin.qq.com/wiki/index.php?title=?????????????????????????????????????????д?????????????????????????????????????????????á?
?????????????????????????????????xml????????????е?????????????????н??????????????????????????????????д??url????????????????????
1 <xml>
2 <ToUserName><![CDATA[toUser]]></ToUserName>
3 <FromUserName><![CDATA[fromUser]]></FromUserName>
4 <CreateTime>1348831860</CreateTime>
5 <MsgType><![CDATA[text]]></MsgType>
6 <Content><![CDATA[this is a test]]></Content>
7 <MsgId>1234567890123456</MsgId>
8 </xml>
|
??????????ashx??????????
1 public void ProcessRequest(HttpContext param_context)
2 {
3 string postString = string.Empty;
4 if (HttpContext.Current.Request.HttpMethod.ToUpper() == "POST")
5 {
6 using (Stream stream = HttpContext.Current.Request.InputStream)
7 {
8 Byte[] postBytes = new Byte[stream.Length];
9 stream.Read(postBytes?? 0?? (Int32)stream.Length);
10 postString = Encoding.UTF8.GetString(postBytes);
11 Handle(postString);
12 }
13 }
14 }
15
16 /// <summary>
17 /// ????????????
18 /// </summary>
19 private void Handle(string postStr)
20 {
21 messageHelp help = new messageHelp();
22 string responseContent = help.ReturnMessage(postStr);
23
24 HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
25 HttpContext.Current.Response.Write(responseContent);
26 }
|
????messageHelp????????????????????2????????????????????????????postString??xml??????????????????????????XmlDocument???н????????
1 //??????????
2 public string TextHandle(XmlDocument xmldoc)
3 {
4 string responseContent = "";
5 XmlNode ToUserName = xmldoc.SelectSingleNode("/xml/ToUserName");
6 XmlNode FromUserName = xmldoc.SelectSingleNode("/xml/FromUserName");
7 XmlNode Content = xmldoc.SelectSingleNode("/xml/Content");
8 if (Content != null)
9 {
10 responseContent = string.Format(ReplyType.Message_Text??
11 FromUserName.InnerText??
12 ToUserName.InnerText??
13 DateTime.Now.Ticks??
14 "??????????????????????????????" + Content.InnerText+"
<a href="http://www.cnblogs.com">???????</a>");
15 }
16 return responseContent;
17 }
18 /// <summary>
19 /// ?????????
20 /// </summary>
21 public static string Message_Text
22 {
23 get { return @"<xml>
24 <ToUserName><![CDATA[{0}]]></ToUserName>
25 <FromUserName><![CDATA[{1}]]></FromUserName>
26 <CreateTime>{2}</CreateTime>
27 <MsgType><![CDATA[text]]></MsgType>
28 <Content><![CDATA[{3}]]></Content>
29 </xml>"; }
30 }
|
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11