Пример #1
0
        /// <summary>
        /// 创建菜单
        /// </summary>
        public static WeiXinResult CreateMenu()
        {
            WeiXinResult rv = new WeiXinResult { IsResult = false, ResultMsg = "系统错误!" };
            IMpClient mpClient = new MpClient();
            AccessTokenGetRequest request = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo() { AppID = appId, AppSecret = appSecret }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);
            if (response.IsError)
            {
                rv.ResultMsg = "获取令牌环失败";
                return rv;
            }
            else
            {
                Menu menu = new Menu();
                List<Button> button = new List<Weixin.Mp.Sdk.Domain.Button>();
                #region 菜单一 产品中心
                Button subBtn1 = new Button()
                {
                    key = "guoneiyou",
                    name = "国内游",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/ProductView.aspx?xianlu=0"
                };
                Button subBtn2 = new Button()
                {
                    key = "guojiyou",
                    name = "国际游",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/ProductView.aspx?xianlu=1"

                };
                Button subBtn3 = new Button()
                {
                    key = "chanpintuijian",
                    name = "产品推荐",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/ProductList.aspx?tuijian=1"
                };
                Button subBtn4 = new Button()
                {
                    key = "chanpinmachaxun",
                    name = "产品码查询",
                    sub_button = null,
                    type = "click",
                    url = "http://www.4008005216.com/AppPage/weixin/Register.aspx"
                };

                Button subBtn5 = new Button()
                {
                    key = "guoneijipiao",
                    name = "国内机票",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/jp_Search.aspx"
                };
                List<Button> subBtnAll = new List<Button>();
                subBtnAll.Add(subBtn1);
                subBtnAll.Add(subBtn2);
                subBtnAll.Add(subBtn3);
                subBtnAll.Add(subBtn4);
                subBtnAll.Add(subBtn5);
                Button btn = new Button()
                {
                    key = "menu1",
                    name = "旅游超市",
                    url = "httpbig",
                    type = "click",
                    sub_button = subBtnAll
                };
                button.Add(btn);

                #endregion
                #region 菜单二 会员中心
                Button Menu2SubBtn1 = new Button()
                {
                    key = "dingdanguanli",
                    name = "订单管理",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/OrderList.aspx"
                };
                Button Menu2SubBtn2 = new Button()
                {
                    key = "zhanghuguanli",
                    name = "账户管理",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/updateUser.aspx"
                };
                Button Menu2SubBtn3 = new Button()
                {
                    key = "yuyue",
                    name = "预约办理",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/YuYue.aspx"
                };

                string _weidianurl = "https://open.weixin.qq.com/connect/oauth2/authorize?";
                _weidianurl += "appid=" + appId;
                _weidianurl += "&redirect_uri=http://www.4008005216.com/WeiXin/oauth2_authorize.aspx";
                _weidianurl += "&response_type=code";
                _weidianurl += "&scope=snsapi_base";
                _weidianurl += "&state=weidian_snsapi_base";
                _weidianurl += "#wechat_redirect";

                Button Menu2SubBtn4 = new Button()
                {
                    key = "wodeweidian",
                    name = "我的微店",
                    sub_button = null,
                    type = "view",
                    url = _weidianurl
                };
                Button Menu2SubBtn5 = new Button()
                {
                    key = "fenxiang",
                    name = "最新分享",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/HuiYuanWeiXin/TuWenFenXiang.aspx"
                };
                List<Button> subBtnAll2 = new List<Button>();
                subBtnAll2.Add(Menu2SubBtn1);
                subBtnAll2.Add(Menu2SubBtn2);
                subBtnAll2.Add(Menu2SubBtn3);
                subBtnAll2.Add(Menu2SubBtn4);
                subBtnAll2.Add(Menu2SubBtn5);

                btn = new Button()
                {
                    key = "huiyuanzhongxin",
                    name = "会员中心",
                    url = "httpbig",
                    type = "click",
                    sub_button = subBtnAll2
                };
                button.Add(btn);

                #endregion
                #region 菜单三 惠旅游
                Button Menu3SubBtn1 = new Button()
                {
                    key = "aboutus",
                    name = "关于我们",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/AppPage/weixin/AboutUs.aspx"
                };
                Button Menu3SubBtn2 = new Button()
                {
                    key = "appdown",
                    name = "APP下载",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/DownApp.aspx"
                };
                Button Menu3SubBtn3 = new Button()
                {
                    key = "recommend",
                    name = "客服反馈",
                    sub_button = null,
                    type = "click",
                    url = "http://www.4008005216.com/AppPage/weixin/Recommend.aspx"
                };

                Button Menu3SubBtn4 = new Button()
                {
                    key = "weimingpian",
                    name = "我的频道",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/huiyuanweixin/mingpian.aspx"
                };

                Button Menu3SubBtn5 = new Button()
                {
                    key = "lvyouguwen",
                    name = "旅游顾问",
                    sub_button = null,
                    type = "view",
                    url = "http://www.4008005216.com/huiyuanweixin/lvyouguwen.aspx"
                };

                List<Button> subBtnAll3 = new List<Button>();
                subBtnAll3.Add(Menu3SubBtn1);
                subBtnAll3.Add(Menu3SubBtn2);
                subBtnAll3.Add(Menu3SubBtn3);

                subBtnAll3.Add(Menu3SubBtn4);
                subBtnAll3.Add(Menu3SubBtn5);

                btn = new Button()
                {
                    key = "menu3",
                    name = "旅游频道",
                    url = "httpbig",
                    type = "click",
                    sub_button = subBtnAll3
                };
                button.Add(btn);
                #endregion
                menu.button = button;
                MenuGroup mg = new MenuGroup()
                {
                    menu = menu
                };
                string postData = mg.ToJsonString();
                CreateMenuRequest createRequest = new CreateMenuRequest()
                {
                    AccessToken = response.AccessToken.AccessToken,
                    SendData = postData
                };
                CreateMenuResponse createResponse = mpClient.Execute(createRequest);
                if (createResponse.IsError)
                {
                    rv.ResultMsg = "创建菜单失败,错误信息为:" + createResponse.ErrInfo.ErrCode + "-" + createResponse.ErrInfo.ErrMsg;
                    return rv;
                }
                else
                {
                    rv.IsResult = true;
                    rv.ResultMsg = "创建成功";
                    return rv;
                }
            }
        }
Пример #2
0
    public static void CreateMenuTest(string corpId, string corpsecret)
    {
        Weixin.Mp.Sdk.Domain.Menu menu = new Weixin.Mp.Sdk.Domain.Menu();

        List <Weixin.Mp.Sdk.Domain.Button> button = new List <Weixin.Mp.Sdk.Domain.Button>();

        Weixin.Mp.Sdk.Domain.Button subBtn1 = new Weixin.Mp.Sdk.Domain.Button()
        {
            key        = "subkey1",
            name       = "订单跟踪",
            sub_button = null,
            type       = "click",
            url        = "http://"
        };
        Weixin.Mp.Sdk.Domain.Button subBtn2 = new Weixin.Mp.Sdk.Domain.Button()
        {
            key        = "subkey2",
            name       = "义齿资料",
            sub_button = null,
            type       = "view",
            url        = ""
        };
        Weixin.Mp.Sdk.Domain.Button subBtn3 = new Weixin.Mp.Sdk.Domain.Button()
        {
            key        = "subkey3",
            name       = "义齿新闻",
            sub_button = null,
            type       = "click",
            url        = "http://"
        };
        List <Weixin.Mp.Sdk.Domain.Button> subBtnAll = new List <Weixin.Mp.Sdk.Domain.Button>();
        List <Weixin.Mp.Sdk.Domain.Button> subBtnAls = new List <Weixin.Mp.Sdk.Domain.Button>();

        subBtnAll.Add(subBtn1);
        subBtnAls.Add(subBtn2);
        subBtnAls.Add(subBtn3);
        Weixin.Mp.Sdk.Domain.Button btn = new Weixin.Mp.Sdk.Domain.Button()
        {
            key        = "key1",
            name       = "专享服务",
            url        = "httpbig",
            type       = "click",
            sub_button = subBtnAll
        };
        button.Add(btn);

        btn = new Weixin.Mp.Sdk.Domain.Button()
        {
            key        = "key2",
            name       = "关于义齿",
            url        = "httpbig",
            type       = "click",
            sub_button = subBtnAls
        };
        button.Add(btn);

        btn = new Weixin.Mp.Sdk.Domain.Button()
        {
            key  = "key3",
            name = "问题解答",
            url  = "httpbig",
            type = "click",
        };
        button.Add(btn);

        menu.button = button;

        MenuGroup mg = new MenuGroup()
        {
            menu = menu
        };

        string            postData = mg.ToJsonString();
        weixinsendmessage wxsend   = new weixinsendmessage();

        wxsend.CreateMenu(corpId, corpsecret, postData, Encoding.UTF8);
    }