使用nodejs将otp发送到所需的手机号码

时间:2017-10-28 15:21:10

标签: node.js express plivo sms-verification

我正在使用Plivo向用户发送短信进行otp验证,我无法更新不同用户的手机号码和消息参数,这是我的代码

global.params = {
    'src': 'xx-xxxx', // Sender's phone number with country code
    'dst' : '91'+'xxxxxxxxxx', // Receiver's phone Number with country code
    'text' : "Hi, message from Plivo", // Your SMS Text Message - English
    'url' : "https://intense-brook-8241.herokuapp.com/report/", // The URL to which with the status of the message is sent
    'method' : "GET" // The method used to call the url
};

module.exports={
    foo: function createOTPverify(mobile_number, id){
    var motp = randomize('0',4);
    console.log("motp "+motp);
    global.params.dst = mobile_number;
    global.params.text = "Hi, your verification one time password is "+motp;
    p.send_message(global.params, function(status, response){
    console.log('Status: ', status);
    console.log('API Response:\n', response);
    })
}
}

这里一切正常但无法更新参数,我尝试使用全球但仍然无法做到,请帮助

1 个答案:

答案 0 :(得分:1)

您没有在任何地方更新配置数组。因此,问题

检查下面的要点,它应该有助于你发送OTP

https://runkit.com/isanjayachar/plivo-send-otp

const plivo = require('plivo').RestAPI({
  authId: '<your AUTH ID>',
  authToken: '<your AUTH TOKEN>',  
})


function getParmas(phone, otp) {
  return {
    'src': 'xx-xxxx',
    'dst' : '91'+ phone,
    'text' : "Your OTP for verification is " + otp,
    'url' : "https://intense-brook-8241.herokuapp.com/report/",
    'method' : "GET"
  }
}

function sendOTP(phone) {
  var otp;
  // Generate your OTP here
  
  plivo.make_call(getParmas(phone, otp), function(status, response) {
    console.log('Status:' + status)
    console.log('Reponse:' + response)
  })
}

sendOTP('9999999999');