From 1b7b5a22053b14dcb7fb6e07c34985e3f109270a Mon Sep 17 00:00:00 2001 From: ypsdf1 Date: Thu, 26 Nov 2026 10:02:09 +0800 Subject: [PATCH] =?UTF-8?q?15m44z=20=E7=AC=AC=E4=B8=89=E9=83=A8=E5=88=86:?= =?UTF-8?q?=20GitHub=20App=20bot=20=E5=8C=BF=E5=90=8D=E5=B7=A5=E5=8D=95=20?= =?UTF-8?q?+=20=E5=8C=BF=E5=90=8D/=E5=AE=9E=E5=90=8D=E5=BC=80=E5=85=B3=20+?= =?UTF-8?q?=20=E5=BD=92=E5=B1=9E=E6=B4=BE=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【匿名工单主体】 - App 鉴权: gh_api.php 新增 ghAppJwt(PEM签RS256 JWT)+ghAppInstallationToken(换1h installation token, 缓存到 /plugin/gh_app_token_cache.json 55min)+ghAppBotReady。 - 匿名代发: 用 installation token(g hs_前缀)建 issue 归属 bot(caoyuan-server[bot]), 不暴露提单人 GitHub 账号; 提单人信息写 issue 正文「玩家:xxx」+ PHP 后台保留。 - loadImgJson 解析 repo.imgrepo."github app"(appid/安装id/私钥路径/匿名模式)。 【匿名/实名开关(用户定调: 共存, 做成开关)】 - json「匿名模式」字段(github app 段): true=gh模式支持匿名(前端出开关); false=gh模式 一律实名授权(即使 appbot 配了也不给匿名选项)。 - 前端: gh_anon_available=true(匿名模式开+appbot可用)才显示「匿名工单」开关; 开关开→提交带 anon=1(bot代发), 关→走玩家OAuth建单; 模式留空(PHP内置工单)不给匿名。 - 建单: anon=1 且匿名模式开→appbot token; 否则玩家 OAuth token。 【归属派发(用户定调: 按工单所有人)】 - ghSyncCreate 建 issue 后回写 gh_issue_owner(bot/realname, 按 token 前缀 ghs_/gho_)。 - 撤单/完结/回复按 ghTicketTokenByTicket 归属: bot建的单→机器人代发撤/完结/评论; 实名单→玩家 OAuth token(保持现有逻辑)。 实测: App JWT→installation token→建issue#24(归属caoyuan-server[bot])全链路通; 线上 gh_cfg 返回 gh_anon_available=true。6件PHP+img.json模板+真值img.json+私钥全MATCH。 --- .gitignore | 2 + api/gh_cfg.php | 15 ++++++++ api/ticket.php | 56 ++++++++++++++++++++++++--- gh_api.php | 101 ++++++++++++++++++++++++++++++++++++++++++++++++- img.json | 20 +++++++++- lsky.php | 27 +++++++++++++ player.php | 51 ++++++++++++++++++++++++- 7 files changed, 263 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 42036a3..4a64e31 100644 --- a/.gitignore +++ b/.gitignore @@ -64,4 +64,6 @@ db/ # ===== .workbuddy/ 工作目录(用户保留区)===== # 存放测试脚本 / 探针 / 测试数据 / 备份文件,已被 git拉黑(2026-10-09) .workbuddy/ +# ★ 15m44z 第三部分:GitHub App bot installation token 缓存(含敏感 token,绝不进 git) +/gh_app_token_cache.json /nul diff --git a/api/gh_cfg.php b/api/gh_cfg.php index 5be74e8..26a84f4 100644 --- a/api/gh_cfg.php +++ b/api/gh_cfg.php @@ -80,8 +80,23 @@ if ($cfg['gh_enabled'] && $probeTk !== '') { } } +// ★ 15m44z 第三部分+开关:匿名工单开关可用性。 +// gh_anon_available = appbot 启用 + 匿名模式开(gh_anon_mode, img.json「匿名模式」字段) +// + 真能取到 installation token。三者齐备前端才显示「匿名工单」开关。 +// 匿名模式关 → 即使 appbot 配了也 gh_anon_available=false,gh 模式一律实名授权。 +$ghAppbot = !empty($cfg['gh_app_bot']); +$ghAnonMode = !isset($cfg['gh_anon_mode']) || $cfg['gh_anon_mode'] === true; // 缺省开 +$ghAnonAvailable = false; +if ($ghAppbot && $ghAnonMode) { + try { + if (function_exists('ghAppBotReady')) $ghAnonAvailable = ghAppBotReady(); + } catch (\Throwable $e) { $ghAnonAvailable = false; } +} + success([ 'gh_enabled' => !empty($cfg['gh_enabled']), 'gh_repo' => isset($cfg['gh_repo']) ? $cfg['gh_repo'] : '', 'gh_authorized' => $ghAuthorized, + 'gh_appbot' => $ghAppbot, + 'gh_anon_available' => $ghAnonAvailable, ], 'ok'); diff --git a/api/ticket.php b/api/ticket.php index 866b95f..ccbd336 100644 --- a/api/ticket.php +++ b/api/ticket.php @@ -501,9 +501,20 @@ function ticketUploadImage() { * 15m44l: 取工单关联的 GitHub access_token(按玩家名从 web_tickets.gh_access_token 读)。 * 列不存在/空 → 返回 ''(调用方据此跳过同步,PHP 工单照常)。 */ -function ghTicketToken($player) { +function ghTicketToken($player, $wantAnon = false) { + // ★ 15m44z 第三部分+开关:匿名/实名共存开关。 + // - $wantAnon=true(前端勾了匿名)且 appbot 可用且「匿名模式」开 → 走 appbot 匿名代发 + // (issue 归属 bot,提单人信息只写正文+PHP后台,管理员可查)。 + // - 「匿名模式」关(img.json gh_anon_mode=false)→ 一律实名:即使 appbot 配了也不匿名, + // 强制走玩家 GitHub OAuth 授权建单。 + // - 没勾匿名 / appbot 不可用 → 回退玩家 OAuth token(老逻辑)。 + $cfg = ghGetCfg(); + $anonModeOn = !isset($cfg['gh_anon_mode']) || $cfg['gh_anon_mode'] === true; // 缺省开 + if ($wantAnon && $anonModeOn && function_exists('ghAppBotReady') && ghAppBotReady()) { + return ghAppInstallationToken(); + } + // 实名路径:玩家 OAuth 授权 token $db = getDB(); - // 15m44m: 授权 token 存独立表 gh_auth_tokens(不污染 web_tickets) try { $st = $db->prepare("SELECT access_token FROM gh_auth_tokens WHERE player_name = :p AND access_token != '' ORDER BY updated_at DESC LIMIT 1"); $st->bindValue(':p', $player, SQLITE3_TEXT); @@ -526,7 +537,33 @@ function ghTicketTokenByTicket($ticketId) { $st->bindValue(':id', (int)$ticketId, SQLITE3_INTEGER); $row = $st->execute()->fetchArray(SQLITE3_ASSOC); if (!$row || empty($row['requester'])) return ''; - return ghTicketToken($row['requester']); + // ★ 15m44z 第三部分:按工单 issue 归属判定撤单/完结的 token 派发—— + // - 工单所有人是机器人(gh_issue_owner=bot) → 撤单/完结交给机器人(appbot installation token) + // - 工单所有人是实名GitHub账号(gh_issue_owner=realname) → 保持现有逻辑(玩家 OAuth token) + // - 老工单/未记录归属 → 回退:匿名模式开且 appbot 可用→bot,否则玩家 token + try { + $stO = $db->prepare("SELECT gh_issue_owner FROM web_tickets WHERE id = :id LIMIT 1"); + $stO->bindValue(':id', (int)$ticketId, SQLITE3_INTEGER); + $oRow = $stO->execute()->fetchArray(SQLITE3_ASSOC); + $owner = $oRow ? (string)$oRow['gh_issue_owner'] : ''; + } catch (\Throwable $eO) { $owner = ''; } + + if ($owner === 'bot') { + // 机器人建的单 → 撤/完结用 appbot token(对安装仓全权限) + return (function_exists('ghAppBotReady') && ghAppBotReady()) ? ghAppInstallationToken() : ''; + } + if ($owner === 'realname') { + // 实名单 → 玩家 OAuth 授权 token(老逻辑,绝不走 bot) + $cfg = ghGetCfg(); + $stT = $db->prepare("SELECT access_token FROM gh_auth_tokens WHERE player_name = :p AND access_token != '' ORDER BY updated_at DESC LIMIT 1"); + $stT->bindValue(':p', $row['requester'], SQLITE3_TEXT); + $tRow = $stT->execute()->fetchArray(SQLITE3_ASSOC); + return ($tRow && !empty($tRow['access_token'])) ? (string)$tRow['access_token'] : ''; + } + // 老工单/未记录归属 → 回退匿名模式开则优先 bot + $cfg = ghGetCfg(); + $anonModeOn = !isset($cfg['gh_anon_mode']) || $cfg['gh_anon_mode'] === true; + return ghTicketToken($row['requester'], $anonModeOn); } catch (\Throwable $e) { return ''; } @@ -678,7 +715,10 @@ function ticketCreate() { } // 15m44l: 同步 GitHub issue(非阻塞:失败不影响 PHP 工单入库;未授权/未配置则跳过) - $ghToken = ghTicketToken($player); + // ★ 15m44z 第三部分+开关:anon=1 → 匿名工单(appbot 代发,需匿名模式开+appbot 可用); + // 否则实名(玩家 OAuth 授权)。匿名模式关时 gh 模式强制实名(ghTicketToken 内判)。 + $wantAnon = (isset($_GET['anon']) && trim((string)$_GET['anon']) === '1'); + $ghToken = ghTicketToken($player, $wantAnon); $ghSyncOk = ghSyncCreate($ticketId, $player, $title, $description, $images, $ghToken); success(['id' => $ticketId, 'images' => $images, 'gh_synced' => (bool)$ghSyncOk], '工单提交成功'); @@ -846,7 +886,9 @@ function ticketReply() { // 15m44s 新功能:用户回单 → 打「已回复」label $ghSyncOk = false; $ghLabel = false; try { - $ghToken = ghTicketToken($player); + // ★ 15m44z 第三部分:回复按工单 issue 归属派发——bot 建的单→机器人代发评论, + // 实名单→玩家 OAuth token(老逻辑)。ghTicketTokenByTicket 内部按 gh_issue_owner 判。 + $ghToken = ghTicketTokenByTicket($id); $ghSyncOk = ghSyncReply($id, $message, $ghToken, $player); $ghLabel = ghSyncLabel($id, 'user_reply', $ghToken); } catch (\Throwable $ignored) { $ghSyncOk = false; $ghLabel = false; } @@ -884,7 +926,9 @@ function ticketWithdraw() { // 15m44s 新功能:撤单 → GitHub issue 打「已撤销」label + 关 issue(state_reason=not_planned) $ghLabel = false; $ghClosed = false; try { - $tk = ghTicketToken($player); + // ★ 15m44z 第三部分:撤销按工单 issue 归属派发——bot 建的单→机器人代发撤/关, + // 实名单→玩家 OAuth token(老逻辑)。 + $tk = ghTicketTokenByTicket($id); $ghLabel = ghSyncLabel($id, 'withdraw', $tk); $ghClosed = ghSyncClose($id, 'rejected', $tk, $player); } catch (\Throwable $ignored) {} diff --git a/gh_api.php b/gh_api.php index 0efe47f..25d6de6 100644 --- a/gh_api.php +++ b/gh_api.php @@ -31,6 +31,99 @@ function ghGetCfg() { return loadImgJson(); } +// ===== ★ 15m44z 第三部分:GitHub App bot 匿名工单鉴权 ===== +// 流程:App 私钥(PEM) 签 RS256 JWT → POST /app/installations/{id}/access_tokens +// 换 installation token(1h 有效)→ 用该 token 建 issue(归属 bot,提单人匿名)。 +// installation token 缓存到文件(/plugin/gh_app_token_cache.json,git 拉黑), +// 有效期内复用,过期/失效重取。私钥路径来自 img.json 的 repo.imgrepo."github app".私钥。 + +/** base64url(无 padding) */ +function ghB64Url($bin) { + return rtrim(strtr(base64_encode($bin), '+/', '-_'), '='); +} + +/** 用 App 私钥签 RS256 JWT(GitHub App 鉴权用,有效期 10min 内即可,取 9min)。 */ +function ghAppJwt() { + $cfg = ghGetCfg(); + $pemPath = isset($cfg['gh_app_pem_path']) ? (string)$cfg['gh_app_pem_path'] : ''; + $appId = isset($cfg['gh_app_id']) ? (string)$cfg['gh_app_id'] : ''; + if ($pemPath === '' || $appId === '' || !is_readable($pemPath)) { + return ''; // 私钥缺失/不可读 + } + $keyPem = file_get_contents($pemPath); + if ($keyPem === false) return ''; + if (!function_exists('openssl_pkey_get_private')) return ''; // openssl 扩展缺失 + $priv = openssl_pkey_get_private($keyPem); + if ($priv === false) return ''; + $now = time(); + $header = ghB64Url(json_encode(['alg' => 'RS256', 'typ' => 'JWT'])); + $payload = ghB64Url(json_encode(['iat' => $now, 'exp' => $now + 540, 'iss' => $appId])); + $signingInput = $header . '.' . $payload; + $ok = openssl_sign($signingInput, $signature, $priv, OPENSSL_ALGO_SHA256); + if (!$ok) return ''; + return $signingInput . '.' . ghB64Url($signature); +} + +/** + * 取(并缓存)installation access token。 + * @return 字符串 token;取不到返回 ''。 + * 缓存文件含 {token, expires_at},有效期 55min(留 5min 余量防过期)。 + */ +function ghAppInstallationToken() { + $cfg = ghGetCfg(); + if (empty($cfg['gh_app_bot'])) return ''; // appbot 未启用 + $cacheFile = __DIR__ . '/gh_app_token_cache.json'; + // 读缓存 + if (is_readable($cacheFile)) { + $c = json_decode((string)file_get_contents($cacheFile), true); + if (is_array($c) && !empty($c['token']) && (int)($c['expires_at'] ?? 0) > time() + 300) { + return (string)$c['token']; + } + } + $jwt = ghAppJwt(); + if ($jwt === '') return ''; + $instId = (string)($cfg['gh_app_installation_id'] ?? ''); + // 未配 installation id → 动态查(取该 App 在目标仓 owner 下的第一个安装) + if ($instId === '' || $instId === '0') { + $r = ghApiRequest('GET', '/app/installations?per_page=100', null, $jwt); + if (!$r['ok'] || !is_array($r['data'])) return ''; + $target = (string)($cfg['gh_repo'] ?? ''); + $owner = $target !== '' ? explode('/', $target)[0] : ''; + $found = ''; + foreach ($r['data'] as $ins) { + if (!is_array($ins)) continue; + $accLogin = isset($ins['account']['login']) ? (string)$ins['account']['login'] : ''; + $accId = isset($ins['account']['id']) ? (int)$ins['account']['id'] : 0; + if ($owner !== '' && ($accLogin === $owner || $accId === (int)$owner)) { $found = (string)$ins['id']; break; } + } + if ($found === '' && !empty($r['data'][0]['id'])) $found = (string)$r['data'][0]['id']; + if ($found === '') return ''; + $instId = $found; + } + // 换 installation token + $r = ghApiRequest('POST', '/app/installations/' . $instId . '/access_tokens', [], $jwt); + if (!$r['ok'] || !is_array($r['data']) || empty($r['data']['token'])) { + ghLog('appbot install token fail: ' . $r['msg']); + return ''; + } + $token = (string)$r['data']['token']; + // 缓存(installation token 有效期 1h,缓存 55min) + @file_put_contents($cacheFile, json_encode([ + 'token' => $token, + 'expires_at' => time() + 3300, + 'installation_id' => $instId, + ])); + @chmod($cacheFile, 0600); + return $token; +} + +/** appbot 是否可用(启用 + 能拿到 installation token)。 */ +function ghAppBotReady() { + $cfg = ghGetCfg(); + if (empty($cfg['gh_app_bot'])) return false; + return ghAppInstallationToken() !== ''; +} + /** * GitHub REST 底层请求。 * @return ['ok'=>bool,'status'=>int,'msg'=>string,'data'=>mixed] @@ -197,8 +290,14 @@ function ghSyncCreate($ticketId, $player, $title, $description, $images = [], $t try { $db = getDB(); try { $db->exec("ALTER TABLE web_tickets ADD COLUMN gh_issue_number TEXT DEFAULT ''"); } catch (\Throwable $e) { /* 列已存在 */ } - $st = $db->prepare("UPDATE web_tickets SET gh_issue_number = :n WHERE id = :id"); + // ★ 15m44z 第三部分:记录 issue 归属(bot/realname)——撤单/完结按归属者派发: + // bot 建的单→撤/完结交给机器人(installation token);实名单→玩家 OAuth token(老逻辑)。 + // 判定:installation token 前缀 ghs_,玩家 OAuth token 前缀 gho_/ghp_。 + try { $db->exec("ALTER TABLE web_tickets ADD COLUMN gh_issue_owner TEXT DEFAULT ''"); } catch (\Throwable $e2) { /* 列已存在 */ } + $owner = (strpos($token, 'ghs_') === 0) ? 'bot' : ((strpos($token, 'gho_') === 0 || strpos($token, 'ghp_') === 0) ? 'realname' : ''); + $st = $db->prepare("UPDATE web_tickets SET gh_issue_number = :n, gh_issue_owner = :o WHERE id = :id"); $st->bindValue(':n', $issueNo, SQLITE3_TEXT); + $st->bindValue(':o', $owner, SQLITE3_TEXT); $st->bindValue(':id', $ticketId, SQLITE3_INTEGER); $st->execute(); } catch (\Throwable $e) { ghLog('write gh_issue_number: ' . $e->getMessage()); } diff --git a/img.json b/img.json index 884a681..45c075a 100644 --- a/img.json +++ b/img.json @@ -63,8 +63,26 @@ "备注": "上述指令均来自git官网,不保证全系统可用。因为系统会更新,git官网会更新。而这份文档是出场就写好的" } }, - "验证git": "终端输入git --version,有输出版本号就成功" + "验证git": "终端输入git --version,有输出版本号就成功", + "注意事项": "php解封shell、exec_shell函数" } + }, + "github app": { + "appid": "88888", + "Client ID": "example", + "安装 id": "", + "私钥": "./私钥.pem", + "匿名模式": true, + "说明": [ + "1. 留空或填占位(88888/example)→ 工单走玩家 OAuth 授权(老逻辑)", + "2. 填真 appid → 启用 GitHub App bot 匿名代发:issue 归属 bot,提单人匿名,", + " 提单人信息只写进 issue 正文「玩家:xxx」+ PHP 后台保留,管理员可查", + "3. appid/GitHub App 的 App ID(数字),私钥填 .pem 文件相对/绝对路径", + "4. 安装 id 可不填——运行时自动查该 App 在目标仓 owner 下的安装;填了更稳", + "5. App 须先安装到目标仓库(如 caoyuanwiki)并授予 issues 读写权限", + "6. 匿名模式:true=支持匿名工单(前端出开关, 开→bot代发/关→实名授权);", + " false=gh模式一律要求实名授权(即使 appbot 配了, 前端也不给匿名选项)" + ] } } }, diff --git a/lsky.php b/lsky.php index ce904f2..03577aa 100644 --- a/lsky.php +++ b/lsky.php @@ -189,6 +189,33 @@ function loadImgJson() { $parts = explode('/', $cfg['imgrepo_full']); $cfg['imgrepo_owner'] = $parts[0]; } + // ★ 15m44z 第三部分:GitHub App bot(匿名工单)凭证。 + // repo.imgrepo."github app" 段:appid / 安装 id / 私钥路径。 + // 仓库版 img.json 填占位(appid=88888 等),.workbuddy 真值版填真凭证。 + // appid 非占位 → 工单走 appbot 代发(issue 归属 bot,提单人匿名)。 + // 私钥路径:绝对路径原样;相对路径拼 Web 根目录(__DIR__=/plugin)。 + $app = isset($ir['github app']) && is_array($ir['github app']) ? $ir['github app'] : null; + if ($app !== null) { + $ghAppId = trim((string)($app['appid'] ?? ($app['Client ID'] ?? ''))); + $cfg['gh_app_id'] = $ghAppId; + $cfg['gh_app_installation_id'] = trim((string)($app['安装 id'] ?? $app['installation_id'] ?? '')); + $cfg['gh_app_bot'] = !empty($ghAppId) && $ghAppId !== '88888' && $ghAppId !== 'example'; + // ★ 15m44z 第三部分+开关:「匿名模式」字段——true=gh模式支持匿名工单(前端出开关); + // false=gh模式一律实名授权(即使 appbot 配了也不给匿名选项)。缺省按 true。 + $anonRaw = $app['匿名模式'] ?? true; + if (is_bool($anonRaw)) { + $cfg['gh_anon_mode'] = $anonRaw; + } else { + $cfg['gh_anon_mode'] = !(strtolower(trim((string)$anonRaw)) === 'false' + || (string)$anonRaw === '0' || $anonRaw === 0); + } + $pemPath = trim((string)($app['私钥'] ?? '')); + if ($pemPath !== '' && !preg_match('#^[A-Za-z]:[\\\\/]#', $pemPath) + && !preg_match('#^/|^\\\\#', $pemPath) && strpos($pemPath, '://') !== 0) { + $pemPath = __DIR__ . '/' . $pemPath; + } + $cfg['gh_app_pem_path'] = $pemPath; + } } } if (!isset($j['repo']['webhook_secret'])) { diff --git a/player.php b/player.php index 6ad9c43..8e42f28 100644 --- a/player.php +++ b/player.php @@ -3861,7 +3861,7 @@ if ($currentVersion !== $BUILD_VERSION) { } // ===== 工单系统 ===== - let ticketState = { view: 'list', filter: 'all', images: [], replying: false }; // images=附件图暂存(URL列表), replying=回复按钮锁(15m44y) + let ticketState = { view: 'list', filter: 'all', images: [], replying: false, anonTicket: false }; // images=附件图暂存(URL列表), replying=回复按钮锁(15m44y), anonTicket=匿名工单开关(15m44z) async function renderTicket(el) { if (IS_PREVIEW || !AUTHENTICATED) { @@ -3954,6 +3954,13 @@ if ($currentVersion !== $BUILD_VERSION) {

提交工单时会同步到 GitHub issue,先授权你的 GitHub 账号

+ +

💡 支持标准Markdown语法:**粗体**、*斜体*、\`代码\`、列表、标题等

@@ -3999,6 +4006,24 @@ if ($currentVersion !== $BUILD_VERSION) { if (sub) sub.textContent = '工单与附件都同步到 GitHub issue,点右侧按钮授权你的 GitHub 账号'; if (btn) { btn.textContent = '授权 GitHub'; btn.onclick = gotoGhOAuth; } } + // ★ 15m44z 第三部分+开关:匿名工单开关(仅 appbot 可用时显示,GitHub 模式专属)。 + // 开 → 本单由系统机器人代发(匿名,不依赖玩家 OAuth 授权); + // 关 → 走玩家 GitHub 授权建单(老逻辑)。开关状态存 ticketState.anonTicket。 + const anonToggle = document.getElementById('ghAnonToggle'); + const anonCheck = document.getElementById('ghAnonCheck'); + if (d.gh_anon_available === true) { + if (anonToggle) anonToggle.style.display = ''; + if (anonCheck) { + anonCheck.checked = !!ticketState.anonTicket; // 恢复上次状态 + anonCheck.onchange = function() { + ticketState.anonTicket = anonCheck.checked; + syncGhAnonUI(); + }; + } + syncGhAnonUI(); + } else if (anonToggle) { + anonToggle.style.display = 'none'; // 非 GitHub 模式 / appbot 不可用 → 不给匿名选项 + } } } catch (e) { /* 端点不存在/未部署 → 不显示 */ } } @@ -4007,6 +4032,26 @@ if ($currentVersion !== $BUILD_VERSION) { const url = API + 'gh_oauth.php?token=' + encodeURIComponent(TOKEN); window.location.href = url; } + // ★ 15m44z 第三部分+开关:匿名开关 UI 联动。 + // 匿名开 → 隐藏「授权 GitHub」按钮(不需要授权,bot 代发),提示改文案; + // 匿名关 → 恢复授权按钮(走玩家 OAuth 建单,老逻辑)。 + function syncGhAnonUI() { + const btn = document.getElementById('ghAuthBtn'); + const sub = document.getElementById('ghAuthSub'); + const txt = document.getElementById('ghAuthText'); + if (ticketState.anonTicket) { + if (btn) { btn.style.display = 'none'; } + if (txt) txt.textContent = '🤖 匿名工单:本单由系统机器人代发,不暴露你的 GitHub 账号'; + if (sub) sub.textContent = '提单人信息仅后台保留,管理员可查;取消勾选改回你自己的 GitHub 账号建单'; + } else { + if (btn) { btn.style.display = ''; } + // 恢复默认文案(具体已授权/未授权由 loadGhCfg 的 isAuthed 段设置,这里只兜底) + if (txt && txt.textContent.indexOf('🤖') === 0) txt.textContent = '⛓️ GitHub 工单同步'; + if (sub && sub.textContent.indexOf('提单人信息仅后台保留') === 0) { + sub.textContent = '提交工单时会同步到 GitHub issue,先授权你的 GitHub 账号'; + } + } + } // ===== 工单附件图:15m44d 改为"选中暂存, 提交工单时一并上传图床"===== // 旧版"选中即上传图床"的问题: 用户填单一半后悔/问题已解决, 图片却已进 API 图床 @@ -4172,6 +4217,10 @@ if ($currentVersion !== $BUILD_VERSION) { const url = new URL(API + 'ticket.php', location.href); url.searchParams.set('action', 'create'); url.searchParams.set('token', TOKEN); + // ★ 15m44z 第三部分+开关:匿名工单开关状态传给后端。 + // anon=1 → 后端优先用 appbot 匿名代发(需 appbot 配置+匿名模式开); + // 匿名模式关或 appbot 没配 → 后端自动回退玩家 OAuth 授权建单。 + if (ticketState.anonTicket) url.searchParams.set('anon', '1'); let res; if (files.length > 0) {