44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
using QRCodeService.Application.Queries;
|
|
using QRCodeService.Extensions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace QRCodeService.Models
|
|
{
|
|
public abstract class CheckSignModel
|
|
{
|
|
public int AppId { get; set; }
|
|
public string Time { get; set; }
|
|
public string Sign { get; set; }
|
|
public async Task<bool> CheckSignAsync(string appkey)
|
|
{
|
|
//除Sign字段以外按key名排序
|
|
var props = this.GetType().GetProperties();
|
|
var signStr = string.Join(null,props.Where(p=>p.Name!="Sign").OrderBy(p => p.Name).Select(p=>p.GetValue(this).ToString()));
|
|
var sign = Convert.ToBase64String((signStr + appkey).ToMD5());
|
|
return sign == Sign;
|
|
}
|
|
public bool CheckTime()
|
|
{
|
|
var timeDate = Time.ToDate("yyyyMMddhhmmss");
|
|
if (timeDate == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (Math.Abs((timeDate.Value - DateTime.Now).TotalSeconds) > 60)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public async Task<bool> CheckValidAsync(string appkey)
|
|
{
|
|
return CheckTime() && await CheckSignAsync(appkey);
|
|
}
|
|
}
|
|
}
|