add auto AckNotification
This commit is contained in:
@ -4,19 +4,26 @@ const nodemailer = require('nodemailer')
|
||||
const { default: axios } = require("axios")
|
||||
const { log } = require("./logger")
|
||||
|
||||
exports.NotificationURL = 'https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/listNotifications?is_sort=true&source=NotificationSourceUnknown&status=NotificationStatusUnread&type=NotificationTypePopup'
|
||||
exports.ListNotificationURL = 'https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/listNotifications?is_sort=true&source=NotificationSourceUnknown&status=NotificationStatusUnread&type=NotificationTypePopup'
|
||||
exports.AckNotificationURL = 'https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/ackNotification'
|
||||
exports.WalletURL = 'https://api-cloudgame.mihoyo.com/hk4e_cg_cn/wallet/wallet/get?cost_method=COST_METHOD_UNSPECIFIED'
|
||||
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.8.0&channel=mihoyo'
|
||||
|
||||
exports.Notification = async function(header) {
|
||||
let tmp = (await axios(exports.NotificationURL,{
|
||||
exports.ListNotification = async function(header) {
|
||||
let tmp = (await axios(exports.ListNotificationURL,{
|
||||
headers:header
|
||||
})).data;
|
||||
tmp.StringVersion = JSON.stringify(tmp);
|
||||
return tmp;
|
||||
}
|
||||
exports.AckNotification = async function(header, id) {
|
||||
let data = `{"id":"${id}"}`;
|
||||
await axios.post(exports.AckNotificationURL, data,{
|
||||
headers:header
|
||||
});
|
||||
}
|
||||
exports.Wallet = async function(header) {
|
||||
let tmp = (await axios(exports.WalletURL,{
|
||||
headers:header
|
||||
|
28
src/index.js
28
src/index.js
@ -2,7 +2,7 @@ const fs = require("fs")
|
||||
|
||||
const reggol = require("reggol")
|
||||
|
||||
const { getConfigs, checkConfigs, makeHeader, Notification, Wallet, SendLog, AppVersion, getGlobalConfig } = require("./config")
|
||||
const { getConfigs, checkConfigs, makeHeader, ListNotification, AckNotification, Wallet, SendLog, AppVersion, getGlobalConfig } = require("./config")
|
||||
const urlconfig = require("./config")
|
||||
|
||||
const { log, addLogContent, getLogs } = require("./logger");
|
||||
@ -39,21 +39,23 @@ const nodemailer = require("nodemailer");
|
||||
totalNum ++;
|
||||
log.info(`正在执行配置 ${key}`)
|
||||
log.info("尝试签到……")
|
||||
var WalletRespond = await Wallet(makeHeader(configs[key]),appversion);
|
||||
var header = makeHeader(configs[key], appversion);
|
||||
var WalletRespond = await Wallet(header);
|
||||
addLogContent(`<span style="color: orange">${key} Wallet返回体 <br> ${JSON.stringify(WalletRespond)}</span><br>`);
|
||||
var NotificationRespond = await Notification(makeHeader(configs[key]));
|
||||
var NotificationRespond = await ListNotification(header);
|
||||
addLogContent(`<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("签到失败")
|
||||
}
|
||||
successNum ++;
|
||||
log.info(`签到完毕! 剩余时长:${WalletRespond.data.free_time.free_time}分钟`)
|
||||
let NotificationLength = NotificationRespond.data.list.length
|
||||
let postHeader = header;
|
||||
Object.assign(postHeader, {
|
||||
"Content-Length": 28,
|
||||
"Content-Type": "application/json",
|
||||
});
|
||||
for (var i = 0; i < NotificationLength; i++) {
|
||||
AckNotification(postHeader, NotificationRespond.data.list[i].id);
|
||||
}
|
||||
} else {
|
||||
log.error("签到失败")
|
||||
}
|
||||
|
Reference in New Issue
Block a user