change in tokens and addtelemetry(addData)
This commit is contained in:
@@ -25,12 +25,14 @@ public class TelemetryController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpGet("AddData")]
|
||||
public async Task<ActionResult<int>> Create(string deviceName, decimal temperatureC, decimal humidityPercent,
|
||||
public async Task<ActionResult<int>> Create(object deviceName, decimal temperatureC, decimal humidityPercent,
|
||||
decimal soilPercent, int gasPPM, decimal lux, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
TelemetryDto dto = new TelemetryDto
|
||||
{
|
||||
DeviceName = deviceName,
|
||||
DeviceName = deviceName.ToString() == "dr110"? "dr110":"",
|
||||
Id= deviceName.ToString() == "dr110" ? 0 : Convert.ToInt32(deviceName),
|
||||
TemperatureC = temperatureC,
|
||||
HumidityPercent = humidityPercent,
|
||||
SoilPercent = soilPercent,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://0.0.0.0:5064"
|
||||
"applicationUrl": "http://127.0.0.1:5064"
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
@@ -14,7 +14,7 @@
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "https://0.0.0.0:7274;http://0.0.0.0:5064"
|
||||
"applicationUrl": "https://127.0.0.1:7274;http://127.0.0.1:5064"
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
|
||||
@@ -107,7 +107,7 @@ public sealed class DeviceTokenService : IDeviceTokenService
|
||||
// ذخیره کدها
|
||||
settings.TokenCode = tokenCode;
|
||||
settings.VerificationCode = verificationCode;
|
||||
settings.TokenExpiresAt = DateTime.UtcNow.AddMinutes(10); // اعتبار 10 دقیقه
|
||||
settings.TokenExpiresAt = DateTime.UtcNow.AddMinutes(30); // اعتبار 10 دقیقه
|
||||
settings.UpdatedAt = DateTime.UtcNow;
|
||||
|
||||
await dbContext.SaveChangesAsync(cancellationToken);
|
||||
@@ -118,7 +118,7 @@ public sealed class DeviceTokenService : IDeviceTokenService
|
||||
await smsService.SendWebserviceSmsAsync(new WebserviceSmsRequest
|
||||
{
|
||||
Recipient = request.DevicePhoneNumber,
|
||||
Message = $"کد تایید دستگاه شما: {tokenCode}\nاعتبار: 10 دقیقه"
|
||||
Message = $"0911925302120#{tokenCode}"
|
||||
}, cancellationToken);
|
||||
}
|
||||
catch (Exception smsEx)
|
||||
@@ -137,7 +137,7 @@ public sealed class DeviceTokenService : IDeviceTokenService
|
||||
{
|
||||
Success = true,
|
||||
Message = "کد تایید با موفقیت ارسال شد",
|
||||
TokenCode = tokenCode
|
||||
TokenCode = $"0911925302120#{tokenCode}"
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -193,12 +193,14 @@ public sealed class DeviceTokenService : IDeviceTokenService
|
||||
Message = "کد تایید نادرست است"
|
||||
};
|
||||
}
|
||||
|
||||
Random rnd = new Random();
|
||||
// رمزگذاری ساده تنظیمات: DeviceName|UploadIntervalMin به Base64
|
||||
var deviceName = settings.Device.DeviceName;
|
||||
var deviceId = settings.Device.Id;
|
||||
var uploadInterval = settings.UploadIntervalMin;
|
||||
var plainText = $"{deviceName}|{uploadInterval}";
|
||||
var encodedSettings = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(plainText));
|
||||
string smsConfig = (settings.MinimumSmsIntervalMinutes != 0 ? "1" : rnd.Next(2, 9).ToString())
|
||||
+ settings.MinimumSmsIntervalMinutes;
|
||||
var plainText = $"{deviceId}01|{rnd.Next(1,9)}{uploadInterval}|{smsConfig}|{rnd.Next(139,97654)}|{rnd.Next(1,9)}{(int)settings.SimCardType}";
|
||||
var encodedSettings = plainText; //Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(plainText));
|
||||
|
||||
// ارسال تنظیمات کدشده از طریق پیامک
|
||||
try
|
||||
@@ -206,7 +208,7 @@ public sealed class DeviceTokenService : IDeviceTokenService
|
||||
await smsService.SendWebserviceSmsAsync(new WebserviceSmsRequest
|
||||
{
|
||||
Recipient = request.DevicePhoneNumber,
|
||||
Message = $"تنظیمات دستگاه:\n{encodedSettings}"
|
||||
Message = $"{encodedSettings}"
|
||||
}, cancellationToken);
|
||||
}
|
||||
catch (Exception smsEx)
|
||||
|
||||
@@ -29,6 +29,14 @@ public sealed class TelemetryService : ITelemetryService
|
||||
dto.DeviceId = device.Id; // Update DTO for alert service
|
||||
}
|
||||
}
|
||||
if (dto.Id!=0)
|
||||
{
|
||||
var device = await dbContext.Devices.FirstOrDefaultAsync(d => d.Id == dto.Id, cancellationToken);
|
||||
if (device != null)
|
||||
{
|
||||
entity.DeviceId = device.Id;
|
||||
}
|
||||
}
|
||||
// ذخیره زمان سرور در لحظه ثبت
|
||||
entity.ServerTimestampUtc = DateTime.Now;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user