chsi-verify
v1.0.3
Published
学信网学籍/学历/学位信息验证库
Downloads
42
Maintainers
Readme
chsi-verify
学信网学籍验证 TypeScript 库,使用 Puppeteer 自动提取学籍信息。
安装
npm install chsi-verify puppeteer使用方法
方式一:使用便捷函数(推荐用于单次验证)
import { verifyChsi } from 'chsi-verify';
async function main() {
const vcode = 'XXXXXXXXXXXXXXXX'; // 替换为实际的验证码
const result = await verifyChsi(vcode);
if (result.success) {
console.log('验证成功!');
console.log('学生信息:', result.data);
} else {
console.error('验证失败:', result.error);
}
}
main();方式二:使用类实例(推荐用于多次验证)
import { ChsiVerifier } from 'chsi-verify';
async function main() {
const verifier = new ChsiVerifier({
puppeteer: {
headless: 'new',
timeout: 30000
}
});
try {
// 第一次验证
const result1 = await verifier.verify('VCODE1');
console.log('第一次验证:', result1);
// 第二次验证(复用浏览器)
const result2 = await verifier.verify('VCODE2');
console.log('第二次验证:', result2);
} finally {
// 记得销毁验证器,关闭浏览器
await verifier.destroy();
}
}
main();方式三:自定义配置
import { verifyChsi } from 'chsi-verify';
async function main() {
const result = await verifyChsi('XXXXXXXXXXXXXXXX', {
baseUrl: 'https://www.chsi.com.cn',
puppeteer: {
headless: false, // 显示浏览器窗口(用于调试)
timeout: 60000,
args: [
'--no-sandbox',
'--disable-setuid-sandbox'
]
}
});
if (result.success) {
console.log('姓名:', result.data?.姓名);
console.log('学校:', result.data?.学校名称);
console.log('专业:', result.data?.专业);
console.log('学籍状态:', result.data?.学籍状态);
}
}
main();API
类型定义
StudentInfo
学籍信息接口,包含以下字段:
姓名: 学生姓名性别: 性别出生日期: 出生日期民族: 民族学校名称: 学校名称层次: 学历层次专业: 专业名称学制: 学制学历类别: 学历类别学习形式: 学习形式分院: 分院系所: 系所入学日期: 入学日期学籍状态: 学籍状态预计毕业日期: 预计毕业日期
VerifyResult
验证结果接口:
interface VerifyResult {
success: boolean; // 是否成功
data?: StudentInfo; // 学生信息(成功时返回)
error?: string; // 错误信息(失败时返回)
timestamp: string; // 时间戳
}ChsiVerifyOptions
配置选项:
interface ChsiVerifyOptions {
puppeteer?: PuppeteerOptions; // Puppeteer 配置
baseUrl?: string; // 学信网基础 URL,默认为 https://www.chsi.com.cn
}导出内容
ChsiVerifier: 验证器类verifyChsi: 便捷验证函数StudentInfo: 学籍信息类型VerifyResult: 验证结果类型ChsiVerifyOptions: 配置选项类型
运行示例
npm run example开发
# 安装依赖
npm install
# 编译 TypeScript
npm run build
# 运行示例
npm run example注意事项
- 需要安装 Chromium 或 Chrome 浏览器(Puppeteer 会自动下载)
- 在生产环境中建议使用
headless: 'new'模式 - 如需调试,可设置
headless: false查看浏览器操作过程 - 验证码需要从学信网获取,确保验证码有效且未过期
- 网络请求可能受学信网服务器响应速度影响,建议设置合理的超时时间
License
MIT
