/// <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); } }
/// <summary> /// 发起Post请求 /// </summary> /// <param name="request"></param> /// <param name="url"></param> /// <returns></returns> private async Task <dynamic> PostRequest(string url) { request.SetSign(); var res = await client.PostFormAsync(url, request.Params); if (res.StatusCode == System.Net.HttpStatusCode.OK || res.StatusCode == 0) { return(ReturnResult(res)); } else { throw new Exception("发起美团请求失败,原因:" + res.ErrorMessage); } }