IQIYI: Add support for node.js or jsbox.

This commit is contained in:
NobyDa 2020-07-29 16:33:12 +08:00
parent 8d3e9b6f33
commit 0fcc8c1406
2 changed files with 172 additions and 66 deletions

View File

@ -73,6 +73,20 @@
"id": "iQIYI",
"name": "爱奇艺",
"keys": ["CookieQY"],
"settings": [{
"id": "iQIYI_LogDetails",
"name": "响应日志",
"val": false,
"type": "boolean",
"desc": ""
}, {
"id": "iQIYI_TimeOut",
"name": "超时退出 (毫秒)",
"val": "",
"type": "number",
"placeholder": "默认无超时 (点击以展开说明)",
"desc": "按需填写, 用于由网络不稳定引起的脚本中断, 正常用户建议留空. 如QX日志出现\"JS Context timeout\"后脚本中断时, 建议填写6000"
}],
"script": "https://raw.githubusercontent.com/NobyDa/Script/master/iQIYI-DailyBonus/iQIYI.js",
"author": "@NobyDa",
"repo": "https://github.com/NobyDa/Script/blob/master/iQIYI-DailyBonus/iQIYI.js",

View File

@ -1,8 +1,8 @@
/*
爱奇艺会员签到脚本
更新时间: 2020.5.11 23:00
脚本兼容: QuantumultX, Surge4, Loon
更新时间: 2020.7.29 16:30
脚本兼容: QuantumultX, Surge4, Loon, JsBox, Node.js
电报频道: @NobyDa
问题反馈: @NobyDa_bot
@ -11,7 +11,15 @@
获取Cookie后, 请将Cookie脚本禁用并移除主机名以免产生不必要的MITM.
脚本将在每天上午9:00执行, 您可以修改执行时间
**********************
如果使用Node.js, 需自行安装'request'模块. : npm install request -g
JsBox, Node.js用户抓取Cookie说明
开启抓包, 打开爱奇艺App后(AppStore中国区)点击"我的" 返回抓包App 搜索url关键字: authcookie= 提取字母数字混合字段, &结束, 填入以下单引号内即可.
*/
var cookie = ''
/*********************
QuantumultX 本地脚本配置:
**********************
[task_local]
@ -51,127 +59,182 @@ http-request https?:\/\/.*\.iqiyi\.com\/.*authcookie= script-path=https://raw.gi
hostname= *.iqiyi.com
*/
var LogDetails = false; // 响应日志
var out = 0; // 超时 (毫秒) 如填写, 则不少于3000
var $nobyda = nobyda();
var done = $nobyda.done();
var notify = "";
var end = "";
if ($nobyda.isRequest) {
GetCookie()
} else {
login()
}
function login() {
var URL = {
url: 'https://cards.iqiyi.com/views_category/3.0/vip_home?secure_p=iPhone&scrn_scale=0&dev_os=0&ouid=0&layout_v=6&psp_cki=' + $nobyda.read("CookieQY") + '&page_st=suggest&app_k=8e48946f144759d86a50075555fd5862&dev_ua=iPhone8%2C2&net_sts=1&cupid_uid=0&xas=1&init_type=6&app_v=11.4.5&idfa=0&app_t=0&platform_id=0&layout_name=0&req_sn=0&api_v=0&psp_status=0&psp_uid=451953037415627&qyid=0&secure_v=0&req_times=0',
headers: {
sign: '7fd8aadd90f4cfc99a858a4b087bcc3a',
t: '479112291'
}
}
$nobyda.get(URL, async function(error, response, data) {
if (!error) {
if (data.match(/\"text\":\"\d.+?\u5230\u671f\"/)) {
end = data.match(/\"text\":\"(\d.+?\u5230\u671f)\"/)[1]
}
}
(async function ReadCookie() {
out = $nobyda.read("iQIYI_TimeOut") || out
cookie = cookie || $nobyda.read("CookieQY")
LogDetails = $nobyda.read("iQIYI_LogDetails") === "true" ? true : LogDetails
if ($nobyda.isRequest) {
GetCookie()
} else if (cookie) {
await login();
await Checkin();
await Lottery();
await $nobyda.time();
await $nobyda.done();
} else {
$nobyda.notify("爱奇艺会员", "", "签到终止, 未获取Cookie");
return $nobyda.done();
}
})()
function login() {
return new Promise(resolve => {
var URL = {
url: 'https://cards.iqiyi.com/views_category/3.0/vip_home?secure_p=iPhone&scrn_scale=0&dev_os=0&ouid=0&layout_v=6&psp_cki=' + cookie + '&page_st=suggest&app_k=8e48946f144759d86a50075555fd5862&dev_ua=iPhone8%2C2&net_sts=1&cupid_uid=0&xas=1&init_type=6&app_v=11.4.5&idfa=0&app_t=0&platform_id=0&layout_name=0&req_sn=0&api_v=0&psp_status=0&psp_uid=451953037415627&qyid=0&secure_v=0&req_times=0',
headers: {
sign: '7fd8aadd90f4cfc99a858a4b087bcc3a',
t: '479112291'
}
}
$nobyda.get(URL, function(error, response, data) {
const Details = LogDetails ? data ? `response:\n${data}` : '' : ''
if (!error && data.match(/\"text\":\"\d.+?\u5230\u671f\"/)) {
$nobyda.expire = data.match(/\"text\":\"(\d.+?\u5230\u671f)\"/)[1]
console.log(`爱奇艺-查询成功: ${$nobyda.expire} ${Details}`)
} else {
console.log(`爱奇艺-查询失败${error || ': 无到期数据 ⚠️'} ${Details}`)
}
resolve()
})
if (out) setTimeout(resolve, out)
})
}
function Checkin() {
return new Promise(resolve => {
var URL = {
url: 'https://tc.vip.iqiyi.com/taskCenter/task/queryUserTask?autoSign=yes&P00001=' + $nobyda.read("CookieQY")
url: 'https://tc.vip.iqiyi.com/taskCenter/task/queryUserTask?autoSign=yes&P00001=' + cookie
}
$nobyda.get(URL, function(error, response, data) {
if (error) {
notify = "签到失败: 接口请求出错 ‼️"
console.log("爱奇艺会员签到失败:\n" + error)
$nobyda.data = "签到失败: 接口请求出错 ‼️"
console.log(`爱奇艺-${$nobyda.data} ${error}`)
} else {
var obj = JSON.parse(data)
const obj = JSON.parse(data)
const Details = LogDetails ? `response:\n${data}` : ''
if (obj.msg == "成功") {
if (obj.data.signInfo.code == "A00000") {
var AwardName = obj.data.signInfo.data.rewards[0].name;
var quantity = obj.data.signInfo.data.rewards[0].value;
var continued = obj.data.signInfo.data.continueSignDaysSum;
notify = "签到成功: " + AwardName + quantity + ", 已连签" + continued + "天 🎉"
$nobyda.data = "签到成功: " + AwardName + quantity + ", 已连签" + continued + "天 🎉"
console.log(`爱奇艺-${$nobyda.data} ${Details}`)
} else {
notify = "签到失败: " + obj.data.signInfo.msg + " ⚠️"
$nobyda.data = "签到失败: " + obj.data.signInfo.msg + " ⚠️"
console.log(`爱奇艺-${$nobyda.data} ${Details}`)
}
} else {
notify = "签到失败: Cookie无效 ⚠️"
$nobyda.data = "签到失败: Cookie无效 ⚠️"
console.log(`爱奇艺-${$nobyda.data} ${Details}`)
}
}
resolve()
})
});
if (out) setTimeout(resolve, out)
})
}
function Lottery() {
return new Promise(resolve => {
var URL = {
url: 'https://iface2.iqiyi.com/aggregate/3.0/lottery_activity?app_k=0&app_v=0&platform_id=0&dev_os=0&dev_ua=0&net_sts=0&qyid=0&psp_uid=0&psp_cki=' + $nobyda.read("CookieQY") + '&psp_status=0&secure_p=0&secure_v=0&req_sn=0'
}
$nobyda.times++
const URL = {
url: 'https://iface2.iqiyi.com/aggregate/3.0/lottery_activity?app_k=0&app_v=0&platform_id=0&dev_os=0&dev_ua=0&net_sts=0&qyid=0&psp_uid=0&psp_cki=' + cookie + '&psp_status=0&secure_p=0&secure_v=0&req_sn=0'
}
$nobyda.get(URL, function(error, response, data) {
if (error) {
notify += "\n抽奖失败: 接口请求出错 ‼️"
console.log("爱奇艺会员抽奖失败:\n" + error)
$nobyda.notify("爱奇艺", "", notify)
$nobyda.data += "\n抽奖失败: 接口请求出错 ‼️"
console.log(`爱奇艺-抽奖失败: 接口请求出错 ‼️ ${error} (${$nobyda.times})`)
$nobyda.notify("爱奇艺", "", $nobyda.data)
} else {
var obj = JSON.parse(data);
const obj = JSON.parse(data);
const Details = LogDetails ? `response:\n${data}` : ''
const last = data.match(/\"daysurpluschance\":\"(1|2)\"/)
if (obj.awardName && obj.code == 0) {
notify += "\n抽奖成功: " + obj.awardName.replace(/《.+》/, "未中奖") + " 🎉"
$nobyda.data += "\n抽奖成功: " + obj.awardName.replace(/《.+》/, "未中奖") + " 🎉"
console.log(`爱奇艺-抽奖成功: ${obj.awardName.replace(/《.+》/, "未中奖")} 🎉 (${$nobyda.times}) ${Details}`)
} else if (data.match(/\"errorReason\"/)) {
msg = data.match(/msg=(.+?)\)/) ? data.match(/msg=(.+?)\)/)[1] : ""
notify += "\n抽奖失败: " + msg.replace(/用户(未登录|不存在)/, "Cookie无效") + " ⚠️"
msg = data.match(/msg=(.+?)\)/) ? data.match(/msg=(.+?)\)/)[1] : "" + '\n'
$nobyda.data += "\n抽奖失败: " + msg.replace(/用户(未登录|不存在)/, "Cookie无效") + " ⚠️"
console.log(`爱奇艺-抽奖失败: ${msg.replace(/用户(未登录|不存在)/, "Cookie无效")} ⚠️ (${$nobyda.times}) ${Details}`)
} else {
notify += "\n抽奖错误: 已输出日志 ⚠️"
console.log("爱奇艺会员抽奖失败:\n" + data)
$nobyda.data += "\n抽奖错误: 已输出日志 ⚠️"
console.log(`爱奇艺-抽奖失败: \n${data} (${$nobyda.times}) ${Details}`)
}
if (data.match(/\"daysurpluschance\":\"(1|2)\"/)) {
Lottery(notify)
if (last) {
Lottery()
} else {
expires = end ? end.replace(/\u5230\u671f/, "") : "获取失败 ⚠️"
$nobyda.notify("爱奇艺", "到期时间: " + expires, notify)
const expires = $nobyda.expire ? $nobyda.expire.replace(/\u5230\u671f/, "") : "获取失败 ⚠️"
if (!$nobyda.isNode) $nobyda.notify("爱奇艺", "到期时间: " + expires, $nobyda.data)
resolve()
}
}
resolve()
})
});
if (out) setTimeout(resolve, out)
})
}
function GetCookie() {
var regex = /authcookie=([A-Za-z0-9]+)/;
var iQIYI = regex.exec($request.url)[1];
if ($nobyda.read("CookieQY")) {
if ($nobyda.read("CookieQY") != iQIYI) {
var cookie = $nobyda.write(iQIYI, "CookieQY");
if (!cookie) {
$nobyda.notify("更新爱奇艺签到Cookie失败‼", "", "")
var iQIYI = $request.url.match(/authcookie=([A-Za-z0-9]+)/);
if (iQIYI) {
if ($nobyda.read("CookieQY")) {
if ($nobyda.read("CookieQY") != iQIYI[1]) {
var cookie = $nobyda.write(iQIYI[1], "CookieQY");
if (!cookie) {
$nobyda.notify("更新爱奇艺签到Cookie失败‼", "", "")
} else {
$nobyda.notify("更新爱奇艺签到Cookie成功 🎉", "", "")
}
} else {
$nobyda.notify("更新爱奇艺签到Cookie成功 🎉", "", "")
console.log("爱奇艺-与本机储存Cookie相同, 跳过写入 ‼️")
}
} else {
var cookie = $nobyda.write(iQIYI[1], "CookieQY");
if (!cookie) {
$nobyda.notify("首次写入爱奇艺Cookie失败‼", "", "")
} else {
$nobyda.notify("首次写入爱奇艺Cookie成功 🎉", "", "")
}
}
} else {
var cookie = $nobyda.write(iQIYI, "CookieQY");
if (!cookie) {
$nobyda.notify("首次写入爱奇艺Cookie失败‼", "", "")
} else {
$nobyda.notify("首次写入爱奇艺Cookie成功 🎉", "", "")
}
$nobyda.notify("写入爱奇艺Cookie失败", "", "URL不匹配 ‼️")
}
$nobyda.done();
}
function nobyda() {
const times = 0
const start = Date.now()
const isRequest = typeof $request != "undefined"
const isSurge = typeof $httpClient != "undefined"
const isQuanX = typeof $task != "undefined"
const isLoon = typeof $loon != "undefined"
const isJSBox = typeof $app != "undefined" && typeof $http != "undefined"
const isNode = typeof require == "function" && !isJSBox;
const node = (() => {
if (isNode) {
const request = require('request');
return ({
request
})
} else {
return (null)
}
})()
const notify = (title, subtitle, message) => {
if (isQuanX) $notify(title, subtitle, message)
if (isSurge) $notification.post(title, subtitle, message)
if (isNode) log('\n' + title + '\n' + subtitle + '\n' + message)
if (isJSBox) $push.schedule({
title: title,
body: subtitle ? subtitle + "\n" + message : message
})
}
const write = (value, key) => {
if (isQuanX) return $prefs.setValueForKey(value, key)
@ -204,6 +267,31 @@ function nobyda() {
if (isSurge) $httpClient.get(options, (error, response, body) => {
callback(error, adapterStatus(response), body)
})
if (isNode) {
node.request(options, (error, response, body) => {
callback(error, adapterStatus(response), body)
})
}
if (isJSBox) {
if (typeof options == "string") options = {
url: options
}
options["header"] = options["headers"]
options["handler"] = function(resp) {
let error = resp.error;
if (error) error = JSON.stringify(resp.error)
let body = resp.data;
if (typeof body == "object") body = JSON.stringify(resp.data);
callback(error, adapterStatus(resp.response), body)
};
$http.get(options);
}
}
const log = (message) => console.log(message)
const time = () => {
const end = ((Date.now() - start) / 1000).toFixed(2)
return console.log('\n签到用时: ' + end + ' 秒')
}
const done = (value = {}) => {
if (isQuanX) isRequest ? $done(value) : null
@ -211,10 +299,14 @@ function nobyda() {
}
return {
isRequest,
isNode,
notify,
write,
read,
get,
log,
time,
times,
done
}
};