encode(...$numbers); } /** * 解密 * * @param string $hash * @return array|mixed * @throws \Exception */ public static function decode(string $hash) { $data = self::getHashIds()->decode($hash); if (empty($data) || !is_array($data)) { throw new \Exception('解密失败'); } return count($data) == 1 ? $data[0] : $data; } /** * 获取 HashIds 实例 * * @return Hashids */ private static function getHashIds(): Hashids { if (!self::$hashIds instanceof Hashids) { self::$hashIds = new Hashids(self::$secretKey, self::$length); } return self::$hashIds; } }