更新token并增加接口错误处理

This commit is contained in:
cheney
2026-10-21 19:59:46 +08:00
parent fd6a6067d4
commit 9cf1aacd74
2 changed files with 38 additions and 12 deletions
+19 -6
View File
@@ -6,7 +6,7 @@ const EXCEL_FILE = path.join(__dirname, '新建 XLSX 工作表.xlsx');
const SHEET_NAME = '2026';
const BASE_URL = 'https://superstar.geelytravel.com';
const AUTH_TOKEN = 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJKV1QtRC1TRVFfVVNFUl9UTUNfMDAwMDAxODMiLCJ1c2VyX2NvZGUiOiJTRVFfVVNFUl9UTUNfMDAwMDAxODMiLCJyb2xlcyI6WyLnu5PnrpfkuJPlkZgiLCLnu5PnrpfkuJPlkZgiXSwiZXhwIjoxNzg2NTMzNTUxLCJpYXQiOjE3ODM5NDE1NTF9.1Mcmf5IM07Scrry4FzPs6TAcfUu0Nqtjre_2iJlNd5c';
const AUTH_TOKEN = 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJKV1QtRC1TRVFfVVNFUl9UTUNfMDAwMDAxODMiLCJ1c2VyX2NvZGUiOiJTRVFfVVNFUl9UTUNfMDAwMDAxODMiLCJyb2xlcyI6WyLnu5PnrpfkuJPlkZgiLCLnu5PnrpfkuJPlkZgiXSwiZXhwIjoxNzk1MDkxMTI3LCJpYXQiOjE3OTI0OTkxMjd9.wPYA-ntdWfT86LsQIYEJdVUHEksbMM9VwE96VqPdGms';
const COMMON_HEADERS = {
'accept': 'application/json, text/plain, */*',
@@ -297,10 +297,21 @@ function sleep(ms) {
return new Promise(function (resolve) { setTimeout(resolve, ms); });
}
function randomDelaySeconds() {
return Math.floor(15 + Math.random() * 31);
}
function randomDelaySeconds() {
return Math.floor(15 + Math.random() * 31);
}
// ========== 接口错误检查 ==========
function ensureOk(resp, what) {
if (resp && resp.code && resp.code !== 'Z000') {
if (resp.code === 'E003') {
console.error(' ✗ token 已失效(E003: ' + (resp.msg || '') + '),请更新 AUTH_TOKEN');
process.exit(1);
}
throw new Error(what + ' 失败: [' + resp.code + '] ' + (resp.msg || resp.message || ''));
}
}
// ========== 主流程 ==========
async function main() {
const teamIds = readTeamIds();
@@ -314,7 +325,8 @@ async function main() {
console.log('[' + (i + 1) + '/' + teamIds.length + '] 处理 ' + teamId + ' ...');
try {
const settlementResp = await querySettlementAccountIds(teamId);
const settlementResp = await querySettlementAccountIds(teamId);
ensureOk(settlementResp, 'querySettlementAccountIds');
const resultList = settlementResp?.result || [];
if (resultList.length === 0) {
console.log(' ⚠ ' + teamId + ' 没有 settlement account,跳过\n');
@@ -324,6 +336,7 @@ async function main() {
console.log(' -> settlementAccountId: ' + settlementAccountId);
const billResp = await queryBillList(settlementAccountId);
ensureOk(billResp, 'queryBillList');
const allBills = billResp?.result?.list || [];
const total = billResp?.result?.total || 0;
console.log(' -> 共 ' + total + ' 条对账单');
+19 -6
View File
@@ -6,7 +6,7 @@ const EXCEL_FILE = path.join(__dirname, '新建 XLSX 工作表.xlsx');
const SHEET_NAME = '2026';
const BASE_URL = 'https://superstar.geelytravel.com';
const AUTH_TOKEN = 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJKV1QtRC1TRVFfVVNFUl9UTUNfMDAwMDAxODMiLCJ1c2VyX2NvZGUiOiJTRVFfVVNFUl9UTUNfMDAwMDAxODMiLCJyb2xlcyI6WyLnu5PnrpfkuJPlkZgiLCLnu5PnrpfkuJPlkZgiXSwiZXhwIjoxNzg2NTMzNTUxLCJpYXQiOjE3ODM5NDE1NTF9.1Mcmf5IM07Scrry4FzPs6TAcfUu0Nqtjre_2iJlNd5c';
const AUTH_TOKEN = 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJKV1QtRC1TRVFfVVNFUl9UTUNfMDAwMDAxODMiLCJ1c2VyX2NvZGUiOiJTRVFfVVNFUl9UTUNfMDAwMDAxODMiLCJyb2xlcyI6WyLnu5PnrpfkuJPlkZgiLCLnu5PnrpfkuJPlkZgiXSwiZXhwIjoxNzk1MDkxMTI3LCJpYXQiOjE3OTI0OTkxMjd9.wPYA-ntdWfT86LsQIYEJdVUHEksbMM9VwE96VqPdGms';
const COMMON_HEADERS = {
'accept': 'application/json, text/plain, */*',
@@ -346,10 +346,21 @@ function sleep(ms) {
return new Promise(function (resolve) { setTimeout(resolve, ms); });
}
function randomDelaySeconds() {
return Math.floor(15 + Math.random() * 31);
}
function randomDelaySeconds() {
return Math.floor(15 + Math.random() * 31);
}
// ========== 接口错误检查 ==========
function ensureOk(resp, what) {
if (resp && resp.code && resp.code !== 'Z000') {
if (resp.code === 'E003') {
console.error(' ✗ token 已失效(E003: ' + (resp.msg || '') + '),请更新 AUTH_TOKEN');
process.exit(1);
}
throw new Error(what + ' 失败: [' + resp.code + '] ' + (resp.msg || resp.message || ''));
}
}
// ========== 主流程 ==========
async function main() {
const teamIds = readTeamIds();
@@ -363,7 +374,8 @@ async function main() {
console.log('[' + (i + 1) + '/' + teamIds.length + '] 处理 ' + teamId + ' ...');
try {
const settlementResp = await querySettlementAccountIds(teamId);
const settlementResp = await querySettlementAccountIds(teamId);
ensureOk(settlementResp, 'querySettlementAccountIds');
const resultList = settlementResp?.result || [];
if (resultList.length === 0) {
console.log(' ⚠ ' + teamId + ' 没有 settlement account,跳过\n');
@@ -373,6 +385,7 @@ async function main() {
console.log(' -> settlementAccountId: ' + settlementAccountId);
const billResp = await queryBillList(settlementAccountId);
ensureOk(billResp, 'queryBillList');
const allBills = billResp?.result?.list || [];
const total = billResp?.result?.total || 0;
console.log(' -> 共 ' + total + ' 条对账单');