(text, desp)
| 347 | }) |
| 348 | } |
| 349 | function ddBotNotify(text, desp) { |
| 350 | return new Promise(resolve => { |
| 351 | const options = { |
| 352 | url: `https://oapi.dingtalk.com/robot/send?access_token=${DD_BOT_TOKEN}`, |
| 353 | json: { |
| 354 | "msgtype": "text", |
| 355 | "text": { |
| 356 | "content": ` ${text}\n\n${desp}` |
| 357 | } |
| 358 | }, |
| 359 | headers: { |
| 360 | 'Content-Type': 'application/json' |
| 361 | }, |
| 362 | timeout |
| 363 | } |
| 364 | if (DD_BOT_TOKEN && DD_BOT_SECRET) { |
| 365 | const crypto = require('crypto'); |
| 366 | const dateNow = Date.now(); |
| 367 | const hmac = crypto.createHmac('sha256', DD_BOT_SECRET); |
| 368 | hmac.update(`${dateNow}\n${DD_BOT_SECRET}`); |
| 369 | const result = encodeURIComponent(hmac.digest('base64')); |
| 370 | options.url = `${options.url}×tamp=${dateNow}&sign=${result}`; |
| 371 | $.post(options, (err, resp, data) => { |
| 372 | try { |
| 373 | if (err) { |
| 374 | console.log('钉钉发送通知消息失败!!\n') |
| 375 | console.log(err); |
| 376 | } else { |
| 377 | data = JSON.parse(data); |
| 378 | if (data.errcode === 0) { |
| 379 | console.log('钉钉发送通知消息成功🎉。\n') |
| 380 | } else { |
| 381 | console.log(`${data.errmsg}\n`) |
| 382 | } |
| 383 | } |
| 384 | } catch (e) { |
| 385 | $.logErr(e, resp); |
| 386 | } finally { |
| 387 | resolve(data); |
| 388 | } |
| 389 | }) |
| 390 | } else if (DD_BOT_TOKEN) { |
| 391 | $.post(options, (err, resp, data) => { |
| 392 | try { |
| 393 | if (err) { |
| 394 | console.log('钉钉发送通知消息失败!!\n') |
| 395 | console.log(err); |
| 396 | } else { |
| 397 | data = JSON.parse(data); |
| 398 | if (data.errcode === 0) { |
| 399 | console.log('钉钉发送通知消息完成。\n') |
| 400 | } else { |
| 401 | console.log(`${data.errmsg}\n`) |
| 402 | } |
| 403 | } |
| 404 | } catch (e) { |
| 405 | $.logErr(e, resp); |
| 406 | } finally { |
no test coverage detected