示例#1
0
        public static void Main(string[] args)
        {
            string settings = GenerateMenuSettings();
            //此应用的token
            string accessToken = GetAccessTokenSubscribe();

            //企业号App应用的ID:比如0,1等
            //string deleteUrl = GenerateDeleteMenuUrl(accessToken, MenuUtil.CORP_AGENT_ID);
            string createUrl = GenerateCreateMenuUrl(accessToken);

            //请求腾讯的服务器以创建自定义菜单
            //string deleteResult = new HttpUtil().ExecuteGet(deleteUrl);
            //Console.WriteLine("The Delete result is: {0}", deleteResult);

            string createResult = new HttpUtil().ExecutePost(createUrl, settings);
            Console.WriteLine("The Create result is: {0}", createResult);
            Console.ReadLine();
        }
示例#2
0
 /// <summary>
 /// 订阅号/服务号的GetAccessToken
 /// </summary>
 /// <returns></returns>
 private static string GetAccessTokenSubscribe()
 {
     string url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="
         + MenuUtil.APP_ID + "&secret=" + MenuUtil.APP_SECRET;
     HttpUtil httpUtil = new HttpUtil();
     string result = httpUtil.ExecuteGet(url);
     SerializeUtil serializeUtil = new SerializeUtil();
     IDictionary<string, object> dict = serializeUtil.ToObject<IDictionary<string, object>>(result);
     string accessToken = (dict["access_token"]).ToString();
     //int expiresIn = Convert.ToInt32((dict["expires_in"]));
     Console.WriteLine("accessToken: {0}", accessToken);
     return accessToken;
 }