// +---------------------------------------------------------------------- declare(strict_types=1); namespace addon\appmall\model; use ywxapp\model\BaseModel; /** * 插件授权(中心站) * 表:appmall_addon_licenses * @mixin \think\Model */ class AddonLicense extends BaseModel { protected function getOptions(): array { return [ 'strict' => true, 'name' => 'appmall_addon_licenses', 'autoWriteTimestamp' => 'int', 'readonly' => ['uid'], 'createTime' => 'create_at', 'updateTime' => 'update_at', ]; } /** * 关联插件信息(核心插件注册表) * @return \think\model\relation\BelongsTo */ public function addon() { return $this->belongsTo(\ywxapp\model\AddonModel::class, 'aid', 'id'); } /** * 生成安全签名(防链接泄漏) * @param string $licenseKey 授权码 * @param int $aid 插件ID * @param int $timestamp 时间戳 * @param string $secret 签名密钥(仅作 HMAC key,不要拼进消息) * @return string */ public function generateSign(string $licenseKey, int $aid, int $timestamp, string $secret): string { $str = $licenseKey . $aid . $timestamp; return hash_hmac('sha256', $str, $secret); } }