$ch) { if ($ch === self::$b) { break; } $index = array_search($ch, self::$r, true); if ($index === false) { continue; } $res = $i === 0 ? $index : $res * self::$binLen + $index; } return $res; } /** * 雪花 ID(需引入 PHP 雪花 ID 工具) * 推荐使用: https://github.com/Gerardojbaez/laravel-snowflake 或你自己的封装 * * @return int */ public static function getSnowFlakeId(): int { // 简化版本,实际应使用类库如 Godruoyi\Snowflake if (!class_exists('Snowflake')) { throw new \RuntimeException("Snowflake class not found."); } return Random::generateRandomPrefixedId(); } /** * 进制转换编码主逻辑 * * @param int $id * @return string */ private static function encodeBase(int $id): string { $buf = []; do { $index = $id % self::$binLen; array_unshift($buf, self::$r[$index]); $id = intdiv($id, self::$binLen); } while ($id > 0); return implode('', $buf); } }