Download the PHP package petalbranch/jpt without Composer

On this page you can find all versions of the php package petalbranch/jpt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package jpt

Json Petal Token (JPT)

PHP Version License Stable

🌏 语言/Language

📘 简介

PetalBranch/jpt (Json Petal Token) 是一个轻量级、安全且灵活的 PHP 令牌生成与验证库。

不同于传统的 JWT,JPT 引入了 "Petal" (花瓣) 概念,支持部分数据加密 。它采用独特的三段式结构,既保留了公开数据的透明性,又通过加密段确保存储在客户端的敏感数据(如用户手机号、邮箱等)不被泄露。

✨ 特性

📦 安装

推荐使用 Composer 进行安装:

🚀 快速开始

  1. 生成 Token 并获取元数据

  2. 验证 Token

⚙️ 配置选项

初始化 Jpt 类时支持以下配置参数:

参数键名 类型 默认值 说明
secret string '' 必填。用于签名和加密的密钥,请确保复杂度。
iss string 'nameless' Token 的签发者标识。不建议使用 *
aud string 'nameless' Token 的接收方/受众标识。不建议使用 *
ttl int 3600 Token 的生命周期,单位为秒。
alg string 'HS256' 签名算法,支持 HS256, HS384, HS512。
leeway int 0 时间容差(秒),允许服务器时间存在微小偏差。
allowed_issuers array [] 验证白名单。若包含 * 则允许任意签发人 (跳过验证);否则需精确匹配。
allowed_audiences array [] 验证白名单。若包含 * 则允许任意受众 (跳过验证);否则需精确匹配。

📚 令牌结构

结构 名称 (Name) 编码/加密 (Encoding) 可见性 (Visibility) 用途 (Usage)
Crown 花冠 (Header & Public Payload) Base64URL 🔓 公开 (Public) 存放元数据(算法、类型)及非敏感业务数据(如 UserID、权限等级)。相当于 JWT 的 Header+Payload。
Petal 花瓣 (Private Payload) PetalCipher 🔒 私密 (Private) 存放敏感业务数据(如手机号、邮箱、内部ID)及完整性摘要。仅持有密钥的服务端可解密。
Thorn 花刺 (Signature) HMAC 🛡️ 签名 (Signature) 防止 Token 被篡改。对 Crown 和 Petal 的密文进行签名。

结构示例:

🌟 JptPayload 捷径访问 (v1.3.0+)

Jpt 类提供了一种捷径访问方式,用于读取嵌套数据。

基本语法

场景对比

场景 旧写法 (传统方法) 新写法 (捷径访问)
读取深层数据 $payload->getCrownData('user')['profile']['name']
(需手动确保中间层级存在)
$payload('c.user.profile.name')
读取加密数据 $data = $payload->getPetalData('contact');
$phone = $data['phone'] ?? '';
$payload('p.contact.phone')
带默认值 ($d = $payload->getCrownData('u')) ? ($d['id']??0) : 0 $payload('c.user.id') ?? 0
动态键名 需拼接数组或复杂逻辑 $payload("c.user.$dynamicKey")

高级用法:多参数模式

如果您的键名中本身包含点号 (.),或者需要动态拼接路径,可以传入多个参数:

📖 API 参考手册

1. Jpt 类 (核心操作)

基础配置 (Chainable)

支持链式调用,用于动态修改初始化时的配置。

数据装载 (Chainable)

用于设置 Token 内携带的业务数据。

核心动作


2. JptPayload 类 (结果对象)

validate()toJptPayload() 的返回结果,所有属性均为 Readonly

公开属性

可以直接访问以下属性:

⚠️ 重要提示 (破坏性变更): 旧属性 $payload->payload 已在 v1.3.0 中被彻底移除

  • 该属性仅在 v1.2.x 版本中可用。
  • v1.3.0 及更高版本中,访问 $payload->payload 将导致错误。
  • 请务必使用 $payload->raw 替代。

辅助方法

📜 更新日志

[1.3.2] - 2026-03-14

Changed

Fixed

⚠️ 重要迁移提示 (Breaking Change): 属性 $payload->payload 已于 v1.3.0 正式移除

  • 错误用法 (v1.3.0+): $token = $payload->payload; (将抛出异常)
  • 正确用法: $token = $payload->raw;

请确保您的代码已更新至使用 raw 属性。

👀 历史更新

📄 许可证

本项目遵循 Apache License 2.0 开源协议。


All versions of jpt with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
petalbranch/petal-cipher Version ^1.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package petalbranch/jpt contains the following files

Loading the files please wait ...