优化所有接口使用form-data类型
This commit is contained in:
@@ -71,7 +71,10 @@ class GameController extends OpenController
|
|||||||
{
|
{
|
||||||
$userId = (int) ($request->player_id ?? 0);
|
$userId = (int) ($request->player_id ?? 0);
|
||||||
$direction = $request->post('direction');
|
$direction = $request->post('direction');
|
||||||
if (!in_array($direction, ['0', '1'], true)) {
|
if ($direction !== null) {
|
||||||
|
$direction = (int) $direction;
|
||||||
|
}
|
||||||
|
if (!in_array($direction, [0, 1], true)) {
|
||||||
return $this->fail('direction 必须为 0 或 1', ReturnCode::PARAMS_ERROR);
|
return $this->fail('direction 必须为 0 或 1', ReturnCode::PARAMS_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,26 +19,20 @@ use plugin\saiadmin\basic\OpenController;
|
|||||||
class UserController extends OpenController
|
class UserController extends OpenController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* 登录(JSON body)
|
* 登录(form-data 参数)
|
||||||
* POST /api/user/Login
|
* POST /api/user/Login
|
||||||
* body: { "username": "+60123456789", "password": "123456", "lang": "chs", "coin": 2000.00, "time": 1772692089 }
|
* body: username, password, lang(可选), coin(可选), time(可选)
|
||||||
* 根据 username 查找或创建 DicePlayer,按 coin 增减平台币,会话写 Redis,返回带 token 的连接地址
|
* 根据 username 查找或创建 DicePlayer,按 coin 增减平台币,会话写 Redis,返回带 token 的连接地址
|
||||||
*/
|
*/
|
||||||
public function Login(Request $request): Response
|
public function Login(Request $request): Response
|
||||||
{
|
{
|
||||||
$body = $request->rawBody();
|
$username = trim((string) ($request->post('username', '')));
|
||||||
if ($body === '' || $body === null) {
|
$password = trim((string) ($request->post('password', '')));
|
||||||
return $this->fail('请提交 JSON body', ReturnCode::PARAMS_ERROR);
|
$lang = trim((string) ($request->post('lang', 'chs')));
|
||||||
}
|
$coin = $request->post('coin');
|
||||||
$data = json_decode($body, true);
|
$coin = $coin !== null && $coin !== '' ? (float) $coin : 0.0;
|
||||||
if (!is_array($data)) {
|
$time = $request->post('time');
|
||||||
return $this->fail('JSON 格式错误', ReturnCode::PARAMS_ERROR);
|
$time = $time !== null && $time !== '' ? (string) $time : (string) time();
|
||||||
}
|
|
||||||
$username = trim((string) ($data['username'] ?? ''));
|
|
||||||
$password = trim((string) ($data['password'] ?? ''));
|
|
||||||
$lang = trim((string) ($data['lang'] ?? 'chs'));
|
|
||||||
$coin = isset($data['coin']) ? (float) $data['coin'] : 0.0;
|
|
||||||
$time = isset($data['time']) ? (string) $data['time'] : (string) time();
|
|
||||||
if ($username === '' || $password === '') {
|
if ($username === '' || $password === '') {
|
||||||
return $this->fail('username、password 不能为空', ReturnCode::PARAMS_ERROR);
|
return $this->fail('username、password 不能为空', ReturnCode::PARAMS_ERROR);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user