farhadhp / zhaket-guard
一个用于 Zhaket 守护许可证系统的 PHP 库。
v2.0.1
2020-02-24 08:43 UTC
Requires
- php: >=7.0.0
- guzzlehttp/guzzle: ^6.5
This package is auto-updated.
Last update: 2024-09-29 05:29:43 UTC
README
图书管家(产品许可证)
库介绍
使用此库,您可以轻松地将 Zhaket 守护许可证系统添加到您的 WordPress 产品(主题和插件)中。
安装教程
要安装此库,请进入主题或插件的根目录,然后使用以下命令通过 Composer 安装。
composer require farhadhp/zhaket-guard
使用教程
首先,您需要在代码的起始处添加 Composer 的 autoload 文件。
require_once 'vendor/autoload.php';
然后,您可以通过以下代码调用 ZhaketGuard 库,从而访问其方法。请注意,该类是静态的,因此不需要从它创建对象。
use Farhadhp\ZhaketGuard\ZhaketGuard;
安装许可证
用户安装插件或主题后,首先需要从用户那里获取许可证。您可以在插件或主题的设置页面完成此操作。
获取用户许可证后,您可以使用以下代码完成许可证的安装过程。
$productToken = 'f2352e4a-4545-4c86-8790-454545'; // توکن محصول شما
$license = 'f2352e4a-82c8-4c86-8790-23234323'; // لایسنس وارد شده توسط کاربر
$res = ZhaketGuard::installLicense($productToken, $license);
if ($res->status=='successful') {
// Lisence successfuly installed
echo $res->message;
} else {
// License not installed / show message
if (!is_object($res->message)) {
echo $res->message;
} else {
foreach ($res->message as $message) {
foreach ($message as $msg) {
echo $msg.'<br>';
}
}
}
}
最好在成功后,将用户许可证也存储到数据库中,以便在需要时进行重新检查。
检查许可证有效性
要检查许可证的有效性,您可以像下面这样使用 isValidLicense 方法。
$license = 'f2352e4a-82c8-4c86-8790-23234323'; // لایسنس وارد شده توسط کاربر
$res = ZhaketGuard::isValidLicense($license);
if ($res->status=='successful') {
// Lisence is valid
echo $res->message;
} else {
// License not valid
// show errors
if (!is_object($res->message)) {
echo $res->message;
} else {
foreach ($res->message as $message) {
foreach ($message as $msg) {
echo $msg.'<br>';
}
}
}
}
使用该方法,您可以在特定时间段或需要时检查许可证的过程。最好使用 WordPress 的 schedule 功能,每 24 小时检查一次。