Update kfh.js

This commit is contained in:
smallfawn
2024-03-26 17:53:38 +08:00
committed by GitHub
parent 6be54c3100
commit b2512d1cd1

View File

@@ -18,141 +18,144 @@ let userList = [];
let shareList = [] let shareList = []
let msg = "" let msg = ""
class Task { class Task {
constructor(str) { constructor(str) {
this.index = ++userIdx; this.index = ++userIdx;
this.ck = str.split(strSplitor)[0]; //单账号多变量分隔符 this.ck = str.split(strSplitor)[0]; //单账号多变量分隔符
this.ckStatus = true; this.ckStatus = true;
//定义在这里的headers会被get请求删掉content-type 而不会重置 //定义在这里的headers会被get请求删掉content-type 而不会重置
} }
async main() { async main() {
await this.userInfo(); await this.userInfo();
await this.signIn() await this.signIn()
await this.getShareUrl() await this.getShareUrl()
} }
async taskRequest(method, url, body = "") { async taskRequest(method, url, body = "") {
// //
let headers = { let headers = {
"Host": "fscrm.kraftheinz.net.cn", "Host": "fscrm.kraftheinz.net.cn",
"Connection": "keep-alive", "Connection": "keep-alive",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x6309092b) XWEB/9079 Flue", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x6309092b) XWEB/9079 Flue",
"token": this.ck, "token": this.ck,
"Content-Type": "application/x-www-form-urlencoded", "Content-Type": "application/x-www-form-urlencoded",
"Accept": "*/*", "Accept": "*/*",
"Origin": "https://fscrm.kraftheinz.net.cn", "Origin": "https://fscrm.kraftheinz.net.cn",
"Referer": "https://fscrm.kraftheinz.net.cn/?code=081dcPGa1MYgaH0yI6Ga1Rw39X0dcPGg&state=&appid=wx65da983ae179e97b", "Referer": "https://fscrm.kraftheinz.net.cn/?code=081dcPGa1MYgaH0yI6Ga1Rw39X0dcPGg&state=&appid=wx65da983ae179e97b",
}
const reqeuestOptions = {
url: url,
method: method,
headers: headers
}
body == "" ? "" : Object.assign(reqeuestOptions, { body: body })
let { body: result } = await $.httpRequest(reqeuestOptions)
return result
} }
async userInfo() { const reqeuestOptions = {
try { url: url,
let result = await this.taskRequest("get", `https://fscrm.kraftheinz.net.cn/crm/public/index.php/api/v1/getUserInfo`) method: method,
//console.log(result); headers: headers
if (result.error_code == 0) { }
$.log(`✅账号[${this.index}] 欢迎用户 ${result.data.nickname} 积分 => ${result.data.memberInfo.score}🎉`) body == "" ? "" : Object.assign(reqeuestOptions, { body: body })
this.ckStatus = true; let { body: result } = await $.httpRequest(reqeuestOptions)
} else { return result
$.log(`❌账号[${this.index}] 用户查询失败[${result.msg}]`); }
this.ckStatus = false; async userInfo() {
} try {
} catch (e) { let result = await this.taskRequest("get", `https://fscrm.kraftheinz.net.cn/crm/public/index.php/api/v1/getUserInfo`)
console.log(e); //console.log(result);
if (result.error_code == 0) {
$.log(`✅账号[${this.index}] 欢迎用户 ${result.data.nickname} 积分 => ${result.data.memberInfo.score}🎉`)
this.ckStatus = true;
} else {
$.log(`❌账号[${this.index}] 用户查询失败[${result.msg}]`);
this.ckStatus = false;
}
} catch (e) {
console.log(e);
}
}
async signIn() {
try {
let result = await this.taskRequest("post", `https://fscrm.kraftheinz.net.cn/crm/public/index.php/api/v1/dailySign`, ``)
//console.log(result);
if (result.error_code == 0) {
$.log(`✅账号[${this.index}] [${result.msg}] 当前积分[${result.data.res}]🎉`)
} else {
$.log(`❌账号[${this.index}] 签到失败[${result.msg}]`);
}
} catch (e) {
console.log(e);
}
}
randomInt(min, max) {
return Math.round(Math.random() * (max - min) + min);
}
async getShareUrl() {
try {
let result = await this.taskRequest("post", `https://fscrm.kraftheinz.net.cn/crm/public/index.php/api/v1/getCookbookIndex`, "page=1&pagesize=10")
//console.log(result);
if (result.error_code == 0) {
let shareid = result.data.chineseCookbook.data[this.randomInt(0, 9)].id
let getShareCodeResult = await this.taskRequest("post", `https://fscrm.kraftheinz.net.cn/crm/public/index.php/api/v1/createCookbookCode`, `cookbook_id=${shareid}`)
if (getShareCodeResult?.error_code == 0) {
//console.log(getShareCodeResult)
let code_url = getShareCodeResult?.data.code_url.replace("https://fscrm.kraftheinz.net.cn/?", "")
shareList.push(code_url)
$.log(`✅账号[${this.index}]${code_url}获取分享文章链接成功,添加到内部助力池成功 🎉`);
} }
} else {
$.log(`❌账号[${this.index}] 签到失败[${result.msg}]`);
}
} catch (e) {
console.log(e);
} }
async signIn() { }
try { //首账号助力作者?//得到助力码数组后 账号一助力账号二 .....最后一个账号助力账号1
let result = await this.taskRequest("post", `https://fscrm.kraftheinz.net.cn/crm/public/index.php/api/v1/dailySign`, ``) async help(params) {
//console.log(result); try {
if (result.error_code == 0) { let result = await this.taskRequest("post", `https://fscrm.kraftheinz.net.cn/crm/public/index.php/api/v1/recordScoreShare`, params)
$.log(`✅账号[${this.index}] [${result.msg}] 当前积分[${result.data.res}]🎉`) //console.log(result);
} else { if (result.error_code == 0) {
$.log(`❌账号[${this.index}] 签到失败[${result.msg}]`); //console.log(`✅账号[${this.index}] 欢迎用户: ${result.errcode}🎉`);
} $.log(`✅账号[${this.index}] 助力情况${result.msg}🎉`)
} catch (e) { } else {
console.log(e); $.log(`❌账号[${this.index}] 助力失败[${result.msg}]`);
} }
} } catch (e) {
randomInt(min, max) { console.log(e);
return Math.round(Math.random() * (max - min) + min);
}
async getShareUrl() {
try {
let result = await this.taskRequest("post", `https://fscrm.kraftheinz.net.cn/crm/public/index.php/api/v1/getCookbookIndex`, "page=1&pagesize=10")
//console.log(result);
if (result.error_code == 0) {
let shareid = result.data.chineseCookbook.data[this.randomInt(0, 9)].id
let getShareCodeResult = await this.taskRequest("post", `https://fscrm.kraftheinz.net.cn/crm/public/index.php/api/v1/createCookbookCode`, `cookbook_id=${shareid}`)
if (getShareCodeResult?.error_code == 0) {
//console.log(getShareCodeResult)
let code_url = getShareCodeResult?.data.code_url.replace("https://fscrm.kraftheinz.net.cn/?", "")
shareList.push(code_url)
$.log(`✅账号[${this.index}]${code_url}获取分享文章链接成功,添加到内部助力池成功 🎉`);
}
} else {
$.log(`❌账号[${this.index}] 签到失败[${result.msg}]`);
}
} catch (e) {
console.log(e);
}
}
//首账号助力作者?//得到助力码数组后 账号一助力账号二 .....最后一个账号助力账号1
async help(params) {
try {
let result = await this.taskRequest("post", `https://fscrm.kraftheinz.net.cn/crm/public/index.php/api/v1/recordScoreShare`, params)
//console.log(result);
if (result.error_code == 0) {
//console.log(`✅账号[${this.index}] 欢迎用户: ${result.errcode}🎉`);
$.log(`✅账号[${this.index}] 助力情况${result.msg}🎉`)
} else {
$.log(`❌账号[${this.index}] 助力失败[${result.msg}]`);
}
} catch (e) {
console.log(e);
}
} }
}
} }
!(async () => { !(async () => {
if (!(await checkEnv())) return; if (!(await checkEnv())) return;
if (userList.length > 0) { if (userList.length > 0) {
let taskall = []; let taskall = [];
for (let user of userList) { for (let user of userList) {
if (user.ckStatus) { if (user.ckStatus) {
taskall.push(await user.main()); taskall.push(await user.main());
} }
}
await Promise.all(taskall);
taskall = [];
for (let i in userList) {
if (userList[i].ckStatus) {
let sharCode = shareList[Number(i) + 1]
if (sharCode !== undefined) {
taskall.push(await userList[i].help(sharCode));
} else {
if (userList.length > 1) {
userList[i].help(await shareList[0])
} else {
$.log(`账号数目为1 不执行内部助力`)
}
}
}
}
await Promise.all(taskall);
} }
await $.sendMsg($.logs.join("\n")) await Promise.all(taskall);
taskall = [];
for (let i in userList) {
if (userList[i].ckStatus) {
let sharCode = shareList[Number(i) + 1]
if (sharCode !== undefined) {
console.log(userList[i].ck + "=>" + sharCode)
taskall.push(await userList[i].help(sharCode));
} else {
if (userList.length > 1) {
console.log(userList[i].ck + "=>" + shareList[0])
taskall.push(await userList[i].help(shareList[0]));
} else {
$.log(`账号数目为1 不执行内部助力`)
}
}
}
}
await Promise.all(taskall);
}
await $.sendMsg($.logs.join("\n"))
})() })()
.catch((e) => console.log(e)) .catch((e) => console.log(e))
.finally(() => $.done()); .finally(() => $.done());
//******************************************************** //********************************************************
/** /**
@@ -160,20 +163,20 @@ class Task {
* @returns * @returns
*/ */
async function checkEnv() { async function checkEnv() {
let userCookie = ($.isNode() ? process.env[ckName] : $.getdata(ckName)) || ""; let userCookie = ($.isNode() ? process.env[ckName] : $.getdata(ckName)) || "";
if (userCookie) { if (userCookie) {
let e = envSplitor[0]; let e = envSplitor[0];
for (let o of envSplitor) for (let o of envSplitor)
if (userCookie.indexOf(o) > -1) { if (userCookie.indexOf(o) > -1) {
e = o; e = o;
break; break;
} }
for (let n of userCookie.split(e)) n && userList.push(new Task(n)); for (let n of userCookie.split(e)) n && userList.push(new Task(n));
} else { } else {
console.log(`未找到CK【${ckName}`); console.log(`未找到CK【${ckName}`);
return; return;
} }
return console.log(`共找到${userList.length}个账号`), true; //true == !0 return console.log(`共找到${userList.length}个账号`), true; //true == !0
} }
//Env Api ============================= //Env Api =============================
/* /*