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"
}]
}]
}";
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;
}
}