我正在尝试使用msg91进行移动验证。代码运行成功,但是MSG没有发送消息…它给出了成功的信息……我的代码:
router.post('/mobile', async (req, res) => {
try {
const sendOtp = new SendOtp(process.env.AUTHKEY);
const mobile = await usermodel.findOne({ mobile: req.body.mobile })
if (!mobile) return res.status(403).send('user not found..')
const otp =`${ Math.floor(1000 + Math.random() * 9000)} `
console.log(otp);
const phonenumber = req.body.mobile
const newPhoneNumber = '+91' + phonenumber
// console.log(newPhoneNumber);
sendOtp.send(newPhoneNumber, otp, function (error, data) {
console.log(data);
console.log(error);
});
res.status(201).send({ status: 'TRUE', message: 'OTP SEND' })
} catch (error) {
res.status(200).send({ status: 'failed', message: 'Unable to Send OTP', error })
console.log(error)
}
})
反应:{消息:'326b6774704a343230323437',类型:'success'}空
import msg91 from "msg91";
/**
*OR
*const msg91 = require('msg91').default;
*/
msg91.initialize({authKey: "Your-Auth-Key"});
let sms = msg91.getSMS();
// Send SMS
sms.send("flowId",'mobile':"MOBILE_NUMBER_WITH_COUNTRY_CODE","VAR1":"123"});
使用官方的MSG91 npm包