我已经为我的项目使用nodemailer向用户发送了确认电子邮件。它工作得很好。
现在我想通过node.js向手机号码发送验证码,但我不知道该怎么做。
有没有像nodemailer那样给手机发送验证码的模块?或者,如果不是,我自己怎么做呢?
我使用node.js和mongodb、JavaScript和jQuery开发我的项目。
发布于 2013-02-09 22:48:28
大多数运营商都提供了SMS网关,您可以将电子邮件发送到该网关,然后将其作为SMS到达。如果您想要一种与当前的nodemailer实现一起工作的免费发送SMS的方式,这可能是您的最佳选择。否则,您可能需要搜索可以与集成的付费SMS服务。
以下是短信网关的列表:http://en.wikipedia.org/wiki/List_of_SMS_gateways
从链接的维基百科页面:例如,要发送到在美国通常表示为9875550100的号码,您可以发送电子邮件到9875550100@SMS-gateway。
发布于 2017-07-13 15:29:01
NodeJS包https://www.npmjs.com/package/springedge将很容易发送短信。您可以安装为
npm install springedge发送短信代码示例:
// send sms
var springedge = require('springedge');
var params = {
'apikey': '', // API Key
'sender': 'SEDEMO', // Sender Name
'to': [
'919019xxxxxxxx' //Moblie Number
],
'message': 'test+message'
};
springedge.messages.send(params, 5000, function (err, response) {
if (err) {
return console.log(err);
}
console.log(response);
});发布于 2017-01-18 19:16:12
为了确保你可以联系到用户的手机,无论他们在哪里和网络,你可能会不得不考虑付费服务,如Nexmo (我为之工作)或Twilio。
使用这些服务,您可以构建自己的验证(2FA -双因素身份验证)工作流:
< code >H111用户在表单中输入授权码并将其提交到您的应用< code >H212
或者,您可以使用他们的2FA身份验证产品(Nexmo - Verify或Twilio - Authy )来帮助简化此工作流程。
使用Nexmo验证代码为:
发送验证请求
var Nexmo = require('nexmo');
var nexmo = new Nexmo({apiKey: API_KEY, apiSecret: API_SECRET});
var verifyRequestId = null; // use in the check process
nexmo.verify.request({number: TO_NUMBER, brand: APP_NAME}, function(err, result) {
if(err) { console.error(err); }
else {
verifyRequestId = result. request_id;
}
});检查验证码
nexmo.verify.control({request_id: verifyRequestId, cmd: 'cancel'}, function(err, result) {
if(err) { console.error(err); }
else {
console.log(result);
}
});https://stackoverflow.com/questions/14788125
复制相似问题