paypal c#accesstoken获取
public static string GenerateAccessToken()
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
string PAYPAL_CLIENT_ID = "";
string PAYPAL_CLIENT_SECRET = "";
var client = new HttpClient();
client.BaseAddress = new Uri("https://api-m.sandbox.paypal.com/");
var authValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(PAYPAL_CLIENT_ID + ":" + PAYPAL_CLIENT_SECRET));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "QVZiQ0lmdlFKV0lJZlluZ2hrTERQblJxUkV6dFFMWnh5a2M5am1GNVlIRzZTU051YUNENERzd09CYlBab2JTUzMxb21MOTRGMlRITEdSc0g6RUp2WnR2cW1ieVVfdlJUTHFKdk5ycjNSb1p0akY4OVBVUVlDd0JOOHM3NWNkckpucjhoRXZUTlVhclhYcmhENnZTeHN4dVJRSmxJcGFoako=");
var response = client.PostAsync("v1/oauth2/token",
new StringContent("grant_type=client_credentials", System.Text.Encoding.UTF8, "application/x-www-form-urlencoded")
).Result;
var responseData = response.Content.ReadAsStringAsync().Result;
dynamic json = Newtonsoft.Json.JsonConvert.DeserializeObject(responseData);
//LogHelper.WriteLog(json.access_token);
return json.access_token;
}
.net 4.5 需要加上https协议认真
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
c# webapi项目,异步请求必需同步接收,要不就会接收不到,异步方法不受影响
var responseData = response.Content.ReadAsStringAsync().Result;
1163

被折叠的 条评论
为什么被折叠?



