首页 > 解决方案 > TypeError:无法读取未定义 Fast2sms 的属性“加入”

问题描述

我正在尝试在 nodejs 中使用 fast2sms 发送短信,但我遇到了一些问题。

错误类似于:TypeError: Cannot read property 'join' of undefined at Object.sendMessage (C:\Users\user\Desktop\node_modules\fast-two-sms\index.js:37:27)

这是我的代码:

try {
  const type = 'phone'
  res.render('verify', {
    'type': type
  })
  console.log(phone)
  await fastTwoSms.sendMessage({
    authorization: process.env.API_KEY,
    message: `Your Otp is ${otp}`,
    number: [phone]
  })
} catch (error) {
  next(error)
}

标签: javascriptnode.jsexpress

解决方案


根据您的错误,我检查了图书馆

https://github.com/raxraj/fast-two-sms/blob/master/index.js

在第 37 行。

let url = 'https://www.fast2sms.com/dev/bulk';
let nums = props.numbers.join(',');

它期望numbers输入键不是number

只需将数字更改为数字即可。

await fastTwoSms.sendMessage({
    authorization: process.env.API_KEY,
    message: `Your Otp is ${otp}`,
    numbers: [phone]
})

推荐阅读