github: https://github.com/cdoco/hashids.phpc.git
一个可以生成类似于 YouTuBe 那种唯一字符串 ID 的功能,可以对用户隐藏数据库中的真正数字 ID
原来有纯 php 代码实现的一个功能,现在把它封装成了一个 php 扩展,性能比纯 php 的版本提升了百倍左右
使用也比较简单:
$hashids = new Hashids();
$hash = $hashids->encode(1, 2, 3, 4, 5); // ADf9h9i0sQ
$numbers = $hashids->decode($hash); // [1, 2, 3, 4, 5]
//你还可以直接使用静态方法
$hash = Hashids::encode(1, 2, 3, 4, 5); // ADf9h9i0sQ
$numbers = Hashids::decode($hash); // [1, 2, 3, 4, 5]
如果你项目中需要这种加密数字 id 的功能,可以试用下这个扩展 😆~