using System; using System.Net.Http; using System.Net.Http.Json; using System.Text; using System.Text.Json; using System.Threading.Tasks; using Newtonsoft.Json; namespace _0_Framework.Application.UID; public class UidService : IUidService { private readonly HttpClient _httpClient; private const string BaseUrl= "https://json-api.uid.ir/api/inquiry/"; public UidService() { _httpClient = new HttpClient() { BaseAddress = new Uri(BaseUrl) }; } public async Task GetPersonalInfo(string nationalCode, string birthDate) { var request = new PersonalInfoRequest { BirthDate = birthDate , NationalId = nationalCode, RequestContext = new UidRequestContext() }; var json = JsonConvert.SerializeObject(request); var contentType = new StringContent(json, Encoding.UTF8, "application/json"); var requestResult = await _httpClient.PostAsync("person/v2", contentType); if(!requestResult.IsSuccessStatusCode) return null; var responseResult = await requestResult.Content.ReadFromJsonAsync(); return responseResult; } public async Task IsMachPhoneWithNationalCode(string nationalCode, string phoneNumber) { var request = new PersonalInfoRequest { MobileNumber = phoneNumber, NationalId = nationalCode, RequestContext = new UidRequestContext() }; var json = JsonConvert.SerializeObject(request); var contentType = new StringContent(json, Encoding.UTF8, "application/json"); var requestResult = await _httpClient.PostAsync("mobile/owner/v2", contentType); if (!requestResult.IsSuccessStatusCode) return null; var responseResult = await requestResult.Content.ReadFromJsonAsync(); return responseResult; } }