123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using System;
- using System.Collections.Generic;
- using System.Net;
- using System.Net.Http;
- using System.Net.Http.Json;
- using System.Text;
- using System.Threading.Tasks;
- using TEAMModelOS.SDK.Extension;
- namespace TEAMModelOS.SDK.Models.Service
- {
- public class CoreAPIHttpService
- {
- private readonly HttpClient _httpClient;
- public CoreAPIHttpService(HttpClient httpClient)
- {
- _httpClient = httpClient;
- }
- /// <summary>
- /// 隐式登录
- /// </summary>
- /// <param name="clientID"></param>
- /// <param name="clientSecret"></param>
- /// <param name="location"></param>
- /// <param name="url"></param>
- /// <param name="data"></param>
- /// <returns></returns>
- public async Task<(int code ,string content)> Implicit(string clientID, string clientSecret, string location, string url,Dictionary<string,string> data)
- {
- if (location.Contains("China"))
- {
- location = "China";
- }
- else if (location.Contains("Global"))
- {
- location = "Global";
- }
- var token = await CoreTokenExtensions.CreateAccessToken(clientID, clientSecret, location);
- _httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.AccessToken}");
- HttpResponseMessage responseMessage = await _httpClient.PostAsJsonAsync(url, data);
- if (responseMessage.StatusCode == HttpStatusCode.OK)
- {
- string content=await responseMessage.Content.ReadAsStringAsync();
- return (200,content);
- }
- else if (responseMessage.StatusCode == HttpStatusCode.Unauthorized)
- {
- return (401,null);
- }
- else
- {
- return (500,null);
- }
- }
- }
- }
|