| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace App\Module\AppGame\Handler\Public;
- use App\Module\AppGame\Handler\BaseHandler;
- use Google\Protobuf\Internal\Message;
- use Illuminate\Support\Facades\Log;
- use Uraus\Kku\Request\RequestPublicLogin4urs;
- use Uraus\Kku\Response\ResponsePublicLogin4urs;
- use Uraus\Kku\Response\LastLoginInfo;
- /**
- * 处理URS login4urs登录请求
- *
- * 使用URS的手机号+密码进行登录,自动创建用户并同步推荐关系
- */
- class Login4ursHandler extends BaseHandler
- {
- /**
- * 是否需要登录
- *
- * @var bool
- */
- protected bool $need_login = false;
- /**
- * 处理login4urs登录请求
- *
- * @param RequestPublicLogin4urs $data 登录请求数据
- * @return ResponsePublicLogin4urs 登录响应
- */
- public function handle(Message $data): Message
- {
- $mobile = '';
- $password = '';
- try {
- Log::info('Login4urs登录请求开始处理');
- // 1. 验证登录参数
- $mobile = $data->getMobile();
- $password = $data->getPassword();
- Log::info('获取登录参数', [
- 'mobile' => $mobile,
- 'has_password' => !empty($password)
- ]);
- if (empty($mobile)) {
- Log::error('手机号验证失败', ['error' => '手机号不能为空']);
- throw new \Exception('手机号不能为空');
- }
- if (empty($password)) {
- Log::error('密码验证失败', ['error' => '密码不能为空']);
- throw new \Exception('密码不能为空');
- }
- // 2. 使用Login4uHandler的公共静态方法处理URS登录逻辑
- $loginResult = Login4uHandler::processUrsLoginByMobilePassword($mobile, $password);
- // 3. 创建响应对象
- $response = new ResponsePublicLogin4urs();
- $response->setToken($loginResult['sessionId']);
- // 设置用户状态(默认不封禁)
- $response->setIsProhibit(false);
- // 设置最后登录信息
- $lastLoginInfo = new LastLoginInfo();
- $lastLoginInfo->setLastLoginTimes(time());
- $response->setLastLoginInfo($lastLoginInfo);
- Log::info('URS login4urs登录成功', [
- 'mobile' => $mobile,
- 'urs_user_id' => $loginResult['ursUserId'],
- 'farm_user_id' => $loginResult['farmUserId'],
- 'session_id' => $loginResult['sessionId']
- ]);
- return $response;
- } catch (\Exception $e) {
- Log::error('URS login4urs登录失败', [
- 'mobile' => $mobile ?? '',
- 'has_password' => !empty($password),
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
- throw $e;
- }
- }
- }
|