Skip to content

Commit

Permalink
移除过期活动
Browse files Browse the repository at this point in the history
  • Loading branch information
fangpidedongsun committed Feb 19, 2021
1 parent a6e0e3f commit e5728d4
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 49 deletions.
File renamed without changes.
60 changes: 57 additions & 3 deletions jd_bean_change.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: LXK9301 https://github.com/LXK9301
* @Date: 2020-11-01 16:25:41
* @Last Modified by: LXK9301
* @Last Modified time: 2020-12-22 10:25:41
* @Last Modified time: 2021-02-19 10:25:41
*/
/*
京豆变动通知脚本:https://gitee.com/lxk0301/jd_scripts/raw/master/jd_bean_change.js
Expand Down Expand Up @@ -62,6 +62,8 @@ if ($.isNode()) {
$.isLogin = true;
$.nickName = '';
$.message = '';
$.balance = 0;
$.expiredBalance = 0;
await TotalBean();
console.log(`\n开始【京东账号${$.index}${$.nickName || $.UserName}\n`);
if (!$.isLogin) {
Expand Down Expand Up @@ -132,7 +134,8 @@ async function bean() {
$.expenseBean += Number(item.amount);
}
}
await queryexpirejingdou();
await queryexpirejingdou();//过期京豆
await redPacket();//过期红包
// console.log(`昨日收入:${$.incomeBean}个京豆 🐶`);
// console.log(`昨日支出:${$.expenseBean}个京豆 🐶`)
}
Expand Down Expand Up @@ -234,10 +237,13 @@ function queryexpirejingdou() {
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (data) {
console.log(data)
// console.log(data)
data = JSON.parse(data.slice(23, -13));
// console.log(data)
if (data.ret === 0) {
data['expirejingdou'].map(item => {
console.log(`${timeFormat(item['time'] * 1000)}日过期京豆:${item['expireamount']}\n`);
})
const expirejingdou = data['expirejingdou'][0]['expireamount'];
if (expirejingdou > 0) {
$.message += `\n今日将过期:${expirejingdou}京豆 🐶`;
Expand All @@ -255,6 +261,45 @@ function queryexpirejingdou() {
})
})
}
function redPacket() {
return new Promise(async resolve => {
const options = {
"url": `https://wq.jd.com/user/info/QueryUserRedEnvelopes?channel=3&type=1&page=0&pageSize=100&orgFlag=JD_PinGou_New&expiredRedFlag=1&sceneval=2&g_login_type=1&g_ty=ls`,
"headers": {
'Host': 'wq.jd.com',
'Accept': '*/*',
'Connection': 'keep-alive',
'Accept-Language': 'zh-cn',
'Referer': 'https://wqs.jd.com/my/redpacket.shtml',
'Accept-Encoding': 'gzip, deflate, br',
"Cookie": cookie,
'User-Agent': $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.2.2;14.2;%E4%BA%AC%E4%B8%9C/9.2.2 CFNetwork/1206 Darwin/20.1.0")
}
}
$.get(options, (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路重试`)
} else {
if (data) {
data = JSON.parse(data).data
$.balance = data.balance
$.expiredBalance = data.expiredBalance || 0;
$.message += `\n当前红包:${$.balance}元🧧`;
if ($.expiredBalance > 0) $.message += `\n今日将过期:${$.expiredBalance}元红包🧧`;
} else {
console.log(`京东服务器返回空数据`)
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
function jsonParse(str) {
if (typeof str == "string") {
try {
Expand All @@ -266,5 +311,14 @@ function jsonParse(str) {
}
}
}
function timeFormat(time) {
let date;
if (time) {
date = new Date(time)
} else {
date = new Date();
}
return date.getFullYear() + '-' + ((date.getMonth() + 1) >= 10 ? (date.getMonth() + 1) : '0' + (date.getMonth() + 1)) + '-' + (date.getDate() >= 10 ? date.getDate() : '0' + date.getDate());
}
// prettier-ignore
function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),n={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(n,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?(this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)})):this.isQuanX()?(this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t))):this.isNode()&&(this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)}))}post(t,e=(()=>{})){if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.post(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())t.method="POST",this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){this.initGotEnv(t);const{url:s,...i}=t;this.got.post(s,i).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl;return{"open-url":e,"media-url":s}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`❗️${this.name}, 错误!`,t.stack):this.log("",`❗️${this.name}, 错误!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,e)}
6 changes: 3 additions & 3 deletions jd_joy_run.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ async function getToken() {
count ++;
console.log(`count: ${count}`)
$.setdata(`${count}`, 'countFlag');
if ($.getdata('countFlag') * 1 >= 2) {
if ($.getdata('countFlag') * 1 === 2) {
count = 0;
$.setdata(`${count}`, 'countFlag');
$.msg($.name, '更新Token: 成功🎉', ``);
console.log(`开始上传Token`)
console.log(`开始上传Token${LKYLToken}\n`)
await $.http.get({url: `http://jd.turinglabs.net/api/v2/jd/joy/create/${LKYLToken}/`}).then((resp) => {
if (resp.statusCode === 200) {
let { body } = resp;
console.log(`Token提交结果:${body}`)
console.log(`Token提交结果:${body}\n`)
body = JSON.parse(body);
console.log(`${body.message}`)
}
Expand Down
98 changes: 58 additions & 40 deletions sendNotify.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ let DD_BOT_SECRET = '';
let QYWX_KEY = '';

// =======================================企业微信应用消息通知设置区域===========================================
//此处填你企业微信应用消息的 值(详见文档 https://work.weixin.qq.com/api/doc/90000/90135/90236),依次填上corpid的值,corpsecret的值,touser的值,agentid的值,素材库图片id(见https://github.com/LXK9301/jd_scripts/issues/519) 注意用,号隔开,例如:wwcff56746d9adwers,B-791548lnzXBE6_BWfxdf3kSTMJr9vFEPKAbh6WERQ,mingcheng,1000001,2COXgjH2UIfERF2zxrtUOKgQ9XklUqMdGSWLBoW_lSDAdafat
//corpid的值,corpsecret的值,touser的值,agentid的值,素材库图片id的获取,可查看此教程(https://note.youdao.com/ynoteshare1/index.html)
//增加一个选择推送消息类型,用图文消息直接填写素材库图片id的值,用卡片消息就填写0(就是数字零)
//此处填你企业微信应用消息的值(详见文档 https://work.weixin.qq.com/api/doc/90000/90135/90236)
//依次填入 corpid,corpsecret,touser,agentid,消息类型
//注意用,号隔开(英文输入法的逗号),例如:wwcff56746d9adwers,B-791548lnzXBE6_BWfxdf3kSTMJr9vFEPKAbh6WERQ,mingcheng,1000001,2COXgjH2UIfERF2zxrtUOKgQ9XklUqMdGSWLBoW_lSDAdafat
//可选推送消息类型:
// - 卡片消息: 0 (数字零)
// - 文字消息: 1 (数字一)
// - 图文消息: 素材库图片id, 可查看此教程(http://note.youdao.com/s/HMiudGkb)
//(环境变量名 QYWX_AM)
let QYWX_AM = '';

Expand Down Expand Up @@ -130,7 +134,7 @@ if (process.env.PUSH_PLUS_USER) {


async function sendNotify(text, desp, params = {}) {
//提供7种通知
//提供6种通知
desp += `\n本脚本开源免费使用 By:https://github.com/LXK9301/jd_scripts`;
await Promise.all([
serverNotify(text, desp),//微信server酱
Expand All @@ -145,7 +149,7 @@ async function sendNotify(text, desp, params = {}) {
qywxBotNotify(text, desp), //企业微信机器人
qywxamNotify(text, desp), //企业微信应用消息推送
iGotNotify(text, desp, params),//iGot
CoolPush(text, desp)//QQ酷推
//CoolPush(text, desp)//QQ酷推
])
}

Expand All @@ -155,7 +159,7 @@ function serverNotify(text, desp, timeout = 2100) {
//微信server酱推送通知一个\n不会换行,需要两个\n才能换行,故做此替换
desp = desp.replace(/[\n\r]/g, '\n\n');
const options = {
url: `https://sc.ftqq.com/${SCKEY}.send`,
url: SCKEY.includes('SCT') ? `https://sctapi.ftqq.com/${SCKEY}.send` : `https://sc.ftqq.com/${SCKEY}.send`,
body: `text=${text}&desp=${desp}`,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
Expand All @@ -169,7 +173,8 @@ function serverNotify(text, desp, timeout = 2100) {
console.log(err);
} else {
data = JSON.parse(data);
if (data.errno === 0) {
//server酱和Server酱·Turbo版的返回json格式不太一样
if (data.errno === 0 || data.data.errno === 0 ) {
console.log('server酱发送通知消息成功\n')
} else if (data.errno === 1024) {
// 一分钟内发送相同的内容会触发
Expand Down Expand Up @@ -476,49 +481,62 @@ function qywxamNotify(text, desp) {
html=desp.replace(/\n/g,"<br/>")
var json = JSON.parse(data);
accesstoken = json.access_token;
const options_textcard = {
url: `https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${accesstoken}`,
json: {
touser:`${QYWX_AM_AY[2]}`,
agentid:`${QYWX_AM_AY[3]}`,
msgtype: 'textcard',
textcard: {
title: `${text}`,
description: `${desp}`,
url: '127.0.0.1',
btntxt: '更多'
},
safe:'0',
},
headers: {
'Content-Type': 'application/json',
},
};
const options_mpnews = {
url: `https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${accesstoken}`,
json: {
touser:`${QYWX_AM_AY[2]}`,
agentid:`${QYWX_AM_AY[3]}`,
msgtype: 'mpnews',
mpnews: {
articles: [
{
title: `${text}`,
let options;

switch (QYWX_AM_AY[4]) {
case '0':
options = {
msgtype: 'textcard',
textcard: {
title: `${text}`,
description: `${desp}`,
url: '127.0.0.1',
btntxt: '更多'
}
}
break;

case '1':
options = {
msgtype: 'text',
text: {
content: `${text}\n\n${desp}`
}
}
break;

default:
options = {
msgtype: 'mpnews',
mpnews: {
articles: [
{
title: `${text}`,
thumb_media_id: `${QYWX_AM_AY[4]}`,
author : `智能助手` ,
content_source_url: ``,
content : `${html}`,
digest: `${desp}`
}
]
},
}
]
}
}
};

options = {
url: `https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${accesstoken}`,
json: {
touser:`${QYWX_AM_AY[2]}`,
agentid:`${QYWX_AM_AY[3]}`,
safe:'0',
...options
},
headers: {
'Content-Type': 'application/json',
},
};
$.post((QYWX_AM_AY[4]==0)?options_textcard:options_mpnews, (err, resp, data) => {
}

$.post(options, (err, resp, data) => {
try {
if (err) {
console.log('企业微信应用消息发送通知消息失败!!\n');
Expand Down
6 changes: 3 additions & 3 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ inputs:
cronExpression: "0 0 0 * * * *"
enable: true
argument: jd_bean_sign
- timer: #东东超市兑换奖品 #摇京豆 #京东汽车兑换 #环球挑战赛 #京东国际盲盒
- timer: #东东超市兑换奖品 #摇京豆 #京东汽车兑换 #环球挑战赛
parameters:
name: blueCoin_clublottery_carexchange_global_globalmh
name: blueCoin_clublottery_carexchange_global
cronExpression: "0 0 0 * * * *"
enable: true
argument: jd_blueCoin&jd_club_lottery&jd_car_exchange&jd_global&jd_global_mh
argument: jd_blueCoin&jd_club_lottery&jd_car_exchange&jd_global
- timer: #东东农场 #东东萌宠 #口袋书店 #京喜农场
parameters:
name: fruit_pet_bookshop_jxnc
Expand Down

0 comments on commit e5728d4

Please sign in to comment.