(text, desp)
| 519 | }); |
| 520 | } |
| 521 | function ddBotNotify(text, desp) { |
| 522 | return new Promise((resolve) => { |
| 523 | const { DD_BOT_TOKEN, DD_BOT_SECRET } = push_config; |
| 524 | const options = { |
| 525 | url: `https://oapi.dingtalk.com/robot/send?access_token=${DD_BOT_TOKEN}`, |
| 526 | json: { |
| 527 | msgtype: 'text', |
| 528 | text: { |
| 529 | content: `${text}\n\n${desp}`, |
| 530 | }, |
| 531 | }, |
| 532 | headers: { |
| 533 | 'Content-Type': 'application/json', |
| 534 | }, |
| 535 | timeout, |
| 536 | }; |
| 537 | if (DD_BOT_TOKEN && DD_BOT_SECRET) { |
| 538 | const crypto = require('crypto'); |
| 539 | const dateNow = Date.now(); |
| 540 | const hmac = crypto.createHmac('sha256', DD_BOT_SECRET); |
| 541 | hmac.update(`${dateNow}\n${DD_BOT_SECRET}`); |
| 542 | const result = encodeURIComponent(hmac.digest('base64')); |
| 543 | options.url = `${options.url}×tamp=${dateNow}&sign=${result}`; |
| 544 | $.post(options, (err, resp, data) => { |
| 545 | try { |
| 546 | if (err) { |
| 547 | console.log('钉钉发送通知消息失败😞\n', err); |
| 548 | } else { |
| 549 | if (data.errcode === 0) { |
| 550 | console.log('钉钉发送通知消息成功🎉\n'); |
| 551 | } else { |
| 552 | console.log(`钉钉发送通知消息异常 ${data.errmsg}\n`); |
| 553 | } |
| 554 | } |
| 555 | } catch (e) { |
| 556 | $.logErr(e, resp); |
| 557 | } finally { |
| 558 | resolve(data); |
| 559 | } |
| 560 | }); |
| 561 | } else if (DD_BOT_TOKEN) { |
| 562 | $.post(options, (err, resp, data) => { |
| 563 | try { |
| 564 | if (err) { |
| 565 | console.log('钉钉发送通知消息失败😞\n', err); |
| 566 | } else { |
| 567 | if (data.errcode === 0) { |
| 568 | console.log('钉钉发送通知消息成功🎉\n'); |
| 569 | } else { |
| 570 | console.log(`钉钉发送通知消息异常 ${data.errmsg}\n`); |
| 571 | } |
| 572 | } |
| 573 | } catch (e) { |
| 574 | $.logErr(e, resp); |
| 575 | } finally { |
| 576 | resolve(data); |
| 577 | } |
| 578 | }); |
no test coverage detected