Files
Java_utils_enhance/src/main/resources/test_trytryOne.js
T

1292 lines
59 KiB
JavaScript
Raw Normal View History

2021-10-26 19:20:52 +08:00
/*
* ç”±ZCY01二次修改:脚本默认ä¸è¿è¡Œ
* ç”± X1a0He ä¿®å¤ï¼šä¾ç„¶ä¿æŒè„šæœ¬é»˜è®¤ä¸è¿è¡Œ
* 如需è¿è¡Œè¯·è‡ªè¡Œæ·»åŠ çŽ¯å¢ƒå˜é‡ï¼šJD_TRY,值填 true å³å¯è¿è¡Œ
* TG交æµç¾¤ï¼šhttps://t.me/jd_zero205
* TG通知频é“:https://t.me/jd_zero205_tz
*
update 2021/09/05
äº¬ä¸œè¯•ç”¨ï¼šè„šæœ¬æ›´æ–°åœ°å€ https://github.com/zero205/JD_tencent_scf/raw/main/jd_try.js
脚本兼容: Node.js
æ¯å¤©æœ€å¤šå…³æ³¨300个商店,但用户商店关注上é™ä¸º500个。
请é…åˆå–关脚本试用,使用 jd_unsubscribe.js æå‰å–关至少250个商店确ä¿äº¬ä¸œè¯•用脚本正常è¿è¡Œã€‚
*
* X1a0Heç•™
* 由于没有兼容Qx,原脚本已失效,建议原脚本的兼容Qx注释删了
* 脚本是å¦è€—æ—¶åªçœ‹args_xh.maxLength的大å°
* 上一作者说了æ¯å¤©æœ€å¤š300个商店,总上é™ä¸º500个,jd_unsubscribe.js我已更新为批é‡å–关版
* 请æå‰å–关至少250个商店确ä¿äº¬ä¸œè¯•用脚本正常è¿è¡Œ
* 没有写通知,是å¦ç”³è¯·æˆåŠŸæ²¡æœ‰è¿›è¡Œé€šçŸ¥ï¼Œä½†è„šæœ¬ä¼šæŠŠçŠ¶æ€log出日志
*/
2021-11-09 14:13:03 +08:00
let dingtalk = "https://oapi.dingtalk.com/robot/send?access_token=d2b6042cb38f0df63e20797c002208d2710104750c18a1dc84d54106a859a3f0"
let dingtalk1 = "https://oapi.dingtalk.com/robot/send?access_token=a3e80da6f064321881fc38e43a07bfde7a61b6f18245454520fb749556cebfcd"
2021-11-10 23:07:52 +08:00
let dingtalk2 = "https://oapi.dingtalk.com/robot/send?access_token=1832f969da101ef8273e8ba2258f06f15ec34bc22282066b28ab617042a7a9b6"
2021-11-09 14:13:03 +08:00
let getManName = ""
let totalPages = 999999 //总页数
const $ = new Env('京东试用')
2021-11-10 23:07:52 +08:00
let roleMap = {
"jd_4521b375ebb5d": "é”Ÿå­æ€ª",
"jd_542c10c0222bc": "åº·å­æ€ª",
"jd_66dcb31363ef6": "æ¶›å­æ€ª",
"jd_45d917547c763": "è·‘è…¿å°æ€ª",
"417040678_m": "æ–Œå­æ€ª",
"jd_73d88459d908e": °æ°å­",
"381550701lol": "漪漪å­",
"jd_4333d5dc1ac5f": "舒楠å­",
"jd_66ea783827d30": "军å­",
"jd_4311ac0ff4456": "å±…å­"
}
2021-11-09 14:13:03 +08:00
const URL = 'https://api.m.jd.com/client.action'
let trialActivityIdList = []
let sensMessage = "试用\n\n"
let trialActivityTitleList = []
let notifyMsg = ''
let message = ""
let minItemValue = 500
let wordLength = 1000
let process = {
env: {
"JD_TRY": "true"
}
}
// default params
let args_xh = {
channelEnd: Math.floor(Math.random() * (4) + 3),
channel: [1, 2, 3, 4, 5, 10, 12, 15],
maxSize: 15,
listCount: 0,
/*
* 是å¦è¿›è¡Œé€šçŸ¥
* å¯è®¾ç½®çŽ¯å¢ƒå˜é‡ï¼šJD_TRY_NOTIFY
* */
// isNotify: process.env.JD_TRY_NOTIFY || true,
// 商å“原价,低于这个价格都ä¸ä¼šè¯•用
jdPrice: 15,
/*
* 获å–试用商å“类型,默认为1
* 1 - 精选
* 2 - 闪电试用
* 3 - 家用电器(å¯èƒ½ä¼šæœ‰å˜åŒ–)
* 4 - 手机数砯能会有å˜åŒ–)
* 5 - 电脑办公(å¯èƒ½ä¼šæœ‰å˜åŒ–)
* å¯è®¾ç½®çŽ¯å¢ƒå˜é‡ï¼šJD_TRY_TABID
* */
// TODO: tab ids as array(support multi tabIds)
// tabId: process.env.JD_TRY_TABID && process.env.JD_TRY_TABID.split('@').map(Number) || [1],
tabId: process.env.JD_TRY_TABID || 1,
/*
* è¯•ç”¨å•†å“æ ‡é¢˜è¿‡æ»¤
* å¯è®¾ç½®çŽ¯å¢ƒå˜é‡ï¼šJD_TRY_TITLEFILTERS,关键è¯ä¸Žå…³é”®è¯ä¹‹é—´ç”¨@分隔
* */
2021-11-10 23:07:52 +08:00
titleFilters: ["登山包","抵用券","急救箱","染头å‘è†",˜å”‡è†","弹力带","儿童零食","儿童剪头å‘工具","平剪牙剪刀打薄剪刀","刘海内扣直å‘器","益生èŒå°¡æ¼±å£æ°´","二锅头","é­”æ³•å£«å¹²è„†é¢æ–¹ä¾¿é¢24袋整箱装","樱ã®è‰²é±¼å­é…±","轻酸瓶3%",’æ±","隔离霜","去枣核","å·å“社", "矶钓钓鱼é…ä»¶", "棉线结矶æ†", Šåœ†æ»‘漂挡", "远投路滑é…ä»¶", "滑漂座", "软电线", "激光剑", ­é¼ ", "æ€ç»´æ£‹", Œå±‚片", "猫用", "鼻腔喷雾", "电脑包", "鸥曼GTL", §é“ºæ¯›æ¯¯", Œå¯¼å", "翻页笔", "蛋白肽", "Tå£å¼¯å¤´", "货车用å“", "床垫套", "电焊护脚", "G100", "擦车清æ´å·¥å…·", "掸å­", "å°„ç¯", "欧布圣剑", "超比ä¹", "滚梳直柄", "å‡èƒ¶ç³–æžœ", "DHA藻油", "水带", "摘果神器", "å®å®å„¿ç«¥é›¶é£Ÿ", "总å¤ä¹ ", "满分冲刺", "黄冈", "å°çŠ¶å…ƒ", "é’“é±¼æ’ä»¶", "寒å‡ä½œä¸š", "作业", œç½©", "手机线", "美容油", "è´ºå¡", "眼贴", "å°æ–—篷", "å°å­©å­æ¼”å¥", "ç æŸ´åˆ€", "消防应急ç¯", "食用色素", "烘焙彩针糖果", "德尔地æ¿", "æ°´ç®¡ä¿æ¸©å¥—", "水管é“", "定ä½å™¨", "追踪器", "电瓶", "快递纸箱", "尤克里里", "金龙鱼 颿¡æŒ‚é¢", "痛风", "KVM切æ¢å™¨", "æ°´æ³¥", "猫ç½å¤´", "去斑霜", "0-12å²", "4/3膜", "FMJ", "H10E", "HDMI", "HEISHA", "HPV", "KB216有线键盘", "LED", "MS116 有线鼠标", "N1162有线鼠标", "Ockered", "PVCæ¿", "SD", "SDå¡", "SMOVES", "SUP掌机", "U盘", "VGA", "hdmi", "hpv", "led开关电æº", "uv镜", "win10", "windows", "一次性", "一片装", "一盒", "䏇呿»‘è½®", "万用表", "万藓çµ", "三角阀", "三轮车", "ä¸å¹²èƒ¶æ ‡ç­¾å¸¦", "䏓凿œ¬", "专用贴", "ä¸è¢œ", "中国电信", "中国结", "中央扶手箱", "中性水笔", "中性笔", "中è€å¹´", "丰胸", "串ç çީ具", "丸", "乒乓çƒ", "ä¹ä¹ä¹˜æ³•", "ä¹ä¹ä¹˜é™¤", "书包", "乳液", "乳腺", "交æ¢", "äº¤æ¢æœº", "产å“体验", "享底价", "亲å­äº’动", "亿优信", "仓鼠零食", "仿真å°è›‹ç³•", "伊å¨", "优盘", "会员", "会员å¡", "会议æ¯å­", "会议记录", "ä¼ èœé“ƒ", "体温计", "体验装", "侧挂å¼", "便秘", "ä¿å¥", "ä¿æŠ¤å£³", "ä¿æŠ¤å¥—", "ä¿æŠ¤è†œ", "ä¿æŠ¤é•œ", "ä¿æš–女裤", "ä¿æš–裤", "ä¿æ¸©æ£‰", "ä¿é²œè†œ", "ä¿¡å°", "信纸", "修护", "修正带", "修眉", "修眉剪", "倒车", "倒车镜", ‡å", ‡ç«æ¯›", œè½¦ç‰Œ", ¥åº·æ£€æµ‹", "储奶袋", "å„¿ç«¥n95", "儿童串ç çީ具", "å„¿ç«¥ä¹å›­", "儿童便æ·", "å„¿ç«¥ä¿æ¸©æ°´æ¯", "儿童医生", "å„¿ç«¥å£ç½©", "å„¿ç«¥å¸ç®¡", "儿童奶粉", "å„¿ç«¥æˆé•¿", "儿童拌饭", "儿童暖暖套", "儿童椅å­", "å„¿ç«¥æ²æµ´éœ²", "儿童牙è†", "儿童玩具枪", "儿童电动牙刷", "å„¿ç«¥ç”µè¯æ‰‹è¡¨", "儿童益生èŒ", "儿童磨牙饼", "儿童背包", "å„¿ç«¥éšèº«", "儿童雨伞", "充电头", "充电桩", "å…‰å’Œé’æ˜¥", "光驱", "å…钉胶水", "å…«å€é•œ", "公主项链", "公文包", "å…»èŠå ", "内胆包", "内衣", "内裤", "冰箱贴", "冰袋", "冷兵器", "冷å‡èƒ¶", "冷敷贴", "冻干粉", "净水剂", "å‡å…³é•œ", "å‡è‚¥", "凳å­å¥—", "刀头", "刀片", "分æµ", "分æµå™¨", "分线盒", "切割片", "åˆ‡èœæ¿", "创å¯è´´", "刨木", "别针", "刮痧", "刮痧æ¿", "刷头", "刷å­", "刷牙头", "刹车油", "刺激贴", "剂", "剃须刀é…ä»¶", "削皮刀", "å‰åˆ—è…º", "剥虾", "剪", "剪钳", "å‰²è‰æœº", "办公会议茶æ¯", "办公å®", "办公æ¯", "加密狗", "加温器", "å‹¿æ‹", "包皮", "包装膜", "化妆", "匙扣", "医生", Šèº«ä¸é", Šèº«è£™", •æ‹ä¸å‘è´§", ¡å†Œ", ¡å¥—", ¡å°º", ¡æ‰˜", ¡ç‰Œ", ¡é’ˆ", §é“ºåž«", ¸å¦†", ¸å¦†æ°´", "压差表", "压片", "去毛器", "去角质", ‚肽片", Œé¢æ¿", å…‰æ¡è´´", å…‰æ¿", 光贴", 光镜", 弹器", ˜èº«å™¨", £ç´", £çº¢", £ç½©", £ç½©ç›’", £è…”", £è…”抑èŒ", £é¦™ç³–", °ç¯", °è´¦æœ¬", ·ç å¡", ƒé¥­è¡£", ˆæˆæœºæ²¹", Œä»å ", Žè†œ", ¯åŠ¨ç”µæº", ¸å¥¶å™¨", ¸é¡¶ç¯", "告知牌", "周å²
2021-11-09 14:13:03 +08:00
// 试用价格(中了è¦èŠ±å¤šå°‘é’±),高于这个价格都ä¸ä¼šè¯•用,å°äºŽç­‰äºŽæ‰ä¼šè¯•用
trialPrice: 0,
/*
* æœ€å°æä¾›æ•°é‡ï¼Œä¾‹å¦‚试用商å“åªæä¾›2份试用资格,当å‰è®¾ç½®ä¸º1,则会进行申请
* è‹¥åªæä¾›5分试用资格,当å‰è®¾ç½®ä¸º10,则ä¸ä¼šç”³è¯·
* å¯è®¾ç½®çŽ¯å¢ƒå˜é‡ï¼šJD_TRY_MINSUPPLYNUM
* */
minSupplyNum: 20,
/*
* 过滤大于设定值的已申请人数,例如下é¢è®¾ç½®çš„1000,A商å“å·²ç»æœ‰1001人申请了,则A商å“ä¸ä¼šè¿›è¡Œç”³è¯·ï¼Œä¼šè¢«è·³è¿‡
* å¯è®¾ç½®çŽ¯å¢ƒå˜é‡ï¼šJD_TRY_APPLYNUMFILTER
* */
applyNumFilter: process.env.JD_TRY_APPLYNUMFILTER || 99999,
/*
* 商å“试用之间和获å–商å“之间的间隔, å•ä½ï¼šæ¯«ç§’(1ç§’=1000毫秒)
* å¯è®¾ç½®çŽ¯å¢ƒå˜é‡ï¼šJD_TRY_APPLYINTERVAL
* */
applyInterval: process.env.JD_TRY_APPLYINTERVAL || 5000,
/*
* 商哿•°ç»„的最大长度,通俗æ¥è¯´å°±æ˜¯å³å°†ç”³è¯·çš„商å“队列长度
* 例如设置为20,当第一次获å–åŽèŽ·å¾—12件,过滤åŽå‰©ä¸‹5件,将会进行第二次获å–,过滤åŽåŠ ä¸Šç¬¬ä¸€æ¬¡å‰©ä½™ä»¶æ•°
* 例如是18件,将会进行第三次获å–,直到过滤完毕åŽä¸º20ä»¶æ‰ä¼šåœæ­¢ï¼Œä¸å»ºè®®è®¾ç½®å¤ªå¤§
* å¯è®¾ç½®çŽ¯å¢ƒå˜é‡ï¼šJD_TRY_MAXLENGTH
* */
maxLength: 10
}
!(async () => {
// console.log(`\n本脚本默认ä¸è¿è¡Œï¼Œä¹Ÿä¸å»ºè®®è¿è¡Œ\n如需è¿è¡Œè¯·è‡ªè¡Œæ·»åŠ çŽ¯å¢ƒå˜é‡ï¼šJD_TRY,值填:true\n`)
await $.wait(1000)
if (process.env.JD_TRY && process.env.JD_TRY === 'true') {
await requireConfig()
if (!$.cookiesArr[0]) {
$.msg($.name, 'ã€æç¤ºã€‘è¯·å…ˆèŽ·å–京东账å·ä¸€cookie\n直接使用NobyDa的京东签到获å–', 'https://bean.m.jd.com/', {
"open-url": "https://bean.m.jd.com/"
})
return
}
for (let i = 0; i < $.cookiesArr.length; i++) {
message += "<font color=\'#FFA500\'>[通知] </font><font color=\'#006400\' size='3'>éšæœºè¯•用</font> \n\n --- \n\n"
await $.wait(Math.floor(Math.random() * (175000) + 5000));
if ($.cookiesArr[i]) {
$.cookie = $.cookiesArr[i];
$.UserName = decodeURIComponent($.cookie.match(/pt_pin=(.+?);/) && $.cookie.match(/pt_pin=(.+?);/)[1])
$.index = i + 1;
$.isLogin = true;
$.nickName = '';
await totalBean();
console.log(`\n开始ã€äº¬ä¸œè´¦å·${$.index}】${$.nickName || $.UserName}\n`);
if (!$.isLogin) {
$.msg($.name, `ã€æç¤ºã€‘cookie已失效`, `京东账å·${$.index} ${$.nickName || $.UserName}\nè¯·é‡æ–°ç™»å½•获å\nhttps://bean.m.jd.com/bean/signIndex.action`, {
"open-url": "https://bean.m.jd.com/bean/signIndex.action"
});
await $.notify.sendNotify(`${$.name}cookie已失效 - ${$.UserName}`, `京东账å·${$.index} ${$.UserName}\nè¯·é‡æ–°ç™»å½•获å–cookie`);
continue
}
username = $.UserName
2021-11-10 23:07:52 +08:00
//èµ°å¦å¤–的途径å¦å¤–处ç
if ($.UserName == "jd_66ea783827d30" || $.UserName == "jd_45d917547c763") {
getManName = roleMap[username]
justGetGain()
2021-11-09 14:13:03 +08:00
continue
}
2021-11-10 23:07:52 +08:00
if (roleMap[username] != undefined) {
username = roleMap[username]
2021-11-09 14:13:03 +08:00
}
2021-11-10 23:07:52 +08:00
2021-11-09 14:13:03 +08:00
getManName = username
args_xh.maxLength = Math.floor(Math.random() * (20) + 10)
let list = getList()
//加上åç§°
message = message + "<font color=\'#778899\' size=2>ã€ç¾Šæ¯›å§å¦¹ã€‘<font color=\'#FFA500\' size=3>" + username + " </font> </font> \n\n "
message = message + "<font color=\'#778899\' size=2>" + "æ•°é‡å¤§å°:" + args_xh.maxLength + "申请列表:" + list + "</font> </font> \n\n "
$.totalTry = 0
$.totalSuccess = 0
let size = 1;
m = i
for (let i = 0; i < list.length; i++) {
args_xh.maxSize = Math.floor(Math.random() * (30) + 10)
message = message + "<font color=\'#FF0000\' size=2>" + "最大列表长度:" + args_xh.maxSize + " 申请列表:" + list[i] + "</font> </font> \n\n"
while (args_xh.listCount + trialActivityIdList.length < args_xh.maxLength && size < args_xh.maxSize && size < totalPages - 1) {
console.log(`\n正在进行第 ${size} 次获å–试用商å“\n`)
console.log(`\n当å‰äº§å“页颿€»é•¿åº¦ä¸º${totalPages} 页\n`)
await try_feedsList(list[i], size++)
2021-11-10 09:42:02 +08:00
if (m == 1 && sensMessage.length > wordLength) {
2021-11-09 14:13:03 +08:00
console.log("-----------------------------------")
console.log("-----------------------------------")
console.log("-----------------------------------")
console.log("-----------------------------------")
console.log("-----------------------------------")
console.log("-----------------------------------")
console.log("-----------------------------------")
postToDingTalk1(sensMessage)
sensMessage = "试用\n\n"
} else {
console.log("------------清空------------")
console.log("------------清空------------")
sensMessage = "试用\n\n"
}
if (args_xh.listCount + trialActivityIdList.length < args_xh.maxLength) {
args_xh.applyInterval = Math.floor(Math.random() * (4000) + 5000)
console.log(`间隔延时中,请等待 ${args_xh.applyInterval} ms`)
await $.wait(args_xh.applyInterval);
}
}
args_xh.listCount += trialActivityIdList.length
console.log("正在执行试用申请...")
await $.wait(args_xh.applyInterval);
for (let i = 0; i < trialActivityIdList.length; i++) {
args_xh.applyInterval = Math.floor(Math.random() * (4000) + 5000)
await try_apply(trialActivityTitleList[i], trialActivityIdList[i])
console.log(`间隔延时中,请等待 ${args_xh.applyInterval} ms\n`)
await $.wait(args_xh.applyInterval);
}
message = message + "<font color=\'#33ff00\' size=2>" + "本循环申请数é‡ï¼š" + trialActivityIdList.length + "总é‡é™åˆ¶ä¸ºï¼š" + args_xh.listCount + "</font> </font> \n\n "
trialActivityIdList = []
trialActivityTitleList = []
size = 1
totalPages == 999999
}
console.log("试用申请执行完毕...")
// await try_MyTrials(1, 1) //申请中的商å“
await try_MyTrials(1, 2) //申请æˆåŠŸçš„å•†å“
// await try_MyTrials(1, 3) //申请失败的商å“
await showMsg()
//下一个è¦é‡æ–°åŽ»æ‹‰åˆ—è¡¨
trialActivityIdList = []
trialActivityTitleList = []
await $.wait(Math.floor(Math.random() * (15000) + 5000));
}
args_xh.listCount = 0
postToDingTalk(message)
message = ""
totalPages == 999999
}
await $.notify.sendNotify(`${$.name}`, notifyMsg);
} else {
console.log(`\n您未设置è¿è¡Œã€äº¬ä¸œè¯•用】脚本,结æŸè¿è¡Œï¼\n`)
}
})().catch((e) => {
postToDingTalk(e + message)
console.log(`â—ï¸ ${$.name} è¿è¡Œé”™è¯¯ï¼\n${e}`)
}).finally(() => {
$.done()
})
2021-11-10 23:07:52 +08:00
function justGetGain() {
message = message + "<font color=\'#778899\' size=2>ã€ç¾Šæ¯›å§å¦¹ã€‘<font color=\'#FFA500\' size=3>" + username + " </font> </font> \n\n "
await try_MyTrials(1, 2) //申请æˆåŠŸçš„å•†å“
await showMsg()
//下一个è¦é‡æ–°åŽ»æ‹‰åˆ—è¡¨
trialActivityIdList = []
trialActivityTitleList = []
args_xh.listCount = 0
postToDingTalk(message)
message = ""
totalPages == 999999
}
2021-11-09 14:13:03 +08:00
function getList() {
for (i = 0; i < Math.floor(Math.random() * (5001) + 500); i++) {
index1 = Math.floor(Math.random() * (args_xh.channel.length) + 0)
index2 = Math.floor(Math.random() * (args_xh.channel.length) + 0)
temp = args_xh.channel[index1]
args_xh.channel[index1] = args_xh.channel[index2]
args_xh.channel[index2] = temp
}
return args_xh.channel.slice(0, args_xh.channelEnd)
}
function requireConfig() {
return new Promise(resolve => {
console.log('开始获å–é…置文件\n')
$.notify = $.isNode() ? require('./sendNotify') : { sendNotify: async () => { } }
//获å Cookies
$.cookiesArr = []
if ($.isNode()) {
//Node.js用户请在jdCookie.js处填写京东ck;
const jdCookieNode = require('./jdCookie.js');
Object.keys(jdCookieNode).forEach((item) => {
if (jdCookieNode[item]) {
$.cookiesArr.push(jdCookieNode[item])
}
})
if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') console.log = () => { };
} else {
//IOS等用户直接用NobyDa的jd $.cookie
$.cookiesArr = [$.getdata('CookieJD'), $.getdata('CookieJD2'), ...jsonParse($.getdata('CookiesJD') || "[]").map(item => item.cookie)].filter(item => !!item);
}
console.log(`å…±${$.cookiesArr.length}个京东账å·\n`)
for (const key in args_xh) {
if (typeof args_xh[key] == 'string') {
args_xh[key] = Number(args_xh[key])
}
}
// console.debug(args_xh)
resolve()
})
}
//获å–商å“列表并且过滤 By X1a0He
function try_feedsList(tabId, page) {
return new Promise((resolve, reject) => {
const body = JSON.stringify({
"tabId": `${tabId}`,
"page": page,
"previewTime": ""
});
let option = taskurl_xh('newtry', 'try_feedsList', body)
$.get(option, (err, resp, data) => {
try {
if (err) {
console.log(`🚫 ${arguments.callee.name.toString()} API请求失败,请检查网路\n${JSON.stringify(err)}`)
} else {
// console.debug(data)
// return
data = JSON.parse(data)
if (totalPages == 999999) {
message = message + "<font color=\'#FF0000\' size=2>" + " 当剿œ€å¤§é¡µæ•°ä¸ºï¼š" + data.data.pages + "</font> </font> \n\n"
}
if (data.success) {
$.totalPages = data.data.pages
totalPages = data.data.pages
console.log(`获å–åˆ°å•†å“ ${data.data.feedList.length} æ¡\n`)
for (let i = 0; i < data.data.feedList.length; i++) {
if (args_xh.listCount + trialActivityIdList.length >= args_xh.maxLength) {
console.log('商å“列表长度已满.结æŸèŽ·å–')
} else
if (data.data.feedList[i].applyState === 1) {
console.log(`商å“已申请试用:${data.data.feedList[i].skuTitle}`)
continue
} else
if (data.data.feedList[i].applyState !== null) {
console.log(`商å“状æ€å¼‚常,跳过:${data.data.feedList[i].skuTitle}`)
continue
} else
if (data.data.feedList[i].skuTitle) {
console.log(`检测第 ${page} 页 第 ${i + 1} 个商å“\n${data.data.feedList[i].skuTitle}`)
if (parseFloat(data.data.feedList[i].jdPrice) <= args_xh.jdPrice) {
console.log(`商å“被过滤,${data.data.feedList[i].jdPrice} < ${args_xh.jdPrice} \n`)
2021-11-10 23:07:52 +08:00
} else if (parseFloat(data.data.feedList[i].applyNum) > args_xh.applyNumFilter && data.data.feedList[i].applyNum !== null) {
2021-11-09 14:13:03 +08:00
console.log(`商å“被过滤,已申请试用人数大于预设人数 \n`)
} else if (args_xh.titleFilters.some(fileter_word => data.data.feedList[i].skuTitle.includes(fileter_word))) {
sensMessage += "<font color=\'#FF0000\' size=2>" + data.data.feedList[i].skuTitle + "</font> </font> \n\n"
args_xh.titleFilters.some(fileter_word => {
if (data.data.feedList[i].skuTitle.includes(fileter_word)) {
sensMessage += "<font color=\'#000099\' size=2>" + "æ•æ„Ÿè¯æ±‡ï¼š" + fileter_word + "</font> </font> \n\n"
}
2021-10-26 19:20:52 +08:00
})
2021-11-09 14:13:03 +08:00
console.log('商å“è¢«è¿‡æ»¤ï¼Œå«æœ‰å…³é”®è¯ \n')
2021-11-10 23:07:52 +08:00
} else if (parseFloat(data.data.feedList[i].trialPrice) > args_xh.trialPrice && data.data.feedList[i].jdPrice < minItemValue) {
sensMessage += "<font color=\'#FF0000\' size=2>" + data.data.feedList[i].skuTitle + "</font> </font> \n\n"
sensMessage += "<font color=\'#FF0000\' size=2>" + "需è¦èŠ±è´¹:" + parseFloat(data.data.feedList[i].trialPrice) + "</font> </font> \n\n"
sensMessage += "<font color=\'#FF0000\' size=2>" + "实际价值:" + parseFloat(data.data.feedList[i].jdPrice) + "</font> </font> \n\n"
console.log(`商å“被过滤,期待价格高于预设价格 \n`)
}else if (parseFloat(data.data.feedList[i].supplyNum) > args_xh.minSupplyNum && data.data.feedList[i].supplyNum !== null) {
console.log(`商å“被过滤,æä¾›ç”³è¯·çš„份数大于预设申请的份数 \n`)
sensMessage += "<font color=\'#FF0000\' size=2>" + data.data.feedList[i].skuTitle + "</font> </font> \n\n"
sensMessage += "<font color=\'#FF0000\' size=2>" + 供申请的份数为:" +parseFloat(data.data.feedList[i].supplyNum) + "</font> </font> \n\n"
2021-11-09 14:13:03 +08:00
} else {
console.log(`商å“通过,将加入试用组,trialActivityId为${data.data.feedList[i].trialActivityId}\n`)
trialActivityIdList.push(data.data.feedList[i].trialActivityId)
trialActivityTitleList.push(data.data.feedList[i].skuTitle)
}
} else {
console.log('skuTitleè§£æžå¼‚常')
return
}
}
console.log(`当å‰è¯•用组id如下,长度为:${trialActivityIdList.length}\n${trialActivityIdList}\n`)
} else {
console.log(`💩 获得试用列表失败: ${data.message}`)
}
}
} catch (e) {
console.log(e);
reject(`âš ï¸ ${arguments.callee.name.toString()} API返回结果解æžå‡ºé”™\n${e}\n${JSON.stringify(data)}`)
console.log(`${JSON.stringify(data)}`)
} finally {
resolve()
}
})
})
}
function try_apply(title, activityId) {
return new Promise((resolve, reject) => {
console.log(`申请试用商å“中...`)
console.log(`商å“:${title}`)
console.log(`id为:${activityId}`)
const body = JSON.stringify({
"activityId": activityId,
"previewTime": ""
});
let option = taskurl_xh('newtry', 'try_apply', body)
$.get(option, (err, resp, data) => {
try {
if (err) {
console.log(`🚫 ${arguments.callee.name.toString()} API请求失败,请检查网路\n${JSON.stringify(err)}`)
} else {
$.totalTry++
data = JSON.parse(data)
if (data.success && data.code === "1") { // 申请æˆåŠŸ
message += "<font color=\'#778899\' size=2>" + title + "</font>\n\n"
message += "<font color=\'#778899\' size=2>" + `-------\n\n` + "</font>\n\n"
console.log(data.message)
$.totalSuccess++
} else if (data.code === "-106") {
console.log(data.message) // 未在申请时间内ï¼
} else if (data.code === "-110") {
console.log(data.message) // 您的申请已æˆåŠŸæäº¤ï¼Œè¯·å‹¿é‡å¤ç”³è¯·â€¦
} else if (data.code === "-120") {
console.log(data.message) // æ‚¨è¿˜ä¸æ˜¯ä¼šå‘˜ï¼Œæœ¬å“åªé™ä¼šå‘˜ç”³è¯·è¯•用,请注册会员åŽç”³è¯·ï¼
} else if (data.code === "-167") {
console.log(data.message) // 抱歉,此试用需为ç§è‰å®˜æ‰èƒ½ç”³è¯·ã€‚查看下方详情了解更多。
} else {
console.log("申请失败", JSON.stringify(data))
}
}
} catch (e) {
reject(`âš ï¸ ${arguments.callee.name.toString()} API返回结果解æžå‡ºé”™\n${e}\n${JSON.stringify(data)}`)
} finally {
resolve()
}
})
})
}
function try_MyTrials(page, selected) {
return new Promise((resolve, reject) => {
switch (selected) {
case 1:
console.log('正在获å–已申请的商å“...')
break;
case 2:
console.log('正在获å–申请æˆåŠŸçš„å•†å“...')
break;
case 3:
console.log('正在获å–申请失败的商å“...')
break;
default:
console.log('selected错误')
}
const body = JSON.stringify({
"page": page,
"selected": selected, // 1 - 已申请 2 - æˆåŠŸåˆ—è¡¨ï¼Œ3 - 失败列表
"previewTime": ""
});
let option = taskurl_xh('newtry', 'try_MyTrials', body)
option.headers.Referer = 'https://pro.m.jd.com/'
$.get(option, (err, resp, data) => {
try {
if (err) {
console.log(`🚫 ${arguments.callee.name.toString()} API请求失败,请检查网路\n${JSON.stringify(err)}`)
} else {
// console.log(data)
// return
data = JSON.parse(data)
if (data.success) {
//temp adjustment
if (selected == 2) {
if (data.success && data.data) {
$.successList = data.data.list.filter(item => {
return item.text.text.includes('试用资格将ä¿ç•™10天')
})
console.log(`待领å: ${$.successList.length}个`)
} else {
console.log(`获得æˆåŠŸåˆ—è¡¨å¤±è´¥: ${data.message}`)
}
}
if (data.data.list.length > 0) {
let count = 0
for (let item of data.data.list) {
console.log(`申请时间:${new Date(parseInt(item.applyTime)).toLocaleString()}`)
console.log(`申请商å“:${item.trialName}`)
console.log(`当å‰çжæ€ï¼š${item.text.text}`)
console.log(`剩余时间:${remaining(item.leftTime)}`)
if (count < 3) {
message += "<font color=\'#4B0082\' size=1>" + `申请商å“:${item.trialName}` + "</font>\n\n"
message += "<font color=\'#4B0082\' size=1>" + `申请时间:${new Date(parseInt(item.applyTime)).toLocaleString()}` + "</font>\n\n"
message += "<font color=\'#4B0082\' size=1>" + `当å‰çжæ€ï¼š${item.text.text}` + "</font>\n\n"
message += "<font color=\'#4B0082\' size=1>" + `剩余时间:${remaining(item.leftTime)}` + "</font>\n\n"
message += "<font color=\'#4B0082\' size=1>" + `-----\n\n` + "</font>\n\n"
count++
}
2021-11-10 09:42:02 +08:00
if (item.text.text.includes('试用资格将ä¿ç•™10天')) {
2021-11-09 14:13:03 +08:00
message1 = "<font color=\'#4B0082\' size=1>" + `${getManName},你的商å“待领å–,请尽快领å` + "</font>\n\n"
message1 += "<font color=\'#4B0082\' size=1>" + `申请商å“:${item.trialName}` + "</font>\n\n"
message1 += "<font color=\'#4B0082\' size=1>" + `剩余时间:${remaining(item.leftTime)}` + "</font>\n\n"
postToDingTalk2(message1)
}
console.log()
}
}
// else {
// switch(selected){
// case 1:
// console.log('无已申请的商å“\n')
// break;
// case 2:
// console.log('无申请æˆåŠŸçš„å•†å“\n')
// break;
// case 3:
// console.log('无申请失败的商å“\n')
// break;
// default:
// console.log('selected错误')
// }
// }
} else {
console.log(`ERROR:try_MyTrials`)
}
}
} catch (e) {
reject(`âš ï¸ ${arguments.callee.name.toString()} API返回结果解æžå‡ºé”™\n${e}\n${JSON.stringify(data)}`)
} finally {
resolve()
}
})
})
}
function remaining(time) {
let days = parseInt(time / (1000 * 60 * 60 * 24));
let hours = parseInt((time % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
let minutes = parseInt((time % (1000 * 60 * 60)) / (1000 * 60));
return `${days} 天 ${hours} å°æ—¶ ${minutes} 分`
}
function taskurl_xh(appid, functionId, body = JSON.stringify({})) {
return {
"url": `${URL}?appid=${appid}&functionId=${functionId}&clientVersion=10.1.2&client=wh5&body=${encodeURIComponent(body)}`,
'headers': {
'Host': 'api.m.jd.com',
'Accept-Encoding': 'gzip, deflate, br',
'Cookie': $.cookie,
'Connection': 'keep-alive',
'UserAgent': 'jdapp;iPhone;10.1.2;15.0;ff2caa92a8529e4788a34b3d8d4df66d9573f499;network/wifi;model/iPhone13,4;addressid/2074196292;appBuild/167802;jdSupportDarkMode/1;Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1',
'Accept-Language': 'zh-cn',
'Referer': 'https://prodev.m.jd.com/'
},
}
}
async function showMsg() {
let message1 = `京东账å·${$.index} ${$.nickName || $.UserName}\n🎉 本次申请:${$.totalSuccess}/${$.totalTry}个商å“🛒\n🎉 ${$.successList.length}个商å“待领å`
message += "<font color=\'#778899\' size=2>" + `🎉 本次申请:${$.totalSuccess}/${$.totalTry}个商å“🛒\n🎉 ${$.successList.length}个商å“待领å` + "</font>\n\n"
if (!args_xh.jdNotify || args_xh.jdNotify === 'false') {
$.msg($.name, ``, message1, {
"open-url": 'https://try.m.jd.com/user'
})
if ($.isNode())
notifyMsg += `${message1}\n\n`
} else {
console.log(message1)
}
}
function totalBean() {
return new Promise(async resolve => {
const options = {
"url": `https://wq.jd.com/user/info/QueryJDUserInfo?sceneval=2`,
"headers": {
"Accept": "application/json,text/plain, */*",
"Content-Type": "application/x-www-form-urlencoded",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-cn",
"Connection": "keep-alive",
"Cookie": $.cookie,
"Referer": "https://wqs.jd.com/my/jingdou/my.shtml?sceneval=2",
"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.4.4;14.3;network/4g;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1")
},
"timeout": 10000,
}
$.post(options, (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败,请检查网路é‡è¯•`)
} else {
if (data) {
data = JSON.parse(data);
if (data['retcode'] === 13) {
$.isLogin = false; //cookie过期
return
}
if (data['retcode'] === 0) {
$.nickName = (data['base'] && data['base'].nickname) || $.UserName;
} else {
$.nickName = $.UserName
}
} else {
console.log(`京东æœåŠ¡å™¨è¿”å›žç©ºæ•°æ®`)
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
})
})
}
function jsonParse(str) {
if (typeof str == "string") {
try {
return JSON.parse(str);
} catch (e) {
console.log(e);
$.msg($.name, '', 'è¯·å‹¿éšæ„在BoxJs输入框修改内容\n建议通过脚本去获å–cookie')
return [];
}
}
}
// æ¥è‡ª @chavyleung 大佬
// https://raw.githubusercontent.com/chavyleung/scripts/master/Env.js
function Env(name, opts) {
class Http {
constructor(env) {
this.env = env
}
send(opts, method = 'GET') {
opts = typeof opts === 'string' ? {
url: opts
} : opts
let sender = this.get
if (method === 'POST') {
sender = this.post
}
return new Promise((resolve, reject) => {
sender.call(this, opts, (err, resp, body) => {
if (err) reject(err)
else resolve(resp)
})
})
}
get(opts) {
return this.send.call(this.env, opts)
}
post(opts) {
return this.send.call(this.env, opts, 'POST')
}
}
return new (class {
constructor(name, opts) {
this.name = name
this.http = new Http(this)
this.data = null
this.dataFile = 'box.dat'
this.logs = []
this.isMute = false
this.isNeedRewrite = false
this.logSeparator = '\n'
this.startTime = new Date().getTime()
Object.assign(this, opts)
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(str, defaultValue = null) {
try {
return JSON.parse(str)
} catch {
return defaultValue
}
}
toStr(obj, defaultValue = null) {
try {
return JSON.stringify(obj)
} catch {
return defaultValue
}
}
getjson(key, defaultValue) {
let json = defaultValue
const val = this.getdata(key)
if (val) {
try {
json = JSON.parse(this.getdata(key))
} catch { }
}
return json
}
setjson(val, key) {
try {
return this.setdata(JSON.stringify(val), key)
} catch {
return false
}
}
getScript(url) {
return new Promise((resolve) => {
this.get({
url
}, (err, resp, body) => resolve(body))
})
}
runScript(script, runOpts) {
return new Promise((resolve) => {
let httpapi = this.getdata('@chavy_boxjs_userCfgs.httpapi')
httpapi = httpapi ? httpapi.replace(/\n/g, '').trim() : httpapi
let httpapi_timeout = this.getdata('@chavy_boxjs_userCfgs.httpapi_timeout')
httpapi_timeout = httpapi_timeout ? httpapi_timeout * 1 : 20
httpapi_timeout = runOpts && runOpts.timeout ? runOpts.timeout : httpapi_timeout
const [key, addr] = httpapi.split('@')
const opts = {
url: `http://${addr}/v1/scripting/evaluate`,
body: {
script_text: script,
mock_type: 'cron',
timeout: httpapi_timeout
},
headers: {
'X-Key': key,
'Accept': '*/*'
}
}
this.post(opts, (err, resp, body) => resolve(body))
}).catch((e) => this.logErr(e))
}
loaddata() {
if (this.isNode()) {
this.fs = this.fs ? this.fs : require('fs')
this.path = this.path ? this.path : require('path')
const curDirDataFilePath = this.path.resolve(this.dataFile)
const rootDirDataFilePath = this.path.resolve(process.cwd(), this.dataFile)
const isCurDirDataFile = this.fs.existsSync(curDirDataFilePath)
const isRootDirDataFile = !isCurDirDataFile && this.fs.existsSync(rootDirDataFilePath)
if (isCurDirDataFile || isRootDirDataFile) {
const datPath = isCurDirDataFile ? curDirDataFilePath : rootDirDataFilePath
try {
return JSON.parse(this.fs.readFileSync(datPath))
} catch (e) {
return {}
}
} else return {}
} else return {}
}
writedata() {
if (this.isNode()) {
this.fs = this.fs ? this.fs : require('fs')
this.path = this.path ? this.path : require('path')
const curDirDataFilePath = this.path.resolve(this.dataFile)
const rootDirDataFilePath = this.path.resolve(process.cwd(), this.dataFile)
const isCurDirDataFile = this.fs.existsSync(curDirDataFilePath)
const isRootDirDataFile = !isCurDirDataFile && this.fs.existsSync(rootDirDataFilePath)
const jsondata = JSON.stringify(this.data)
if (isCurDirDataFile) {
this.fs.writeFileSync(curDirDataFilePath, jsondata)
} else if (isRootDirDataFile) {
this.fs.writeFileSync(rootDirDataFilePath, jsondata)
} else {
this.fs.writeFileSync(curDirDataFilePath, jsondata)
}
}
}
lodash_get(source, path, defaultValue = undefined) {
const paths = path.replace(/\[(\d+)\]/g, '.$1').split('.')
let result = source
for (const p of paths) {
result = Object(result)[p]
if (result === undefined) {
return defaultValue
}
}
return result
}
lodash_set(obj, path, value) {
if (Object(obj) !== obj) return obj
if (!Array.isArray(path)) path = path.toString().match(/[^.[\]]+/g) || []
path.slice(0, -1).reduce((a, c, i) => (Object(a[c]) === a[c] ? a[c] : (a[c] = Math.abs(path[i + 1]) >> 0 === +path[i + 1] ? [] : {})), obj)[
path[path.length - 1]
] = value
return obj
}
getdata(key) {
let val = this.getval(key)
// 如果以 @
if (/^@/.test(key)) {
const [, objkey, paths] = /^@(.*?)\.(.*?)$/.exec(key)
const objval = objkey ? this.getval(objkey) : ''
if (objval) {
try {
const objedval = JSON.parse(objval)
val = objedval ? this.lodash_get(objedval, paths, '') : val
} catch (e) {
val = ''
}
}
}
return val
}
setdata(val, key) {
let issuc = false
if (/^@/.test(key)) {
const [, objkey, paths] = /^@(.*?)\.(.*?)$/.exec(key)
const objdat = this.getval(objkey)
const objval = objkey ? (objdat === 'null' ? null : objdat || '{}') : '{}'
try {
const objedval = JSON.parse(objval)
this.lodash_set(objedval, paths, val)
issuc = this.setval(JSON.stringify(objedval), objkey)
} catch (e) {
const objedval = {}
this.lodash_set(objedval, paths, val)
issuc = this.setval(JSON.stringify(objedval), objkey)
}
} else {
issuc = this.setval(val, key)
}
return issuc
}
getval(key) {
if (this.isSurge() || this.isLoon()) {
return $persistentStore.read(key)
} else if (this.isQuanX()) {
return $prefs.valueForKey(key)
} else if (this.isNode()) {
this.data = this.loaddata()
return this.data[key]
} else {
return (this.data && this.data[key]) || null
}
}
setval(val, key) {
if (this.isSurge() || this.isLoon()) {
return $persistentStore.write(val, key)
} else if (this.isQuanX()) {
return $prefs.setValueForKey(val, key)
} else if (this.isNode()) {
this.data = this.loaddata()
this.data[key] = val
this.writedata()
return true
} else {
return (this.data && this.data[key]) || null
}
}
initGotEnv(opts) {
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()
if (opts) {
opts.headers = opts.headers ? opts.headers : {}
if (undefined === opts.headers.Cookie && undefined === opts.cookieJar) {
opts.cookieJar = this.ckjar
}
}
}
get(opts, callback = () => { }) {
if (opts.headers) {
delete opts.headers['Content-Type']
delete opts.headers['Content-Length']
}
if (this.isSurge() || this.isLoon()) {
if (this.isSurge() && this.isNeedRewrite) {
opts.headers = opts.headers || {}
Object.assign(opts.headers, {
'X-Surge-Skip-Scripting': false
})
}
$httpClient.get(opts, (err, resp, body) => {
if (!err && resp) {
resp.body = body
resp.statusCode = resp.status
}
callback(err, resp, body)
})
} else if (this.isQuanX()) {
if (this.isNeedRewrite) {
opts.opts = opts.opts || {}
Object.assign(opts.opts, {
hints: false
})
}
$task.fetch(opts).then(
(resp) => {
const {
statusCode: status,
statusCode,
headers,
body
} = resp
callback(null, {
status,
statusCode,
headers,
body
}, body)
},
(err) => callback(err)
)
} else if (this.isNode()) {
this.initGotEnv(opts)
this.got(opts).on('redirect', (resp, nextOpts) => {
try {
if (resp.headers['set-cookie']) {
const ck = resp.headers['set-cookie'].map(this.cktough.Cookie.parse).toString()
if (ck) {
this.ckjar.setCookieSync(ck, null)
}
nextOpts.cookieJar = this.ckjar
}
} catch (e) {
this.logErr(e)
}
// this.ckjar.setCookieSync(resp.headers['set-cookie'].map(Cookie.parse).toString())
}).then(
(resp) => {
const {
statusCode: status,
statusCode,
headers,
body
} = resp
callback(null, {
status,
statusCode,
headers,
body
}, body)
},
(err) => {
const {
message: error,
response: resp
} = err
callback(error, resp, resp && resp.body)
}
)
}
}
post(opts, callback = () => { }) {
// 如果指定了请求体, 但没指定`Content-Type`, 则自动生æˆ
if (opts.body && opts.headers && !opts.headers['Content-Type']) {
opts.headers['Content-Type'] = 'application/x-www-form-urlencoded'
}
if (opts.headers) delete opts.headers['Content-Length']
if (this.isSurge() || this.isLoon()) {
if (this.isSurge() && this.isNeedRewrite) {
opts.headers = opts.headers || {}
Object.assign(opts.headers, {
'X-Surge-Skip-Scripting': false
})
}
$httpClient.post(opts, (err, resp, body) => {
if (!err && resp) {
resp.body = body
resp.statusCode = resp.status
}
callback(err, resp, body)
})
} else if (this.isQuanX()) {
opts.method = 'POST'
if (this.isNeedRewrite) {
opts.opts = opts.opts || {}
Object.assign(opts.opts, {
hints: false
})
}
$task.fetch(opts).then(
(resp) => {
const {
statusCode: status,
statusCode,
headers,
body
} = resp
callback(null, {
status,
statusCode,
headers,
body
}, body)
},
(err) => callback(err)
)
} else if (this.isNode()) {
this.initGotEnv(opts)
const {
url,
..._opts
} = opts
this.got.post(url, _opts).then(
(resp) => {
const {
statusCode: status,
statusCode,
headers,
body
} = resp
callback(null, {
status,
statusCode,
headers,
body
}, body)
},
(err) => {
const {
message: error,
response: resp
} = err
callback(error, resp, resp && resp.body)
}
)
}
}
/**
*
* 示例:$.time('yyyy-MM-dd qq HH:mm:ss.S')
* :$.time('yyyyMMddHHmmssS')
* y:年 M:月 d:日 q:季 H:时 m:分 s:秒 S:毫秒
* 其中yå¯é€‰0-4ä½å ä½ç¬¦ã€¯é€‰0-1ä½å ä½ç¬¦ï¼Œå…¶ä½™å¯é€‰0-2ä½å ä½ç¬¦
* @param {*} fmt æ ¼å¼åŒ–傿•°
*
*/
time(fmt) {
let o = {
'M+': new Date().getMonth() + 1,
'd+': new Date().getDate(),
'H+': new Date().getHours(),
'm+': new Date().getMinutes(),
's+': new Date().getSeconds(),
'q+': Math.floor((new Date().getMonth() + 3) / 3),
'S': new Date().getMilliseconds()
}
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (new Date().getFullYear() + '').substr(4 - RegExp.$1.length))
for (let k in o)
if (new RegExp('(' + k + ')').test(fmt))
fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length))
return fmt
}
/**
* 系统通知
*
* > é€šçŸ¥å‚æ•°: åŒæ—¶æ”¯æŒ QuanX å’Œ Loon ä¸¤ç§æ ¼å¼, EnvJsæ ¹æ®è¿è¡ŒçŽ¯å¢ƒè‡ªåŠ¨è½¬æ¢, Surge çŽ¯å¢ƒä¸æ”¯æŒå¤šåª’体通知
*
* 示例:
* $.msg(title, subt, desc, 'twitter://')
* $.msg(title, subt, desc, { 'open-url': 'twitter://', 'media-url': 'https://github.githubassets.com/images/modules/open_graph/github-mark.png' })
* $.msg(title, subt, desc, { 'open-url': 'https://bing.com', 'media-url': 'https://github.githubassets.com/images/modules/open_graph/github-mark.png' })
*
* @param {*} title 标题
* @param {*} subt 副标题
* @param {*} desc 通知详情
* @param {*} opts é€šçŸ¥å‚æ•°
*
*/
msg(title = name, subt = '', desc = '', opts) {
const toEnvOpts = (rawopts) => {
if (!rawopts) return rawopts
if (typeof rawopts === 'string') {
if (this.isLoon()) return rawopts
else if (this.isQuanX()) return {
'open-url': rawopts
}
else if (this.isSurge()) return {
url: rawopts
}
else return undefined
} else if (typeof rawopts === 'object') {
if (this.isLoon()) {
let openUrl = rawopts.openUrl || rawopts.url || rawopts['open-url']
let mediaUrl = rawopts.mediaUrl || rawopts['media-url']
return {
openUrl,
mediaUrl
}
} else if (this.isQuanX()) {
let openUrl = rawopts['open-url'] || rawopts.url || rawopts.openUrl
let mediaUrl = rawopts['media-url'] || rawopts.mediaUrl
return {
'open-url': openUrl,
'media-url': mediaUrl
}
} else if (this.isSurge()) {
let openUrl = rawopts.url || rawopts.openUrl || rawopts['open-url']
return {
url: openUrl
}
}
} else {
return undefined
}
}
if (!this.isMute) {
if (this.isSurge() || this.isLoon()) {
$notification.post(title, subt, desc, toEnvOpts(opts))
} else if (this.isQuanX()) {
$notify(title, subt, desc, toEnvOpts(opts))
}
}
if (!this.isMuteLog) {
let logs = ['', '==============📣系统通知📣==============']
logs.push(title)
subt ? logs.push(subt) : ''
desc ? logs.push(desc) : ''
console.log(logs.join('\n'))
this.logs = this.logs.concat(logs)
}
}
log(...logs) {
if (logs.length > 0) {
this.logs = [...this.logs, ...logs]
}
console.log(logs.join(this.logSeparator))
}
logErr(err, msg) {
const isPrintSack = !this.isSurge() && !this.isQuanX() && !this.isLoon()
if (!isPrintSack) {
this.log('', `â—ï¸${this.name}, 错误!`, err)
} else {
this.log('', `â—ï¸${this.name}, 错误!`, err.stack)
}
}
wait(time) {
return new Promise((resolve) => setTimeout(resolve, time))
}
done(val = {}) {
const endTime = new Date().getTime()
const costTime = (endTime - this.startTime) / 1000
this.log('', `🔔${this.name}, 结æŸ! 🕛 ${costTime} ç§’`)
this.log()
if (this.isSurge() || this.isQuanX() || this.isLoon()) {
$done(val)
}
}
})(name, opts)
}
//我加的函数
function postToDingTalk(messgae) {
const message1 = "" + messgae
// that.log(messgae)
const body = {
"msgtype": "markdown",
"markdown": {
"title": "éšæœºè¯•用",
"text": message1
},
"at": {
"atMobiles": [],
2021-11-10 09:42:02 +08:00
"isAtAll": false
2021-11-09 14:13:03 +08:00
}
}
$.post(toDingtalk(dingtalk, JSON.stringify(body)), (data, status, xhr) => {
try {
that.log(resp)
that.log(data)
if (err) {
that.log(JSON.stringify(err));
$.logErr(err);
} else {
if (safeGet(data)) {
$.duckRes = JSON.parse(data);
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
}, "json")
}
function toDingtalk(urlmain, bodyMain) {
return {
url: urlmain,
body: bodyMain,
headers: { 'Content-Type': 'application/json;charset=utf-8' },
timeout: 10000,
}
}
function postToDingTalk1(messgae) {
2021-10-26 19:20:52 +08:00
const message1 = "" + messgae
// that.log(messgae)
const body = {
"msgtype": "markdown",
"markdown": {
"title": "错误筛选",
"text": message1
},
"at": {
"atMobiles": [],
"isAtAll": false
}
}
$.post(toDingtalk(dingtalk1, JSON.stringify(body)), (data, status, xhr) => {
try {
that.log(resp)
that.log(data)
if (err) {
that.log(JSON.stringify(err));
$.logErr(err);
} else {
if (safeGet(data)) {
$.duckRes = JSON.parse(data);
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
}, "json")
2021-11-09 14:13:03 +08:00
}
function postToDingTalk2(messgae) {
const message1 = "" + messgae
// that.log(messgae)
const body = {
"msgtype": "markdown",
"markdown": {
"title": "éšæœºè¯•用(待领å–)",
"text": message1
},
"at": {
"atMobiles": [],
"isAtAll": true
}
}
$.post(toDingtalk(dingtalk2, JSON.stringify(body)), (data, status, xhr) => {
try {
that.log(resp)
that.log(data)
if (err) {
that.log(JSON.stringify(err));
$.logErr(err);
} else {
if (safeGet(data)) {
$.duckRes = JSON.parse(data);
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
}, "json")
2021-10-26 19:20:52 +08:00
}