Exemplo n.º 1
0
        public async Task ConditionalMenuAPi_TestAsync()
        {
            var list = await MpApi.UserApi.GetListAsync();

            var menuCreate = new AddConditionalRequestModel();

            menuCreate.Button = new List <MenuButtonModel>();
            menuCreate.Button.Add(new MenuButtonModel()
            {
                Name = "abc",
                Type = MenuButtonType.Click,
                Key  = "001",
            });

            menuCreate.MatchRule = new MenuConditionalMatchRuleModel()
            {
                Sex = 1,
            };

            var result1 = await MpApi.MenuApi.AddConditional(menuCreate);

            Assert.True(result1.ErrorCode == 0);

            var result2 = await MpApi.MenuApi.ConditionalTryMatch(list.Data.Openid[0]);

            Assert.True(result2.ErrorCode == 0 && result2.Menu?.Button?.Count > 0);

            var result3 = await MpApi.MenuApi.DeleteConditional();

            Assert.True(result3.ErrorCode == 0);
        }
Exemplo n.º 2
0
        /// <summary>
        ///  创建个性化菜单
        /// </summary>
        /// <remarks>
        /// <![CDATA[https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1455782296]]>
        /// </remarks>
        public async Task <AddConditionalResultModel> AddConditional(AddConditionalRequestModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            string url = $"{ServerHostConfig.DefaultApiHost}/cgi-bin/menu/addconditional?access_token={_api.Token?.AccessToken}";

            return((await HttpService.PostAsync <AddConditionalResultModel>(url, model)).Data);
        }