2020-07-02 11:50:39 +08:00
const chavy = init ( )
const cookieName = '叮咚买菜'
const KEY _homeurl = 'chavy_home_url_mcdd'
const KEY _homeheader = 'chavy_home_header_mcdd'
const signinfo = { }
let VAL _homeurl = chavy . getdata ( KEY _homeurl )
let VAL _homeheader = chavy . getdata ( KEY _homeheader )
; ( exec = async ( ) => {
2020-07-02 11:52:57 +08:00
chavy . log ( ` 🔔 ${ cookieName } 开始签到 ` )
await signapp ( )
await getlottery ( )
if ( signinfo . draw _num > 0 ) for ( let i = 0 ; i < signinfo . draw _num ; i ++ ) await lotteryapp ( i )
await browseapp ( )
await getinfo ( )
showmsg ( )
chavy . done ( )
2020-07-02 11:50:39 +08:00
} ) ( ) . catch ( ( e ) => chavy . log ( ` ❌ ${ cookieName } 签到失败: ${ e } ` ) , chavy . done ( ) )
function getinfo ( ) {
2020-07-02 11:52:57 +08:00
return new Promise ( ( resolve , reject ) => {
const url = { url : VAL _homeurl , headers : JSON . parse ( VAL _homeheader ) }
chavy . get ( url , ( error , response , data ) => {
try {
signinfo . info = JSON . parse ( data )
if ( typeof signinfo . is _today _sign === 'undefined' ) signinfo . is _today _sign = signinfo . info . data . user _sign . is _today _sign
resolve ( )
} catch ( e ) {
chavy . msg ( cookieName , ` 获取信息: 失败 ` , ` 说明: ${ e } ` )
chavy . log ( ` ❌ ${ cookieName } getinfo - 获取信息失败: ${ e } ` )
chavy . log ( ` ❌ ${ cookieName } getinfo - response: ${ JSON . stringify ( response ) } ` )
resolve ( )
}
} )
2020-07-02 11:50:39 +08:00
} )
}
function signapp ( ) {
2020-07-02 11:52:57 +08:00
return new Promise ( ( resolve , reject ) => {
const url = { url : ` https://ddxq.mobi/api/v2/user/signin/ ` , headers : JSON . parse ( VAL _homeheader ) }
url . headers [ 'Accept' ] = '*/*'
url . headers [ 'Origin' ] = 'https://activity.m.ddxq.mobi'
url . headers [ 'Accept-Encoding' ] = 'gzip, deflate, br'
url . headers [ 'Content-Type' ] = 'application/x-www-form-urlencoded'
url . headers [ 'Host' ] = 'ddxq.mobi'
url . headers [ 'Connection' ] = 'keep-alive'
url . headers [ 'Referer' ] = 'https://activity.m.ddxq.mobi/'
url . headers [ 'Content-Length' ] = '129'
url . headers [ 'Accept-Language' ] = 'zh-cn'
url . body = VAL _homeurl . split ( '?' ) [ 1 ]
chavy . post ( url , ( error , response , data ) => {
try {
signinfo . signapp = JSON . parse ( data )
resolve ( )
} catch ( e ) {
chavy . msg ( cookieName , ` 签到结果: 失败 ` , ` 说明: ${ e } ` )
chavy . log ( ` ❌ ${ cookieName } signapp - 签到失败: ${ e } ` )
chavy . log ( ` ❌ ${ cookieName } signapp - response: ${ JSON . stringify ( response ) } ` )
resolve ( )
}
} )
2020-07-02 11:50:39 +08:00
} )
}
function getlottery ( ) {
2020-07-02 11:52:57 +08:00
return new Promise ( ( resolve , reject ) => {
const getlotteryurl = ` https://maicai.api.ddxq.mobi/lottery/index? ${ VAL _homeurl . split ( '?' ) [ 1 ] } &event_id=5dbacee44df3e3ed628ce721 `
const url = { url : getlotteryurl , headers : JSON . parse ( VAL _homeheader ) }
url . headers [ 'Origin' ] = 'https://activity.m.ddxq.mobi'
url . headers [ 'Connection' ] = 'keep-alive'
url . headers [ 'Accept' ] = '*/*'
url . headers [ 'Referer' ] = 'https://activity.m.ddxq.mobi/'
url . headers [ 'Host' ] = 'maicai.api.ddxq.mobi'
url . headers [ 'Accept-Encoding' ] = 'gzip, deflate, br'
url . headers [ 'Accept-Language' ] = 'zh-cn'
chavy . get ( url , ( error , response , data ) => {
try {
signinfo . lotteryinfo = JSON . parse ( data )
if ( typeof signinfo . draw _num === 'undefined' ) signinfo . draw _num = signinfo . lotteryinfo . data . draw _num
resolve ( )
} catch ( e ) {
chavy . msg ( cookieName , ` 获取抽奖: 失败 ` , ` 说明: ${ e } ` )
chavy . log ( ` ❌ ${ cookieName } getlottery - 获取抽奖失败: ${ e } ` )
chavy . log ( ` ❌ ${ cookieName } getlottery - response: ${ JSON . stringify ( response ) } ` )
resolve ( )
}
} )
2020-07-02 11:50:39 +08:00
} )
}
function lotteryapp ( cnt ) {
2020-07-02 11:52:57 +08:00
return new Promise ( ( resolve , reject ) => {
setTimeout ( ( ) => {
const lotteryappurl = ` https://maicai.api.ddxq.mobi/lottery/draw? ${ VAL _homeurl . split ( '?' ) [ 1 ] } &event_id=5dbacee44df3e3ed628ce721 `
const url = { url : lotteryappurl , headers : JSON . parse ( VAL _homeheader ) }
url . headers [ 'Origin' ] = 'https://activity.m.ddxq.mobi'
url . headers [ 'Connection' ] = 'keep-alive'
url . headers [ 'Accept' ] = '*/*'
url . headers [ 'Referer' ] = 'https://activity.m.ddxq.mobi/'
url . headers [ 'Host' ] = 'maicai.api.ddxq.mobi'
url . headers [ 'Accept-Encoding' ] = 'gzip, deflate, br'
url . headers [ 'Accept-Language' ] = 'zh-cn'
chavy . get ( url , ( error , response , data ) => {
try {
if ( ! signinfo . lottery ) signinfo . lottery = [ ]
signinfo . lottery . push ( JSON . parse ( data ) )
resolve ( )
} catch ( e ) {
chavy . msg ( cookieName , ` 获取抽奖: 失败 ` , ` 说明: ${ e } ` )
chavy . log ( ` ❌ ${ cookieName } lotteryapp - 获取抽奖失败: ${ e } ` )
chavy . log ( ` ❌ ${ cookieName } lotteryapp - response: ${ JSON . stringify ( response ) } ` )
resolve ( )
}
} )
} , cnt * 5000 )
} )
2020-07-02 11:50:39 +08:00
}
function browseapp ( ) {
2020-07-02 11:52:57 +08:00
return new Promise ( ( resolve , reject ) => {
const browseappurl = ` https://maicai.api.ddxq.mobi/point/completeTask `
const url = { url : browseappurl , headers : JSON . parse ( VAL _homeheader ) }
url . body = ` ${ VAL _homeurl . split ( '?' ) [ 1 ] } &station_id=5500fe01916edfe0738b4e43&task_type=21 `
url . headers [ 'Accept' ] = '*/*'
url . headers [ 'Origin' ] = 'https://maicai.m.ddxq.mobi'
url . headers [ 'Accept-Encoding' ] = 'gzip, deflate, br'
url . headers [ 'Content-Type' ] = 'application/x-www-form-urlencoded'
url . headers [ 'Host' ] = 'maicai.api.ddxq.mobi'
url . headers [ 'Connection' ] = 'keep-alive'
url . headers [ 'User-Agent' ] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 xzone/9.7.5 station_id/5500fe01916edfe0738b4e43'
url . headers [ 'Referer' ] = 'https://maicai.m.ddxq.mobi/?v=1.30.0'
url . headers [ 'Content-Length' ] = '152'
url . headers [ 'Accept-Language' ] = 'zh-cn'
chavy . post ( url , ( error , response , data ) => {
try {
signinfo . browseapp = JSON . parse ( data )
resolve ( )
} catch ( e ) {
chavy . msg ( cookieName , ` 浏览商品: 失败 ` , ` 说明: ${ e } ` )
chavy . log ( ` ❌ ${ cookieName } browseapp - 浏览商品失败: ${ e } ` )
chavy . log ( ` ❌ ${ cookieName } browseapp - response: ${ JSON . stringify ( response ) } ` )
resolve ( )
}
} )
2020-07-02 11:50:39 +08:00
} )
}
function showmsg ( ) {
2020-07-02 11:52:57 +08:00
let subTitle , detail
if ( signinfo . signapp . code == 0 ) {
if ( signinfo . is _today _sign === false ) subTitle = '签到: 成功'
else subTitle = '签到: 重复'
detail = ` 积分: ${ signinfo . info . data . point _num } (+ ${ signinfo . signapp . data . point } ), 价值: ${ signinfo . info . data . point _money } `
} else {
subTitle = '签到: 失败'
detail = ` 编码: ${ signinfo . signapp . code } , 说明: ${ signinfo . signapp . message } `
chavy . log ( ` ❌ ${ cookieName } showmsg - 签到失败: ${ JSON . stringify ( signinfo . signapp ) } ` )
}
2020-07-02 11:50:39 +08:00
2020-07-02 11:52:57 +08:00
if ( signinfo . lotteryinfo . code == 0 ) {
if ( signinfo . draw _num == 0 ) subTitle += '; 抽奖: 已转'
else subTitle += ` ; 抽奖: ${ signinfo . draw _num } 次 `
} else {
subTitle = '抽奖: 失败'
detail = ` 编码: ${ signinfo . lotteryinfo . code } , 说明: ${ signinfo . lotteryinfo . message } `
chavy . log ( ` ❌ ${ cookieName } showmsg - 抽奖失败: ${ JSON . stringify ( signinfo . lotteryinfo ) } ` )
}
2020-07-02 11:50:39 +08:00
2020-07-02 11:52:57 +08:00
if ( signinfo . browseapp . code == 0 ) {
subTitle += '; 浏览任务: 成功'
} else if ( signinfo . browseapp . code == - 1 ) {
subTitle += '; 浏览任务: 重复'
} else {
subTitle = '浏览任务: 失败'
detail = ` 编码: ${ signinfo . browseapp . code } , 说明: ${ signinfo . browseapp . msg } `
chavy . log ( ` ❌ ${ cookieName } showmsg - 浏览任务失败: ${ JSON . stringify ( signinfo . browseapp ) } ` )
}
2020-07-02 11:50:39 +08:00
2020-07-02 11:52:57 +08:00
if ( signinfo . lottery ) {
detail += '\n查看抽奖详情\n'
for ( let i = 0 ; i < signinfo . lottery . length ; i ++ ) {
if ( signinfo . lottery [ i ] . code == 0 ) detail += ` \n 抽奖 ( ${ i + 1 } ): ${ signinfo . lottery [ i ] . data . prize . title } `
else detail += ` \n 抽奖 ( ${ i + 1 } ): ${ signinfo . lottery [ i ] . msg } `
}
2020-07-02 11:50:39 +08:00
}
2020-07-02 11:52:57 +08:00
chavy . msg ( cookieName , subTitle , detail )
2020-07-02 11:50:39 +08:00
}
function init ( ) {
2020-07-02 11:52:57 +08:00
isSurge = ( ) => {
return undefined === this . $httpClient ? false : true
}
isQuanX = ( ) => {
return undefined === this . $task ? false : true
2020-07-02 11:50:39 +08:00
}
2020-07-02 11:52:57 +08:00
getdata = ( key ) => {
if ( isSurge ( ) ) return $persistentStore . read ( key )
if ( isQuanX ( ) ) return $prefs . valueForKey ( key )
2020-07-02 11:50:39 +08:00
}
2020-07-02 11:52:57 +08:00
setdata = ( key , val ) => {
if ( isSurge ( ) ) return $persistentStore . write ( key , val )
if ( isQuanX ( ) ) return $prefs . setValueForKey ( key , val )
}
msg = ( title , subtitle , body ) => {
if ( isSurge ( ) ) $notification . post ( title , subtitle , body )
if ( isQuanX ( ) ) $notify ( title , subtitle , body )
}
log = ( message ) => console . log ( message )
get = ( url , cb ) => {
if ( isSurge ( ) ) {
$httpClient . get ( url , cb )
}
if ( isQuanX ( ) ) {
url . method = 'GET'
$task . fetch ( url ) . then ( ( resp ) => cb ( null , resp , resp . body ) )
}
}
post = ( url , cb ) => {
if ( isSurge ( ) ) {
$httpClient . post ( url , cb )
}
if ( isQuanX ( ) ) {
url . method = 'POST'
$task . fetch ( url ) . then ( ( resp ) => cb ( null , resp , resp . body ) )
}
2020-07-02 11:50:39 +08:00
}
2020-07-02 11:52:57 +08:00
done = ( value = { } ) => {
$done ( value )
2020-07-02 11:50:39 +08:00
}
2020-07-02 11:52:57 +08:00
return { isSurge , isQuanX , msg , log , getdata , setdata , get , post , done }
2020-07-02 11:50:39 +08:00
}