實(shí)訓(xùn)答案查詢?nèi)肟?/h3>
頭歌EduCoder平臺(tái)實(shí)訓(xùn)答案在此,里面搜集了一些答案,可以查查有沒有想看的。
https://edaser.github.io/
一定不要直接復(fù)制答案,建議還是自己做,實(shí)在不會(huì)做的,參考看完后要獨(dú)立完成。
在這里可以查詢一些實(shí)訓(xùn)的答案,后臺(tái)的數(shù)據(jù)庫記錄了幾百個(gè)實(shí)訓(xùn)關(guān)卡的答案,實(shí)現(xiàn)的方法見下文。
實(shí)現(xiàn)方法
EduCoder平臺(tái)需要花費(fèi)金幣來解鎖答案,平均每個(gè)關(guān)卡需要150金幣。首先每天進(jìn)行自動(dòng)簽到領(lǐng)取金幣,通過這些金幣,就可以解鎖大部分實(shí)訓(xùn)的答案了,然后通過接口獲取到答案,保存為數(shù)據(jù)庫就行了。文章來源:http://www.zghlxwxcb.cn/news/detail-506821.html
以下代碼為nodejs環(huán)境文章來源地址http://www.zghlxwxcb.cn/news/detail-506821.html
EduCoder接口封裝代碼
const rp = require("request-promise");
class Session{
/**
簡單的一個(gè)Session會(huì)話類,用于記錄cookies
*/
constructor(cookies){
this.cookies = cookies||""; //記錄cookies
}
async request({url, method="GET",header, data, success, fail, complete}){
var options = {
method,
json:true,
uri: url,
headers:{
Cookie: this.cookies, ...header //每次請求帶上cookies
},
resolveWithFullResponse:true // 加上這個(gè)可以獲取到請求頭,從而得到新cookies,否則只返回請求得到的數(shù)據(jù)
}
if(method=="GET"){
options.qs = data //如果是GET,把data傳入querystring
}else if(method=="POST"){
options.body = data //如果是POST,把data傳入body
}
try{
console.debug("request options", options);
let {headers, body} = await rp(options); //用request-promise發(fā)起網(wǎng)絡(luò)請求
console.debug("request_success", headers, body);
if(headers["set-cookie"]){ //如果有新cookies,則獲取
this.cookies = headers["set-cookie"].map(i=>i.split(/;/g)[0]).join(";") // 簡單的記錄cookies
}else if(headers["Set-Cookie"]){
this.cookies = headers["set-cookie"].map(i=>i.split(/;/g)[0]).join(";")
}
success&&success(body); //成功,回調(diào)success函數(shù)
complete&&complete(body);
return body; // 返回?cái)?shù)據(jù)
}catch(e){
fail&&fail(e);
complete&&complete(e);
throw e;
}
}
}
const apiUrl = "https://www.educoder.net/api/"; //接口地址
async function eduHTTPApi({session,url,method,data}){
// 訪問EduCoder的api接口,并處理返回的數(shù)據(jù)
url = apiUrl + url;
let res = await session.request({
url,
method,
data
});
// 拋出調(diào)用EduCoder接口時(shí)的錯(cuò)誤,status<0或status>100時(shí)錯(cuò)誤
if(res.status && res.status > 100 || res.status<0){
let e = new Error(res.message);
e.code = res.status;
throw e;
}else
return res;
}
// 所有已經(jīng)封裝的EduCoder的接口函數(shù)合集
const eduApi = {
//登錄
async ["accounts.login"]({session, data}){
return eduHTTPApi({
session,
method:"POST",
url:"accounts/login.json",
data
});
},
// 獲取自己的所有實(shí)訓(xùn)
async ["users.shixuns"]({session, data}){
let url = `users/${data.login}/shixuns.json`;
delete data.login;
return eduHTTPApi({
session,
url,
data
})
},
// 獲取實(shí)訓(xùn)的詳情
async ["shixuns"]({session, data}){
let url = `shixuns/${data.identifier}`;
delete data.identifier;
return eduHTTPApi({
session,
url,
data
})
},
// 獲取實(shí)訓(xùn)的關(guān)卡
async ["shixuns.challenges"]({session, data}){
let url =`shixuns/${data.identifier}/challenges.json`;
delete url.identifier;
return eduHTTPApi({
session,
url,
data
})
},
// 獲取已解鎖的答案
async ["tasks.get_answer_info"]({session, data}){
let url = `tasks/${data.identifier}/get_answer_info.json`;
delete data.identifier;
return eduHTTPApi({
session,
url,
data
})
},
// 解鎖答案
async ["tasks.unlock_answer"]({session, data}){
let url = `tasks/${data.identifier}/unlock_answer.json`;
delete data.identifier;
return eduHTTPApi({
session,
url,
data
})
}
}
調(diào)用封裝的函數(shù)獲取答案
async function main(){
let session = new Session() //創(chuàng)建會(huì)話對象
let login = "用戶名";
let password = "對應(yīng)的密碼";
// 調(diào)用登錄接口
let {login} = await eduApi["accounts.login"]({session, data:{login, password}}); // 獲取用戶的login
// 獲取自己的實(shí)訓(xùn)列表
let {shixuns} = await eduApi["users.shixuns"]({session, data:{login, page:1, per_page:10}});
// 以獲取第一個(gè)實(shí)訓(xùn)的第一個(gè)關(guān)卡的答案為例
let {identifier} = shixuns[0]; //第一個(gè)實(shí)訓(xùn)
// 獲取實(shí)訓(xùn)的所有關(guān)卡
let {challenge_list} = await eduApi["shixuns.challenges"]({session, data:{identifier}});
let challenge = challenge_list[0]; // 第一個(gè)關(guān)卡
var task_identifier = challenge.open_game.match( /\/tasks\/(.*)/)[1];
try{
var {message} = await eduApi["tasks.get_answer_info"]({session, data:{identifier: task_identifier}});
// 如果答案已經(jīng)解鎖了,則成功獲取答案
console.info(message);
// ...其他函數(shù)邏輯
}catch(e){ // 答案沒有解鎖的情況
// 解鎖答案
var {contents} = await eduApi["tasks.unlock_answer"]({session, data:{identifier: task_identifier}});
console.info(contents);
// ...其他函數(shù)邏輯
}
}
到了這里,關(guān)于獲取頭歌實(shí)訓(xùn)參考答案(EduCoder)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!