| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- namespace App\Module\AppGame\Commands;
- use Illuminate\Console\Command;
- use App\Module\AppGame\Handler\Public\Login4uHandler;
- /**
- * 测试两个URS Handler的完整功能
- *
- * 验证Login4uHandler和Login4ursHandler都能正确工作
- */
- class TestBothUrsHandlersCommand extends Command
- {
- /**
- * 命令签名
- *
- * @var string
- */
- protected $signature = 'test:both-urs-handlers
- {userkey? : 用户密钥,默认使用测试密钥}
- {mobile? : 手机号码,默认使用测试账号}
- {password? : 登录密码,默认使用测试密码}';
- /**
- * 命令描述
- *
- * @var string
- */
- protected $description = '测试两个URS Handler的完整功能';
- /**
- * 执行命令
- *
- * @return int
- */
- public function handle(): int
- {
- $this->info('=== 两个URS Handler完整功能测试 ===');
- $this->info('测试Login4uHandler和Login4ursHandler');
- $this->newLine();
- try {
- // 获取测试参数
- $userKey = $this->argument('userkey') ?? '$2y$10$vSeIMeziuwcio10eTvLRiuXwSFtSWmVrOqMbewgrbszFfckwmP1bw';
- $mobile = $this->argument('mobile') ?? '18600648353';
- $password = $this->argument('password') ?? 'a123123';
- $this->info("🔑 测试用户密钥: " . substr($userKey, 0, 20) . '...');
- $this->info("📱 测试手机号: {$mobile}");
- $this->info("🔐 测试密码: " . str_repeat('*', strlen($password)));
- $this->newLine();
- // 测试Login4ursHandler(手机号密码登录)
- $this->testLogin4ursHandler($mobile, $password);
- $this->newLine();
- // 测试Login4uHandler(也使用手机号密码登录)
- $this->testLogin4uHandlerWithMobilePassword($mobile, $password);
- $this->newLine();
- $this->info('✅ 两个URS Handler完整功能测试完成');
- return 0;
- } catch (\Exception $e) {
- $this->error('❌ 测试失败: ' . $e->getMessage());
- $this->error('错误详情: ' . $e->getTraceAsString());
- return 1;
- }
- }
- /**
- * 测试Login4uHandler(使用手机号密码)
- *
- * @param string $mobile
- * @param string $password
- */
- protected function testLogin4uHandlerWithMobilePassword(string $mobile, string $password): void
- {
- $this->info('🔍 测试Login4uHandler(使用手机号密码静态方法)...');
- try {
- // 使用静态方法处理登录
- $loginResult = Login4uHandler::processUrsLoginByMobilePassword($mobile, $password);
- // 验证响应
- $this->info(' 📋 Login4uHandler测试结果:');
- $this->info(" ✅ 会话ID: {$loginResult['sessionId']}");
- $this->info(" ✅ 农场用户ID: {$loginResult['farmUserId']}");
- $this->info(" ✅ URS用户ID: {$loginResult['ursUserId']}");
- if (isset($loginResult['user'])) {
- $user = $loginResult['user'];
- $this->info(" ✅ 用户名: {$user->username}");
- }
- $this->info(' ✅ Login4uHandler静态方法调用成功');
- } catch (\Exception $e) {
- $this->error(' ❌ Login4uHandler测试失败: ' . $e->getMessage());
- throw $e;
- }
- }
- /**
- * 测试Login4ursHandler
- *
- * @param string $mobile
- * @param string $password
- */
- protected function testLogin4ursHandler(string $mobile, string $password): void
- {
- $this->info('🔍 测试Login4ursHandler(使用静态方法)...');
- try {
- // 使用静态方法处理登录
- $loginResult = Login4uHandler::processUrsLoginByMobilePassword($mobile, $password);
- // 验证响应
- $this->info(' 📋 Login4ursHandler测试结果:');
- $this->info(" ✅ 会话ID: {$loginResult['sessionId']}");
- $this->info(" ✅ 农场用户ID: {$loginResult['farmUserId']}");
- $this->info(" ✅ URS用户ID: {$loginResult['ursUserId']}");
- if (isset($loginResult['user'])) {
- $user = $loginResult['user'];
- $this->info(" ✅ 用户名: {$user->username}");
- }
- $this->info(' ✅ Login4ursHandler静态方法调用成功');
- } catch (\Exception $e) {
- $this->error(' ❌ Login4ursHandler测试失败: ' . $e->getMessage());
- throw $e;
- }
- }
- }
|