军训的时候拿到一个别人写好的脚本,然后那个脚本的逻辑是自动获取CourseID,有一点小Bug,然后这次就直接手动改他的CourseID,讲道理应该适用于所有人。
找室友试了一下,发现那个ID不一样,然后需要手动获取一下。方法也很简单。录了个小视频放在下面。
下面附上代码:
function randomNum(minNum, maxNum) {
switch (arguments.length) {
case 1:
return parseInt(Math.random() * minNum + 1, 10);
case 2:
return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
default:
return 0;
}
}
function getTimeStamp() {
return randomNum(1000000000, 9999999999);
}//随机时间戳
var user = JSON.parse(localStorage.getItem("user"));
var finishWxHost = finishWxHost = "weiban.mycourse.cn";
var finishWxUrl = "https://weiban.mycourse.cn/pharos/usercourse/finish.do";
var userid = user.userId;
var jiaoxuejihuaid = user.tenantCode;
var finishData = { "userCourseId": userid, "tenantCode": jiaoxuejihuaid };
var userProjectId = "2b169437-f378-4a8f-a7d3-0ef448fb3c91"
//var userProjectId = user.preUserProjectId;
var courseList = {}
$.ajax({
url: "https://weiban.mycourse.cn/pharos/usercourse/listCourse.do?timestamp=" + getTimeStamp(),
type: 'POST',
async: false,
data: {
userProjectId: userProjectId,
chooseType: 3,
tenantCode: jiaoxuejihuaid,
name: '',
},
success: function(result) {
courseList = JSON.parse(result).data;
console.log("成功获取课程列表。")
console.log(courseList)
},
}); // get course list.
function doStudy(courseId) {
var courseUrl = "";
$.ajax({
url: "https://weiban.mycourse.cn/pharos/usercourse/study.do?timestamp=" + getTimeStamp(),
type: 'POST',
data: {
userProjectId: userProjectId,
courseId: courseId,
tenantCode: jiaoxuejihuaid,
}
});
$.ajax({
url: "https://weiban.mycourse.cn/pharos/usercourse/getCourseUrl.do?timestamp=" + getTimeStamp(),
type: 'POST',
async: false,
data: {
userProjectId: userProjectId,
courseId: courseId,
tenantCode: jiaoxuejihuaid,
},
jsonp: 'callback',
success: function(result) {
courseUrl = result.data;
},
});
$.get(courseUrl);
}
function sleep(delay) {
var start = (new Date()).getTime();
while ((new Date()).getTime() - start < delay) {
continue;
}
}
let runTrainer = () => {
for (var i = 0; i < 10; ++i) {
for (var j = 0; j < courseList[i].totalNum; ++j) {
finishData.userCourseId = courseList[i].courseList[j].userCourseId;
if (courseList[i].courseList[j].finished === 1)
continue;
doStudy(courseList[i].courseList[j].resourceId);
//var waitTime = (1 + randomNum(0, 1));
//console.log("等待" + waitTime + "s后完成一个课程的学习")
//sleep(waitTime * 1000);
$.ajax({
async: false,
url: finishWxUrl,
type: "GET",
dataType: "jsonp",
data: finishData,
timeout: 5000,
success: function(data) {
if (data.msg == "ok") {
console.log("恭喜,您已完成本微课的学习:" + i + 1 + "-" + j + 1);
} else {
alert("发送完成数据失败。");
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
},
});
}
}
}
runTrainer()//执行runTrainer
Comments | NOTHING