C#/ASP.NET MVC微信接口開發文章目錄:html
1.C#/ASP.NET MVC微信公衆號接口開發之從零開發(一) 接入微信公衆平臺git
2.C#/ASP.NET MVC微信公衆號接口開發之從零開發(二) 接收微信消息而且解析XML(附源碼)github
3.C#/ASP.NET MVC微信公衆號接口開發之從零開發(三)回覆消息 (附源碼)json
自定義菜單開發api
1.配置Json字符串服務器
首先配置菜單/menu所須要的Json字符串,而後用post請求微信接口地址便可。配置json格式參看微信接口文檔:http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html微信
2.Post請求發佈微信開發
配置好Json字符串以後請求微信api地址代碼:微信公衆平臺
1 /// <summary> 2 /// 發佈菜單 3 /// </summary> 4 /// <param name="MenuJson">配置的菜單json數據</param> 5 /// <param name="AppID">AppID</param> 6 /// <param name="AppSecret">AppSecret</param> 7 /// <returns>返回0成功不然錯誤碼</returns> 8 public string MenuCreate(string MenuJson,string AppID,string AppSecret) { 9 string setMenuUrl = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={0}"; 10 setMenuUrl = string.Format(setMenuUrl, BasicApi.GetTokenSession(AppID,AppSecret));//獲取token、拼湊url 11 string respText = sohovan.com.common.CommonMethod.WebRequestPostOrGet(setMenuUrl, MenuJson); 12 Dictionary<string, object> respDic = (Dictionary<string, object>)Jss.DeserializeObject(respText); 13 return respDic["errcode"].ToString();//返回0發佈成功 14 }
若發佈成功則返回0,發佈失敗返回錯誤碼。
3.響應菜單事件post
菜單發佈成功,根據配置的Json字符串,菜單分爲兩種基本的經常使用類型click(單擊)、view(跳轉url),view直接跳轉到配置的url,click事件的微信服務器發送事件XML給對於的微信用戶格式爲:
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[FromUser]]></FromUserName> <CreateTime>123456789</CreateTime> <MsgType><![CDATA[event]]></MsgType> <Event><![CDATA[CLICK]]></Event> <EventKey><![CDATA[EVENTKEY]]></EventKey> </xml>
EventKey爲咱們發佈本身定義的key值,根據key值咱們能夠設置對於的回覆消息。
本文版權歸做者(謝俊)和博客園全部,歡迎轉載,轉載請標明出處。
原文地址:http://www.cnblogs.com/net-xiejun/
完整源碼下載:https://github.com/xiejun-net/weixin
公衆帳號: