Example #1
0
        /// <summary>
        /// 通用的操作结果
        /// </summary>
        /// <param name="url">网页地址</param>
        /// <param name="postData">提交的数据内容</param>
        /// <returns></returns>
        public static CommonResult GetExecuteResult(string url, string postData = null)
        {
            CommonResult success = new CommonResult();

            try
            {
                ErrorJsonResult result;
                if (postData != null)
                {
                    result = JsonHelper <ErrorJsonResult> .ConvertJson(url, postData);
                }
                else
                {
                    result = JsonHelper <ErrorJsonResult> .ConvertJson(url);
                }

                if (result != null)
                {
                    success.Success      = (result.errcode == ReturnCode.请求成功);
                    success.ErrorMessage = result.errmsg;
                }
            }
            catch (WeixinException ex)
            {
                success.ErrorMessage = ex.Message;
            }

            return(success);
        }
Example #2
0
        /// <summary>
        /// 获取用户基本信息
        /// </summary>
        /// <param name="accessToken">调用接口凭证</param>
        /// <param name="openId">普通用户的标识,对当前公众号唯一</param>
        /// <param name="lang">返回国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语</param>
        public UserJson GetUserDetail(string accessToken, string openId, Language lang = Language.zh_CN)
        {
            string url = string.Format("https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang={2}",
                                       accessToken, openId, lang.ToString());

            UserJson result = JsonHelper <UserJson> .ConvertJson(url);

            return(result);
        }
Example #3
0
        /// <summary>
        /// 获取菜单数据
        /// </summary>
        /// <param name="accessToken">调用接口凭证</param>
        /// <returns></returns>
        public MenuJson GetMenu(string accessToken)
        {
            MenuJson menu = null;

            var          url  = string.Format("https://api.weixin.qq.com/cgi-bin/menu/get?access_token={0}", accessToken);
            MenuListJson list = JsonHelper <MenuListJson> .ConvertJson(url);

            if (list != null)
            {
                menu = list.menu;
            }
            return(menu);
        }
Example #4
0
        /// <summary>
        /// 查询用户所在分组
        /// </summary>
        /// <param name="accessToken">调用接口凭证</param>
        /// <param name="openid">用户的OpenID</param>
        /// <returns></returns>
        public int GetUserGroupId(string accessToken, string openid)
        {
            string url  = string.Format("https://api.weixin.qq.com/cgi-bin/groups/getid?access_token={0}", accessToken);
            var    data = new
            {
                openid = openid
            };
            string postData = data.ToJson();

            int groupId = -1;
            GroupIdJsonResult result = JsonHelper <GroupIdJsonResult> .ConvertJson(url, postData);

            if (result != null)
            {
                groupId = result.groupid;
            }
            return(groupId);
        }
Example #5
0
        /// <summary>
        /// 获取关注用户列表
        /// </summary>
        /// <param name="accessToken">调用接口凭证</param>
        /// <param name="nextOpenId">第一个拉取的OPENID,不填默认从头开始拉取</param>
        /// <returns></returns>
        public List <string> GetUserList(string accessToken, string nextOpenId = null)
        {
            List <string> list = new List <string>();

            string url = string.Format("https://api.weixin.qq.com/cgi-bin/user/get?access_token={0}", accessToken);

            if (!string.IsNullOrEmpty(nextOpenId))
            {
                url += "&next_openid=" + nextOpenId;
            }

            UserListJsonResult result = JsonHelper <UserListJsonResult> .ConvertJson(url);

            if (result != null && result.data != null)
            {
                list.AddRange(result.data.openid);
            }

            return(list);
        }
Example #6
0
        /// <summary>
        /// 创建分组
        /// </summary>
        /// <param name="accessToken">调用接口凭证</param>
        /// <param name="name">分组名称</param>
        /// <returns></returns>
        public GroupJson CreateGroup(string accessToken, string name)
        {
            string url  = string.Format("https://api.weixin.qq.com/cgi-bin/groups/create?access_token={0}", accessToken);
            var    data = new
            {
                group = new
                {
                    name = name
                }
            };
            string postData = data.ToJson();

            GroupJson         group  = null;
            CreateGroupResult result = JsonHelper <CreateGroupResult> .ConvertJson(url, postData);

            if (result != null)
            {
                group = result.group;
            }
            return(group);
        }