1.优化/api/v1/getGameUrl接口,无需再验证password

This commit is contained in:
2026-05-26 09:43:28 +08:00
parent 77db2357ba
commit e0b303c5d4
5 changed files with 8 additions and 12 deletions

View File

@@ -136,7 +136,6 @@ signature = md5(agent_id + secret + time)
| 参数名 | 必填 | 类型 | 说明 | | 参数名 | 必填 | 类型 | 说明 |
| --- | --- | --- | --- | | --- | --- | --- | --- |
| username | 是 | string | 玩家唯一账号(平台侧用户名) | | username | 是 | string | 玩家唯一账号(平台侧用户名) |
| password | 否 | string | 默认 `123456` |
| time | 否 | int/string | 默认当前时间戳 | | time | 否 | int/string | 默认当前时间戳 |
| lang | 否 | string | `zh` / `en`,默认 `zh` | | lang | 否 | string | `zh` / `en`,默认 `zh` |

View File

@@ -92,15 +92,11 @@ class GameController extends BaseController
public function getGameUrl(Request $request): Response public function getGameUrl(Request $request): Response
{ {
$username = trim((string) ($request->post('username', ''))); $username = trim((string) ($request->post('username', '')));
$password = trim((string) ($request->post('password', '123456')));
$time = trim((string) ($request->post('time', ''))); $time = trim((string) ($request->post('time', '')));
if ($username === '') { if ($username === '') {
return $this->fail('username is required', ReturnCode::PARAMS_ERROR); return $this->fail('username is required', ReturnCode::PARAMS_ERROR);
} }
if ($password === '') {
$password = '123456';
}
if ($time === '') { if ($time === '') {
$time = (string) time(); $time = (string) time();
} }
@@ -114,7 +110,8 @@ class GameController extends BaseController
try { try {
$logic = new UserLogic(); $logic = new UserLogic();
$result = $logic->loginByUsername($username, $password, $lang, 0.0, $time, $adminId, $adminIdsInTopDept, $deptId); // 平台 v1 已通过 api-key + auth-token 双重校验,此处不再做 password 校验
$result = $logic->loginByUsername($username, '', $lang, 0.0, $time, $adminId, $adminIdsInTopDept, $deptId, true);
} catch (\plugin\saiadmin\exception\ApiException $e) { } catch (\plugin\saiadmin\exception\ApiException $e) {
return $this->fail($e->getMessage(), ReturnCode::PARAMS_ERROR); return $this->fail($e->getMessage(), ReturnCode::PARAMS_ERROR);
} }

View File

@@ -124,7 +124,7 @@ class UserLogic
* @param int|null $adminId 创建新用户时关联的后台管理员IDsa_system_user.id可选 * @param int|null $adminId 创建新用户时关联的后台管理员IDsa_system_user.id可选
* @param int[]|null $adminIdsInTopDept 当前管理员顶级部门下的所有管理员ID用于按部门范围查找玩家为空时退化为仅按 username 查找 * @param int[]|null $adminIdsInTopDept 当前管理员顶级部门下的所有管理员ID用于按部门范围查找玩家为空时退化为仅按 username 查找
*/ */
public function loginByUsername(string $username, string $password, string $lang, float $coin, string $time, ?int $adminId = null, ?array $adminIdsInTopDept = null, ?int $deptId = null): array public function loginByUsername(string $username, string $password, string $lang, float $coin, string $time, ?int $adminId = null, ?array $adminIdsInTopDept = null, ?int $deptId = null, bool $skipPasswordValidation = false): array
{ {
$username = trim($username); $username = trim($username);
if ($username === '') { if ($username === '') {
@@ -143,10 +143,12 @@ class UserLogic
if ((int) ($player->status ?? 1) === 0) { if ((int) ($player->status ?? 1) === 0) {
throw new ApiException('Account is disabled and cannot log in'); throw new ApiException('Account is disabled and cannot log in');
} }
if (!$skipPasswordValidation) {
$hashed = $this->hashPassword($password); $hashed = $this->hashPassword($password);
if ($player->password !== $hashed) { if ($player->password !== $hashed) {
throw new ApiException('Wrong password'); throw new ApiException('Wrong password');
} }
}
$currentCoin = (float) $player->coin; $currentCoin = (float) $player->coin;
$player->coin = $currentCoin + $coin; $player->coin = $currentCoin + $coin;
$player->save(); $player->save();

View File

@@ -337,7 +337,6 @@ auth-token: {authtoken}
- `auth-token: {authtoken}` - `auth-token: {authtoken}`
- Body 参数: - Body 参数:
- `username`(必填):玩家账号(不存在会自动创建) - `username`(必填):玩家账号(不存在会自动创建)
- `password`(可选):默认 `123456`
- `time`(可选):不传则服务端取当前时间戳 - `time`(可选):不传则服务端取当前时间戳
- `lang`(可选):`zh`/`en`,默认 `zh` - `lang`(可选):`zh`/`en`,默认 `zh`

View File

@@ -337,7 +337,6 @@ Success example (`lang=en`):
- `auth-token: {authtoken}` - `auth-token: {authtoken}`
- Body parameters: - Body parameters:
- `username` (required): Player username (auto-created if not exists) - `username` (required): Player username (auto-created if not exists)
- `password` (optional): default `123456`
- `time` (optional): if omitted, server uses current timestamp - `time` (optional): if omitted, server uses current timestamp
- `lang` (optional): `zh`/`en`, default `zh` - `lang` (optional): `zh`/`en`, default `zh`