コード例 #1
0
        /// <summary>
        /// 获取钉钉Token
        /// </summary>
        /// <param name="corpId"></param>
        /// <param name="corpSecret"></param>
        /// <returns></returns>
        public static string GetAccessToken(string corpId, string corpSecret)
        {
            string url = string.Format("https://oapi.dingtalk.com/gettoken?corpid={0}&corpsecret={1}", corpId, corpSecret);

            try
            {
                string response = HttpRequestHelper.Get(url);
                ResultModel.AccessTokenModel oat = Newtonsoft.Json.JsonConvert.DeserializeObject <ResultModel.AccessTokenModel>(response);

                if (oat != null)
                {
                    {
                        return(oat.access_token);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(string.Empty);
        }
コード例 #2
0
        /// <summary>
        /// 获取UserInfo
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static ResultModel.Dingding_User GetUserInfo(string accessToken, string userId)
        {
            string url = string.Format("https://oapi.dingtalk.com/user/get?access_token={0}&userid={1}", accessToken, userId);

            try
            {
                string response = HttpRequestHelper.Get(url);
                ResultModel.Dingding_User model = Newtonsoft.Json.JsonConvert.DeserializeObject <ResultModel.Dingding_User>(response);

                if (model != null)
                {
                    return(model);
                }
            }

            catch (Exception ex)
            {
                throw;
            }
            return(null);
        }
コード例 #3
0
        /// <summary>
        /// 获取JS ticket
        /// </summary>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public static string GetJsApiTicket(string accessToken)
        {
            string url = string.Format("https://oapi.dingtalk.com/get_jsapi_ticket?access_token={0}", accessToken);

            try
            {
                string response = HttpRequestHelper.Get(url);
                ResultModel.JsApiTicketModel model = Newtonsoft.Json.JsonConvert.DeserializeObject <ResultModel.JsApiTicketModel>(response);

                if (model != null)
                {
                    {
                        return(model.ticket);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(string.Empty);
        }
コード例 #4
0
        /// <summary>
        /// 获取企业部门列表
        /// </summary>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public static string GetDepartmentsList(string accessToken)
        {
            string url = string.Format("https://oapi.dingtalk.com/department/list?access_token={0}", accessToken);

            try
            {
                string response = HttpRequestHelper.Get(url);
                ResultModel.DepartmentListModel oat = Newtonsoft.Json.JsonConvert.DeserializeObject <ResultModel.DepartmentListModel>(response);

                if (oat != null)
                {
                    {
                        return(Newtonsoft.Json.JsonConvert.SerializeObject(oat.Department));
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(string.Empty);
        }
コード例 #5
0
        public static ResultModel.DepartmentInfo GetDepartmentInfo(string accessToken, string id)
        {
            string url = string.Format("https://oapi.dingtalk.com/department/get?access_token={0}&id={1}", accessToken, id);

            try
            {
                string response = HttpRequestHelper.Get(url);
                ResultModel.DepartmentInfo model = Newtonsoft.Json.JsonConvert.DeserializeObject <ResultModel.DepartmentInfo>(response);

                if (model != null)
                {
                    {
                        return(model);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(null);
        }
コード例 #6
0
        /// <summary>
        /// 获取Userid
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string GetUserId(string accessToken, string code)
        {
            string url = string.Format("https://oapi.dingtalk.com/user/getuserinfo?access_token={0}&code={1}", accessToken, code);

            try
            {
                string response = HttpRequestHelper.Get(url);
                ResultModel.GetUserInfoModel model = Newtonsoft.Json.JsonConvert.DeserializeObject <ResultModel.GetUserInfoModel>(response);

                if (model != null)
                {
                    return(model.userid);
                }
                else
                {
                    throw new Exception(model.errmsg);
                }
            }

            catch (Exception ex)
            {
                throw;
            }
        }