Files
Sdf1_login/api/gh_diag.php
T
ypsdf1 a8ac78a87f 15m44w 续5c 根治横条消失: 删全仓 curl_close + JSON 端点抑制 deprecation 输出
真根因(推翻 token 过期说): PHP8.5 下 curl_close() 已废弃, 每次调用都输出
<br><b>Deprecated</b> 污染 JSON 响应体 → 前端 res.json() 解析失败进 catch
(端点 catch 注释'不显示') → GitHub 授权横条消失。实测 gh_cfg 后端验活 status=200
ok=true 但响应体被警告污染, 非纯 JSON。

修: ① 全仓 8 处独立 curl_close 语句删除(PHP8+ 是 no-op,  出作用域自动关闭,
   删了不改行为还消除 deprecation 源头); ② gh_cfg/gh_diag/gh_git_probe 顶部加
   error_reporting(0)+display_errors=0 兜底, 彻底防任何警告污染响应体。
实测部署后 gh_cfg.php 返回纯 JSON, gh_authorized=true。
2026-11-25 20:40:38 +08:00

55 lines
2.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* 15m44w 续4 临时诊断端点:gh_cfg.php 验活全链路逐步输出,定位横条消失断点。
* 带 ?token= 跑:反解玩家名 → 查 gh_auth_tokens → 验活 /user → gh_authorized 判定。
* 每步 status/结果都打印,找出哪步断了。验完可删(不影响主流程)。
*/
while (ob_get_level() > 0) { @ob_end_clean(); }
ob_start();
// ★ 15m44w 续5c:PHP8.5 下 deprecation/notice 会输出 <br> 污染 JSON 响应体致前端 res.json() 失败,
// 抑制一切错误输出,保证响应体纯净(curl_close 已删, 此为其它警告兜底)。
error_reporting(0);
ini_set('display_errors', '0');
header('Content-Type: application/json; charset=utf-8');
header('X-Content-Type-Options: nosniff');
header('Cache-Control: no-store');
require_once __DIR__ . '/../core.php';
require_once __DIR__ . '/../lsky.php';
require_once __DIR__ . '/../gh_api.php';
$out = [];
$probeTk = isset($_GET['token']) ? trim((string)$_GET['token']) : '';
$out['step0_token'] = ($probeTk === '') ? '(no token passed)' : ('len=' . strlen($probeTk) . ' prefix=' . substr($probeTk, 0, 6));
// 1) 反解玩家名
$pi = validateTokenSilent($probeTk);
$out['step1_validateTokenSilent'] = $pi ? ('player=' . $pi['player'] . ' purpose=' . $pi['purpose']) : 'false';
$probePlayer = ($pi && !empty($pi['player'])) ? $pi['player'] : '';
$out['step2_player'] = ($probePlayer === '') ? '(empty)' : $probePlayer;
if ($probePlayer !== '') {
// 3) 查 gh_auth_tokens
$db = getDB();
$out['step3_db_class'] = get_class($db);
try {
// 不建表(避免 TEXT PK 在 MySQL 抛),直接查表(表已存在 varchar PK)
$st = $db->prepare("SELECT access_token, gh_login, updated_at FROM gh_auth_tokens WHERE player_name = :p AND access_token != '' ORDER BY updated_at DESC LIMIT 1");
$st->bindValue(':p', $probePlayer, SQLITE3_TEXT);
$res = $st->execute();
$trow = $res->fetchArray(SQLITE3_ASSOC);
$out['step4_token_found'] = $trow ? ('token_prefix=' . substr((string)$trow['access_token'], 0, 8) . ' gh_login=' . $trow['gh_login'] . ' updated=' . $trow['updated_at']) : '(no row)';
if ($trow && !empty($trow['access_token'])) {
// 5) 验活
$v = ghApiRequest('GET', '/user?x=nocache_' . (int)microtime(true) . mt_rand(100000, 999999), null, $trow['access_token']);
$out['step5_verify'] = ['status' => (int)($v['status'] ?? -1), 'ok' => !empty($v['ok']), 'msg' => mb_substr((string)($v['msg'] ?? ''), 0, 120)];
}
} catch (\Throwable $e) {
$out['step4_exception'] = get_class($e) . ': ' . $e->getMessage();
}
} else {
$out['step4'] = 'skipped (no player)';
}
success($out, 'diag');