81 lines
2.6 KiB
C#
81 lines
2.6 KiB
C#
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<PersonalInfoResponse> 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");
|
|
|
|
try
|
|
{
|
|
var requestResult = await _httpClient.PostAsync("person/v2", contentType);
|
|
if (!requestResult.IsSuccessStatusCode)
|
|
return null;
|
|
var responseResult = await requestResult.Content.ReadFromJsonAsync<PersonalInfoResponse>();
|
|
responseResult.BasicInformation.FirstName = responseResult.BasicInformation.FirstName.ToPersian();
|
|
responseResult.BasicInformation.LastName = responseResult.BasicInformation.LastName.ToPersian();
|
|
responseResult.BasicInformation.FatherName = responseResult.BasicInformation.FatherName.ToPersian();
|
|
|
|
|
|
return responseResult;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
public async Task<MatchMobileWithNationalCodeResponse> 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");
|
|
try
|
|
{
|
|
var requestResult = await _httpClient.PostAsync("mobile/owner/v2", contentType);
|
|
if (!requestResult.IsSuccessStatusCode)
|
|
return null;
|
|
|
|
var responseResult = await requestResult.Content.ReadFromJsonAsync<MatchMobileWithNationalCodeResponse>();
|
|
return responseResult;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
}
|
|
} |