/// <summary> /// 获取token /// </summary> /// <param name="code"></param> /// <param name="state"></param> /// <returns></returns> public async Task <string> GetToken(string code, string state, string host) { string authCode = System.Convert.ToBase64String(Encoding.ASCII.GetBytes($"{ElemeOptions.Key}:{ElemeOptions.Secret}")); client.AddAuthorization("Basic", authCode); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("grant_type", "authorization_code"); dic.Add("code", code); string returnUrl = "http://" + host + "/api/elmpoi/authcallback"; //returnUrl = HttpUtility.UrlEncode(returnUrl); dic.Add("redirect_uri", returnUrl); dic.Add("client_id", ElemeOptions.Key); var res = await client.PostFormAsync(ElemeOptions.GetAuthTokenUrl(), dic); if (res.StatusCode == System.Net.HttpStatusCode.OK) { return(res.Result); } else { throw new Exception(res.ErrorMessage); } }