using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using TalentCloud.Base.Entities; using TalentCloud.Base.Utils; namespace TalentCloud.Agriculture.Weixin.Web.Weixin { public partial class CreateMenu : System.Web.UI.Page { public string output; protected void Page_Load(object sender, EventArgs e) {
//知足JSON格式 string menu = "{
"button": [{
"type": "view",
"name": "11",
"url": "http://www.baidu.com/Weixin/wxProcess.aspx?reurl=http://www.baidu.com"
}, {
"type": "view",
"name": "22",
"url": "http://www.baidu.com/Weixin/wxProcess.aspx?reurl=http://www.baidu.com"
}, {
"name": "55",
"sub_button": [{
"type": "view",
"name": "55-1",
"url": "http://www.baidu.com/Weixin/wxProcess.aspx?reurl=http://www.baidu.com"
}, {
"type": "click",
"name": "55-2",
"key": "BTN_QRCODE"
}]
}]
}";css
string access_token = WeiXinCommom.GetAccsss_token();
//生成微信菜單 string i = WeiXinCommom.PostData("https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + access_token, menu); output = i;//必定要返回成功,不返回就是失敗 } } }
/// <summary> /// 獲取access_token /// </summary> /// <returns></returns> public static string GetAccsss_token() { string access_token = CheckAccsss_token(); if (!string.IsNullOrWhiteSpace(access_token)) { return access_token; } else { //自定義菜單token的獲取 是用 下面的兩個參數 獲取的 不能直接用 公衆平臺的token string url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + appsecret + ""; access_token = GetData(url); access_token = access_token.Substring(17, access_token.Length - 37); //更新access_token的值和獲取時間 WeixinDA.UpdateCodeConfig(access_token, "Access_tokenID"); return access_token; } }