diff --git a/application/common/service/SplitRedirectService.php b/application/common/service/SplitRedirectService.php index 86c3af3..09f9db5 100755 --- a/application/common/service/SplitRedirectService.php +++ b/application/common/service/SplitRedirectService.php @@ -195,7 +195,8 @@ class SplitRedirectService $keys = array_keys($groups); if (count($keys) === 1) { - return $keys[0]; + // PHP 会把纯数字字符串键转成 int,需强转以匹配 ?string 返回类型 + return (string) $keys[0]; } $r = random_int(1, $total); @@ -203,11 +204,11 @@ class SplitRedirectService foreach ($groups as $key => $rows) { $acc += count($rows); if ($r <= $acc) { - return $key; + return (string) $key; } } - return $keys[0]; + return (string) $keys[0]; } /** diff --git a/patches/application/common/service/SplitRedirectService.php b/patches/application/common/service/SplitRedirectService.php index 86c3af3..09f9db5 100755 --- a/patches/application/common/service/SplitRedirectService.php +++ b/patches/application/common/service/SplitRedirectService.php @@ -195,7 +195,8 @@ class SplitRedirectService $keys = array_keys($groups); if (count($keys) === 1) { - return $keys[0]; + // PHP 会把纯数字字符串键转成 int,需强转以匹配 ?string 返回类型 + return (string) $keys[0]; } $r = random_int(1, $total); @@ -203,11 +204,11 @@ class SplitRedirectService foreach ($groups as $key => $rows) { $acc += count($rows); if ($r <= $acc) { - return $key; + return (string) $key; } } - return $keys[0]; + return (string) $keys[0]; } /**