/// <summary> /// 获取授权token等信息 /// </summary> /// <param name="code"></param> /// <returns></returns> public async Task <MyJsonResult> AccessTokenAsync(string code) { if (code.IsNullOrEmpty()) { throw new ArgumentException("code无效"); } //拼接参数 HttpContent content = new FormUrlEncodedContent(new Dictionary <string, string>() { { "client_id", Appid }, { "client_secret", AppSecret }, { "grant_type", "authorization_code" }, { "code", code }, { "redirect_uri", ReturnUrl } }); //调用接口获取token var res = (await httpRequest.DoPostAsync(AccessTokenUrl, content, null)); if (res == null) { throw new ApplicationException("接口调用失败"); } if (!res.ContainsKey("access_token") || res["access_token"].ToString().IsNullOrEmpty()) { throw new ApplicationException(res.ContainsKey("error_description") ? res["error_description"].ToString() : "token获取失败"); } myJsonResult.rows = res.ToJson(); return(myJsonResult); }
/// <summary> /// 获取钉钉的用户信息 /// </summary> /// <param name="token">接口凭证</param> /// <param name="code"></param> /// <returns></returns> public async Task <MyJsonResult> GetUserInfoAsync(string token, string code) { var res = await httpRequest.DoPostAsync(string.Format(DingDingGetUserInfoUrl, token), new StringContent("{ \"tmp_auth_code\": \"" + code + "\"}"), null, null, PostContentTypeEnum.JSON); if (res != null && res["errcode"].ToString().Equals("0")) { var userinfo = res["user_info"] != null ? res["user_info"].ToString() : ""; myJsonResult.rows = userinfo; } else { myJsonResult.code = (int)MyJsonResultEnum.thirdError; myJsonResult.rows = res["errmsg"] != null ? res["errmsg"].ToString() : ""; } return(myJsonResult); }