Exemplo n.º 1
0
 public static string AddCondition(string access_token, MenuMatchRule rule, List <MenuBase> buttons) =>
 ApiJTokenPost(JsonCreate.AddCondition(rule, buttons), "/cgi-bin/menu/addconditional?access_token={0}", access_token)
 ?.GetString("menuid") ?? throw new Exception("未找到个性化菜单Id信息");
            public void WeChatApiMenuTest()
            {
                //Config = new Api.Config("gh_69438e79ea75", "wx95dfa97f9fca2358", "4e053f53f278347179416898e3d7883a");
                Assert.AreEqual(JsonCreate.Create(new List <Model.MenuBase>()
                {
                    new Model.MenuClick("今日歌曲", "V1001_TODAY_MUSIC"),
                    new Model.MenuTop("菜单", new List <Model.MenuBase>()
                    {
                        new Model.MenuView("搜索", "http://www.soso.com/"),
                        new Model.MenuMiniProgram("wxa", "wx286b93c14bbf93aa", "pages/lunar/index.html", "http://mp.weixin.qq.com"),
                        new Model.MenuClick("赞一下我们", "V1001_GOOD")
                    })
                }), "{\"button\":[{\"type\":\"click\",\"name\":\"今日歌曲\",\"key\":\"V1001_TODAY_MUSIC\"},{\"name\":\"菜单\",\"sub_button\":[{\"type\":\"view\",\"name\":\"搜索\",\"url\":\"http://www.soso.com/\"},{\"type\":\"miniprogram\",\"name\":\"wxa\",\"url\":\"http://mp.weixin.qq.com\",\"appid\":\"wx286b93c14bbf93aa\",\"pagepath\":\"pages/lunar/index.html\"},{\"type\":\"click\",\"name\":\"赞一下我们\",\"key\":\"V1001_GOOD\"}]}]}");
                Assert.AreEqual(JsonCreate.Create(new List <Model.MenuBase>()
                {
                    new Model.MenuTop("扫码", new List <Model.MenuBase>()
                    {
                        new Model.MenuScanWait("扫码带提示", "rselfmenu_0_0"),
                        new Model.MenuScanPush("扫码推事件", "rselfmenu_0_1")
                    }),
                    new Model.MenuTop("发图", new List <Model.MenuBase>()
                    {
                        new Model.MenuSysPhoto("系统拍照发图", "rselfmenu_1_0"),
                        new Model.MenuPhotoOrAlbum("拍照或者相册发图", "rselfmenu_1_1"),
                        new Model.MenuPicWeixin("微信相册发图", "rselfmenu_1_2")
                    }),
                    new Model.MenuLocationSelect("发送位置", "rselfmenu_2_0"),
                    new Model.MenuMedia("图片", "MEDIA_ID1"),
                    new Model.MenuViewLimited("图文消息", "MEDIA_ID2")
                }), "{\"button\":[{\"name\":\"扫码\",\"sub_button\":[{\"type\":\"scancode_waitmsg\",\"name\":\"扫码带提示\",\"key\":\"rselfmenu_0_0\"},{\"type\":\"scancode_push\",\"name\":\"扫码推事件\",\"key\":\"rselfmenu_0_1\"}]},{\"name\":\"发图\",\"sub_button\":[{\"type\":\"pic_sysphoto\",\"name\":\"系统拍照发图\",\"key\":\"rselfmenu_1_0\"},{\"type\":\"pic_photo_or_album\",\"name\":\"拍照或者相册发图\",\"key\":\"rselfmenu_1_1\"},{\"type\":\"pic_weixin\",\"name\":\"微信相册发图\",\"key\":\"rselfmenu_1_2\"}]},{\"type\":\"location_select\",\"name\":\"发送位置\",\"key\":\"rselfmenu_2_0\"},{\"type\":\"media_id\",\"name\":\"图片\",\"media_id\":\"MEDIA_ID1\"},{\"type\":\"view_limited\",\"name\":\"图文消息\",\"media_id\":\"MEDIA_ID2\"}]}");

                Assert.AreEqual(JsonCreate.AddCondition(new Model.MenuMatchRule()
                {
                    TagId              = 2,
                    Sex                = MenuMatchSex.男,
                    Country            = "中国",
                    Province           = "广东",
                    City               = "广州",
                    ClientPlatformType = Enums.MenuMatchPlatform.Android,
                    Language           = MenuMatchLanguage.简体中文
                }, new List <Model.MenuBase>()
                {
                    new Model.MenuClick("今日歌曲", "V1001_TODAY_MUSIC"),
                    new Model.MenuTop("菜单", new List <Model.MenuBase>()
                    {
                        new Model.MenuView("搜索", "http://www.soso.com/"),
                        new Model.MenuMiniProgram("wxa", "wx286b93c14bbf93aa", "pages/lunar/index.html", "http://mp.weixin.qq.com"),
                        new Model.MenuClick("赞一下我们", "V1001_GOOD")
                    })
                }), "{\"button\":[{\"type\":\"click\",\"name\":\"今日歌曲\",\"key\":\"V1001_TODAY_MUSIC\"},{\"name\":\"菜单\",\"sub_button\":[{\"type\":\"view\",\"name\":\"搜索\",\"url\":\"http://www.soso.com/\"},{\"type\":\"miniprogram\",\"name\":\"wxa\",\"url\":\"http://mp.weixin.qq.com\",\"appid\":\"wx286b93c14bbf93aa\",\"pagepath\":\"pages/lunar/index.html\"},{\"type\":\"click\",\"name\":\"赞一下我们\",\"key\":\"V1001_GOOD\"}]}],\"matchrule\":{\"tag_id\":\"2\",\"sex\":\"1\",\"country\":\"中国\",\"province\":\"广东\",\"city\":\"广州\",\"client_platform_type\":\"2\",\"language\":\"zh_CN\"}}");
                Assert.AreEqual(JsonCreate.TryMatch("weixin"), "{\"user_id\":\"weixin\"}");
                Assert.AreEqual(JsonCreate.DelCondition("208379533"), "{\"menuid\":\"208379533\"}");

                //Api.Menu.Create(Api.GetAccessToken(Config), new List<Model.MenuBase>() {
                //    new Model.MenuTop("菜单",new List<Model.MenuBase>(){
                //        new Model.MenuView("搜索","http://www.soso.com/"),
                //        new Model.MenuClick("赞一下我们","V1001_GOOD"),
                //        new Model.MenuLocationSelect("发送位置","rselfmenu_2_0"),
                //    }),
                //    new Model.MenuTop("扫码",new List<Model.MenuBase>(){
                //        new Model.MenuScanWait("扫码带提示","rselfmenu_0_0"),
                //        new Model.MenuScanPush("扫码推事件","rselfmenu_0_1")
                //    }),
                //    new Model.MenuTop("发图",new List<Model.MenuBase>(){
                //        new Model.MenuSysPhoto("系统拍照发图","rselfmenu_1_0"),
                //        new Model.MenuPhotoOrAlbum("拍照或者相册发图","rselfmenu_1_1"),
                //        new Model.MenuPicWeixin("微信相册发图","rselfmenu_1_2")
                //    }),
                //});

                //var data = Api.Menu.Get(Api.GetAccessToken(Config));
                //data = Api.Menu.GetCurrentSelfMenuInfo(Api.GetAccessToken(Config));

                //var condition = Api.Menu.AddCondition(Api.GetAccessToken(Config), new Model.MenuMatchRule()
                //{
                //    TagId = 2,
                //    Sex = MenuMatchSex.男,
                //    Country = "中国",
                //    Province = "广东",
                //    City = "广州",
                //    ClientPlatformType = MenuMatchPlatform.Android,
                //    Language = MenuMatchLanguage.简体中文
                //}, new List<Model.MenuBase>() {
                //    new Model.MenuClick("今日歌曲","V1001_TODAY_MUSIC"),
                //    new Model.MenuTop("菜单",new List<Model.MenuBase>(){
                //        new Model.MenuView("搜索","http://www.soso.com/"),
                //        new Model.MenuClick("赞一下我们","V1001_GOOD")
                //    })
                //});
                //Api.Menu.DelCondition(Api.GetAccessToken(Config), condition);
                //var match = Api.Menu.TryMatch(Api.GetAccessToken(Config), "oOk2XjhrbcHP3tGgzDGAVHppo3Bs");
                //Api.Menu.Delete(Api.GetAccessToken(Config));
            }