我把脚本修改了一下,可以自动更新refresh_token了,我觉得这个应该不算模拟登录,就是那旧的token换新的而已,跟前面的post操作没啥本质区别
[JavaScript] 纯文本查看 复制代码 var myDate = new Date(); // 创建一个表示当前时间的 Date 对象
var data_time = myDate.toLocaleDateString(); // 获取当前日期的字符串表示
function sleep(d) {
for (var t = Date.now(); Date.now() - t <= d;); // 使程序暂停执行一段时间
}
function log(message) {
console.log(message); // 打印消息到控制台
// TODO: 将日志写入文件
}
var tokenColumn = "A"; // 设置列号变量为 "A"
var qiandaoColumn = "B"; // 设置列号变量为 "B"
var serverchanColumn = "C"; // 设置列号变量为 "C"
var pushplusColumn = "D"; // 设置列号变量为 "D"
var pushColumn = "E"; // 设置列号变量为 "E"
var logindateColumn = "G"; // 设置列号变量为 "G"
for (let row = 1; row <= 10; row++) { // 循环遍历从第 1 行到第 10 行的数据
var refresh_token = Application.Range(tokenColumn + row).Text; // 获取指定单元格的值
var qiandao = Application.Range(qiandaoColumn + row).Text; // 获取指定单元格的值
var servertoken = Application.Range(serverchanColumn + row).Text; // 获取指定单元格的值
var pushtoken = Application.Range(pushplusColumn + row).Text; // 获取指定单元格的值
var push = Application.Range(pushColumn + row).Text; // 获取指定单元格的值
var ldate = Application.Range(logindateColumn + row).Text; // 获取指定单元格的值
if (refresh_token != "") { // 如果刷新令牌不为空
if (qiandao == "是") {//签到&领奖开关
//获取Bearer-token
let data = HTTP.post("https://auth.aliyundrive.com/v2/account/token",
JSON.stringify({
"grant_type": "refresh_token",
"refresh_token": refresh_token
})
)
data = data.json()
var access_token = data['access_token']
var phone = data["user_name"]
if (access_token == undefined) { // 如果报错
console.log("单元格【" + tokenColumn + row + "】token执行出错,请检查token或者API接口");
continue; // 跳过当前行的后续操作()
}
Time.sleep(3000)
try {
// 签到
var access_token2 = 'Bearer ' + access_token; // 构建包含访问令牌的请求头
let data2 = HTTP.post("https://member.aliyundrive.com/v1/activity/sign_in_list",
JSON.stringify({ "_rx-s": "mobile" }),
{ headers: { "Authorization": access_token2 } }
);
data2 = data2.json(); // 将响应数据解析为 JSON 格式
var signin_count = data2['result']['signInCount']; // 获取签到次数
var result1 = "账号:" + phone + " - 签到成功";
var result2 = "本月累计签到 " + signin_count + " 天";
console.log(result1)
} catch (error) {
console.log("单元格【" + tokenColumn + row + "】签到出错,请检查API接口");
continue; // 跳过当前行的后续操作()
}
Time.sleep(3000)
try {
// 领取奖励
let data3 = HTTP.post(
"https://member.aliyundrive.com/v1/activity/sign_in_reward?_rx-s=mobile",
JSON.stringify({ "signInDay": signin_count }),
{ headers: { "Authorization": access_token2 } }
);
data3 = data3.json(); // 将响应数据解析为 JSON 格式
var result3 = data3["result"]["name"]; // 获取奖励名称
var result4 = data3["result"]["notice"]; // 获取奖励描述
console.log(result4)
} catch (error) {
console.log("单元格【" + tokenColumn + row + "】领奖出错,请手动确认");
continue; // 跳过当前行的后续操作()
}
var loginnotice = "" //20天后自动刷新refresh_token
var ldate = Application.Range(logindateColumn + row).Text; // 获取指定单元格的值
if (ldate !== '') {
Application.Range(logindateColumn + row).NumberFormat = 'yyyy-mm-dd;@'
var formatlogindate = Application.Range(logindateColumn + row).Text
console.log(formatlogindate)
function formatDateTime(date) {
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
return `${year}-${pad(month)}-${pad(day)} `;
}
function pad(num) {
return num.toString().padStart(2, '0');
}
const currentDate = new Date();
var formacurrentdate = formatDateTime(currentDate);
console.log(formacurrentdate)
function getDate(strDate) {
if (strDate == null || strDate === undefined) return null;
var date = new Date();
try {
if (strDate == undefined) {
date = null;
} else if (typeof strDate == 'string') {
strDate = strDate.replace(/:/g, '-');
strDate = strDate.replace(/ /g, '-');
var dtArr = strDate.split("-");
if (dtArr.length >= 3 && dtArr.length < 6) {
date = new Date(dtArr[0], dtArr[1], dtArr[2]);
} else if (date.length > 8) {
date = new Date(Date.UTC(dtArr[0], dtArr[1] - 1, dtArr[2], dtArr[3] - 8, dtArr[4], dtArr[5]));
}
} else {
date = null;
}
return date;
} catch (e) {
alert('格式化日期出现异常:' + e.message);
}
}
var timeslong = getDate(formacurrentdate).getTime() - getDate(formatlogindate).getTime();
console.log(timeslong)
if (timeslong > 1728000000) {//时间差单位毫秒
var loginnotice = "登录已超20天自动刷新refresh_token";
let my_token = HTTP.post("https://auth.aliyundrive.com/v2/account/token",
JSON.stringify({
"grant_type": "refresh_token",
"refresh_token": refresh_token
}));
my_token = my_token.json()["refresh_token"]
if(my_token){
console.log("当前账号refresh_token刷新为", my_token);
Application.Range(tokenColumn + row).Value = my_token;
console.log("当前账号登录日期刷新为", formacurrentdate);
Application.Range(logindateColumn + row).Value = formacurrentdate
}
}
}
//推送
if (servertoken !== '' && push == "Serverchan") {//serverchan通道推送
const urls = "https://sctapi.ftqq.com/" + servertoken + ".send"
let response = HTTP.post(
urls,
{
title: result1,
desp: '' + result2 + '\n\n' + result4 + '\n\n' + loginnotice + '',
},
{
headers: {
"Content-Type": "application/json",
},
timeout: 60000, // 设置超时时间
}
);
// 打印推送结果
console.log(response.text());
}
if (pushtoken !== '' && push == "Pushplus") {//pushplus通道推送
const urlp = "http://www.pushplus.plus/send"
let response = HTTP.post(
urlp,
{
"token": pushtoken,
"title": "阿里云盘-签到通知",
"content": '' + result1 + '\n' + result2 + '\n' + result4 + '\n' + loginnotice + '',
"channel": "wechat",
"template": "html"
},
{
headers: {
"Content-Type": "application/json",
},
timeout: 60000, // 设置超时时间
}
);
// 打印推送结果
console.log(response.text());
}
}
}
//无有效token
} |