2

我正在使用 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);
    })
}
}

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

4

1 回答 1

2

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

检查以下要点,它应该可以帮助您发送 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');

于 2017-10-28T18:29:37.627 回答