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

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

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); }) } } 

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

你不会在任何地方更新你的configuration数组。 因此,这个问题

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