15m44w 续5: 横条根因(gh_auth_tokens建表TEXT PK改VARCHAR)+webhook撤销联动+诊断端点

① 横条: gh_auth_tokens 建表声明 TEXT PRIMARY KEY 在 MySQL 下不合法(TEXT 不能做 PK),
   改 VARCHAR(500) 对齐线上 caoyuanphp 实际 schema(gh_cfg.php+gh_oauth.php 两处)。
   gh_cfg.php 验活加 ghLog 日志(status/ok/token前缀)便于定位断点。
② webhook 撤销联动(用户定调): issue 关闭事件 state_reason=completed/done 且 label 含「已撤销」
   → PHP 工单撤销(withdrawn)。原只分 not_planned→rejected/其它→completed, 现加 已撤销+done→withdrawn。
③ 新增 api/gh_diag.php 临时诊断端点(验活全链路逐步输出, 定位横条断点)。
This commit is contained in:
ypsdf1
2026-11-25 19:47:23 +08:00
parent fb541038d9
commit 7acbcf6198
4 changed files with 93 additions and 12 deletions
+50
View File
@@ -0,0 +1,50 @@
<?php
/**
* 15m44w 续4 临时诊断端点:gh_cfg.php 验活全链路逐步输出,定位横条消失断点。
* 带 ?token= 跑:反解玩家名 → 查 gh_auth_tokens → 验活 /user → gh_authorized 判定。
* 每步 status/结果都打印,找出哪步断了。验完可删(不影响主流程)。
*/
while (ob_get_level() > 0) { @ob_end_clean(); }
ob_start();
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');