hashids 隐藏真实id

最后更新于:2022-04-02 02:23:43

[TOC] > [github](https://github.com/vinkla/hashids) ## 安装 `$ composer require hashids/hashids ` ## 使用 ### 简单demo ``` use Hashids\Hashids; $hashids = new Hashids(); echo $res = $hashids->encode(1).PHP_EOL;//jR print_r($hashids->decode($res));//Array ( [0] => 1 ) ``` ### 多种传入方式 ``` use Hashids\Hashids; $hashids = new Hashids(); $hashids->encode(1, 2, 3); // o2fXhV $hashids->encode([1, 2, 3]); // o2fXhV $hashids->encode('1', '2', '3'); // o2fXhV $hashids->encode(['1', '2', '3']); // o2fXhV ``` ### 加入盐 ``` use Hashids\Hashids; $hashids = new Hashids('My Project'); $hashids->encode(1, 2, 3); // Z4UrtW $hashids = new Hashids('My Other Project'); $hashids->encode(1, 2, 3); // gPUasb ``` ### 填充长度 ``` use Hashids\Hashids; $hashids = new Hashids(); // no padding $hashids->encode(1); // jR $hashids = new Hashids('', 10); // pad to length 10 $hashids->encode(1); // VolejRejNm ``` ### 16进制 php 7+ ``` use Hashids\Hashids; $hashids = new Hashids(); $id = $hashids->encodeHex('507f1f77bcf86cd799439011'); // y42LW46J9luq3Xq9XMly $hex = $hashids->decodeHex($id); // 507f1f77bcf86cd799439011 ```
';