UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

77 lines (74 loc) 2.29 kB
import _regeneratorRuntime from '@babel/runtime/regenerator'; import { _ as __awaiter } from '../tslib.es6-848120af.js'; import { getImgMd5, saveBase64ImgToFile } from '../node-img/img.mjs'; import { getPath } from '../nodejs/path.mjs'; import { sendWxRobotImg } from './base.mjs'; import '../nodejs/crypto.mjs'; import '../nodejs/fs.mjs'; import '../nodejs/request.mjs'; import './helper.mjs'; import 'axios'; /** * 发送企业微信机器人base64图片,其实就是先保存到本地,然后生成md5,最后发送 * @param {object} config 配置信息 * @param {string} config.img base64图片 * @param {string} config.chatId 会话Id * @param {string} config.webhookUrl webhook地址 * @returns {Promise<object>} 请求Promise * @example * * sendWxRobotBase64Img({ * img: 'xxx', * chatId: 'xxx', * webhookUrl: 'xxx', * }).then(() => { * * }) * */ function sendWxRobotBase64Img(_ref) { var img = _ref.img, chatId = _ref.chatId, webhookUrl = _ref.webhookUrl; return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { var saveFilePath, pureSrc, md5Val; return _regeneratorRuntime.wrap(function (_context) { while (1) switch (_context.prev = _context.next) { case 0: if (!(!img || !webhookUrl)) { _context.next = 1; break; } return _context.abrupt("return", Promise.reject('参数不全')); case 1: saveFilePath = getPath().resolve(__dirname, '.temp.png'); _context.next = 2; return saveBase64ImgToFile({ imgUrl: img, savePath: saveFilePath }); case 2: pureSrc = _context.sent; _context.next = 3; return getImgMd5({ savePath: saveFilePath }); case 3: md5Val = _context.sent; _context.next = 4; return sendWxRobotImg({ webhookUrl: webhookUrl, chatId: chatId, content: pureSrc, md5Val: md5Val }); case 4: return _context.abrupt("return", _context.sent); case 5: case "end": return _context.stop(); } }, _callee); })); } export { sendWxRobotBase64Img };