1.优化/api/v1/getGameUrl接口,无需再验证password
This commit is contained in:
@@ -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` |
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ class UserLogic
|
|||||||
* @param int|null $adminId 创建新用户时关联的后台管理员ID(sa_system_user.id),可选
|
* @param int|null $adminId 创建新用户时关联的后台管理员ID(sa_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,9 +143,11 @@ 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');
|
||||||
}
|
}
|
||||||
$hashed = $this->hashPassword($password);
|
if (!$skipPasswordValidation) {
|
||||||
if ($player->password !== $hashed) {
|
$hashed = $this->hashPassword($password);
|
||||||
throw new ApiException('Wrong password');
|
if ($player->password !== $hashed) {
|
||||||
|
throw new ApiException('Wrong password');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$currentCoin = (float) $player->coin;
|
$currentCoin = (float) $player->coin;
|
||||||
$player->coin = $currentCoin + $coin;
|
$player->coin = $currentCoin + $coin;
|
||||||
|
|||||||
@@ -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`
|
||||||
|
|
||||||
|
|||||||
@@ -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`
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user