(text, desp)
| 445 | } |
| 446 | |
| 447 | function ddBotNotify(text, desp) { |
| 448 | return new Promise(resolve => { |
| 449 | const options = { |
| 450 | url: `https://oapi.dingtalk.com/robot/send?access_token=${DD_BOT_TOKEN}`, |
| 451 | json: { |
| 452 | "msgtype": "text", |
| 453 | "text": { |
| 454 | "content": `${text}\n\n${desp}` |
| 455 | } |
| 456 | }, |
| 457 | headers: { |
| 458 | 'Content-Type': 'application/json' |
| 459 | }, |
| 460 | timeout |
| 461 | } |
| 462 | if (DD_BOT_TOKEN && DD_BOT_SECRET) { |
| 463 | const crypto = require('crypto'); |
| 464 | const dateNow = Date.now(); |
| 465 | const hmac = crypto.createHmac('sha256', DD_BOT_SECRET); |
| 466 | hmac.update(`${dateNow}\n${DD_BOT_SECRET}`); |
| 467 | const result = encodeURIComponent(hmac.digest('base64')); |
| 468 | options.url = `${options.url}×tamp=${dateNow}&sign=${result}`; |
| 469 | $.post(options, (err, resp, data) => { |
| 470 | try { |
| 471 | if (err) { |
| 472 | console.log('钉钉发送通知消息失败!!\n') |
| 473 | console.log(err); |
| 474 | } else { |
| 475 | data = JSON.parse(data); |
| 476 | if (data.errcode === 0) { |
| 477 | console.log('钉钉发送通知消息成功🎉。\n') |
| 478 | } else { |
| 479 | console.log(`${data.errmsg}\n`) |
| 480 | } |
| 481 | } |
| 482 | } catch (e) { |
| 483 | $.logErr(e, resp); |
| 484 | } finally { |
| 485 | resolve(data); |
| 486 | } |
| 487 | }) |
| 488 | } else if (DD_BOT_TOKEN) { |
| 489 | $.post(options, (err, resp, data) => { |
| 490 | try { |
| 491 | if (err) { |
| 492 | console.log('钉钉发送通知消息失败!!\n') |
| 493 | console.log(err); |
| 494 | } else { |
| 495 | data = JSON.parse(data); |
| 496 | if (data.errcode === 0) { |
| 497 | console.log('钉钉发送通知消息完成。\n') |
| 498 | } else { |
| 499 | console.log(`${data.errmsg}\n`) |
| 500 | } |
| 501 | } |
| 502 | } catch (e) { |
| 503 | $.logErr(e, resp); |
| 504 | } finally { |
no test coverage detected