• c# 微信开发 《生成菜单》


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

      

  • 相关阅读:
    JS 实现鼠标移入移出透明度动画变化效果
    Undefined和null的本质区别
    网格布局知识点总结
    用CSS3搭建立方体
    缩放实例
    浮动与细线边框制作广告商标
    用伪元素制作列表菜单
    元素的分类与转换
    网易云导航栏
    CSS中内边距和宽度内减
  • 原文地址:https://www.cnblogs.com/yyyuguo/p/8426745.html
Copyright © 2020-2023  润新知