feat 获取新token
This commit is contained in:
@@ -152,6 +152,39 @@ public class AssignmentService : IAssignmentService
|
||||
}).ToList();
|
||||
});
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取新token
|
||||
/// </summary>
|
||||
/// <param name="taskId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<string> Token(long taskId)
|
||||
{
|
||||
var task = await _dbContext.Queryable<DeviceTaskEntity>().Where(x => x.Id == taskId).FirstAsync();
|
||||
|
||||
task.ThrowIfNull("该任务不存在");
|
||||
if (task.Status != DeviceTaskStatusEnumType.Success)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
string newtoken="";
|
||||
Scoped.Request.Value.Create((sp) =>
|
||||
{
|
||||
FaceUrlOptions faceUrlOptions = sp.GetService<IOptions<FaceUrlOptions>>().Value;
|
||||
var dataProtectionProvider = sp.GetService<IDataProtectionProvider>();
|
||||
|
||||
var timeLimitedDataProtector = dataProtectionProvider
|
||||
.CreateProtector("down:face")
|
||||
.ToTimeLimitedDataProtector();
|
||||
var userCode = task.UserCode;
|
||||
|
||||
var key = $"face:{userCode}";
|
||||
var token = timeLimitedDataProtector.Protect(key, TimeSpan.FromSeconds(faceUrlOptions.Limit));
|
||||
newtoken = faceUrlOptions.Url + token;
|
||||
});
|
||||
|
||||
return newtoken;
|
||||
}
|
||||
|
||||
|
||||
public async Task UpdateDeviceTaskStatusAsync(UpdateDeviceTaskStatusRequest request)
|
||||
|
||||
Reference in New Issue
Block a user