|
|
|
|
@@ -18,6 +18,8 @@ public class SmsService : ISmsService
|
|
|
|
|
{
|
|
|
|
|
private readonly IConfiguration _configuration;
|
|
|
|
|
private readonly ISmsResultRepository _smsResultRepository;
|
|
|
|
|
private readonly bool _isDevEnvironment;
|
|
|
|
|
private readonly List<string> _testNumbers;
|
|
|
|
|
public SmsIr SmsIr { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -27,6 +29,33 @@ public class SmsService : ISmsService
|
|
|
|
|
_smsResultRepository = smsResultRepository;
|
|
|
|
|
SmsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa");
|
|
|
|
|
|
|
|
|
|
// خواندن تنظیمات SMS از appsettings
|
|
|
|
|
var smsSettings = _configuration.GetSection("SmsSettings");
|
|
|
|
|
_isDevEnvironment = smsSettings.GetValue<bool>("IsTestMode");
|
|
|
|
|
_testNumbers = smsSettings.GetSection("TestNumbers").Get<List<string>>() ?? new List<string>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// متد مرکزی برای ارسال پیامک که محیط dev را چک میکند
|
|
|
|
|
/// </summary>
|
|
|
|
|
private async Task<SmsIrResult<VerifySendResult>> VerifySendSmsAsync(string number, int templateId, VerifySendParameter[] parameters)
|
|
|
|
|
{
|
|
|
|
|
// اگر محیط dev است و شمارههای تست وجود دارد، به شمارههای تست ارسال میشود
|
|
|
|
|
if (_isDevEnvironment && _testNumbers is { Count: > 0 })
|
|
|
|
|
{
|
|
|
|
|
// ارسال به همه شمارههای تست
|
|
|
|
|
SmsIrResult<VerifySendResult> lastResult = null;
|
|
|
|
|
foreach (var testNumber in _testNumbers)
|
|
|
|
|
{
|
|
|
|
|
lastResult = await SmsIr.VerifySendAsync(testNumber, templateId, parameters);
|
|
|
|
|
}
|
|
|
|
|
return lastResult; // برگرداندن نتیجه آخرین ارسال
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// ارسال به شماره واقعی
|
|
|
|
|
return await SmsIr.VerifySendAsync(number, templateId, parameters);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Send(string number, string message)
|
|
|
|
|
@@ -56,12 +85,7 @@ public class SmsService : ISmsService
|
|
|
|
|
}
|
|
|
|
|
public bool VerifySend(string number, string message)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
SmsIr smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa");
|
|
|
|
|
|
|
|
|
|
//var bulkSendResult = smsIr.BulkSendAsync(95007079000006, "your text message", new string[] { "9120000000" });
|
|
|
|
|
|
|
|
|
|
var verificationSendResult = smsIr.VerifySendAsync(number, 768382, new VerifySendParameter[] { new VerifySendParameter("VerificationCode", message) });
|
|
|
|
|
var verificationSendResult = VerifySendSmsAsync(number, 768382, new VerifySendParameter[] { new VerifySendParameter("VerificationCode", message) });
|
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
|
if (verificationSendResult.IsCompletedSuccessfully)
|
|
|
|
|
{
|
|
|
|
|
@@ -90,11 +114,7 @@ public class SmsService : ISmsService
|
|
|
|
|
|
|
|
|
|
public bool LoginSend(string number, string message)
|
|
|
|
|
{
|
|
|
|
|
SmsIr smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa");
|
|
|
|
|
|
|
|
|
|
//var bulkSendResult = smsIr.BulkSendAsync(95007079000006, "your text message", new string[] { "9120000000" });
|
|
|
|
|
|
|
|
|
|
var verificationSendResult = smsIr.VerifySendAsync(number, 635330, new VerifySendParameter[] { new VerifySendParameter("LOGINCODE", message) });
|
|
|
|
|
var verificationSendResult = VerifySendSmsAsync(number, 635330, new VerifySendParameter[] { new VerifySendParameter("LOGINCODE", message) });
|
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
|
if (verificationSendResult.IsCompletedSuccessfully)
|
|
|
|
|
{
|
|
|
|
|
@@ -119,11 +139,8 @@ public class SmsService : ISmsService
|
|
|
|
|
|
|
|
|
|
public async Task<SentSmsViewModel> SendVerifyCodeToClient(string number, string code)
|
|
|
|
|
{
|
|
|
|
|
SmsIr smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa");
|
|
|
|
|
var result = new SentSmsViewModel();
|
|
|
|
|
//var bulkSendResult = smsIr.BulkSendAsync(95007079000006, "your text message", new string[] { "9120000000" });
|
|
|
|
|
|
|
|
|
|
var sendResult = await smsIr.VerifySendAsync(number, 768382, new VerifySendParameter[] { new VerifySendParameter("VerificationCode", code) });
|
|
|
|
|
var sendResult = await VerifySendSmsAsync(number, 768382, new VerifySendParameter[] { new VerifySendParameter("VerificationCode", code) });
|
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
|
|
|
|
|
|
if (sendResult.Message == "موفق")
|
|
|
|
|
@@ -148,9 +165,8 @@ public class SmsService : ISmsService
|
|
|
|
|
var checkLength = fullName.Length;
|
|
|
|
|
if (checkLength > 25)
|
|
|
|
|
fullName = fullName.Substring(0, 24);
|
|
|
|
|
SmsIr smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa");
|
|
|
|
|
|
|
|
|
|
var sendResult = smsIr.VerifySendAsync(number, 725814, new VerifySendParameter[] { new VerifySendParameter("FULLNAME", fullName), new VerifySendParameter("USERNAME", userName), new VerifySendParameter("PASSWORD", userName) });
|
|
|
|
|
var sendResult = VerifySendSmsAsync(number, 725814, new VerifySendParameter[] { new VerifySendParameter("FULLNAME", fullName), new VerifySendParameter("USERNAME", userName), new VerifySendParameter("PASSWORD", userName) });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(userName + " - " + sendResult.Result.Status);
|
|
|
|
|
@@ -332,18 +348,39 @@ public class SmsService : ISmsService
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public async Task<bool> SendInstitutionVerificationLink(string number, string fullName, Guid institutionId, long contractingPartyId, long institutionContractId)
|
|
|
|
|
|
|
|
|
|
public async Task<bool> SendInstitutionCreationVerificationLink(string number, string fullName, Guid institutionId, long contractingPartyId, long institutionContractId)
|
|
|
|
|
{
|
|
|
|
|
var guidStr=institutionId.ToString();
|
|
|
|
|
var firstPart = guidStr.Substring(0, 15);
|
|
|
|
|
var secondPart = guidStr.Substring(15);
|
|
|
|
|
var verificationSendResult =await SmsIr.VerifySendAsync(number, 527519, new VerifySendParameter[]
|
|
|
|
|
var verificationSendResult =await VerifySendSmsAsync(number, 527519, new VerifySendParameter[]
|
|
|
|
|
{
|
|
|
|
|
new("FULLNAME", fullName),
|
|
|
|
|
new("CODE1",firstPart),
|
|
|
|
|
new("CODE2",secondPart)
|
|
|
|
|
});
|
|
|
|
|
var smsResult = new SmsResult(verificationSendResult.Data.MessageId, verificationSendResult.Message, "لینک تاییدیه قرارداد مالی",
|
|
|
|
|
|
|
|
|
|
var smsResult = new SmsResult(verificationSendResult.Data.MessageId, verificationSendResult.Message, "لینک تاییدیه ایجاد قرارداد مالی",
|
|
|
|
|
fullName, number, contractingPartyId, institutionContractId);
|
|
|
|
|
await _smsResultRepository.CreateAsync(smsResult);
|
|
|
|
|
await _smsResultRepository.SaveChangesAsync();
|
|
|
|
|
return verificationSendResult.Status == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<bool> SendInstitutionAmendmentVerificationLink(string number, string fullName, Guid institutionId,
|
|
|
|
|
long contractingPartyId, long institutionContractId)
|
|
|
|
|
{
|
|
|
|
|
var guidStr=institutionId.ToString();
|
|
|
|
|
var firstPart = guidStr.Substring(0, 15);
|
|
|
|
|
var secondPart = guidStr.Substring(15);
|
|
|
|
|
var verificationSendResult =await VerifySendSmsAsync(number, 527519, new VerifySendParameter[]
|
|
|
|
|
{
|
|
|
|
|
new("FULLNAME", fullName),
|
|
|
|
|
new("CODE1",firstPart),
|
|
|
|
|
new("CODE2",secondPart)
|
|
|
|
|
});
|
|
|
|
|
var smsResult = new SmsResult(verificationSendResult.Data.MessageId, verificationSendResult.Message, "لینک تاییدیه ارتقا قرارداد مالی",
|
|
|
|
|
fullName, number, contractingPartyId, institutionContractId);
|
|
|
|
|
await _smsResultRepository.CreateAsync(smsResult);
|
|
|
|
|
await _smsResultRepository.SaveChangesAsync();
|
|
|
|
|
@@ -353,7 +390,7 @@ public class SmsService : ISmsService
|
|
|
|
|
public async Task<bool> SendInstitutionVerificationCode(string number, string code, string contractingPartyFullName,
|
|
|
|
|
long contractingPartyId, long institutionContractId)
|
|
|
|
|
{
|
|
|
|
|
var verificationSendResult =await SmsIr.VerifySendAsync(number, 965348, new VerifySendParameter[]
|
|
|
|
|
var verificationSendResult =await VerifySendSmsAsync(number, 965348, new VerifySendParameter[]
|
|
|
|
|
{
|
|
|
|
|
new("VERIFYCODE", code)
|
|
|
|
|
});
|
|
|
|
|
|