c# - 获取“原始”日期时间
问题描述
我正在创建一个具有基于日期的许可证的程序,如果从到期日期通过,则许可证无效。但是,我的问题是:
如果用户更改了计算机的日期,他也会更改程序,从而“破解”程序。我是这样解决的:
在 PHP 中,我现在得到服务器 Hosting / MySQL 的日期:
127.0.0.1/getdateserver.php
$query = "SELECT NOW() as `now`";
$result = $conn->query($query);
$row = $result->fetch_array();
$now = $row['now'];
echo "$now";
在 C# 中,我每秒为我的网站提出请求并立即返回日期:
private Timer timer;
private DateTime timeserver;
public void InitTimer()
{
timer = new Timer();
timer.Tick += new EventHandler(timer_Tick);
timer.Interval = 1000;
timer.Start();
}
private void timer_Tick(object sender, EventArgs e)
{
setDateServerAsync();
}
private async void setDateServerAsync()
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("127.0.0.1/getdateserver.php");
HttpResponseMessage response = await client.GetAsync("");
response.EnsureSuccessStatusCode();
string result = response.Content.ReadAsStringAsync().Result;
timerserver = DateTime.ParseExact(result, "yyyy-MM-dd HH:mm:ss",
System.Globalization.CultureInfo.InvariantCulture);
}
一切正常。但是这种方法每分钟执行许多请求 (RPM),并且由于我可以有多个用户使用该程序,所以数量只会增加。所以我的问题是:还有其他有效的方法吗?
PS:我的程序只适用于互联网
解决方案
推荐阅读
- android - 如何在 C# 中以编程方式列出来自设备(iOS/Android)的 SMS 对话?
- python - 使用 Selenium 时是否需要设置等待时间?
- flutter - 如何将小部件添加到 Sliver 应用栏区域?
- pointers - 是否有通用的 Rust 指针类型可以存储任何其他类型的指针,类似于 C 的 void *?
- html - 为什么div里面有空格?
- ios - 保存到相机胶卷后从路径加载特定图像
- android - 我正在尝试使用 ViewPager 和 picasso 将来自 firebase 的图像显示到轮播视图中,但图像没有进入视图
- sql - 如何在 sqlite 中对具有限制的 group_concat 子组进行分组?
- javascript - webdriverIO - 添加junit记者
- woocommerce - 最好的方法?在产品页面上添加标签作为图像