diff --git a/src/constants/strings.ts b/src/constants/strings.ts index 1f2d000..8e89bf6 100644 --- a/src/constants/strings.ts +++ b/src/constants/strings.ts @@ -254,6 +254,7 @@ export const NETWORK_USER_INFO = export const THOS_SELECT_ONE_URL = "https://webvpn.tsinghua.edu.cn/https/77726476706e69737468656265737421e4ff4e8f69247b59700f81b9991b2631ca359dd4/fp/fp/Uniformcommon/selectOnePresetData"; +export const CARD_I_VERSION_URL = "https://webvpn.tsinghua.edu.cn/http/77726476706e69737468656265737421f1e751d2242326446d0187ab9040227b239c069338e2/api/CardIVersion"; export const CARD_USER_BY_TOKEN_URL = "https://card.tsinghua.edu.cn/login/getUserInfoFromToken"; export const CARD_INFO_BY_USER_URL = "https://card.tsinghua.edu.cn/business/getCardUserinfo"; export const CARD_PHOTO_URL = "https://card.tsinghua.edu.cn/myaccount/showDbImage?idserial="; diff --git a/src/index.ts b/src/index.ts index 2d93fe1..60ed567 100644 --- a/src/index.ts +++ b/src/index.ts @@ -126,6 +126,7 @@ import {uFetch} from "./utils/network"; import {getNetworkBalance, getNetworkDetail, getOnlineDevices} from "./lib/network"; import {getScoreByCourseId} from "./lib/thos"; import { + canRechargeCampusCard, cardCancelLoss, cardChangeTransactionPassword, cardGetInfo, cardGetPhotoUrl, @@ -948,6 +949,9 @@ export class InfoHelper { * @return Uri to request to complete the payment process, undefined for Bank */ public rechargeCampusCard = async (amount: number, transactionPassword: string, type: CardRechargeType) => { + if (!await canRechargeCampusCard(this)) { + throw new Error("暂不支持校园卡充值,请升级应用程序。"); + } if (type === CardRechargeType.Bank) { return cardRechargeFromBank(this, transactionPassword, amount); } diff --git a/src/lib/card.ts b/src/lib/card.ts index eba3488..9870baa 100644 --- a/src/lib/card.ts +++ b/src/lib/card.ts @@ -1,10 +1,11 @@ import {AES, enc, mode, pad} from "crypto-js"; -import {roam} from "./core"; +import {roam, roamingWrapperWithMocks} from "./core"; import {InfoHelper} from "../index"; import {uFetch} from "../utils/network"; import { CARD_CANCEL_LOSS_URL, CARD_CHANGE_PWD_URL, + CARD_I_VERSION_URL, CARD_INFO_BY_USER_URL, CARD_MOD_MAX_CONSUME_URL, CARD_PHOTO_URL, CARD_RECHARGE_FROM_ALIPAY_URL, @@ -20,6 +21,8 @@ import {CardTransaction, CardTransactionType} from "../models/card/transaction"; import {MOCK_CARD_INFO} from "../mocks/card"; import {LoginError} from "../utils/error"; +const CARD_API_VERSION = 1; + const accountBaseInfo = { user: "", cardId: "", @@ -190,6 +193,22 @@ export const cardCancelLoss = async (helper: InfoHelper, transactionPassword: st }); }; +export const canRechargeCampusCard = async (helper: InfoHelper) => + roamingWrapperWithMocks( + helper, + undefined, + "", + async () => { + try { + const {version} = await uFetch(CARD_I_VERSION_URL).then(JSON.parse); + return version <= CARD_API_VERSION; + } catch { + throw new Error("Failed to query card API version."); + } + }, + false, + ); + export const cardRechargeFromBank = async (helper: InfoHelper, transactionPassword: string, amount: number) => { if (helper.mocked()) { return;