Catalog
1. Operating Wechat Public Platform with. net - Access
2. Operating the Wechat Public Platform with. net --- Generating the Wechat Menu
3. Operating Wechat Public Platform with. net-Receiving User Operations
3.1. Operation of Wechat Public Platform with. net - Receiving User Operations - Detailed Analysis
Focus on the Public Number
1. Received xml
<xml> <ToUserName><![CDATA[gh_8f9d464d2……]]></ToUserName> <FromUserName><![CDATA[ouHTz1LfufLC5Idj5nUWh4CD8……]]></FromUserName> <CreateTime>1540008097</CreateTime> <MsgType><![CDATA[event]]></MsgType> <Event><![CDATA[subscribe]]></Event> </xml>
parameter | explain |
ToUserName | Developer Microsignal |
FromUserName | Sender account (operator openId) |
CreateTime | Message creation time (integer) |
MsgType | Type (the value given to demo is event event event) |
Event | Event Name (subscribe: Focus on Public Number) |
2. Code
/// <summary> ///Message type adapter /// </summary> /// <param name=""></param> private void ResponseMsg(ExmlMsg xmlMsg) { string messageType = xmlMsg.MsgType;//Gets the type of message received. Text, image, voice, etc. try { switch (messageType) { case "text": break; case "event": // Focus on the Public Number if (!string.IsNullOrEmpty(xmlMsg.EventName) && xmlMsg.EventName.Trim() == "subscribe") { // Focus on Public Number Operation } break; case "image": break; case "voice": break; case "vedio": break; case "location": break; case "link": break; default: break; } Response.End(); } catch (Exception) { } }
Cancel Public Number Concern
1. Received xml
<xml> <ToUserName><![CDATA[gh_8f9d464d2……]]></ToUserName> <FromUserName><![CDATA[ouHTz1LfufLC5Idj5nUWh4CD8……]]></FromUserName> <CreateTime>1540008088</CreateTime> <MsgType><![CDATA[event]]></MsgType> <Event><![CDATA[unsubscribe]]></Event> </xml>
parameter | explain |
ToUserName | Developer Microsignal |
FromUserName | Sender account (operator openId) |
CreateTime | Message creation time (integer) |
MsgType | Type (the value given to demo is event event event) |
Event | Event Name (unsubscribe: Unnoticed Public Number) |
2. Code
/// <summary> ///Message type adapter /// </summary> /// <param name=""></param> private void ResponseMsg(ExmlMsg xmlMsg) { string messageType = xmlMsg.MsgType;//Gets the type of message received. Text, image, voice, etc. try { switch (messageType) { case "text": break; case "event": // Cancel Public Number Concern if (!string.IsNullOrEmpty(xmlMsg.EventName) && xmlMsg.EventName.Trim() == "unsubscribe") { // Cancel Public Number Operation } break; case "image": break; case "voice": break; case "vedio": break; case "location": break; case "link": break; default: break; } Response.End(); } catch (Exception) { } }