encode number 1 but got different values in laravel and hyperf project
jimmyyem opened this issue · 2 comments
jimmyyem commented
The package versions:
hashids/hashids version 4.1.0
Laravel version 9.19
Hyperf version 2.2.33
PHP version 8.0.23
$number = 1;
I encode $number in laravel project got : 4ZMEKQEV
But in hyperf project I got: JWLY3P24
the code for laravel and hyperf:
<?php
namespace App\Lib;
use Hashids\Hashids;
class HashId
{
public static $instance;
public static function getInstance(
int $length = 8,
string $alphabet = 'ABCDEFGHJKLMNPQRSTUVWXYZ1234567890'
): Hashids {
if (is_null(self::$instance)) {
$salt = config('HASHIDS_KEY');
self::$instance = new Hashids($salt, $length, $alphabet);
}
return self::$instance;
}
}
// use the App/Lib/Hashid to encode number
$number = HashId::getInstance()->encode(1);
echo $number;
xiaohuilam commented
Key reason for the problem possible is the salt.
jimmyyem commented
Key reason for the problem possible is the salt.
I checked that again, you're right. Thanks man.