Commit 22498f16c7c651370bb1f2f8e165ad68e27b59de
1 parent
a7998dcd
chore: enable full request/response logging for debug
Showing
2 changed files
with
21 additions
and
1 deletions
| @@ -37,25 +37,34 @@ class AuthService | @@ -37,25 +37,34 @@ class AuthService | ||
| 37 | 37 | ||
| 38 | // 2. 如果有 phoneCode,获取真实手机号 | 38 | // 2. 如果有 phoneCode,获取真实手机号 |
| 39 | if ($phoneCode) { | 39 | if ($phoneCode) { |
| 40 | + $this->logDebug("Fetching phone with code: ... " . substr($phoneCode, -4)); | ||
| 40 | $realPhone = $this->getPhoneNumber($phoneCode); | 41 | $realPhone = $this->getPhoneNumber($phoneCode); |
| 42 | + $this->logDebug("Resolved phone number: " . ($realPhone ?: 'NULL')); | ||
| 41 | if ($realPhone) { | 43 | if ($realPhone) { |
| 42 | $phone = $realPhone; | 44 | $phone = $realPhone; |
| 43 | } | 45 | } |
| 44 | } | 46 | } |
| 45 | 47 | ||
| 48 | + $this->logDebug("Final Phone before check: " . ($phone ?: 'EMPTY')); | ||
| 49 | + | ||
| 46 | if (empty($phone)) { | 50 | if (empty($phone)) { |
| 51 | + $this->logDebug("Error: Phone is empty"); | ||
| 47 | return ['ok' => false, 'error' => '手机号不能为空']; | 52 | return ['ok' => false, 'error' => '手机号不能为空']; |
| 48 | } | 53 | } |
| 49 | 54 | ||
| 50 | // 3. 查找或创建用户 | 55 | // 3. 查找或创建用户 |
| 51 | $user = $this->findOrCreateUser($phone, $openid, $unionid); | 56 | $user = $this->findOrCreateUser($phone, $openid, $unionid); |
| 52 | if (!$user) { | 57 | if (!$user) { |
| 58 | + $this->logDebug("Error: Failed to find/create user"); | ||
| 53 | return ['ok' => false, 'error' => '用户创建失败']; | 59 | return ['ok' => false, 'error' => '用户创建失败']; |
| 54 | } | 60 | } |
| 55 | 61 | ||
| 62 | + $this->logDebug("User ID: " . $user['id']); | ||
| 63 | + | ||
| 56 | // 4. 创建 Session | 64 | // 4. 创建 Session |
| 57 | $token = $this->createSession($user['id']); | 65 | $token = $this->createSession($user['id']); |
| 58 | if (!$token) { | 66 | if (!$token) { |
| 67 | + $this->logDebug("Error: Failed to create session"); | ||
| 59 | return ['ok' => false, 'error' => 'Session 创建失败']; | 68 | return ['ok' => false, 'error' => 'Session 创建失败']; |
| 60 | } | 69 | } |
| 61 | 70 |
| @@ -323,12 +323,23 @@ $http_worker->onMessage = function ($connection, $request) use ($config, $authSe | @@ -323,12 +323,23 @@ $http_worker->onMessage = function ($connection, $request) use ($config, $authSe | ||
| 323 | $phone = $body['phone'] ?? null; | 323 | $phone = $body['phone'] ?? null; |
| 324 | $phoneCode = $body['phoneCode'] ?? null; | 324 | $phoneCode = $body['phoneCode'] ?? null; |
| 325 | 325 | ||
| 326 | + // Debug: Log Request | ||
| 327 | + $logPrefix = "[" . date('Y-m-d H:i:s') . "] [HTTP-Login] "; | ||
| 328 | + file_put_contents(__DIR__ . '/debug.log', $logPrefix . "Request: " . json_encode($body) . "\n", FILE_APPEND); | ||
| 329 | + | ||
| 326 | if (!$code) { | 330 | if (!$code) { |
| 327 | - $jsonResponse(['ok' => false, 'error' => 'code is required'], 400); | 331 | + $result = ['ok' => false, 'error' => 'code is required']; |
| 332 | + // Debug: Log Response | ||
| 333 | + file_put_contents(__DIR__ . '/debug.log', $logPrefix . "Response: " . json_encode($result) . "\n", FILE_APPEND); | ||
| 334 | + $jsonResponse($result, 400); | ||
| 328 | return; | 335 | return; |
| 329 | } | 336 | } |
| 330 | 337 | ||
| 331 | $result = $authService->wechatLogin($code, $phone, $phoneCode); | 338 | $result = $authService->wechatLogin($code, $phone, $phoneCode); |
| 339 | + | ||
| 340 | + // Debug: Log Response | ||
| 341 | + file_put_contents(__DIR__ . '/debug.log', $logPrefix . "Response: " . json_encode($result) . "\n", FILE_APPEND); | ||
| 342 | + | ||
| 332 | $jsonResponse($result, $result['ok'] ? 200 : 400); | 343 | $jsonResponse($result, $result['ok'] ? 200 : 400); |
| 333 | return; | 344 | return; |
| 334 | } | 345 | } |
Please
register
or
login
to post a comment