コード例 #1
0
        /// <summary>
        /// 获取通用菜单
        /// </summary>
        /// <param name="appId"></param>
        /// <returns></returns>
        public async Task <ResultReturn <GetMenus_Result> > GetMenus(string appId)
        {
            var ret = await CommonApi.Get(appId, "/cgi-bin/get_current_selfmenu_info?access_token=ACCESS_TOKEN");

            if (ret.IsSuccess)
            {
                var isMenuOpen = ret.ReturnData.GetInt("is_menu_open");

                var result = new GetMenus_Result();
                result.IsMenuOpen = isMenuOpen == 1;

                var menuInfoJson = ret.ReturnData.GetJObject("selfmenu_info");

                var buttons = menuInfoJson.GetJObjectArray("button");

                var lst = new List <MPMenuBase>();

                foreach (var button in buttons)
                {
                    lst.Add(button.ToObject <MPMenuBase>());
                }

                result.Menus = lst;

                return(new SuccessResultReturn <GetMenus_Result>(result));
            }
            else
            {
                return(ret.Cast <GetMenus_Result>(null));
            }
        }
コード例 #2
0
        /// <summary>
        /// 通过网页跳转后获取到的code,取得用户openID
        /// </summary>
        /// <param name="appID"></param>
        /// <param name="code">授权跳转后,传入的code值</param>
        /// <returns></returns>
        public async Task <ResultReturn <GetAccessToken_Result> > GetAccessToken(string appID, string code)
        {
            var item = _gateway.Get(appID);

            if (item == null)
            {
                throw new ArgumentOutOfRangeException(nameof(appID));
            }

            if (string.IsNullOrWhiteSpace(code))
            {
                throw new ArgumentNullException(nameof(code));
            }

            var result = await CommonApi.Get(appID,
                                             $"/sns/oauth2/access_token?appid={appID}&secret={item.AppSerect}&code={code}&grant_type=authorization_code");

            if (result.IsSuccess)
            {
                var json = result.ReturnData;
                var ret  = new GetAccessToken_Result()
                {
                    AccessToken  = json.GetString("access_token"),
                    Expires      = json.GetInt("expires_in"),
                    RefreshToken = json.GetString("refresh_token"),
                    OpenId       = json.GetString("openid"),
                    Type         = json.GetString("scope") == "base" ? SnsapiType.Base : SnsapiType.UserInfo,
                    UionId       = json.GetString("unionid")
                };

                return(new SuccessResultReturn <GetAccessToken_Result>(ret));
            }
            else
            {
                return(result.Cast <GetAccessToken_Result>(default));
コード例 #3
0
        /// <summary>
        /// 获取所有菜单,包括个性化菜单和通用菜单
        /// </summary>
        /// <param name="appId"></param>
        /// <returns></returns>
        public async Task <ResultReturn <GetAllMenus_Result> > GetAllMenus(string appId)
        {
            var data = await CommonApi.Get(appId, "/cgi-bin/menu/get?access_token=ACCESS_TOKEN");

            if (data.IsSuccess)
            {
                var result = new GetAllMenus_Result();

                var commonMenusJson = data.ReturnData.GetJObject("menu");

                var commonMenuButtonsJson = commonMenusJson.GetJObjectArray("button");

                var commonButtons = commonMenuButtonsJson.Select(x => x.ToObject <MPMenuBase>()).ToArrayEx();

                result.CommonMenus  = commonButtons;
                result.CommonMenuId = commonMenusJson.GetString("menuid");

                if (data.ReturnData.ContainsKey("conditionalmenu"))
                {
                    var conditionalMenusJson = data.ReturnData.GetJObjectArray("conditionalmenu");

                    if (conditionalMenusJson.HasData())
                    {
                        var conditionalMenus = new List <GetAllMenus_Result.PersonalizedMenu>();

                        foreach (var item in conditionalMenusJson)
                        {
                            var buttonsJson = item.GetJObjectArray("button");
                            var rulsJson    = item.GetJObject("matchrule");

                            var tmp = new GetAllMenus_Result.PersonalizedMenu();

                            tmp.MenuId = item.GetString("menuid");
                            tmp.Menus  = buttonsJson.Select(x => x.ToObject <MPMenuBase>()).ToList();
                            tmp.Rule   = rulsJson.ToObject <PersonalizedMenuRule>();

                            conditionalMenus.Add(tmp);
                        }

                        result.PersonalizedMenus = conditionalMenus;
                    }
                }

                return(new SuccessResultReturn <GetAllMenus_Result>(result));
            }
            else
            {
                return(data.Cast <GetAllMenus_Result>(default));
コード例 #4
0
        /// <summary>
        /// 通过OpenId获取订阅用户信息,如果未关注的用户,只能获取到基础信息,已关注用户可以获取到详细信息
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="userOpenId"></param>
        /// <returns></returns>
        public async Task <ResultReturn <SubscribeWxUserInfo_Result> > GetSubscribeUserInfo(string appId, string userOpenId)
        {
            var ret = await CommonApi.Get(appId,
                                          $"/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid={userOpenId}&lang=zh_CN");

            if (ret.IsSuccess)
            {
                var data = ret.ReturnData;

                return(new SuccessResultReturn <SubscribeWxUserInfo_Result>(jsonToSubscribeWxUserInfo(data)));
            }
            else
            {
                return(ret.Cast <SubscribeWxUserInfo_Result>(null));
            }
        }
コード例 #5
0
        } //FindAsync

        public async Task <Response <List <AutocompleteModelItem> > > GetAutocompleteFiltersAsync(
            string SiteId, string eleccionId,
            bool siMesas    = false, bool siLocalidades = false, bool siCircuitos = false, bool siEscuelas = false,
            bool siPartidos = false, bool siListas      = false, bool siCargos    = false)
        {
            var apiResult = await commonApi.Get <List <AutocompleteModelItem> >(
                ApiEndPoints.API_SERVICE_URL, ApiPrefixes.API_PREFIX, "/Common/autocomplete_filters",
                new
            {
                SiteId        = SiteId,
                EleccionId    = eleccionId,
                SiMesas       = siMesas,
                SiLocalidades = siLocalidades,
                SiCircuitos   = siCircuitos,
                SiEscuelas    = siEscuelas,
                SiPartidos    = siPartidos,
                SiListas      = siListas,
                SiCargos      = siCargos,
            }, authService.Token.AccessToken);

            return(apiResult);
        } //FindAsync
コード例 #6
0
        /// <summary>
        /// 分页获取用户OpenId列表
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="nextUserOpenId">上一次最后一条记录的OpenId,如果第一次获取,传空字符串</param>
        /// <returns></returns>
        public async Task <ResultReturn <GetUserOpenIds_Result> > GetUserOpenIds(
            string appId, string nextUserOpenId = "")
        {
            var json = await CommonApi.Get(appId,
                                           $"/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid={nextUserOpenId}");

            if (json.IsSuccess)
            {
                var result = new GetUserOpenIds_Result();

                result.TotalCount   = json.ReturnData.GetInt("total");
                result.CurrentCount = json.ReturnData.GetInt("count");
                result.NextOpenId   = json.ReturnData.GetString("next_openid");
                result.OpenIds      = json.ReturnData.GetJArray("openid").Select(x => x.ToStringEx()).ToArrayEx();

                return(new SuccessResultReturn <GetUserOpenIds_Result>(result));
            }
            else
            {
                return(json.Cast <GetUserOpenIds_Result>(null));
            }
        }
コード例 #7
0
        /// <summary>
        /// 获取当前小程序的模板消息列表
        /// </summary>
        /// <param name="appID"></param>
        /// <returns></returns>
        public async Task <ResultReturn <GetTemplateListItem_Result[]> > GetTemplateList(string appID)
        {
            var data = await CommonApi.Get(appID, "/wxaapi/newtmpl/gettemplate?access_token=ACCESS_TOKEN");

            if (data.IsSuccess)
            {
                var list = data.ReturnData.GetJObjectArray("data");

                return(new SuccessResultReturn <GetTemplateListItem_Result[]>(list.Select(x =>
                                                                                          new GetTemplateListItem_Result()
                {
                    PriTmplId = x.GetString("priTmplId"),
                    Content = x.GetString("content"),
                    Title = x.GetString("title"),
                    Example = x.GetString("example"),
                    Type = x.GetInt("type")
                }).ToArrayEx()));
            }
            else
            {
                return(data.Cast <GetTemplateListItem_Result[]>(null, null));
            }
        }
コード例 #8
0
 /// <summary>
 /// 删除所有菜单,包括个性化菜单
 /// </summary>
 /// <param name="appId"></param>
 /// <returns></returns>
 public async Task <ResultReturn> DeleteMenu(string appId)
 {
     return(await CommonApi.Get(appId, "/cgi-bin/menu/delete?access_token=ACCESS_TOKEN"));
 }