栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP > php开源框架 > tpAdmin

id加密 - tpAdmin 文档

tpAdmin 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

id加密 - tpAdmin 文档


id 加密使用的是 [Hashids](http://hashids.org/),支持自定义字符串库和生成加密字符串的长度,使用对称加密,详细介绍请到Hashids官网查看 [http://hashids.org/](http://hashids.org/)

##配置
```
return [
// Hashids 的配置项
'length' => 8, // 加密字符串长度
'salt' => 'tpadmin', // 加密盐值
'alphabet' => '', // 字符仓库,不填写默认为扩展里的字符仓库
];
```

##方法
`HashidsHashids::instance($length = null, $salt = null, $alphabet = null)`
```
// id 加密
HashidsHashids::instance($length = null, $salt = null, $alphabet = null)->encode($id)
// id 解密
HashidsHashids::instance($length = null, $salt = null, $alphabet = null)->decode($hashedStr)
```
##参数
| 名称 | 类型 | 说明 |
| --- | --- | --- |
| length | int | 加密生成字符串长度 |
| salt | string | 加密盐值 |
| alphabet | string | 加密用到字符串的字符串库 |

##使用示例
```
$id = $this->request->post("id");
$hashids = HashidsHashids::instance(8, "tpadmin");
$encode_id = $hashids->encode($id); //加密
$decode_id = $hashids->decode($encode_id); //解密
return ajax_return_adv("操作成功", '', false, '', '', ['encode' => $encode_id, 'decode' => $decode_id]);
```

##助手函数
`hashids($length = null, $salt = null, $alphabet = null)`
```
hashids($length=null,$salt=null,$alphabet=null)->encode('你的字符串')
hashids($length=null,$salt=null,$alphabet=null)->decode('需要解密的字符串')
```

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/214023.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号