@rx-frontend/php-sign
v0.4.5
Published
用于与PHP端对接使用的接口参数(`json`或`form`)签名生成工具
Readme
PHP对接签名
用于与PHP端对接使用的接口参数(json或form)签名生成工具
支持浏览器和uni小程序
使用
安装
pnpm i @rx-frontend/php-sign
yarn add @rx-frontend/php-sign
npm i @rx-frontend/php-sign基本用法
import { sign } from '@rx-frontend/php-sign';
const SIGN_KEY = 'sepveneto';
sign.SIGN_KEY = SIGN_KEY;
const mock = { id: 1, name: 'vv' };
sign(mock)可配置参数
| 名称 | 类型 | 必填 | 默认值 | 说明 | | -- | --- | --- | --- | --- | | SIGN_KEY | string | ✔| - | 签名密钥 | | log | boolean | ✘ | - | 是否需要在控制台输出md5加密前的结果 | | reserveFalse | boolean | ✘ | - | 签名时是否保留false | | reserveEmptyString | boolean | ✘ | - | 签名时是否保留空字符串 | | reserveNull | boolean | ✘ | - | 签名时是否保留null | | normalizeTrue | string | number | boolean | ✘ | 1 | 签名时将true转换成其它内容 |
生成结果
除原始参数外,会额外附带随机字符串nonce和时间戳timestamp
{
...res,
nonce: string,
timestamp: string,
}说明
- 生成结果默认会带有
timestamp和nonce,因此如果原始参数中带有timestamp和nonce会覆盖原始参数的内容 - 如果需要添加签名的数据是表单类型,那么只有非
Blob的值会参与签名,比如
const file = new File(['foo'], 'foo.txt', {
type: 'text/plain',
})
const form = new FormData()
form.append('file', file)
form.append('name', 'sepveneto')最终参与签名的字段是name,nonce和timestamp
