Skip to content

Commit

Permalink
增加米游社接口
Browse files Browse the repository at this point in the history
  • Loading branch information
limingxinleo committed Jan 13, 2024
1 parent 206122b commit 3824945
Show file tree
Hide file tree
Showing 4 changed files with 422 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app/Constants/ContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace App\Constants;

use App\Exception\BusinessException;
use App\Schema\ContentTypeSchema;

enum ContentType: int
Expand Down Expand Up @@ -53,4 +54,15 @@ public static function all(): array

return $result;
}

public function checkContent(string $content): void
{
if ($this === self::YUAN_SHEN) {
$exploded = explode(PHP_EOL, $content);
$exploded = array_filter($exploded);
if (count($exploded) !== 2) {
throw new BusinessException(ErrorCode::PARAMS_INVALID, '原神类型,必须第一行传入米游社 UID,第二行传入登录后的 weblogin_token');
}
}
}
}
10 changes: 10 additions & 0 deletions app/Constants/ErrorCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ enum ErrorCode: int implements ErrorCodeInterface
*/
case SECRET_INVALID = 702;

/**
* @Message("访问米哈游服务器报错")
*/
case REQUEST_MIHOYO_FAILED = 703;

/**
* @Message("米哈游验证码登录失败")
*/
case REQUEST_MIHOYO_LOGIN_BY_MOBILE_CAPTCHA = 704;

/**
* @Message("参数错误")
*/
Expand Down
10 changes: 9 additions & 1 deletion app/Service/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,20 @@ public function list(int $secretId, UserAuth $userAuth): ContentListSchema

public function save(
int $id,
#[ArrayShape(['secret_id' => 'int', 'title' => 'string', 'content' => 'string', 'type' => 'int'])]
#[ArrayShape([
'secret_id' => 'int',
'title' => 'string',
'content' => 'string',
'type' => 'int',
])]
array $input,
UserAuth $userAuth
): bool {
$userAuth->build();

$type = ContentType::from($input['type']);
$type->checkContent($input['content']);

$secret = di()->get(SecretDao::class)->first((int) $input['secret_id'], true);
if ($secret->share_id > 0) {
throw new BusinessException(ErrorCode::CONTENT_CANNOT_SAVE_CAUSED_BY_SHARE);
Expand Down
Loading

0 comments on commit 3824945

Please sign in to comment.