4.0 ?? ??/??
①?? ??/?? ?? ??
?? WeChat ???? ???? ???? ?? ? ?? ?? ?? WeChat ??? ???? ??? URL? POST ???? XML ??? ??? ????. ??? ???? ?? WeChat ?? ????? ?? ???? ????? WeChat ?? ??? ???? ??? ?????. WeChat? ??? ?? ????(?? ??? ??? ?? WeChat ?? ??)? ?? ?? ?? ???? ??? ???.
??:
1. msgid ?? ??? ???? ?? ????.
2. WeChat ??? 5? ??? ??? ?? ??? ??? ?? ??? ?? ???? ? 3?? ?? ?????. ??? 5? ??? ?? ? ??? ??? ? ?? ?? ? ???? ?? ??? ? ????. WeChat ??? ?? ?? ?? ??? ???? ??? ???? ???? ????. ??? ??? "??? ??? - ???? ?? ??"? ?????.
3. ? ?? ??? ???? ?? ???? ?? ??? ?? ????? ??? ???? ??? ???? ??? ? ????. ???? ???? ??? ???? ?? ???? ?????, ?? ???? ????? ????? ??? ???? ?????? ???. (?, ?? ??? ?????? ?? API ??? ?? ????? ???? ??? ???? ??? ?? ????.) ??? ??? ? ?? ??? ?? ??? ??? "??? ??? ? ?? ?? ??"? ?????.
??? ??? ?? POST? XML ??? ??? ????.
?<xml> ?<ToUserName><![CDATA[toUser]]></ToUserName> ?<FromUserName><![CDATA[fromUser]]></FromUserName>? ?<CreateTime>1348831860</CreateTime> ?<MsgType><![CDATA[text]]></MsgType> ?<Content><![CDATA[this is a test]]></Content> ?<MsgId>1234567890123456</MsgId> ?</xml>
?? ??? ?? ???? ??:
?? ???? XML ??? ?????.
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>12345678</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[你好]]></Content> </xml>
?? ??? ?? ????? ?????. ?? :
②?? ??? ??/?? ?? ??
???? ?? ???? WeChat? ????. ??? ??? XML ??? ??? ???? ?? ??? ??? ????:
if(IsPostBack) { //*********************************自動(dòng)應(yīng)答代碼塊********************************* string postString = string.Empty; using (Stream stream = HttpContext.Current.Request.InputStream) { Byte[] postBytes = new Byte[stream.Length]; stream.Read(postBytes, 0, (Int32)stream.Length); //接收的消息為GBK格式 postString = Encoding.GetEncoding("GBK").GetString(postBytes); string responseContent = help.ReturnMessage(postString ); //返回的消息為UTF-8格式 HttpContext.Current.Response.ContentEncoding = Encoding.UTF8; HttpContext.Current.Response.Write(responseContent); } //********************************自動(dòng)應(yīng)答代碼塊end******************************* }
??: ???? ??? ? ??? ??? "GBK" ???? ???? ???. ??? ??? ?? ?? ? ????? ?? ???? ????. ???? ???.
ReturnMessage() ?? ??? ??? ??? ????.
/// <summary> /// 統(tǒng)一全局返回消息處理方法 /// </summary> /// <param name="postStr"></param> /// <returns></returns> public string ReturnMessage(string postStr) { string responseContent = ""; XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(new System.IO.MemoryStream(System.Text.Encoding.GetEncoding("GB2312").GetBytes(postStr))); XmlNode MsgType = xmldoc.SelectSingleNode("/xml/MsgType"); if (MsgType != null) { switch (MsgType.InnerText) { case "event": responseContent = EventHandle(xmldoc);//菜單事件處理 break; case "text": responseContent = TextHandle(xmldoc);//文本消息處理 break; default: break; } } return responseContent; }
TextHandle(xmldoc) ?? ??? ??? ??? ????.
/// <summary> /// 接受文本消息并回復(fù)自定義消息 /// </summary> /// <param name="xmldoc"></param> /// <returns></returns> public string TextHandle(XmlDocument xmldoc) { string responseContent = ""; XmlNode ToUserName = xmldoc.SelectSingleNode("/xml/ToUserName"); XmlNode FromUserName = xmldoc.SelectSingleNode("/xml/FromUserName"); XmlNode Content = xmldoc.SelectSingleNode("/xml/Content"); if (Content != null) { if (Content.InnerText == "指定回復(fù)消息的自定義文本") { responseContent = string.Format(XMLTemplate.Message_Text, FromUserName.InnerText, ToUserName.InnerText, DateTime.Now.Ticks, "自定義回復(fù)消息內(nèi)容"); } } return responseContent; }
??? ??? ???? ?? ??? ??? ????. ??? ?? ??? ? ??? ???? ?? ?????. ?? ?? ?? ???, ?? ???, ?? ???, ?? ???, ?? ?? ???, ??? ?? ???, ?? ??? ?? ??/?????. ?? ??? ???? ?? ??? ? ????.
? ?? C# WeChat ?? ??? - ?? ??/?? ?? ??? ??? PHP ??? ????? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)