UNPKG

qiao-sms

Version:

nodejs tencent sms tool

92 lines (83 loc) 2.01 kB
// qiao import { post } from 'qiao-ajax'; // Logger import { Logger } from 'qiao.log.js'; const logger = Logger('qiao-sms'); /** * submailSMS * @param {*} options * @returns */ export const submailSMS = async (options) => { return await sendSubmailSMS('https://api-v4.mysubmail.com/sms/send', options); }; /** * submailInternationalSMS * @param {*} options * @returns */ export const submailInternationalSMS = async (options) => { return await sendSubmailSMS('https://api-v4.mysubmail.com/internationalsms/send', options); }; // send submail sms async function sendSubmailSMS(url, options) { const methodName = 'sendSubmailSMS'; // const const resMsg = { status: 'error', }; // check if (!options) { const msg = 'need options'; logger.error(methodName, msg); resMsg.msg = msg; return resMsg; } if (!options.appid) { const msg = 'need options.appid'; logger.error(methodName, msg); resMsg.msg = msg; return resMsg; } if (!options.appkey) { const msg = 'need options.appkey'; logger.error(methodName, msg); resMsg.msg = msg; return resMsg; } if (!options.mobile) { const msg = 'need options.mobile'; logger.error(methodName, msg); resMsg.msg = msg; return resMsg; } if (!options.content) { const msg = 'need options.content'; logger.error(methodName, msg); resMsg.msg = msg; return resMsg; } // go try { const res = await post(url, { data: { appid: options.appid, signature: options.appkey, to: options.mobile, content: options.content, }, }); if (!res || res.status !== 200) { const msg = `ajax fail: ${res}`; logger.error(methodName, msg); resMsg.msg = msg; return resMsg; } // return return res.data; } catch (error) { logger.error(methodName, error); resMsg.msg = `request submail sms error, url is ${url}, options is ${JSON.stringify(options)}`; return resMsg; } }