1.安装
composer require vinkla/hashids
2.注册服务提供者
在bootsrap/app.php
$app->register(Vinkla\Hashids\HashidsServiceProvider::class);
3.配置
vendor\vinkla\hashids\config\hashids.php
4.调用
use Vinkla\Hashids\Facades\Hashids;
var_dump(Hashids::encode(4815162342)); var_dump(Hashids::decode('R164qykq6lDn5RKOpjeV'));
5.结果
string(20) "R164qykq6lDn5RKOpjeV" array(1) { [0]=> int(4815162342) }
==========================================================
错误:缺少扩展
lumen.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Call to undefined function Hashids\bcmod() in /var/www/html/im_api/vendor/hashids/hashids/src/Math.php:103 Stack trace:
解决:
在docker里的php环境/usr/local/bin下
执行./docker-php-ext-install bcmath