首页 > 解决方案 > 获取“原始”日期时间

问题描述

我正在创建一个具有基于日期的许可证的程序,如果从到期日期通过,则许可证无效。但是,我的问题是:

如果用户更改了计算机的日期,他也会更改程序,从而“破解”程序。我是这样解决的:

在 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:我的程序只适用于互联网

标签: c#phpmysqlhttpclient

解决方案


推荐阅读