15m44s 工单 GitHub 三项:token继承+label打标+webhook联动关单
需求1(token继承): 玩家授权过且 access_token 仍有效→gh_oauth.php 发起授权前 先查 gh_auth_tokens 调 /user 验活,有效则 302 回 player.php?gh_inherit=1 直接继承 不弹 GitHub;真失效才重新走 OAuth。不再一股脑报'无效要重新授权'。 需求2(label打标): 撤单/用户回/管理回/驳回/完结 5 个动作调 ghSyncLabel,按 img.json repo.tag 映射(正常关单→已完成/驳回→已驳回/已回复/撤销)给对应 issue 打 label,并摘掉互斥状态类 label。gh_label_map 可配置,缺省中文兜底。 需求3(webhook联动关单): ghHandleWebhook issue 关闭事件按 state_reason 联动 PHP: completed(done)→已完结;not_planned→已驳回;缺省 done。 附件占位符 [图片N] 未替换根因=历史单(OPcache 跑旧编译)+漏清 OPcache,本轮部署 后会清 OPcache,新建单正常替换。
This commit is contained in:
@@ -26,6 +26,7 @@ if (function_exists('opcache_invalidate')) { @opcache_invalidate(__FILE__); }
|
||||
|
||||
require_once __DIR__ . '/../core.php';
|
||||
require_once __DIR__ . '/../lsky.php';
|
||||
require_once __DIR__ . '/../gh_api.php'; // 15m44s: ghApiRequest(验活 token)
|
||||
|
||||
$cfg = loadImgJson();
|
||||
if (!$cfg['gh_enabled']) {
|
||||
@@ -46,6 +47,44 @@ $ghToken = 'https://github.com/login/oauth/access_token';
|
||||
|
||||
$code = isset($_GET['code']) ? trim((string)$_GET['code']) : '';
|
||||
|
||||
// ★ 15m44s 变动:token 继承 —— 玩家已授权过且 access_token 仍有效,直接继承,不重弹授权。
|
||||
// 只有真无效(401/过期)才重新走 OAuth。避免"一股脑说无效要重新授权"。
|
||||
// 发起授权前(无 code)先查 gh_auth_tokens 里该玩家的 token,调 GitHub /user 验活:
|
||||
// - 有效 → 302 回 player.php?gh_ok=1&gh_inherit=1(前端据此显示「已授权」,不弹 GitHub)
|
||||
// - 无效/无记录 → 继续走下方 authorize 302 重新授权
|
||||
if ($code === '') {
|
||||
$probePlayer = '';
|
||||
$probeTk = isset($_GET['token']) ? trim((string)$_GET['token']) : '';
|
||||
if ($probeTk !== '') {
|
||||
$pi = validateTokenSilent($probeTk);
|
||||
if ($pi && !empty($pi['player'])) $probePlayer = $pi['player'];
|
||||
}
|
||||
if ($probePlayer === '' && isset($_GET['player'])) $probePlayer = trim((string)$_GET['player']);
|
||||
if ($probePlayer !== '') {
|
||||
$db = getDB();
|
||||
try {
|
||||
$db->exec("CREATE TABLE IF NOT EXISTS gh_auth_tokens (
|
||||
player_name TEXT PRIMARY KEY,
|
||||
gh_login TEXT DEFAULT '',
|
||||
access_token TEXT NOT NULL,
|
||||
updated_at INTEGER NOT NULL
|
||||
)");
|
||||
$st = $db->prepare("SELECT access_token, gh_login FROM gh_auth_tokens WHERE player_name = :p AND access_token != '' LIMIT 1");
|
||||
$st->bindValue(':p', $probePlayer, SQLITE3_TEXT);
|
||||
$trow = $st->execute()->fetchArray(SQLITE3_ASSOC);
|
||||
} catch (\Throwable $e) { $trow = null; }
|
||||
if ($trow && !empty($trow['access_token'])) {
|
||||
// 验活:GitHub /user 用该 token,200=有效 401=失效
|
||||
$v = ghApiRequest('GET', '/user', null, $trow['access_token']);
|
||||
if (!empty($v['ok'])) {
|
||||
header('Location: ' . $baseSite . '/player.php?gh_ok=1&gh_inherit=1&gh_user=' . urlencode((string)($trow['gh_login'] ?: '')));
|
||||
exit;
|
||||
}
|
||||
// token 失效 → 继续走下方 authorize 重新授权
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($code !== '') {
|
||||
// ===== 回调:换 token =====
|
||||
$player = isset($_GET['state']) ? trim((string)$_GET['state']) : '';
|
||||
|
||||
Reference in New Issue
Block a user