(feedNum)
| 102 | } |
| 103 | } |
| 104 | function feedPets(feedNum) { |
| 105 | return new Promise(resolve => { |
| 106 | console.log(`您设置的喂食数量::${FEED_NUM}g\n`); |
| 107 | if (FEED_NUM === 0) { console.log(`跳出喂食`);resolve();return } |
| 108 | console.log(`实际的喂食数量::${feedNum}g\n`); |
| 109 | let opt = { |
| 110 | url: `//jdjoy.jd.com/common/pet/feed?feedCount=${feedNum}&reqSource=h5&invokeKey=Oex5GmEuqGep1WLC`, |
| 111 | // url: "//draw.jdfcloud.com/common/pet/getPetTaskConfig?reqSource=h5&invokeKey=Oex5GmEuqGep1WLC", |
| 112 | method: "GET", |
| 113 | data: {}, |
| 114 | credentials: "include", |
| 115 | header: {"content-type": "application/json"} |
| 116 | } |
| 117 | const url = "https:"+ taroRequest(opt)['url'] |
| 118 | const options = { |
| 119 | url, |
| 120 | headers: { |
| 121 | 'Cookie': cookie, |
| 122 | 'reqSource': 'h5', |
| 123 | 'Host': 'jdjoy.jd.com', |
| 124 | 'Connection': 'keep-alive', |
| 125 | 'Content-Type': 'application/json', |
| 126 | 'Referer': 'https://jdjoy.jd.com/pet/index', |
| 127 | '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"), |
| 128 | 'Accept-Language': 'zh-cn', |
| 129 | 'Accept-Encoding': 'gzip, deflate, br', |
| 130 | } |
| 131 | } |
| 132 | $.get(options, async (err, resp, data) => { |
| 133 | try { |
| 134 | $.data = JSON.parse(data); |
| 135 | if ($.data.success) { |
| 136 | if ($.data.errorCode === 'feed_ok') { |
| 137 | console.log('喂食成功') |
| 138 | message += `【喂食成功】${feedNum}g\n`; |
| 139 | } else if ($.data.errorCode === 'time_error') { |
| 140 | console.log('喂食失败:正在食用') |
| 141 | message += `【喂食失败】您的汪汪正在食用\n`; |
| 142 | } else if ($.data.errorCode === 'food_insufficient') { |
| 143 | console.log(`当前喂食${feedNum}g狗粮不够, 现为您降低一档次喂食\n`) |
| 144 | if ((feedNum) === 80) { |
| 145 | feedNum = 40; |
| 146 | } else if ((feedNum) === 40) { |
| 147 | feedNum = 20; |
| 148 | } else if ((feedNum) === 20) { |
| 149 | feedNum = 10; |
| 150 | } else if ((feedNum) === 10) { |
| 151 | feedNum = 0; |
| 152 | } |
| 153 | // 如果喂食设置的数量失败, 就降低一个档次喂食. |
| 154 | if ((feedNum) !== 0) { |
| 155 | await feedPets(feedNum); |
| 156 | } else { |
| 157 | console.log('您的狗粮已不足10g') |
| 158 | message += `【喂食失败】您的狗粮已不足10g\n`; |
| 159 | } |
| 160 | } else { |
| 161 | console.log(`其他状态${$.data.errorCode}`) |
no test coverage detected