init
This commit is contained in:
135
src/config.js
Normal file
135
src/config.js
Normal file
@ -0,0 +1,135 @@
|
||||
const { exit } = require("process")
|
||||
const fs = require("fs")
|
||||
const nodemailer = require('nodemailer')
|
||||
const { default: axios } = require("axios")
|
||||
|
||||
exports.NotificationURL = 'https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/listNotifications?status=NotificationStatusUnread&type=NotificationTypePopup&is_sort=true'
|
||||
exports.WalletURL = 'https://api-cloudgame.mihoyo.com/hk4e_cg_cn/wallet/wallet/get'
|
||||
exports.AnnouncementURL = 'https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/getAnnouncementInfo'
|
||||
// Here must be an earlier version so that the response won't be null
|
||||
exports.AppVersionURL = 'https://api-takumi.mihoyo.com/ptolemaios/api/getLatestRelease?app_id=1953443910&app_version=3.3.0&channel=mihoyo'
|
||||
|
||||
exports.Notification = async function(header) {
|
||||
let tmp = (await axios("GET",exports.NotificationURL,{
|
||||
headers:header
|
||||
})).data;
|
||||
tmp.StringVersion = JSON.stringify(tmp);
|
||||
return tmp;
|
||||
}
|
||||
exports.Wallet = async function(header) {
|
||||
let tmp = (await axios("GET",exports.WalletURL,{
|
||||
headers:header
|
||||
})).data;
|
||||
tmp.StringVersion = JSON.stringify(tmp);
|
||||
return tmp;
|
||||
}
|
||||
exports.Announcement = async function(header) {
|
||||
let tmp = (await axios("GET",exports.AnnouncementURL,{
|
||||
headers:header
|
||||
})).data;
|
||||
tmp.StringVersion = JSON.stringify(tmp);
|
||||
return tmp;
|
||||
}
|
||||
exports.AppVersion = async function() {
|
||||
let tmp = (await axios("GET",exports.AppVersionURL)).data;
|
||||
tmp.StringVersion = JSON.stringify(tmp);
|
||||
return tmp;
|
||||
}
|
||||
var configKeys = [
|
||||
"token",
|
||||
"client_type",
|
||||
"device_name",
|
||||
"device_model",
|
||||
"sys_version",
|
||||
"channel"
|
||||
]
|
||||
|
||||
exports.getGlobalConfig = function() {
|
||||
try {
|
||||
var globalConfig = fs.readFileSync("global.json")
|
||||
} catch(e) {
|
||||
if(e.toString().includes("Error: ENOENT: no such file or directory")) {
|
||||
log.error(`读取配置失败!找不到全局配置文件`)
|
||||
} else {
|
||||
log.error(`读取配置失败!错误信息:${e}`);
|
||||
}
|
||||
exit()
|
||||
}
|
||||
return JSON.parse(globalConfig);
|
||||
}
|
||||
|
||||
exports.getConfigs = function(){
|
||||
// var configsList;
|
||||
try {
|
||||
var configsList = fs.readdirSync("configs")
|
||||
} catch(e) {
|
||||
if(e == "Error: ENOENT: no such file or directory, scandir 'configs'") {
|
||||
log.error(`读取配置失败!找不到configs文件夹`)
|
||||
} else {
|
||||
log.error(`读取配置失败!错误信息:${e}`);
|
||||
}
|
||||
exit()
|
||||
}
|
||||
log.info(`检测到${configsList.length}个配置文件:`)
|
||||
configsList.forEach(file => {
|
||||
log.info(`${file}`)
|
||||
})
|
||||
var configs = {}
|
||||
configsList.forEach(file => {
|
||||
configs[file] = JSON.parse(fs.readFileSync(`configs/${file}`))
|
||||
})
|
||||
return configs
|
||||
}
|
||||
exports.checkConfigs = function(configs){
|
||||
for(file in configs) {
|
||||
var configThis = configs[file];
|
||||
var isNoProbem = true;
|
||||
for(key in configKeys) {
|
||||
if(configThis[configKeys[key]] == "" || configThis[configKeys[key]] == undefined || configThis[configKeys[key]] == null || configThis[configKeys[key]] == NaN) {
|
||||
log.error(`配置文件 ${file} 异常:`);
|
||||
log.error(` —— ${configKeys[key]}字段缺失`);
|
||||
// isNoProbem = false;
|
||||
}
|
||||
}
|
||||
|
||||
// if(!isNoProbem) {
|
||||
// exit();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
// var appversion = exports.AppVersion();
|
||||
|
||||
exports.makeHeader = function(data,appversion){
|
||||
return {
|
||||
'x-rpc-combo_token': data.token,
|
||||
'x-rpc-client_type': data.client_type,
|
||||
'x-rpc-app_version': appversion,
|
||||
'x-rpc-sys_version': data.sys_version,
|
||||
'x-rpc-channel': data.channel,
|
||||
'x-rpc-device_id': data.device_id,
|
||||
'x-rpc-device_name': data.device_name,
|
||||
'x-rpc-device_model': data.device_model,
|
||||
'x-rpc-app_id': 1953439974,
|
||||
'Referer': 'https://app.mihoyo.com',
|
||||
'Host': 'api-cloudgame.mihoyo.com',
|
||||
'Connection': 'Keep-Alive',
|
||||
'Accept-Encoding': 'gzip',
|
||||
'User-Agent': 'okhttp/4.9.0'
|
||||
}
|
||||
}
|
||||
|
||||
exports.SendLog = function(transporter,mailfrom,mailto,successNum,totalNum,content) {
|
||||
transporter.sendMail({
|
||||
from: mailfrom+'" Genshin CloudPlay Helper"', //邮件来源
|
||||
to: mailto, //邮件发送到哪里,多个邮箱使用逗号隔开
|
||||
subject: `今日已签到${successNum}/${totalNum}名用户`, // 邮件主题
|
||||
text: '☺️😍😎', // 存文本类型的邮件正文
|
||||
html: `${content}` // html类型的邮件正文
|
||||
}, (error, info) => {
|
||||
if (error) {
|
||||
return console.log(error);
|
||||
}
|
||||
log.info("日志已丢出!")
|
||||
});
|
||||
}
|
89
src/index.js
Normal file
89
src/index.js
Normal file
@ -0,0 +1,89 @@
|
||||
const fs = require("fs")
|
||||
|
||||
const reggol = require("reggol")
|
||||
|
||||
const { getConfigs, checkConfigs, makeHeader, Notification, Wallet, SendLog, AppVersion, getGlobalConfig } = require("./config")
|
||||
const urlconfig = require("./config")
|
||||
|
||||
const nodemailer = require('nodemailer')
|
||||
|
||||
const baseLogger = new reggol("GenshinCloudPlayHelper")
|
||||
var logContent = ``
|
||||
|
||||
global.log = {
|
||||
info(content){
|
||||
logContent += `<strong style="color: green">[info]</strong> ${content}<br>`
|
||||
baseLogger.info(content)
|
||||
},
|
||||
error(content){
|
||||
logContent += `<strong style="color: red">[error]</strong> ${content}<br>`
|
||||
baseLogger.error(content)
|
||||
}
|
||||
}
|
||||
|
||||
log.info("开始获取全局配置")
|
||||
var globalConfig = getGlobalConfig();
|
||||
log.info("获取成功")
|
||||
if (globalConfig.sendMail == true) {
|
||||
log.info("组装邮件发射器")
|
||||
var transporter = nodemailer.createTransport({
|
||||
host: globalConfig.mailConfig.smtpServer,
|
||||
port: globalConfig.mailConfig.smtpPort,
|
||||
secure: globalConfig.mailConfig.smtpSecure,
|
||||
auth: {
|
||||
user: globalConfig.mailConfig.user,
|
||||
pass: globalConfig.mailConfig.pass
|
||||
}
|
||||
});
|
||||
}
|
||||
var configs = getConfigs();
|
||||
// console.log(configs);
|
||||
log.info(`正在检测配置有效性`)
|
||||
checkConfigs(configs)
|
||||
log.info("检测完毕!")
|
||||
|
||||
(async () => {
|
||||
log.info("正在获取版本号")
|
||||
var appversion = await AppVersion();
|
||||
appversion = appversion.data.package_version
|
||||
log.info(`获取成功!当前版本号:${appversion}`)
|
||||
var successNum = 0,totalNum = 0;
|
||||
for (key in configs) {
|
||||
totalNum ++;
|
||||
log.info(`正在执行配置 ${key}`)
|
||||
log.info("尝试签到……")
|
||||
var WalletRespond = await Wallet(makeHeader(configs[key]),appversion);
|
||||
logContent += `<span style="color: orange">${key} Wallet返回体 <br> ${JSON.stringify(WalletRespond)}</span><br>`;
|
||||
var NotificationRespond = await Notification(makeHeader(configs[key]));
|
||||
logContent += `<span style="color: orange">${key} Notification返回体 <br> ${JSON.stringify(NotificationRespond)}</span><br>`;
|
||||
if(WalletRespond.data != null) {
|
||||
if(WalletRespond.data.free_time.free_time != undefined) {
|
||||
successNum ++;
|
||||
log.info(`签到完毕! 剩余时长:${WalletRespond.data.free_time.free_time}分钟`)
|
||||
let NotificationLength = NotificationRespond.data.list.length
|
||||
if(NotificationLength != 0) {
|
||||
log.info(`已堆积 ${NotificationLength} 个签到通知 请及时处理!`)
|
||||
}
|
||||
} else {
|
||||
log.error("签到失败")
|
||||
}
|
||||
} else {
|
||||
log.error("签到失败")
|
||||
}
|
||||
// log.info(`Wallet ${Wallet(makeHeader(configs[key])).StringVersion}`)
|
||||
// log.info(`Announcement ${Announcement(makeHeader(configs[key])).StringVersion}`)
|
||||
// console.log(makeHeader(configs[key]));
|
||||
}
|
||||
|
||||
if (globalConfig.sendMail == true) {
|
||||
log.info(`运行完毕!丢出日志`)
|
||||
SendLog(
|
||||
transporter,
|
||||
globalConfig.mailConfig.user,
|
||||
globalConfig.mailConfig.mailto,
|
||||
successNum,
|
||||
totalNum,
|
||||
logContent
|
||||
)
|
||||
}
|
||||
})()
|
Reference in New Issue
Block a user