Esempio n. 1
0
        public static async Task <string> GetToken(string corpId, string corpSecret, IAccessTokenCacher cacher = null)
        {
            if (cacher == null)
            {
                cacher = new MemoryAccessTokenCacher();
            }
            var token = await cacher.GetAsync(corpId, corpSecret);

            if (!string.IsNullOrEmpty(token))
            {
                return(token);
            }

            var result = await CommonApi.AccessDingtalkServerAsync <GetTokenResponse>(
                $"https://oapi.dingtalk.com/gettoken?corpid={corpId}&corpsecret={corpSecret}", null, "GET");

            if (result.errcode == 0)
            {
                await cacher.SetAsync(corpId, corpSecret, result.access_token, DateTime.Now.AddSeconds(7200));

                return(result.access_token);
            }
            throw new Exception($"errcode: {result.errcode}, errmsg: {result.errmsg}");
        }
Esempio n. 2
0
        public static async Task <string> GetJsApiTicket(string accessToken, IJsApiTicketCacher cacher = null)
        {
            if (cacher == null)
            {
                cacher = new MemoryJsApiTicketCacher();
            }
            var ticket = await cacher.GetAsync(accessToken);

            if (!string.IsNullOrEmpty(ticket))
            {
                return(ticket);
            }

            var result = await CommonApi.AccessDingtalkServerAsync <GetJsApiTicketResponse>(
                $"https://oapi.dingtalk.com/get_jsapi_ticket?access_token={accessToken}&type=jsapi", null, "GET");

            if (result.errcode == 0)
            {
                await cacher.SetAsync(accessToken, result.ticket, DateTime.Now.AddSeconds(7200));

                return(result.ticket);
            }
            throw new Exception($"errcode: {result.errcode}, errmsg: {result.errmsg}");
        }
Esempio n. 3
0
 public static async Task <GetSuiteTokenResponse> GetSuiteAccessTokenAsync(GetSuiteTokenRequest requestData)
 {
     return(await CommonApi.AccessDingtalkServerAsync <GetSuiteTokenResponse>(
                "https://oapi.dingtalk.com/service/get_suite_token", requestData));
 }
Esempio n. 4
0
 public static async Task <GetCorpTokenResponse> GetCorpTokenAsync(string accessToken, CommonIsvRequest isvRequestData)
 {
     return(await CommonApi.AccessDingtalkServerAsync <GetCorpTokenResponse>(
                "https://oapi.dingtalk.com/service/get_corp_token?suite_access_token=" + accessToken, isvRequestData));
 }
Esempio n. 5
0
 public static async Task <GetPermanentCodeResponse> GetPermanentCodeAsync(string accessToken, GetPermanentCodeRequest requestData)
 {
     return(await CommonApi.AccessDingtalkServerAsync <GetPermanentCodeResponse>(
                "https://oapi.dingtalk.com/service/get_permanent_code?suite_access_token=" + accessToken, requestData));
 }
Esempio n. 6
0
 public static async Task <GetUserInfoResponse> GetUserInfo(string accessToken, string code)
 {
     return(await CommonApi.AccessDingtalkServerAsync <GetUserInfoResponse>(
                $"https://oapi.dingtalk.com/user/getuserinfo?access_token={accessToken}&code={code}", null, "GET"));
 }
Esempio n. 7
0
 public static async Task <UserGetResponse> GetUser(UserBaseGetRequest request)
 {
     return(await CommonApi.AccessDingtalkServerAsync <UserGetResponse>(
                $"https://oapi.dingtalk.com/user/get?access_token={request.access_token}&userid={request.userid}", null, "GET"));
 }