diff --git a/jd_carnivalcity.js b/jd_carnivalcity.js index 2f3ba3f6..9ea747e7 100644 --- a/jd_carnivalcity.js +++ b/jd_carnivalcity.js @@ -2,7 +2,7 @@ * @Author: LXK9301 https://github.com/LXK9301 * @Date: 2020-11-03 09:25:47 * @Last Modified by: LXK9301 - * @Last Modified time: 2021-4-3 15:27:07 + * @Last Modified time: 2021-5-25 09:27:07 */ /* 京东手机狂欢城活动,每日可获得20+以上京豆(其中20京豆是往期奖励,需第一天参加活动后,第二天才能拿到) @@ -152,6 +152,7 @@ async function JD818() { await getListRank(); await getListIntegral(); await getListJbean(); + await check();//查询抽奖记录(未兑换的,发送提醒通知); await showMsg() } catch (e) { $.logErr(e) @@ -398,8 +399,12 @@ function lottery() { data = JSON.parse(data); if (data.code === 200) { if (data.data.prizeId !== 8) { + //已中奖 + const url = 'https://carnivalcity.m.jd.com/#/integralDetail'; console.log(`积分抽奖获得:${data.data.prizeName}`); - message += `积分抽奖获得:${data.data.prizeName}\n` + message += `积分抽奖获得:${data.data.prizeName}\n`; + $.msg($.name, '', `京东账号 ${$.index} ${$.nickName || $.UserName}\n积分抽奖获得:${data.data.prizeName}\n兑换地址:${url}`, { 'open-url': url }); + if ($.isNode()) await notify.sendNotify($.name, `京东账号 ${$.index} ${$.nickName || $.UserName}\n积分抽奖获得:${data.data.prizeName}\n兑换地址:${url}`); } else { console.log(`积分抽奖结果:${data['data']['prizeName']}}`); } @@ -413,6 +418,80 @@ function lottery() { }) }); } +//查询抽奖记录(未兑换的) +function check() { + const options = taskUrl('/khc/record/convertRecord', { t: Date.now(), pageNum: 1 }) + return new Promise( (resolve) => { + $.get(options, async (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} API请求失败,请检查网路重试`) + } else { + data = JSON.parse(data); + let str = ''; + if (data.code === 200) { + for (let obj of data.data) { + if (obj.hasOwnProperty('fillStatus') && obj.fillStatus !== true) { + str += JSON.stringify(obj); + } + } + } + if (str.length > 0) { + const url = 'https://carnivalcity.m.jd.com/#/integralDetail'; + $.msg($.name, '', `京东账号 ${$.index} ${$.nickName || $.UserName}\n积分抽奖获得:${str}\n兑换地址:${url}`, { 'open-url': url }); + if ($.isNode()) await notify.sendNotify($.name, `京东账号 ${$.index} ${$.nickName || $.UserName}\n积分抽奖获得:${str}\n兑换地址:${url}`); + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(); + } + }) + }); + return new Promise((resolve)=>{ + var request = require('request'); + let timestamp = (new Date()).getTime() + var headers = { + 'Sgm-Context': '144512924112128160;144512924112128160', + 'Host': 'carnivalcity.m.jd.com', + 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Mobile/15E148 Safari/604.1', + 'sign': 'c5a92160e87206287af0faee2b056429', + 'Referer': 'https://carnivalcity.m.jd.com/', + 'timestamp': `${timestamp}`, + 'Cookie': cookie + }; + + var options = { + url: `https://carnivalcity.m.jd.com/khc/record/convertRecord?pageNum=1&t=${timestamp}`, + headers: headers + }; + + async function callback(error, response, body) { + if (!error && response.statusCode == 200) { + // $.log(body); + let result = JSON.parse(body) + let message = "" + if (result.data.length > 0) { + message += message += `\n开始【京东账号${$.index}】${$.nickName || $.UserName}\n` + } + for (let obj of result.data) { + if (obj.hasOwnProperty('fillStatus') && obj.fillStatus != true) { + message += JSON.stringify(obj) + } + } + if (message.length > 0) { + await notify.sendNotify($.name, message); + } + resolve() + } + } + + request(options, callback); + + }) +} function myRank() { return new Promise(resolve => { const body = { @@ -596,8 +675,10 @@ function getListIntegral() { if (data.code === 200) { $.integralCount = data.data.integralNum || 0;//累计活动积分 message += `累计获得积分:${$.integralCount}\n`; + console.log(`开始抽奖,当前积分可抽奖${parseInt($.integralCount / 50)}次\n`); for (let i = 0; i < parseInt($.integralCount / 50); i ++) { await lottery(); + await $.wait(500); } } else { console.log(`integralRecord失败:${JSON.stringify(data)}`);