Пример #1
0
        /// <summary>
        /// 获取部门成员详情
        /// </summary>
        /// <param name="access_token">调用接口凭证</param>
        /// <param name="department_id">获取的部门id</param>
        /// <param name="fetch_child">1/0:是否递归获取子部门下面的成员</param>
        public static async Task <ListUserResult> ListAsync(string access_token, string department_id, int fetch_child)
        {
            var url    = $"https://qyapi.weixin.qq.com/cgi-bin/user/list?access_token={access_token}&department_id={department_id}&fetch_child={fetch_child}";
            var result = await HttpClientManager.GetAsync <ListUserResult>(url);

            return(result);
        }
Пример #2
0
        /// <summary>
        /// 获取部门列表【未完成】
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="id">部门id。获取指定部门及其下的子部门。 如果不填,默认获取全量组织架构</param>
        /// <returns></returns>
        public static async Task <(bool isSuccess, string msg)> ListAsync(string access_token, int?id = null)
        {
            var url     = $"https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={access_token}&id={id}";
            var httpRet = await HttpClientManager.GetAsync(url);

            return(true, httpRet);
        }
Пример #3
0
        /// <summary>
        /// 获取access_token
        /// </summary>
        /// <param name="corpid"></param>
        /// <param name="corpsecret"></param>
        /// <param name="refresh">是否强制刷新access_token</param>
        /// <returns></returns>
        public static async Task <AccessTokenReturn> GetTokenAsync(string corpid, string corpsecret, bool refresh = false)
        {
            if (refresh == false)
            {
                lock (_tokenLocker)
                {
                    var token = _tokenCache.FirstOrDefault(s => s.Corpid == corpid && s.Corpsecret == corpsecret && s.Expires > DateTime.Now);
                    if (token != null)
                    {
                        return(new AccessTokenReturn {
                            errcode = 0, access_token = token.Access_Token
                        });
                    }
                }
            }

            var url    = $"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={corpid}&corpsecret={corpsecret}";
            var result = await HttpClientManager.GetAsync <AccessTokenReturn>(url);

            if (result.IsSuccess())
            {
                lock (_tokenLocker)
                {
                    var token = _tokenCache.FirstOrDefault(s => s.Corpid == corpid && s.Corpsecret == corpsecret);
                    if (token != null)
                    {
                        token.Access_Token = result.access_token;
                        token.Expires      = DateTime.Now.AddSeconds(result.expires_in).AddSeconds(-10);
                    }
                    else
                    {
                        _tokenCache.Add(new Token
                        {
                            Corpid       = corpid,
                            Corpsecret   = corpsecret,
                            Access_Token = result.access_token,
                            Expires      = DateTime.Now.AddSeconds(result.expires_in).AddSeconds(-10),
                        });
                    }
                }
            }
            return(result);
        }
Пример #4
0
        /// <summary>
        /// 获取jsapi_ticket
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="refresh"></param>
        /// <returns></returns>
        public static async Task <TicketResult> GetJsApiTicketAsync(string access_token, bool refresh = false)
        {
            if (refresh == false)
            {
                lock (_ticketLocker)
                {
                    var token = _ticketCache.FirstOrDefault(s => s.Access_Token == access_token && s.Expires > DateTime.Now);
                    if (token != null)
                    {
                        return(new TicketResult {
                            errcode = 0, ticket = token.Ticket
                        });
                    }
                }
            }

            var url    = $"https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token={access_token}";
            var result = await HttpClientManager.GetAsync <TicketResult>(url);

            if (result.IsSuccess())
            {
                lock (_ticketLocker)
                {
                    var ticket = _ticketCache.FirstOrDefault(s => s.Access_Token == access_token);
                    if (ticket != null)
                    {
                        ticket.Ticket  = result.ticket;
                        ticket.Expires = DateTime.Now.AddSeconds(result.expires_in).AddSeconds(-10);
                    }
                    else
                    {
                        _ticketCache.Add(new TicketEntity
                        {
                            Access_Token = access_token,
                            Ticket       = result.ticket,
                            Expires      = DateTime.Now.AddSeconds(result.expires_in).AddSeconds(-10),
                        });
                    }
                }
            }
            return(result);
        }
Пример #5
0
        /// <summary>
        /// 删除标签
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="id">标签ID</param>
        /// <returns></returns>
        public static async Task <ReturnBase> DeleteAsync(string access_token, int tagid)
        {
            var url = $"https://qyapi.weixin.qq.com/cgi-bin/tag/delete?access_token={access_token}&tagid={tagid}";

            return(await HttpClientManager.GetAsync <ReturnBase>(url));
        }
Пример #6
0
        /// <summary>
        /// 根据code获取成员信息
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public static async Task <GetUserInfoResult> GetUserInfoAsync(string access_token, string code)
        {
            var url = $"https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token={access_token}&code={code}";

            return(await HttpClientManager.GetAsync <GetUserInfoResult>(url));
        }
Пример #7
0
        /// <summary>
        /// 验证成员信息成功后,调用如下接口即可让成员成功加入企业。
        /// https://work.weixin.qq.com/api/doc#11378
        /// </summary>
        /// <param name="access_token"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public static async Task <ReturnBase> Authsucc(string access_token, string userid)
        {
            var url = $"https://qyapi.weixin.qq.com/cgi-bin/user/authsucc?access_token={access_token}&userid={userid}";

            return(await HttpClientManager.GetAsync <ReturnBase>(url));
        }