任务时间: 2025年06月28日 15:00-15:30
任务类型: 功能重构和扩展
模块: AppGame、ThirdParty、URS
根据用户需求,完成以下工作:
RequestPublicLogin4urs 的 HandlerLogin4uHandler 的公共逻辑提取为公开的静态方法Login4ursHandler 调用 Login4uHandler 的公共静态方法文件: ThirdParty/Urs/Request/UrsLoginRequest.php
功能:
使用方式:
use ThirdParty\Urs\Request\UrsLoginRequest;
$request = new UrsLoginRequest();
$result = $request->request([
'mobile' => '18600648353',
'password' => 'a123123'
]);
文件: ThirdParty/Urs/Services/UrsService.php
新增方法:
public static function login(string $mobile, string $password): array
文件: app/Module/AppGame/Handler/Public/Login4uHandler.php
重构内容:
processUrsLoginByUserKey(string $userKey): array
processUrsLoginByMobilePassword(string $mobile, string $password): array
completeUrsLogin(int $ursUserId, int $farmUserId, string $userKey): array
syncReferralRelations(int $ursUserId, int $farmUserId): bool
triggerUserEnteredFarmEvent(int $ursUserId, int $farmUserId, string $userKey): void
getUrsUserInfoByUserKey(string $keylogin): array
文件: app/Module/AppGame/Handler/Public/Login4ursHandler.php
功能:
RequestPublicLogin4urs 请求Login4uHandler 的公共静态方法ResponsePublicLogin4urs 响应核心逻辑:
public function handle(Message $data): Message
{
$mobile = $data->getMobile();
$password = $data->getPassword();
// 调用Login4uHandler的公共静态方法
$loginResult = Login4uHandler::processUrsLoginByMobilePassword($mobile, $password);
$response = new ResponsePublicLogin4urs();
$response->setToken($loginResult['sessionId']);
return $response;
}
文件: app/Module/ThirdParty/Commands/TestUrsLoginCommand.php
命令: php artisan thirdparty:test-urs-login
文件: app/Module/AppGame/Commands/TestLogin4ursCommand.php
命令: php artisan test:login4urs
测试选项:
--static: 测试静态方法--direct: 测试Handler类(模拟)文件: ThirdParty/Urs/Request/readme.md
文件: ThirdParty/Urs/readme.md
php artisan thirdparty:test-urs-login
# ✅ 测试通过,成功获取用户ID和用户密钥
php artisan test:login4urs --static
# ✅ 测试通过,所有静态方法正常工作
php artisan test:login4urs
# ✅ 测试通过,Handler逻辑正确
Login4uHandlerLogin4ursHandler问题: 两个Handler使用了不同的Response类型
Login4uHandler 使用 ResponsePublicLogin4uLogin4ursHandler 使用 ResponsePublicLogin4urs初始尝试: 统一使用 ResponsePublicLogin4u
Handler must return instance of ResponsePublicLogin4urs, ResponsePublicLogin4u given根本原因发现: 通过分析protobuf定义发现
public_login4urs字段期望的类型是ResponsePublicLogin4uResponsePublicLogin4urs最终修复: 统一使用ResponsePublicLogin4u类型
Login4uHandler 使用 ResponsePublicLogin4uLogin4ursHandler 也使用 ResponsePublicLogin4u问题: 原有Handler只设置了token字段
修复: 设置完整的响应字段
// Login4uHandler
$response = new ResponsePublicLogin4u();
$response->setToken($loginResult['sessionId']);
$response->setIsProhibit(false);
$lastLoginInfo = new LastLoginInfo();
$lastLoginInfo->setLastLoginTimes(time());
$response->setLastLoginInfo($lastLoginInfo);
// Login4ursHandler
$response = new ResponsePublicLogin4u();
$response->setToken($loginResult['sessionId']);
$response->setIsProhibit(false);
$lastLoginInfo = new LastLoginInfo();
$lastLoginInfo->setLastLoginTimes(time());
$response->setLastLoginInfo($lastLoginInfo);
问题: 使用了错误的protobuf方法名 setLoginTime()
修复: 使用正确的方法名 setLastLoginTimes()
setLastLoginTimes()本次重构成功实现了:
通过 php artisan test:both-urs-handlers 命令验证:
重构后的代码具有更好的可维护性、可扩展性和可复用性,为后续的功能开发奠定了良好的基础。