hashids 一个可以把数字加盐编码成不可预测的字符串的库。

示例代码 PHP

use Hashids\Hashids;
require 'vendor/autoload.php';
$hid = new Hashids("salt");
var_dump($hash = $hid->encode(101, 202, 303));
var_dump($hid->decode($hash));

/** output
string(9) "7nZURqhoq"
array(3) {
  [0] =>
  int(101)
  [1] =>
  int(202)
  [2] =>
  int(303)
}
*/

示例代码 Java

class Main
    public static void main(String[] args) {
        var hid = new Hashids("salt");
        var hrs = hid.encode(101, 202, 303);
        System.out.println(hrs);
        System.out.println(Arrays.toString(hid.decode(hrs)));
    }
}

/** output
7nZURqhoq
[101, 202, 303]
*/