Exemplo n.º 1
0
        /* https://oapi.dingtalk.com/get_jsapi_ticket?access_token=79721ed2fc46317197e27d9bedec0425
         *
         * errmsg    "ok"
         * ticket    "KJWkoWOZ0BMYaQzWFDF5AUclJOHgO6WvzmNNJTswpAMPh3S2Z98PaaJkRzkjsmT5HaYFfNkMdg8lFkvxSy9X01"
         * expires_in    7200
         * errcode    0
         */
        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);
                JsApiTicketModel model    = Newtonsoft.Json.JsonConvert.DeserializeObject <JsApiTicketModel>(response);
                if (model != null)
                {
                    if (model.errcode == 0)
                    {
                        return(model.ticket);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(string.Empty);
        }
Exemplo n.º 2
0
        public static UserDetailInfo GetUserDetail(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);
                UserDetailInfo model    = Newtonsoft.Json.JsonConvert.DeserializeObject <UserDetailInfo>(response);

                if (model != null)
                {
                    if (model.errcode == 0)
                    {
                        return(model);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(null);
        }
Exemplo n.º 3
0
        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);
                AccessTokenModel oat      = Newtonsoft.Json.JsonConvert.DeserializeObject <AccessTokenModel>(response);

                if (oat != null)
                {
                    if (oat.errcode == 0)
                    {
                        return(oat.access_token);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(string.Empty);
        }