对鑫考云校园系统API的研究

学校用的饭卡系统是鑫考教育提供的。

由于个人心理因素影响,总感觉饭卡扣钱扣的不够数,想写个Watchdog定时获取饭卡数据。
后来打开鑫考云校园系统家长系统一看,惊奇的发现,鑫考教育的这套系统是提供API的

http://home.xinkaoyun.com/login.html
比如通过上面的登录界面可以获取到登录界面的API使用范例:
http://home.xinkaoyun.com/js/login.js

login.js 使用范例

[cc lang="JavaScript"]$('title').html('鑫考云校园系统');
if(navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion.split(";")[1].replace(/[ ]/g, "").replace("MSIE", "")) < 10) { alert("您的浏览器版本过低,请下载IE9及以上版本或这360,谷歌等高版本浏览器"); } //---------------------------------------登录------------------------------------- $('.btn_login').click(function() { var userName = $('.img1').val(); var passWord = $('.img2').val(); $.ajax({ type: "post", url: url_s + '/api/HSCPC/Login', dataType: 'json', data: { userName: userName, passWord: passWord, IP: Ip, }, success: function(data) { console.log(data) var resultCode = data.resultCode; if(resultCode == 0) { var date = data.data; var pardt = date.pardt; var UserId = pardt[0].UserId; var token = date.token; var BusinessTypeID = pardt[0].BusinessTypeID; var SchoolId = pardt[0].SchoolId; var SchoolCode = pardt[0].SchoolCode; var OnlyCode = pardt[0].OnlyCode; var StuId = pardt[0].StuId; var ClassId = pardt[0].ClassId; var GradeName = pardt[0].GradeName; var SchoolName = pardt[0].SchoolName; var ImageUrl = pardt[0].ImageUrl; var as = null; if(pardt.length != 0) { $.cookie('as', as, { expires: 7, path: '/' }); $.cookie('token', token, { expires: 7, path: '/' }); $.cookie('UserId', UserId, { expires: 7, path: '/' }); $.cookie('BusinessTypeID', BusinessTypeID, { expires: 7, path: '/' }); $.cookie('SchoolId', SchoolId, { expires: 7, path: '/' }); $.cookie('SchoolCode', SchoolCode, { expires: 7, path: '/' }); $.cookie('OnlyCode', OnlyCode, { expires: 7, path: '/' }); $.cookie('StuId', StuId, { expires: 7, path: '/' }); $.cookie('ClassId', ClassId, { expires: 7, path: '/' }); $.cookie('GradeName', GradeName, { expires: 7, path: '/' }); $.cookie('SchoolName', SchoolName, { expires: 7, path: '/' }); $.cookie('ImageUrl', ImageUrl, { expires: 7, path: '/' }); $(".btn").html("登录中..."); window.location.href = "public.html"; } else { Eject('子女信息异常'); } } else if(resultCode == -1) { Eject(data.data); } else if(resultCode == -2) { Eject(data.data); } else if(resultCode == -3) { Eject(data.data); } }, error: function(data) { alert("其使用360急速模式或其他更高版本浏览器"); } }); }); $("body").keydown(function() { if(event.keyCode == "13") { $('.btn_login').click(); } }); //---------------------------------------登录------------------------------------- //---------------------------------------忘记------------------------------------- $('.fsdx').hide(); $('.czmm').hide(); $('.wjmm_btn').click(function() { $('.zhdl').hide(); $('.fsdx').show(); $('.fsdx_btn').val('发送短信'); }) $('.fsdx_btn').click(function() { var phone = $('.phones').val(); if(phone != '') { $.ajax({ type: "post", url: url_cz + 'checkPhone', dataType: 'json', data: { phone: phone, }, success: function(data) { var resultCode = data.resultCode; var data = data.data; checkStatus = data.checkStatus; if(resultCode == 0) { if(checkStatus == 1) { showtime(30); $.ajax({ type: "post", url: url_cz + 'getVeriCode', dataType: 'json', data: { phone: phone, }, success: function(data) { var resultCode = data.resultCode if(resultCode == 0) { } else { alert('系统繁忙请稍后再试') } }, error: function(data) { alert("请求错误"); } }); } else { alert('手机号未注册') } } else { alert('系统繁忙请稍后重试') } }, error: function(data) { alert("请求错误"); } }); } else { alert('帐号不能为空'); } }) $('.wjmm_xyb').click(function() { var vericode = $('.yzm_val').val(); var phone = $('.phones').val(); if(vericode != '' && phone != '') { $('.fsdx').hide(); $('.czmm').show(); $.ajax({ type: "post", url: url_cz + 'checkPhone', dataType: 'json', data: { phone: phone, }, success: function(data) { var resultCode = data.resultCode; var data = data.data; checkStatus = data.checkStatus; if(resultCode == 0) { if(checkStatus != 1) { alert('手机号未注册'); } } else { alert('系统繁忙请稍后再试'); } }, error: function(data) { alert("请求错误"); } }); $('.czmm_wc').click(function() { var password = $('.password').val(); var password1 = $('.password1').val(); var reg = /^(?!\d{6,8}$)(?! )(?=.*[a-zA-Z])[a-zA-Z0-9_]{6,16}$/; if(password.length >= 6) {
if(password.match(reg)) {

if(password === password1) {
$.ajax({
type: "post",
url: url_cz + 'checkVeriCode',
dataType: 'json',
data: {
phone: phone,
vericode: vericode,
password: password,
},
success: function(data) {
// console.log(data)
var resultCode = data.resultCode;
var data = data.data;
var checkStatus = data.checkStatus;

if(resultCode == 0) {
if(checkStatus == 1) {
alert("成功修改密码,新密码为" + password1);
$('.czmm').hide();
$('.fsdx').hide();
$('.zhdl').show();
} else if(checkStatus == 0) {
alert('验证码错误')
$('.czmm').hide();
$('.fsdx').show();
} else if(checkStatus == -1) {
alert('修改密码失败')
$('.zhdl').show();
$('.czmm').hide();
$('.fsdx').hide();
}
} else {
alert("系统繁忙稍后重试")
}

},
error: function(data) {
alert("请求错误");
}
});
} else {
alert("两次输入的密码不同请重新输入")
}

} else {
Eject('密码至少包含一个字母')
return;
}
} else {
alert('新密码不能小于6位')
}

});
} else {
alert('手机号和验证码不能为空')
}

});

//---------------------------------------忘记-------------------------------------
//---------------------------------------验证-------------------------------------

function showtime(t) {
document.myform.phone.disabled = true;
for(i = 1; i <= t; i++) {
window.setTimeout("update_p(" + i + "," + t + ")", i * 1000);
}

}

function update_p(num, t) {
if(num == t) {
document.myform.phone.value = " 重新发送 ";
document.myform.phone.disabled = false;
} else {
printnr = t - num;
document.myform.phone.value = " (" + printnr + ")再次获取";
}
}
//---------------------------------------验证-------------------------------------
//---------------------------------------切换-------------------------------------
var code = '';
var sjc = '';

function Appendzero(obj) {
if(obj < 10) return "0" + "" + obj;
else return obj;
}

function sjcs() {
var oDate = new Date(); //实例一个时间对象;
var oyear = oDate.getFullYear(); //获取系统的年;
var omonth = oDate.getMonth() + 1; //获取系统月份,由于月份是从0开始计算,所以要加1
var oday = oDate.getDate(); // 获取系统日,
var ohour = oDate.getHours(); //获取系统时,
var ominute = oDate.getMinutes(); //分
var osecond = oDate.getSeconds(); //秒
sjc = oyear + '' + Appendzero(omonth) + '' + Appendzero(oday) + '' + Appendzero(ohour) + '' + Appendzero(ominute) + '' + Appendzero(osecond);

}

function randomWord(randomFlag, min, max) {
var str = "";
range = min,
arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];

// 随机产生
if(randomFlag) {
range = Math.round(Math.random() * (max - min)) + min;
}
for(var i = 0; i < range; i++) {
pos = Math.round(Math.random() * (arr.length - 1));
str += arr[pos];
}
return str;
}

var timer = '';
var xs = true;
$('.smdl').hide();
$('.qh_box').click(function() {
if(xs == true) {
$('.rwm_img').html('');
sjcs();
str = randomWord(true, 8, 8);

$(".rwm_ewm").qrcode({
render: "table", //table方式
width: 132, //宽度
height: 120, //高度
text: "xinkao-0-" + str + sjc //任意内容
});
$('.qh_box').css('background', 'no-repeat');
$('.qh_box').css('background-image', 'url(img/pc_img.png)');
$('.qh_box').css('background-size', '100%');
$('.zhdl').hide();
$('.fsdx').hide();
$('.czmm').hide();
$('.smdl').show();
timer = setInterval('showUnreadNews()', 500); //轮询执行,500ms一次
xs = false;
} else {
$('.rwm_img').html('');
$(".rwm_ewm").empty();
$('.qh_box').html();
$('.qh_box').css('background', 'no-repeat');
$('.qh_box').css('background-image', 'url(img/erwm_img.png)');
$('.qh_box').css('background-size', '100%');
$('.smdl').hide();
$('.fsdx').hide();
$('.czmm').hide();
$('.zhdl').show();
clearInterval(timer);
overtime = 240;
xs = true;
}
})

//---------------------------------------切换-------------------------------------

//---------------------------------------轮循-------------------------------------
var overtime = 240;
$('.rwm_img').click(function() {
sjcs();
str = randomWord(true, 8, 8);
$('.rwm_img').html('');
$(".rwm_ewm").qrcode({
render: "table", //table方式
width: 132, //宽度
height: 120, //高度
text: "xinkao-0-" + str + sjc //任意内容
});
timer = setInterval('showUnreadNews()', 500); //轮询执行,500ms一次
overtime = 240

})

function showUnreadNews() {
var stri = '请求超时

';
$(function() {
overtime--
// console.log(overtime + '--后超时');
code = str + sjc;
//console.log(code)
$.ajax({
type: "post",
url: url_s + '/api/HSCPC/CodeLoginPC',
dataType: 'json',
data: {
code: code,
ip: Ip,
type: 0,
},
success: function(data) {
// console.log(data)
var resultCode = data.resultCode;
if(resultCode == 0) {
clearInterval(timer);
var date = data.data;
var pardt = date.pardt;
var UserId = pardt[0].UserId;
var token = date.token;
var BusinessTypeID = pardt[0].BusinessTypeID;
var SchoolId = pardt[0].SchoolId;
var SchoolCode = pardt[0].SchoolCode;
var OnlyCode = pardt[0].OnlyCode;
var StuId = pardt[0].StuId;
var ClassId = pardt[0].ClassId;
var GradeName = pardt[0].GradeName;
var SchoolName = pardt[0].SchoolName;
var ImageUrl = pardt[0].ImageUrl;
var as = null;
if(pardt.length != 0) {
$.cookie('token', token, {
expires: 7,
path: '/'
});
$.cookie('UserId', UserId, {
expires: 7,
path: '/'
});
$.cookie('BusinessTypeID', BusinessTypeID, {
expires: 7,
path: '/'
});
$.cookie('SchoolId', SchoolId, {
expires: 7,
path: '/'
});
$.cookie('SchoolCode', SchoolCode, {
expires: 7,
path: '/'
});
$.cookie('OnlyCode', OnlyCode, {
expires: 7,
path: '/'
});
$.cookie('StuId', StuId, {
expires: 7,
path: '/'
});
$.cookie('ClassId', ClassId, {
expires: 7,
path: '/'
});
$.cookie('GradeName', GradeName, {
expires: 7,
path: '/'
});
$.cookie('SchoolName', SchoolName, {
expires: 7,
path: '/'
});
$.cookie('ImageUrl', ImageUrl, {
expires: 7,
path: '/'
});

window.location.href = "public.html";
} else {
Eject('子女信息异常');
}

} else if(resultCode == -1) {
// alert(data.data);
} else if(resultCode == -3) {
alert(data.data);
}
},
error: function(data) {
alert("其使用360急速模式或其他更高版本浏览器");
}
});
if(overtime <= 0) {
clearInterval(timer);
$('.rwm_ewm').html('');
$('.rwm_img').html(stri);
}
})
}

//---------------------------------------轮循-------------------------------------[/cc]

登录成功后,返回的data对象有如下属性:

[cc lang="JavaScript"]
var date = data.data; //date这是什么鬼命名方式
var UserId = pardt[0].UserId; //用户ID(跟家长手机号不同)
var token = date.token; //登录token,有效期大概是10分钟左右
var BusinessTypeID = pardt[0].BusinessTypeID; //套餐类型,无实际用途
var SchoolId = pardt[0].SchoolId; //学校ID
var SchoolCode = pardt[0].SchoolCode; //学校代码
var OnlyCode = pardt[0].OnlyCode; //唯一码(应该跟入学的时候填写的录取通知书上的编码有关)
var StuId = pardt[0].StuId; //学生代码
var ClassId = pardt[0].ClassId; //班级代码
var GradeName = pardt[0].GradeName; //年级名称
var SchoolName = pardt[0].SchoolName; //学校名称
var ImageUrl = pardt[0].ImageUrl; //后台主页显示的学生头像地址
var as = null;
[/cc]

提供的所有API如下:

PCGetSchoolUrl

获取学校介绍界面URL

PUSH http://usr.xinkaoyun.com/api/HSCPC/PCGetSchoolUrl

Args:
SchoolID: 学校ID

MySchool

查询学生所在学校介绍内容

PUSH http://usr.xinkaoyun.com/Api/HSCPC/MySchool

Args:
userid: 用户ID
token: 登录token
schoolId: 学校ID
stuId: 学生ID

MyTeacher

查询学生任课老师(数据不准)

PUSH http://usr.xinkaoyun.com/Api/HSCPC/MyTeacher

Args:
userid: 用户ID
token: 登录token
schoolId: 学校ID
stuId: 学生ID

MyClass

查询学生班级信息(数据不准)

PUSH http://usr.xinkaoyun.com/Api/HSCPC/MyClass

Args:
userid: 用户ID
token: 登录token
schoolId: 学校ID
stuId: 学生ID

SelectChild

获取家长目前选择的孩子(一个账户家长可以绑定上多个孩子的)

PUSH http://usr.xinkaoyun.com/api/HSCPC/SelectChild

Args:
userid: 用户ID
token: 登录token

PCScoJson

获取孩子的月考(调研考试及大考)成绩数据(分数)
数据准确

PUSH http://usr.xinkaoyun.com/Api/Sco/PCScoJson

Args:
token: 登录token
userid: 用户ID
stuId: 学生ID
schoolId: 学校ID
schoolCode: 学校编码
onlyCode: 唯一码
stime: 起始时间戳(不填写代表不限制)
etime: 终止时间戳(不填写代表不限制,两项都不填写代表获取所有)
pageIndex: 查看的页数
pageRows: 一页显示个数

PCFeeJson

获取孩子的消费情况概览数据(统计数据)
数据准确

PUSH http://usr.xinkaoyun.com/api/fee/PCFeeJson

Args:
token: 登录token
userid: 用户ID
stuId: 学生ID
schoolId: 学校ID
schoolCode: 学校编码
onlyCode: 唯一码
pageIndex: 查看的页数

PCFeeDetail

获取孩子的消费详细记录
数据准确

PUSH http://usr.xinkaoyun.com/Api/fee/PCFeeDetail

Args:
token: 登录token
userid: 用户ID
stuId: 学生ID
schoolId: 学校ID
schoolCode: 学校编码
onlyCode: 唯一码
stime: 起始时间戳(不填写代表不限制)
etime: 终止时间戳(不填写代表不限制,两项都不填写代表获取所有)
pageIndex: 查看的页数
pageRows: 一页显示个数