| 648 | } |
| 649 | //喂食 |
| 650 | function feedPets(feedNum) { |
| 651 | return new Promise(resolve => { |
| 652 | console.log(`您设置的喂食数量:${FEED_NUM}g\n`); |
| 653 | if (FEED_NUM === 0) { console.log(`跳出喂食`);resolve();return } |
| 654 | console.log(`实际的喂食数量:${feedNum}g\n`); |
| 655 | // const url = `${weAppUrl}/feed?feedCount=${feedNum}&reqSource=weapp`; |
| 656 | const host = `draw.jdfcloud.com`; |
| 657 | const reqSource = 'weapp'; |
| 658 | let opt = { |
| 659 | // url: "//jdjoy.jd.com/common/pet/getPetTaskConfig?reqSource=h5", |
| 660 | url: `//draw.jdfcloud.com/common/pet/feed?feedCount=${feedNum}&reqSource=h5&invokeKey=Oex5GmEuqGep1WLC`, |
| 661 | method: "GET", |
| 662 | data: {}, |
| 663 | credentials: "include", |
| 664 | header: {"content-type": "application/json"} |
| 665 | } |
| 666 | const url = "https:"+ taroRequest(opt)['url'] |
| 667 | $.get(taskUrl(url, host, reqSource), async (err, resp, data) => { |
| 668 | try { |
| 669 | if (err) { |
| 670 | console.log('\n京东宠汪汪: API查询请求失败 ‼️‼️') |
| 671 | } else { |
| 672 | data = JSON.parse(data); |
| 673 | if (data.success) { |
| 674 | if (data.errorCode === 'feed_ok') { |
| 675 | console.log('喂食成功') |
| 676 | message += `【喂食成功】消耗${feedNum}g狗粮\n`; |
| 677 | } else if (data.errorCode === 'time_error') { |
| 678 | console.log('喂食失败:您的汪汪正在食用中,请稍后再喂食') |
| 679 | message += `【喂食失败】您的汪汪正在食用中,请稍后再喂食\n`; |
| 680 | } else if (data.errorCode === 'food_insufficient') { |
| 681 | console.log(`当前喂食${feedNum}g狗粮不够, 现为您降低一档次喂食\n`) |
| 682 | if ((feedNum) === 80) { |
| 683 | feedNum = 40; |
| 684 | } else if ((feedNum) === 40) { |
| 685 | feedNum = 20; |
| 686 | } else if ((feedNum) === 20) { |
| 687 | feedNum = 10; |
| 688 | } else if ((feedNum) === 10) { |
| 689 | feedNum = 0; |
| 690 | } |
| 691 | // 如果喂食设置的数量失败, 就降低一个档次喂食. |
| 692 | if ((feedNum) !== 0) { |
| 693 | await feedPets(feedNum); |
| 694 | } else { |
| 695 | console.log('您的狗粮已不足10g') |
| 696 | message += `【喂食失败】您的狗粮已不足10g\n`; |
| 697 | } |
| 698 | } else { |
| 699 | console.log(`其他状态${data.errorCode}`) |
| 700 | } |
| 701 | } |
| 702 | } |
| 703 | } catch (e) { |
| 704 | $.logErr(e, resp); |
| 705 | } finally { |
| 706 | resolve(); |
| 707 | } |