数据库主键 id 尽量不要暴露出去,找到了这个库 # vinkla/hashids
1
2composer require hashids/hashids
1<?php
2use Hashids\Hashids;
3
4$hashids = new Hashids();
5
6$id = $hashids->encode(1, 2, 3); // o2fXhV
7$numbers = $hashids->decode($id); // [1, 2, 3]
1<?php
2use Hashids\Hashids;
3
4$salt = '';//
5$minLength = 0;
6$str = 'abcdefghijklmnopqrstuvwxyz';
7$hashids = new Hashids($salt, 0, $str); // all lowercase
8$hashids->encode(1, 2, 3); // mdfphx
1<?php
2use Hashids\Hashids;
3$hashids = new Hashids();
4$id = $hashids->encodeHex('507f1f77bcf86cd799439011'); // y42LW46J9luq3Xq9XMly
5$hex = $hashids->decodeHex($id); // 507f1f77bcf86cd799439011