本文主要是介绍怎么利用NodeJS发送视频短信,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
随着5G时代的来临,企业的数字化转型步伐日益加快,视频短信作为新兴的数字营销工具,正逐步展现出其大的潜力。视频群发短信以其独特的形式和内容,将图片、文字、视频、声音融为一体,为用户带来全新的直观感受,为企业营销注入新的活力。
支持免费对接试用乐讯通PaaS平台 找好用的短信平台,选择乐讯通,短信群发|短信平台|群发短信软件|群发短信平台|乐讯通PaaS平台http://yun.loktong.com/login/register/0c61bafb77
const http = require('http');
const crypto = require('crypto');
const querystring = require('querystring');
const fs = require('fs');
const encodingConvert = require('encoding');//参数
let url = "http://www.lokapi.cn/smsUTF8.aspx"
let rece = "json"
let username = "******"
let password = "123456"
let token = "333293sd"let passwd = md5(password);
let timestamp = Date.now();
let body = "action=sendimagetext&username=" + username + "&password=" + passwd + "&token=" + token + "×tamp=" + timestamp;
let sign = md5(body);//发送帧//文字
let content = '祝你生日快乐';
let buff = Buffer.from(content, 'utf8');
let resultBuffer = encodingConvert.convert(buff, "GBK", "UTF8");
let base64Content = resultBuffer.toString('base64');//图片
let path = 'D:\\我的文档\\Pictures\\d2e10cb3ac49dc63d013cb63ab6ca7cd.jpg';
let ext = 'jpg';//图片后缀
let base64str = base64_encode(path);
let message = 'txt|' + base64Content + ',' + ext + '|' + base64str + ';';
message = message.replace('%', '%25');
message = message.replace('&', '%26');
message = message.replace('+', '%2B');// 用于请求的选项
let contents = querystring.stringify({"action": "sendimagetext","username": username,"password": passwd,"token": token,"timestamp": timestamp,"sign": sign,"rece": rece,"mobile": '17712345678',"title": '祝福短信','message': message
});let options = {host: 'localhost',port: 59414,path: '/smsUTF8.aspx',method: 'POST',headers: {'Content-Type': 'application/x-www-form-urlencoded','Content-Length': contents.length}
}let req = http.request(options, function (res) {res.setEncoding('utf8');res.on('data', function (data) {console.log("data:", data); //一段html代码});
});req.write(contents);
req.end;function md5(data) {// 以md5的格式创建一个哈希值let hash = crypto.createHash('md5');return hash.update(data).digest('hex').toUpperCase();
}function base64_encode(file) {var bitmap = fs.readFileSync(file);return Buffer.from(bitmap, 'utf8').toString('base64');
}
这篇关于怎么利用NodeJS发送视频短信的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!