65 lines
2.6 KiB
C#
65 lines
2.6 KiB
C#
using Furion;
|
|
using Furion.DependencyInjection;
|
|
using Nirvana.Common;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Waste.Domain;
|
|
|
|
namespace Waste.Application.ThirdApiInfo
|
|
{
|
|
/// <summary>
|
|
/// 设备对接接口
|
|
/// </summary>
|
|
public class OpenService : IOpenService, ITransient
|
|
{
|
|
private static string ApiUrl = App.Configuration["SZDevPlatSetting:ApiUrl"];
|
|
private static string UserId = App.Configuration["SZDevPlatSetting:UserId"];
|
|
private static string ApiSecret = App.Configuration["SZDevPlatSetting:ApiSecret"];
|
|
private static string ApiSecretHash = App.Configuration["SZDevPlatSetting:ApiSecretHash"];
|
|
private readonly ISqlSugarRepository<W_Device> repository;
|
|
private readonly SqlSugarClient dbClient;
|
|
private readonly ISuZhouService _suZhouService;
|
|
public OpenService(ISqlSugarRepository<W_Device> sqlSugarRepository, ISuZhouService suZhouService)
|
|
{
|
|
repository = sqlSugarRepository;
|
|
dbClient = repository.Context;
|
|
_suZhouService = suZhouService;
|
|
}
|
|
/// <summary>
|
|
/// 获取设备上报相关信息
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <returns></returns>
|
|
public async Task<ResultInfo> GetDevInfoAsync(GetDevInfoRequestDto data)
|
|
{
|
|
var device = await dbClient.Queryable<W_Device>().FirstAsync(x => x.Ecode == data.ECode);
|
|
if(device == null)
|
|
{
|
|
return new ResultInfo(ResultState.FAIL, "设备未找到");
|
|
}
|
|
var devicesecret = await dbClient.Queryable<W_SZDevice>().FirstAsync(x => x.DeviceId == device.Id);
|
|
if(devicesecret == null || string.IsNullOrEmpty(devicesecret.Secret)
|
|
|| string.IsNullOrEmpty(devicesecret.SecretHash)
|
|
|| string.IsNullOrEmpty(devicesecret.DevId))
|
|
{
|
|
return new ResultInfo(ResultState.FAIL, "设备还未获取验证信息");
|
|
}
|
|
int timestamp = _suZhouService.GetTimestamp();
|
|
int noncestr = _suZhouService.GetNonce();
|
|
var returndata = new GetDevInfoResponseDto {
|
|
DeviceId = devicesecret.DevId,
|
|
noncestr = noncestr,
|
|
timestamp = timestamp,
|
|
Secret = devicesecret.Secret,
|
|
SecretHash = devicesecret.SecretHash,
|
|
UserId = UserId
|
|
};
|
|
return new ResultInfo(ResultState.SUCCESS, "success", returndata);
|
|
}
|
|
}
|
|
}
|