整个按钮设置(可以直接用ButtonGroup实例返回JSON对象)
Beispiel #1
0
        private void ComposeMenu()
        {
            _group = new ButtonGroup();
            //报表
            SubButton subBtn1 = new SubButton();
            subBtn1.name = "管理";

            //SingleViewButton btn11 = new SingleViewButton();
            //btn11.url = "http://180.169.11.53/senlan2.weixin/pages/inventory.html";
            SingleClickButton btn11 = new SingleClickButton();
            btn11.key = "btnReport";
            btn11.name = "报表";

            SingleClickButton btn12 = new SingleClickButton();
            btn12.name = "账号绑定";
            btn12.key = "btnBind";

            subBtn1.sub_button.Add(btn11);
            subBtn1.sub_button.Add(btn12);

            _group.button.Add(subBtn1);

            //审批中心
            SubButton subBtn2 = new SubButton();
            subBtn2.name = "审批中心";

            //SingleViewButton btn21 = new SingleViewButton();
            //btn21.url = "http://180.169.11.53/senlan2.weixin/pages/approval_contract.html";
            SingleClickButton btn21 = new SingleClickButton();
            btn21.name = "待审合同";
            btn21.key = "btn_approval_contract";

            //SingleViewButton btn22 = new SingleViewButton();
            //btn22.url = "http://180.169.11.53/senlan2.weixin/pages/approval_paymentrequest.html";
            SingleClickButton btn22 = new SingleClickButton();
            btn22.name = "待审付款申请";
            btn22.key = "btn_approval_paymentrequest";

            SingleClickButton btn23 = new SingleClickButton();
            btn23.name = "审批推送订阅";
            btn23.key = "btn_customer_service";

            subBtn2.sub_button.Add(btn21);
            subBtn2.sub_button.Add(btn22);
            subBtn2.sub_button.Add(btn23);

            _group.button.Add(subBtn2);

            //交易下单
            //SingleViewButton btn31 = new SingleViewButton();
            //btn31.url = "http://180.169.11.53/senlan2.weixin/pages/add_contract.html";
            SubButton subBtn3 = new SubButton();
            subBtn3.name = "业务单据";

            SingleClickButton btn31 = new SingleClickButton();
            btn31.name = "合同";
            btn31.key = "btn_Contract";
            subBtn3.sub_button.Add(btn31);
            _group.button.Add(subBtn3);
        }
        public void CreateMenuTest()
        {
            return;//已经通过测试

            LoadToken();

            ButtonGroup bg = new ButtonGroup();

            //单击
            bg.button.Add(new SingleClickButton()
                              {
                                  name = "单击测试",
                                  key = "OneClick",
                                  type = ButtonType.click.ToString(),//默认已经设为此类型,这里只作为演示
                              });

            //二级菜单
            var subButton = new SubButton()
                                {
                                    name = "二级菜单"
                                };
            subButton.sub_button.Add(new SingleClickButton()
                                        {
                                            key = "SubClickRoot_Text",
                                            name = "返回文本"
                                        });
            subButton.sub_button.Add(new SingleClickButton()
                                        {
                                            key = "SubClickRoot_News",
                                            name = "返回图文"
                                        });
            subButton.sub_button.Add(new SingleClickButton()
                                        {
                                            key = "SubClickRoot_Music",
                                            name = "返回音乐"
                                        });
            subButton.sub_button.Add(new SingleViewButton()
                                        {
                                            url = "http://weixin.senparc.com",
                                            name = "Url跳转"
                                        });
            bg.button.Add(subButton);

            //url跳转
            var viewButton = new SingleViewButton()
                                {
                                    name = "Url跳转",
                                    url = "http://weixin.senparc.com"
                                };
            bg.button.Add(viewButton);

            var result = CommonApi.CreateMenu(tokenResult.access_token, bg);

            Assert.IsNotNull(result);
            Assert.AreEqual("ok", result.errmsg);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
#if SETTING
            string appId = System.Configuration.ConfigurationManager.AppSettings["AppId"].ToString();
            string appSecret = System.Configuration.ConfigurationManager.AppSettings["AppSecret"].ToString();
            string appWebUrl = System.Configuration.ConfigurationManager.AppSettings["AppWebUrl"].ToString();
#else
            string appId = "wx4df221a4e9845aea";
            string appSecret = "c2c6e3220de9609c79e3d1f425bba0fb";
            string appHost = "http://recruit.casco.com.cn";
            
#endif
            
            var appOauth2 = appHost + "/oauth";
            var appUrl =
                string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type={2}&scope={3}&state={4}#wechat_redirect",
                                appId, appOauth2.UrlEncode(), "code", "snsapi_userinfo", "1");

            ButtonGroup btGroup = new ButtonGroup();
            var serviceButton = new SingleViewButton() { 
                name = "在线服务",
                url = appUrl
            };
            var userButton = new SubButton() { name = "个人中心" };
            userButton.sub_button.Add(new SingleClickButton()
            {
                name = "账号绑定",
                type = ButtonType.click.ToString(),
                key = "UserBind"
            });
            userButton.sub_button.Add(new SingleClickButton()
            {
                name = "个人信息",
                type = ButtonType.click.ToString(),
                key = "UserInfo"
            });

            btGroup.button.Add(serviceButton);
            btGroup.button.Add(userButton);

            var accessToken = AccessTokenContainer.TryGetToken(appId, appSecret);
            WxJsonResult result = CommonApi.CreateMenu(accessToken, btGroup);
            if (result.errmsg != null && result.errmsg != "ok")
            {
                Console.WriteLine(result.errmsg);
                Console.WriteLine("------------------->Build Error!");
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("Success!");
                Console.ReadKey();
            }
            
        }
        public void CreateMenuTest()
        {
            return;//已经通过测试

            var accessToken = AccessTokenContainer.GetAccessToken(_appId);

            ButtonGroup bg = new ButtonGroup();

            //单击
            bg.button.Add(new SingleClickButton()
            {
                name = "单击测试",
                key = "OneClick",
                type = ButtonType.click.ToString(),//默认已经设为此类型,这里只作为演示
            });

            //二级菜单
            var subButton = new SubButton()
            {
                name = "二级菜单"
            };
            subButton.sub_button.Add(new SingleClickButton()
            {
                key = "SubClickRoot_Text",
                name = "返回文本"
            });
            subButton.sub_button.Add(new SingleClickButton()
            {
                key = "SubClickRoot_News",
                name = "返回图文"
            });
            subButton.sub_button.Add(new SingleClickButton()
            {
                key = "SubClickRoot_Music",
                name = "返回音乐"
            });
            subButton.sub_button.Add(new SingleViewButton()
            {
                url = "http://sdk.weixin.senparc.com",
                name = "Url跳转"
            });
            subButton.sub_button.Add(new SingleLocationSelectButton()
            {
                key = "SingleLocationSelectButton",
                name = "位置",
            });
            bg.button.Add(subButton);


            var result = CommonApi.CreateMenu(accessToken, bg);

            Assert.IsNotNull(result);
            Assert.AreEqual("ok", result.errmsg);
        }
Beispiel #5
0
        public void CreateMenuFesco()
        {
            //Console.WriteLine("************************************开始创建微信菜单*******************************************************\n");
            string appid = "wx82315287d9fc52ae";
            string secret = "00dbe4ae7304f61ef9f77c7bd8fc0f48";
            string PROJECT_NAME = "FESCOAsecco";
            string PROJECT_URL = "weixin.hrone.cn";
            var accessToken = AccessTokenContainer.TryGetAccessToken(appid, secret);
            Console.WriteLine("  accessToken:" + accessToken + "\n");
            ButtonGroup bg = new ButtonGroup();
            //首页

            var About = new SingleClickButton()
            {
                name = "账户绑定",
                key = "bind_account",
                type = ButtonType.click.ToString(),
            };
            bg.button.Add(About);
            //我的
            var AboutMe = new SubButton()
            {
                name = "我的信息"
            };
            AboutMe.sub_button.Add(new SingleViewButton()
            {
                url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME
                    + "%2FView%2FCommUtil%2FLoading.html?pageType=10009&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect",
                name = "个人信息"
            });
            AboutMe.sub_button.Add(new SingleViewButton()
            {
                url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME
                    + "%2FView%2FCommUtil%2FLoading.html?pageType=10011&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect",
                name = "银行信息"
            });
            bg.button.Add(AboutMe);
            //申请&签核
            var ApplyAndApprove = new SingleViewButton()
            {
                name = "进入系统",
                type = ButtonType.view.ToString(),
                url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME
                   + "%2FView%2FCommUtil%2FMenuLoading.html&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"
            };
            bg.button.Add(ApplyAndApprove);
            var result = CommonApi.CreateMenu(accessToken, bg);
            Console.WriteLine("  Errcode:  " + result.errcode + "\n\n  Errmsg:  " + result.errmsg + "\n\n  P2PData:  " + result.P2PData + "\n");
            Console.WriteLine("************************************创建微信菜单结束*******************************************************\n");
            Console.ReadKey();
        }
Beispiel #6
0
 /// <summary>
 /// 创建菜单
 /// </summary>
 /// <param name="accessToken"></param>
 /// <param name="buttonData">菜单内容</param>
 /// <returns></returns>
 public static WxJsonResult CreateMenu(string accessToken, ButtonGroup buttonData)
 {
     JavaScriptSerializer js = new JavaScriptSerializer();
     var jsonString = js.Serialize(buttonData);
     var cookieContainer = new CookieContainer();
     using (MemoryStream ms = new MemoryStream())
     {
         using (var sr = new StreamWriter(ms))
         {
             sr.Write(jsonString);
         }
         var url = string.Format("https://api.weixin.qq.com/cgi-bin/menu/create?access_token={0}", accessToken);
         var result = Post.PostGetJson<WxJsonResult>(url, cookieContainer, ms);
         return result;
     }
 }
Beispiel #7
0
        /// <summary>
        /// 创建菜单
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="buttonData">菜单内容</param>
        /// <returns></returns>
        public static WxJsonResult CreateMenu(string accessToken, ButtonGroup buttonData)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            var jsonString = js.Serialize(buttonData);
            CookieContainer cookieContainer = null;// new CookieContainer();

            using (MemoryStream ms = new MemoryStream())
            {
                var bytes = Encoding.UTF8.GetBytes(jsonString);
                ms.Write(bytes, 0, bytes.Length);
                ms.Seek(0, SeekOrigin.Begin);

                var url = string.Format("https://api.weixin.qq.com/cgi-bin/menu/create?access_token={0}", accessToken);
                var result = Post.PostGetJson<WxJsonResult>(url, cookieContainer, ms);
                return result;
            }
        }
 ///// <summary>
 ///// 特殊符号转义
 ///// </summary>
 ///// <param name="name"></param>
 ///// <returns></returns>
 //private static string ButtonNameEncode(string name)
 //{
 //    //直接用UrlEncode不行,显示内容超长
 //    return name.Replace("&", "%26");
 //}
 /// <summary>
 /// 创建菜单
 /// </summary>
 /// <param name="accessToken"></param>
 /// <param name="buttonData">菜单内容</param>
 /// <returns></returns>
 public static WxJsonResult CreateMenu(string accessToken, ButtonGroup buttonData)
 {
     var urlFormat = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={0}";
     ////对特殊符号进行URL转义
     //foreach (var button in buttonData.button)
     //{
     //    button.name = ButtonNameEncode(button.name);//button.name.UrlEncode();
     //    if (button is SubButton)
     //    {
     //        var subButtonList = button as SubButton;
     //        foreach (var subButton in subButtonList.sub_button)
     //        {
     //            subButton.name = ButtonNameEncode(button.name);//button.name.UrlEncode();
     //        }
     //    }
     //}
     return CommonJsonSend.Send(accessToken, urlFormat, buttonData);
 }
Beispiel #9
0
        private void CreateMenus()
        {
            ButtonGroup bg = new ButtonGroup();

            //单击
            bg.button.Add(new SingleClickButton()
            {
                name = "单击测试",
                key = "OneClick",
                type = ButtonType.click.ToString(),//默认已经设为此类型,这里只作为演示
            });

            //二级菜单
            var subButton = new SubButton()
            {
                name = "二级菜单"
            };
            subButton.sub_button.Add(new SingleClickButton()
            {
                key = "SubClickRoot_Text",
                name = "返回文本"
            });
            subButton.sub_button.Add(new SingleClickButton()
            {
                key = "SubClickRoot_News",
                name = "返回图文"
            });
            subButton.sub_button.Add(new SingleClickButton()
            {
                key = "SubClickRoot_Music",
                name = "返回音乐"
            });
            subButton.sub_button.Add(new SingleViewButton()
            {
                url = string.Format("{0}Home/OperateMsg", KeyStore.DemoUrl),
                name = "使用说明"
            });
            bg.button.Add(subButton);

            var accessToken = AccessTokenContainer.GetAccessToken(KeyStore.AppId);
            var result = CommonApi.CreateMenu(accessToken, bg);
        }
Beispiel #10
0
        ///// <summary>
        ///// 特殊符号转义
        ///// </summary>
        ///// <param name="name"></param>
        ///// <returns></returns>
        //private static string ButtonNameEncode(string name)
        //{
        //    //直接用UrlEncode不行,显示内容超长
        //    return name.Replace("&", "%26");
        //}
        /// <summary>
        /// 创建菜单
        /// </summary>
        /// <param name="accessTokenOrAppId">AccessToken或AppId。当为AppId时,如果AccessToken错误将自动获取一次。当为null时,获取当前注册的第一个AppId。</param>
        /// <param name="buttonData">菜单内容</param>
        /// <returns></returns>
        public static WxJsonResult CreateMenu(string accessTokenOrAppId, ButtonGroup buttonData, int timeOut = Config.TIME_OUT)
        {
            return ApiHandlerWapper.TryCommonApi(accessToken =>
             {
                 var urlFormat = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={0}";
                 ////对特殊符号进行URL转义
                 //foreach (var button in buttonData.button)
                 //{
                 //    button.name = ButtonNameEncode(button.name);//button.name.UrlEncode();
                 //    if (button is SubButton)
                 //    {
                 //        var subButtonList = button as SubButton;
                 //        foreach (var subButton in subButtonList.sub_button)
                 //        {
                 //            subButton.name = ButtonNameEncode(button.name);//button.name.UrlEncode();
                 //        }
                 //    }
                 //}
                 return CommonJsonSend.Send(accessToken, urlFormat, buttonData, timeOut: timeOut);

             }, accessTokenOrAppId);
        }
Beispiel #11
0
        /// <summary>
        /// 根据微信返回的Json数据得到可用的GetMenuResult结果
        /// </summary>
        /// <param name="resultFull"></param>
        /// <returns></returns>
        public static GetMenuResult GetMenuFromJsonResult(GetMenuResultFull resultFull)
        {
            GetMenuResult result = null;
            try
            {
                //重新整理按钮信息
                ButtonGroup bg = new ButtonGroup();
                foreach (var rootButton in resultFull.menu.button)
                {
                    if (string.IsNullOrEmpty(rootButton.name))
                    {
                        continue;//没有设置一级菜单
                    }
                    var availableSubButton = rootButton.sub_button == null ? 0 : rootButton.sub_button.Count(z => !string.IsNullOrEmpty(z.name));//可用二级菜单按钮数量
                    if (availableSubButton == 0)
                    {
                        //底部单击按钮
                        if (rootButton.type == null ||
                            (rootButton.type.Equals("CLICK", StringComparison.OrdinalIgnoreCase)
                            && string.IsNullOrEmpty(rootButton.key)))
                        {
                            throw new WeixinMenuException("单击按钮的key不能为空!");
                        }

                        if (rootButton.type.Equals("CLICK", StringComparison.OrdinalIgnoreCase))
                        {
                            //点击
                            bg.button.Add(new SingleClickButton()
                            {
                                name = rootButton.name,
                                key = rootButton.key,
                                type = rootButton.type
                            });
                        }
                        else if (rootButton.type.Equals("VIEW", StringComparison.OrdinalIgnoreCase))
                        {
                            //URL
                            bg.button.Add(new SingleViewButton()
                            {
                                name = rootButton.name,
                                url = rootButton.url,
                                type = rootButton.type
                            });
                        }
                        else if (rootButton.type.Equals("LOCATION_SELECT", StringComparison.OrdinalIgnoreCase))
                        {
                            //弹出地理位置选择器
                            bg.button.Add(new SingleLocationSelectButton()
                            {
                                name = rootButton.name,
                                key = rootButton.key,
                                type = rootButton.type
                            });
                        }
                        else if (rootButton.type.Equals("PIC_PHOTO_OR_ALBUM", StringComparison.OrdinalIgnoreCase))
                        {
                            //弹出拍照或者相册发图
                            bg.button.Add(new SinglePicPhotoOrAlbumButton()
                            {
                                name = rootButton.name,
                                key = rootButton.key,
                                type = rootButton.type
                            });
                        }
                        else if (rootButton.type.Equals("PIC_SYSPHOTO", StringComparison.OrdinalIgnoreCase))
                        {
                            //弹出系统拍照发图
                            bg.button.Add(new SinglePicSysphotoButton()
                            {
                                name = rootButton.name,
                                key = rootButton.key,
                                type = rootButton.type
                            });
                        }
                        else if (rootButton.type.Equals("PIC_WEIXIN", StringComparison.OrdinalIgnoreCase))
                        {
                            //弹出微信相册发图器
                            bg.button.Add(new SinglePicWeixinButton()
                            {
                                name = rootButton.name,
                                key = rootButton.key,
                                type = rootButton.type
                            });
                        }
                        else if (rootButton.type.Equals("SCANCODE_PUSH", StringComparison.OrdinalIgnoreCase))
                        {
                            //扫码推事件
                            bg.button.Add(new SingleScancodePushButton()
                            {
                                name = rootButton.name,
                                key = rootButton.key,
                                type = rootButton.type
                            });
                        }
                        else
                        {
                            //扫码推事件且弹出“消息接收中”提示框
                            bg.button.Add(new SingleScancodeWaitmsgButton()
                            {
                                name = rootButton.name,
                                key = rootButton.key,
                                type = rootButton.type
                            });
                        }
                    }
                    //else if (availableSubButton < 2)
                    //{
                    //    throw new WeixinMenuException("子菜单至少需要填写2个!");
                    //}
                    else
                    {
                        //底部二级菜单
                        var subButton = new SubButton(rootButton.name);
                        bg.button.Add(subButton);

                        foreach (var subSubButton in rootButton.sub_button)
                        {
                            if (string.IsNullOrEmpty(subSubButton.name))
                            {
                                continue; //没有设置菜单
                            }

                            if (subSubButton.type.Equals("CLICK", StringComparison.OrdinalIgnoreCase)
                                && string.IsNullOrEmpty(subSubButton.key))
                            {
                                throw new WeixinMenuException("单击按钮的key不能为空!");
                            }

                            if (subSubButton.type.Equals("CLICK", StringComparison.OrdinalIgnoreCase))
                            {
                                //点击
                                subButton.sub_button.Add(new SingleClickButton()
                                {
                                    name = subSubButton.name,
                                    key = subSubButton.key,
                                    type = subSubButton.type
                                });
                            }
                            else if (subSubButton.type.Equals("VIEW", StringComparison.OrdinalIgnoreCase))
                            {
                                //URL
                                subButton.sub_button.Add(new SingleViewButton()
                                {
                                    name = subSubButton.name,
                                    url = subSubButton.url,
                                    type = subSubButton.type
                                });
                            }
                            else if (subSubButton.type.Equals("LOCATION_SELECT", StringComparison.OrdinalIgnoreCase))
                            {
                                //弹出地理位置选择器
                                subButton.sub_button.Add(new SingleLocationSelectButton()
                                {
                                    name = subSubButton.name,
                                    key = subSubButton.key,
                                    type = subSubButton.type
                                });
                            }
                            else if (subSubButton.type.Equals("PIC_PHOTO_OR_ALBUM", StringComparison.OrdinalIgnoreCase))
                            {
                                //弹出拍照或者相册发图
                                subButton.sub_button.Add(new SinglePicPhotoOrAlbumButton()
                                {
                                    name = subSubButton.name,
                                    key = subSubButton.key,
                                    type = subSubButton.type
                                });
                            }
                            else if (subSubButton.type.Equals("PIC_SYSPHOTO", StringComparison.OrdinalIgnoreCase))
                            {
                                //弹出系统拍照发图
                                subButton.sub_button.Add(new SinglePicSysphotoButton()
                                {
                                    name = subSubButton.name,
                                    key = subSubButton.key,
                                    type = subSubButton.type
                                });
                            }
                            else if (subSubButton.type.Equals("PIC_WEIXIN", StringComparison.OrdinalIgnoreCase))
                            {
                                //弹出微信相册发图器
                                subButton.sub_button.Add(new SinglePicWeixinButton()
                                {
                                    name = subSubButton.name,
                                    key = subSubButton.key,
                                    type = subSubButton.type
                                });
                            }
                            else if (subSubButton.type.Equals("SCANCODE_PUSH", StringComparison.OrdinalIgnoreCase))
                            {
                                //扫码推事件
                                subButton.sub_button.Add(new SingleScancodePushButton()
                                {
                                    name = subSubButton.name,
                                    key = subSubButton.key,
                                    type = subSubButton.type
                                });
                            }
                            else
                            {
                                //扫码推事件且弹出“消息接收中”提示框
                                subButton.sub_button.Add(new SingleScancodeWaitmsgButton()
                                {
                                    name = subSubButton.name,
                                    key = subSubButton.key,
                                    type = subSubButton.type
                                });
                            }
                        }
                    }
                }

                result = new GetMenuResult()
                {
                    menu = bg
                };
            }
            catch (Exception ex)
            {
                throw new WeixinMenuException(ex.Message, ex);
            }
            return result;
        }
        /// <summary>
        /// 根据微信返回的Json数据得到可用的GetMenuResult结果
        /// </summary>
        /// <param name="resultFull"></param>
        /// <returns></returns>
        public static GetMenuResult GetMenuFromJsonResult(GetMenuResultFull resultFull)
        {
            GetMenuResult result = null;
            try
            {
                //重新整理按钮信息
                ButtonGroup bg = new ButtonGroup();
                foreach (var rootButton in resultFull.menu.button)
                {
                    if (rootButton.name == null)
                    {
                        continue;//没有设置一级菜单
                    }
                    var availableSubButton = rootButton.sub_button.Count(z => !string.IsNullOrEmpty(z.name));//可用二级菜单按钮数量
                    if (availableSubButton == 0)
                    {
                        //底部单击按钮
                        if (rootButton.type == null ||
                            (rootButton.type.Equals("CLICK", StringComparison.OrdinalIgnoreCase)
                            && string.IsNullOrEmpty(rootButton.key)))
                        {
                            throw new WeixinMenuException("单击按钮的key不能为空!");
                        }

                        if (rootButton.type.Equals("CLICK", StringComparison.OrdinalIgnoreCase))
                        {
                            //点击
                            bg.button.Add(new SingleClickButton()
                                              {
                                                  name = rootButton.name,
                                                  key = rootButton.key,
                                                  type = rootButton.type
                                              });
                        }
                        else
                        {
                            //URL
                            bg.button.Add(new SingleViewButton()
                            {
                                name = rootButton.name,
                                url = rootButton.url,
                                type = rootButton.type
                            });
                        }
                    }
                    else if (availableSubButton < 2)
                    {
                        throw new WeixinMenuException("子菜单至少需要填写2个!");
                    }
                    else
                    {
                        //底部二级菜单
                        var subButton = new SubButton(rootButton.name);
                        bg.button.Add(subButton);

                        foreach (var subSubButton in rootButton.sub_button)
                        {
                            if (subSubButton.name == null)
                            {
                                continue; //没有设置菜单
                            }

                            if (subSubButton.type.Equals("CLICK", StringComparison.OrdinalIgnoreCase)
                                && string.IsNullOrEmpty(subSubButton.key))
                            {
                                throw new WeixinMenuException("单击按钮的key不能为空!");
                            }

                            if (subSubButton.type.Equals("CLICK", StringComparison.OrdinalIgnoreCase))
                            {
                                //点击
                                subButton.sub_button.Add(new SingleClickButton()
                                {
                                    name = subSubButton.name,
                                    key = subSubButton.key,
                                    type = subSubButton.type
                                });
                            }
                            else
                            {
                                //URL
                                subButton.sub_button.Add(new SingleViewButton()
                                {
                                    name = subSubButton.name,
                                    url = subSubButton.url,
                                    type = subSubButton.type
                                });
                            }
                        }
                    }
                }

                if (bg.button.Count < 2)
                {
                    throw new WeixinMenuException("一级菜单按钮至少为2个!");
                }

                result = new GetMenuResult()
                             {
                                 menu = bg
                             };
            }
            catch (Exception ex)
            {
                throw new WeixinMenuException(ex.Message, ex);
            }
            return result;
        }
 /// <summary>
 /// 创建菜单
 /// </summary>
 /// <param name="accessToken"></param>
 /// <param name="buttonData">菜单内容</param>
 /// <returns></returns>
 public static WxJsonResult CreateMenu(string accessToken, ButtonGroup buttonData)
 {
     var urlFormat = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={0}";
     return CommonJsonSend.Send(accessToken, urlFormat, buttonData);
 }
Beispiel #14
0
 /// <summary>
 /// 根据微信返回的Json数据得到可用的GetMenuResult结果
 /// 将Json结构自定义菜单转换为自定义菜单实体
 /// </summary>
 /// <param name="resultFull"></param>
 /// <returns></returns>
 private static GetMenuResult GetMenuFromJsonResult(GetMenuResultJson resultFull)
 {
     GetMenuResult result = null;
     try
     {
         ButtonGroup bg = new ButtonGroup();
         //循环遍历Json结构
         foreach (var rootButton in resultFull.menu.button)
         {
             if (rootButton.name == null)
             {
                 continue;//没有设置一级菜单
             }
             //可用二级菜单按钮数量
             var availableSubButton = rootButton.sub_button.Count(z => !string.IsNullOrEmpty(z.name));
             //一级菜单格式转换
             if (availableSubButton == 0)
             {
                 //按钮格式校验
                 if (rootButton.type == null ||
                     (rootButton.type.Equals("CLICK", StringComparison.OrdinalIgnoreCase)
                     && string.IsNullOrEmpty(rootButton.key)))
                 {
                     throw new WeixinMenuException("单击按钮的key不能为空!");
                 }
                 if (rootButton.type.Equals("CLICK", StringComparison.OrdinalIgnoreCase))
                 {
                     //底部单击按钮
                     bg.button.Add(new SingleClickButton()
                     {
                         name = rootButton.name,
                         key = rootButton.key,
                         type = rootButton.type
                     });
                 }
                 else
                 {
                     //底部URL按钮
                     bg.button.Add(new SingleViewButton()
                     {
                         name = rootButton.name,
                         url = rootButton.url,
                         type = rootButton.type
                     });
                 }
             }
             else if (availableSubButton < 1)
             {
                 throw new WeixinMenuException("子菜单至少需要填写1个!");
             }
             //二级菜单格式转换
             else
             {
                 //底部二级菜单
                 var subButton = new SubButton(rootButton.name);
                 bg.button.Add(subButton);
                 foreach (var subSubButton in rootButton.sub_button)
                 {
                     if (subSubButton.name == null)
                     {
                         continue; //没有设置菜单
                     }
                     //按钮格式校验
                     if (subSubButton.type.Equals("CLICK", StringComparison.OrdinalIgnoreCase)
                         && string.IsNullOrEmpty(subSubButton.key))
                     {
                         throw new WeixinMenuException("单击按钮的key不能为空!");
                     }
                     if (subSubButton.type.Equals("CLICK", StringComparison.OrdinalIgnoreCase))
                     {
                         //底部单击按钮
                         subButton.sub_button.Add(new SingleClickButton()
                         {
                             name = subSubButton.name,
                             key = subSubButton.key,
                             type = subSubButton.type
                         });
                     }
                     else
                     {
                         //底部URL按钮
                         subButton.sub_button.Add(new SingleViewButton()
                         {
                             name = subSubButton.name,
                             url = subSubButton.url,
                             type = subSubButton.type
                         });
                     }
                 }
             }
         }
         if (bg.button.Count < 1)
         {
             throw new WeixinMenuException("一级菜单按钮至少为1个!");
         }
         //保存到自定义菜单实体
         result = new GetMenuResult()
         {
             menu = bg
         };
     }
     catch (Exception ex)
     {
         throw new WeixinMenuException(ex.Message, ex);
     }
     return result;
 }
        /// <summary>
        /// 测试创建菜单的部分
        /// </summary>
        /// <param name="MemuName"></param>
        /// <returns></returns>
        public ActionResult CreateMenuTest()
        {
            var accesstoken = AccessTokenContainer.TryGetToken(AppId, AppSecret);

            var btnGroup = new ButtonGroup();
            //二级菜单
            var subButton = new SubButton()
            {
                name = "羊客商城"
            };
            subButton.sub_button.Add(new SingleViewButton() {
                url="http://yk.kerchinsheep.com/home/presaleproduct",
                name = "羊客商城"
            });
            subButton.sub_button.Add(new SingleViewButton()
            {
                url = "http://yk.kerchinsheep.com/home/PreSaleOrderList",
                name = "商城订单"
            });
            subButton.sub_button.Add(new SingleViewButton()
            {
                url = "http://yk.kerchinsheep.com/html/recipeMain.html",
                name = "羊客食谱"
            });
            btnGroup.button.Add(subButton);
            var clickButton = new SingleViewButton()
            {
                url = "http://yk.kerchinsheep.com/",
                name = "羊羊得益"
            };
            btnGroup.button.Add(clickButton);
            var subButton1 = new SubButton()
            { 
              name="更多精彩"
            };
            subButton1.sub_button.Add(new SingleViewButton()
            {
                url = "http://yk.kerchinsheep.com/html/micro.html",
                name = "羊客介绍"
            });
            subButton1.sub_button.Add(new SingleClickButton()
            {
                key = "learnmore",
                name = "了解更多"
            });
           
            var clickButton1 = new SingleViewButton()
            {
                url = "http://activity.kerchinsheep.com/app/h5/zy",
                name = "全民套羊"
            };
            subButton1.sub_button.Add(clickButton1);
            btnGroup.button.Add(subButton1);
            var result = CommonApi.CreateMenu(accesstoken, btnGroup);
            return Json(result,JsonRequestBehavior.AllowGet);
        }
Beispiel #16
0
        MenuMgr mMrg = new MenuMgr(); //创建菜单类

        #endregion Fields

        #region Methods

        //保存
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                string error = string.Empty;
                string accessToken = cpp.GetAccessToken(this.id, out error);

                if (!string.IsNullOrEmpty(error))
                {
                    JscriptMsg(error, string.Empty);
                    return;
                }

                //重新整理按钮信息
                ButtonGroup bg = new ButtonGroup();
                TextBox txtName = new TextBox();
                TextBox txtKey = new TextBox();
                TextBox txtUrl = new TextBox();
                IList<BaseButton> topList = new List<BaseButton>();
                IList<SingleButton> subList = new List<SingleButton>();
                //菜单设置
                for (int i = 0; i < 3; i++)
                {
                    txtName = this.FindControl("txtTop" + (i + 1) + "Name") as TextBox;
                    txtKey = this.FindControl("txtTop" + (i + 1) + "Key") as TextBox;
                    txtUrl = this.FindControl("txtTop" + (i + 1) + "Url") as TextBox;
                    if (txtName.Text.Trim() == "")
                    {
                        // 如果名称为空,则忽略该菜单,以及下面的子菜单
                        continue;
                    }

                    subList = new List<SingleButton>();
                    TextBox txtSubName = new TextBox();
                    TextBox txtSubKey = new TextBox();
                    TextBox txtSubUrl = new TextBox();
                    for (int j = 0; j < 5; j++)
                    {
                        //子菜单的设置
                        txtSubName = this.FindControl("txtMenu" + (i + 1) + (j + 1) + "Name") as TextBox;
                        txtSubKey = this.FindControl("txtMenu" + (i + 1) + (j + 1) + "Key") as TextBox;
                        txtSubUrl = this.FindControl("txtMenu" + (i + 1) + (j + 1) + "Url") as TextBox;
                        if (txtSubName.Text.Trim() == "")
                        {
                            continue;
                        }

                        if (txtSubUrl.Text.Trim() != "")
                        {
                            SingleViewButton sub = new SingleViewButton();
                            sub.name = txtSubName.Text.Trim();
                            sub.url = txtSubUrl.Text.Trim();
                            subList.Add(sub);
                        }
                        else if (txtSubKey.Text.Trim() != "")
                        {
                            SingleClickButton sub = new SingleClickButton();
                            sub.name = txtSubName.Text.Trim();
                            sub.key = txtSubKey.Text.Trim();
                            subList.Add(sub);
                        }
                        else
                        {
                            //报错 :子菜单必须有key和name
                            JscriptMsg("二级菜单的名称和key或者url必填!", string.Empty);
                            return;
                        }
                    }

                    if (subList != null && subList.Count > 0)
                    {
                        //有子菜单, 该一级菜单是SubButton
                        if (subList.Count < 1)
                        {
                            JscriptMsg("子菜单个数必须为2至5个!", string.Empty);
                            return;
                        }
                        SubButton topButton = new SubButton(Utils.CutString(txtName.Text.Trim(), 16));
                        topButton.sub_button.AddRange(subList);
                        topList.Add(topButton);
                    }
                    else
                    {
                        // 无子菜单
                        if (txtKey.Text.Trim() == "" && txtUrl.Text.Trim() == "")
                        {
                            JscriptMsg("如无子菜单,必须填写Key或者URL值!", string.Empty);
                            return;
                        }

                        if (txtUrl.Text.Trim() != "")
                        {  //view 页面跳转
                            SingleViewButton topSingleButton = new SingleViewButton();
                            topSingleButton.name = txtName.Text.Trim();
                            topSingleButton.url = txtUrl.Text.Trim();
                            topList.Add(topSingleButton);
                        }
                        else if (txtKey.Text.Trim() != "")
                        {
                            SingleClickButton topSingleButton = new SingleClickButton();
                            topSingleButton.name = txtName.Text.Trim();
                            topSingleButton.key = txtKey.Text.Trim();
                            topList.Add(topSingleButton);
                        }
                    }
                }

                bg.button.AddRange(topList);
                var result = mMrg.CreateMenu(accessToken, bg);
                JscriptMsg("自定义菜单保存成功!", "menu_list.aspx");
            }
            catch (Exception ex)
            {
                JscriptMsg("出错了:" + ex.Message, string.Empty);
            }
        }
        /// <summary>
        /// 测试创建菜单的部分
        /// </summary>
        /// <param name="MemuName"></param>
        /// <returns></returns>
        public ActionResult CreateMenuTest()
        {
            var accesstoken = AccessTokenContainer.TryGetToken(AppId, AppSecret);

            var btnGroup = new ButtonGroup();
            //二级菜单
            var subButton = new SubButton()
            {
                name = "关于羊客"
            };
            subButton.sub_button.Add(new SingleViewButton()
            {
                url = "http://yk.kerchinsheep.com/html/micro.html",
                name = "羊客介绍"
            });
            subButton.sub_button.Add(new SingleClickButton()
            {
                key = "learnmore",
                name = "了解更多"
            });
            btnGroup.button.Add(subButton);
            var clickButton = new SingleViewButton()
            {
                url = "http://yk.kerchinsheep.com/",
                name = "羊羊得益"
            };
            btnGroup.button.Add(clickButton);
            var result = CommonApi.CreateMenu(accesstoken, btnGroup);
            return Json(result,JsonRequestBehavior.AllowGet);
        }
Beispiel #18
0
        /// <summary>
        /// 更新菜单
        /// </summary>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                Model.wx_userweixin weixin = GetWeiXinCode();

                string error = "";
                string accessToken = cpp.getAccessToken(weixin.id, out error);

                if (error != "")
                {
                    JscriptMsg(error, "", "Error");
                    return;
                }

                //重新整理按钮信息
                ButtonGroup bg = new ButtonGroup();
                TextBox txtName = new TextBox();
                TextBox txtKey = new TextBox();
                TextBox txtUrl = new TextBox();
                IList<BaseButton> topList = new List<BaseButton>();
                IList<SingleButton> subList = new List<SingleButton>();
                #region 菜单设置
                for (int i = 0; i < 3; i++)
                {
                    txtName = this.FindControl("txtTop" + (i + 1)) as TextBox;
                    txtKey = this.FindControl("txtTop" + (i + 1) + "Key") as TextBox;
                    txtUrl = this.FindControl("txtTop" + (i + 1) + "Url") as TextBox;
                    if (txtName.Text.Trim() == "")
                    {
                        // 如果名称为空,则忽略该菜单,以及下面的子菜单
                        continue;
                    }

                    subList = new List<SingleButton>();
                    TextBox txtSubName = new TextBox();
                    TextBox txtSubKey = new TextBox();
                    TextBox txtSubUrl = new TextBox();
                    for (int j = 0; j < 5; j++)
                    {
                        #region 子菜单的设置
                        txtSubName = this.FindControl("txtMenu" + (i + 1) + (j + 1)) as TextBox;
                        txtSubKey = this.FindControl("txtMenu" + (i + 1) + (j + 1) + "Key") as TextBox;
                        txtSubUrl = this.FindControl("txtMenu" + (i + 1) + (j + 1) + "Url") as TextBox;
                        if (txtSubName.Text.Trim() == "")
                        {
                            continue;
                        }

                        if (txtSubUrl.Text.Trim() != "")
                        {
                            SingleViewButton sub = new SingleViewButton();
                            sub.name = txtSubName.Text.Trim();
                            sub.url = txtSubUrl.Text.Trim();
                            subList.Add(sub);

                        }
                        else if (txtSubKey.Text.Trim() != "")
                        {
                            SingleClickButton sub = new SingleClickButton();
                            sub.name = txtSubName.Text.Trim();
                            sub.key = txtSubKey.Text.Trim();
                            subList.Add(sub);
                        }
                        else
                        {
                            //报错 :子菜单必须有key和name
                            JscriptMsg("二级菜单的名称和key或者url必填!", "", "Error");
                            return;
                        }
                        #endregion

                    } //子菜单循环结束

                    if (subList != null && subList.Count > 0)
                    {
                        //有子菜单, 该一级菜单是SubButton
                        if (subList.Count < 1)
                        {
                            JscriptMsg("子菜单个数为2~5个!", "", "Error");
                            return;
                        }
                        SubButton topButton = new SubButton(Utils.CutString(txtName.Text.Trim(), 16));
                        topButton.sub_button.AddRange(subList);
                        topList.Add(topButton);
                    }
                    else
                    {
                        // 无子菜单
                        if (txtKey.Text.Trim() == "" && txtUrl.Text.Trim() == "")
                        {
                            JscriptMsg("若无子菜单,必须填写key或者url值!", "", "Error");
                            return;
                        }

                        if (txtUrl.Text.Trim() != "")
                        {  //view 页面跳转
                            SingleViewButton topSingleButton = new SingleViewButton();
                            topSingleButton.name = txtName.Text.Trim();
                            topSingleButton.url = txtUrl.Text.Trim();
                            topList.Add(topSingleButton);
                        }
                        else if (txtKey.Text.Trim() != "")
                        {
                            SingleClickButton topSingleButton = new SingleClickButton();
                            topSingleButton.name = txtName.Text.Trim();
                            topSingleButton.key = txtKey.Text.Trim();
                            topList.Add(topSingleButton);
                        }
                    }
                }
                #endregion

                bg.button.AddRange(topList);

                var result = mMrg.CreateMenu(accessToken, bg);
                JscriptMsg("菜单提交成功!", "wxMenu.aspx", "Success");
            }
            catch (Exception ex)
            {
                JscriptMsg("报错:" + ex.Message, "", "Error");
            }
        }
Beispiel #19
0
 public GetMenuResult()
 {
     menu = new ButtonGroup();
 }
Beispiel #20
0
 /// <summary>
 /// 创建菜单
 /// </summary>
 /// <param name="accessToken"></param>
 /// <param name="buttonData">菜单内容</param>
 /// <returns></returns>
 public static WxJsonResult CreateMenu(string accessToken, ButtonGroup buttonData)
 {
     //微信公众平台创建自定义菜单接口地址
     var urlFormat = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={0}";
     return ApiHelper.Post(accessToken, urlFormat, buttonData);
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            string signature = Request["signature"];
            string timestamp = Request["timestamp"];
            string nonce = Request["nonce"];
            string echostr = Request["echostr"];

            string inputXml = string.Empty;
            using (StreamReader sr = new StreamReader(Request.InputStream))
            {
                inputXml = sr.ReadToEnd();
                inputXml = HttpUtility.UrlDecode(inputXml);
            }

            string updateMenu = Request["updatemenu"];

            if (!string.IsNullOrWhiteSpace(updateMenu))
            {
                foreach (var menu in Activator.WeChatMenuContainer.WeChatMenus)
                {
                    try
                    {
                        if (!AccessTokenContainer.CheckRegistered(menu.AppId))
                        {
                            AccessTokenContainer.Register(menu.AppId, menu.Secret);
                        }

                        AccessTokenResult tokenRes = null;
                        try
                        {
                            tokenRes = AccessTokenContainer.GetTokenResult(menu.AppId); //CommonAPIs.CommonApi.GetToken(appId, appSecret);
                            WriteContent(string.Format("获取到 token 为:{0}, 有效时间为 {1} 秒。", tokenRes.access_token, tokenRes.expires_in));

                            //var menuRes = CommonApi.GetMenu(tokenRes.access_token);
                        }
                        catch
                        {
                            WriteContent(string.Format("获取到 token 失败, appid: {0},secret: {1}。", menu.AppId, menu.Secret));
                        }

                        try
                        {
                            if (tokenRes != null)
                            {
                                //重新整理按钮信息
                                ButtonGroup bg = new ButtonGroup();
                                foreach (var menuButton in menu.MenuButtons)
                                {
                                    BaseButton but = null;
                                    switch (menuButton.Type)
                                    {
                                        case ButtonType.Click:
                                            but = new SingleClickButton() { name = menuButton.Name, key = menuButton.Key, type = "click" };
                                            break;
                                        case ButtonType.View:
                                            but = new SingleViewButton() { name = menuButton.Name, url = menuButton.Url, type = "view" };
                                            break;
                                        case ButtonType.SubButton:
                                            List<SingleButton> subButtons = new List<SingleButton>();

                                            foreach (var subBut in menuButton.MenuSubButtons)
                                            {
                                                SingleButton singleBut = null;
                                                switch (subBut.Type)
                                                {
                                                    case ButtonType.Click:
                                                        singleBut = new SingleClickButton() { name = subBut.Name, key = subBut.Key, type = "click" };
                                                        break;
                                                    case ButtonType.View:
                                                        singleBut = new SingleViewButton() { name = subBut.Name, url = subBut.Url, type = "view" };
                                                        break;
                                                }

                                                if (singleBut != null)
                                                    subButtons.Add(singleBut);
                                            }

                                            but = new SubButton() { name = menuButton.Name, sub_button = subButtons };
                                            break;
                                    }

                                    if (but != null)
                                        bg.button.Add(but);
                                }

                                var result = CommonApi.CreateMenu(tokenRes.access_token, bg);
                                WriteContent(string.Format("创建结果信息:{0}, 返回值 {1} ({2})。", result.errmsg, (int)result.errcode, result.errcode.ToString()));
                            }
                        }
                        catch
                        {
                            WriteContent("创建菜单失败!");
                        }
                    }
                    catch (Exception)
                    {
                        //TODO:为简化代码,这里不处理异常(如Token过期)
                        WriteContent("执行过程发生错误!");
                    }
                }
            }

            foreach (var proxy in Activator.WeChatProxyContainer.WeChatProxies)
            {
                string token = proxy.Token;

                if (Request.HttpMethod == "GET")
                {
                    //get method - 仅在微信后台填写URL验证时触发
                    if (CheckSignature.Check(signature, timestamp, nonce, token))
                    {
                        WriteContent(echostr); //返回随机字符串则表示验证通过
                        //如果有多个相同的Token,则第一个验证通过就返回
                        break;
                    }
                    else
                    {
                        //WriteContent("failed:" + signature + "," + CheckSignature.GetSignature(timestamp, nonce, token) + "。" +
                        //            "如果你在浏览器中看到这句话,说明此地址可以被作为微信公众账号后台的Url,请注意保持Token一致。");
                        //如果失败应该不返回任何东西,以便循环校验下一个Token
                        continue;
                    }
                }
                else
                {
                    //post method - 当有用户想公众账号发送消息时触发
                    if (!CheckSignature.Check(signature, timestamp, nonce, token))
                    {
                        WriteContent("参数错误!");
                        continue;
                    }

                    //v4.2.2之后的版本,可以设置每个人上下文消息储存的最大数量,防止内存占用过多,如果该参数小于等于0,则不限制
                    var maxRecordCount = 10;

                    //自定义MessageHandler,对微信请求的详细判断操作都在这里面。
                    //var messageHandler = new CustomMessageHandler(Request.InputStream, maxRecordCount);

                    IMessageHandler messageHandler = null;
                    using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(inputXml)))
                    {
                        Type type = proxy.Bundle.LoadClass(proxy.Handler);
                        var parameters = new object[] { stream, token, proxy.AppID, proxy.Secret, maxRecordCount };
                        messageHandler = System.Activator.CreateInstance(type, parameters) as IMessageHandler;
                    }

                    try
                    {
                        if (messageHandler != null)
                        {
                            //测试时可开启此记录,帮助跟踪数据,使用前请确保App_Data文件夹存在,且有读写权限。
                            messageHandler.RequestDocument.Save(
                                Server.MapPath("~/App_Data/" + DateTime.Now.Ticks + "_Request_" +
                                               messageHandler.RequestMessage.FromUserName + ".txt"));
                            //执行微信处理过程
                            messageHandler.Execute();
                            //测试时可开启,帮助跟踪数据
                            messageHandler.ResponseDocument.Save(
                                Server.MapPath("~/App_Data/" + DateTime.Now.Ticks + "_Response_" +
                                               messageHandler.ResponseMessage.ToUserName + ".txt"));
                            WriteContent(messageHandler.ResponseDocument.ToString());

                            continue;
                        }
                    }
                    catch (Exception ex)
                    {
                        using (TextWriter tw = new StreamWriter(Server.MapPath("~/App_Data/Error_" + DateTime.Now.Ticks + ".txt")))
                        {
                            tw.WriteLine(ex.Message);
                            tw.WriteLine(ex.InnerException.Message);

                            if (messageHandler.ResponseDocument != null)
                            {
                                tw.WriteLine(messageHandler.ResponseDocument.ToString());
                            }

                            tw.Flush();
                            tw.Close();
                        }

                        WriteContent("");
                    }
                }
            }

            Response.End();
        }
Beispiel #22
0
        public void CreateMenuGaiaWX()
        {
            //Console.WriteLine("************************************开始创建微信菜单*******************************************************\n");
            string appid = "wxe7c51862f6de2f3e";
            string secret = "bb66c368c6c6462dc62b9118e8058ff5";
            string PROJECT_NAME = "FESCOAsecco";
            string PROJECT_URL = "weixin.hrone.cn";
            var accessToken = AccessTokenContainer.TryGetAccessToken(appid, secret);
            Console.WriteLine("  accessToken:" + accessToken + "\n");
            ButtonGroup bg = new ButtonGroup();
            //首页

            var About = new SingleClickButton()
            {
                name = "账户绑定",
                key = "bind_account",
                type = ButtonType.click.ToString(),
            };
            //var About = new SubButton()
            //{
            //    name = "首页"
            //};
            //About.sub_button.Add(new SingleClickButton()
            //{
            //    name = "账户绑定",
            //    key = "bind_account",
            //    type = ButtonType.click.ToString(),//默认已经设为此类型,这里只作为演示
            //});
            //About.sub_button.Add(new SingleViewButton()
            //{
            //    url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME
            //        + "%2FView%2FCommUtil%2FLoading.html?pageType=10011&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect",
            //    name = "银行信息"
            //});
            bg.button.Add(About);
            //我的
            var AboutMe = new SubButton()
            {
                name = "我的信息"
            };
            AboutMe.sub_button.Add(new SingleViewButton()
            {
                url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME
                    + "%2FView%2FCommUtil%2FLoading.html?pageType=10009&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect",
                name = "个人信息"
            });
            //AboutMe.sub_button.Add(new SingleViewButton()
            //{
            //    url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME
            //        + "%2FView%2FCommUtil%2FLoading.html?pageType=10011&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect",
            //    name = "银行信息"
            //});
            AboutMe.sub_button.Add(new SingleViewButton()
            {
                url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME
                    + "%2FView%2FCommUtil%2FLoading.html?pageType=10008&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect",
                name = "我的薪资"
            });
            AboutMe.sub_button.Add(new SingleViewButton()
            {
                url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME
                    + "%2FView%2FCommUtil%2FLoading.html?pageType=10007&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect",
                name = "我的店铺"
            });
            AboutMe.sub_button.Add(new SingleViewButton()
            {
                url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME
                    + "%2FView%2FCommUtil%2FLoading.html?pageType=10001&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect",
                name = "我的排班"
            });
            AboutMe.sub_button.Add(new SingleViewButton()
            {
                url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME
                    + "%2FView%2FCommUtil%2FLoading.html?pageType=10010&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect",
                name = "员工可用性"
            });
            bg.button.Add(AboutMe);
            //申请&签核
            var ApplyAndApprove = new SubButton()
            {
                name = "申请&签核"
            };
            ApplyAndApprove.sub_button.Add(new SingleViewButton()
            {
                url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME
                    + "%2FView%2FCommUtil%2FLoading.html?pageType=10003&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect",
                name = "请假申请"
            });
            ApplyAndApprove.sub_button.Add(new SingleViewButton()
            {
                url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME
                    + "%2FView%2FCommUtil%2FLoading.html?pageType=10004&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect",
                name = "加班申请"
            });
            ApplyAndApprove.sub_button.Add(new SingleViewButton()
            {
                url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME
                    + "%2FView%2FCommUtil%2FLoading.html?pageType=10005&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect",
                name = "异常申诉"
            });
            ApplyAndApprove.sub_button.Add(new SingleViewButton()
            {
                url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME
                    + "%2FView%2FCommUtil%2FLoading.html?pageType=10006&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect",
                name = "主管审批"
            });
            ApplyAndApprove.sub_button.Add(new SingleViewButton()
            {
                url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME
                    + "%2FView%2FCommUtil%2FLoading.html?pageType=10002&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect",
                name = "考勤打卡"
            });
            bg.button.Add(ApplyAndApprove);
            var result = CommonApi.CreateMenu(accessToken, bg);
            Console.WriteLine("  Errcode:  " + result.errcode + "\n\n  Errmsg:  " + result.errmsg + "\n\n  P2PData:  " + result.P2PData + "\n");
            Console.WriteLine("************************************创建微信菜单结束*******************************************************\n");
            Console.ReadKey();
        }