番外篇2:自定义菜单.
这个是要认证才能做的,后台代码:
public string Doevent(string xml)
{
//***前面省略***
//自定义菜单事件Click
if (!string.IsNullOrEmpty(element.SelectSingleNode("EventKey").InnerText))
{
string ClickKey = element.SelectSingleNode("EventKey").InnerText;
switch (ClickKey)
{
case "b1":
rexml = xmlhelper.CreatTextXml(FromUserName, "how are you");
break;
case "b2":
rexml = xmlhelper.CreateNewsXml(FromUserName, "智能");
break;
case "c1":
rexml = xmlhelper.CreateNewsXml(FromUserName, "微社区");
break;
case "c2":
rexml = xmlhelper.CreateNewsXml(FromUserName, "云课堂");
break;
default:
rexml = xmlhelper.CreateNewsXml(FromUserName, "无法识别!");
break;
}
}
}
在获得ClickKey之前,你要先创建菜单,可以使用它官网的调试工具.
菜单参数说明:
{
"button": [
{
"type":"view",
"name": "服务",
"url":"http://www.baidu.com/"
},
{
"name": "服务项目",
"sub_button": [
{
"type": "click",
"name": "你好",
"key": "b1"
},
{
"type": "click",
"name": "智能",
"key": "b2"
},
{
"type": "view",
"name": "监管",
"url":"http://www.baidu.com/"
}
]
},
{
"name": "社区",
"sub_button": [
{
"type": "click",
"name": "微社区",
"key": "c1"
},
{
"type": "click",
"name": "云课堂",
"key": "c2"
}
]
}
]
}
当然,创建的时候,你得有access_token,认证了有的.
拜了个拜