(text, desp)
| 629 | } |
| 630 | |
| 631 | function pushPlusNotify(text, desp) { |
| 632 | return new Promise(resolve => { |
| 633 | if (PUSH_PLUS_TOKEN) { |
| 634 | desp = desp.replace(/[\n\r]/g, '<br>'); // 默认为html, 不支持plaintext |
| 635 | const body = { |
| 636 | token: `${PUSH_PLUS_TOKEN}`, |
| 637 | title: `${text}`, |
| 638 | content: `${desp}`, |
| 639 | topic: `${PUSH_PLUS_USER}` |
| 640 | }; |
| 641 | const options = { |
| 642 | url: `http://www.pushplus.plus/send`, |
| 643 | body: JSON.stringify(body), |
| 644 | headers: { |
| 645 | 'Content-Type': ' application/json' |
| 646 | }, |
| 647 | timeout |
| 648 | } |
| 649 | $.post(options, (err, resp, data) => { |
| 650 | try { |
| 651 | if (err) { |
| 652 | console.log(`push+发送${PUSH_PLUS_USER ? '一对多' : '一对一'}通知消息失败!!\n`) |
| 653 | console.log(err); |
| 654 | } else { |
| 655 | data = JSON.parse(data); |
| 656 | if (data.code === 200) { |
| 657 | console.log(`push+发送${PUSH_PLUS_USER ? '一对多' : '一对一'}通知消息完成。\n`) |
| 658 | } else { |
| 659 | console.log(`push+发送${PUSH_PLUS_USER ? '一对多' : '一对一'}通知消息失败:${data.msg}\n`) |
| 660 | } |
| 661 | } |
| 662 | } catch (e) { |
| 663 | $.logErr(e, resp); |
| 664 | } finally { |
| 665 | resolve(data); |
| 666 | } |
| 667 | }) |
| 668 | } else { |
| 669 | console.log('您未提供push+推送所需的PUSH_PLUS_TOKEN,取消push+推送消息通知🚫\n'); |
| 670 | resolve() |
| 671 | } |
| 672 | }) |
| 673 | } |
| 674 | |
| 675 | module.exports = { |
| 676 | sendNotify, |
no test coverage detected