更新token并增加接口错误处理
This commit is contained in:
+19
-6
@@ -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 + ' 条对账单');
|
||||
|
||||
Reference in New Issue
Block a user