Api/Brizco.Infrastructure/Services/SmsService.cs

49 lines
1.6 KiB
C#

using Microsoft.Extensions.Hosting;
namespace Brizco.Infrastructure.Services;
public class SmsService(
IRestApiWrapper restApiWrapper,
IOptionsSnapshot<SiteSettings> optionsSnapshot,
ILogger<SmsService> logger,
IHostEnvironment environment)
: ISmsService
{
private readonly SiteSettings _siteSettings = optionsSnapshot.Value;
public async Task SendForgerPasswordAsync(string phoneNumber, string newPassword)
{
var rest = await restApiWrapper.KaveNegarRestApi.SendLookUp(_siteSettings.KaveNegarApiKey, phoneNumber, newPassword, null, null, null, "forgetPassword");
if (rest.Return.status != 200)
throw new BaseApiException(ApiResultStatusCode.SendSmsError, rest.Return.message);
}
public async Task SendVerifyCodeAsync(string phoneNumber, string verifyCode)
{
try
{
var rest = await restApiWrapper.KaveNegarRestApi.SendLookUp(_siteSettings.KaveNegarApiKey, phoneNumber,
verifyCode, null, null, null, "login-brizco");
if (rest.Return.status != 200 && environment.IsProduction())
throw new BaseApiException(ApiResultStatusCode.SendSmsError, rest.Return.message);
}
catch (ApiException apiException)
{
if (environment.IsProduction())
throw ;
else
logger.LogError(apiException.Message);
}
catch (Exception apiException)
{
if (environment.IsProduction())
throw;
else
logger.LogError(apiException.Message);
}
}
}