[RestException [错误]:“收件人”号码9977428080不是有效的电话号码

时间:2019-10-27 15:58:35

标签: node.js twilio one-time-password

我正在尝试使用Twilio API将短信发送到号码,但出现类似[RestException [Error]: The 'To' number 9977428080 is not a valid phone number.] { status: 400, message: "The 'To' number 9977428080 is not a valid phone number.", code: 21211, moreInfo: 'https://www.twilio.com/docs/errors/21211', detail: undefined }的错误

在获得the from number is not valid之前,我将API的凭据测试切换为实时凭据,这是另一个问题。 这些是下面的代码

const client = require('twilio')(config.SId, config.AccesToekn);
// SEND OTP TO USER ACCOUNT
router.post('/sendsms',(req, res, next)=>{
client.messages.create({
     from:'+15204770942',
     to:"9977428080",
     body:'Please user this OPT to verify your number 74536',
 }, function(error, data){
     if(error){
   console.log(error,'error')
    console.log(data,"data")
     }
 })
})

和我的凭证是正确的。 造成此问题的原因可能是什么,我们将不胜感激

预先感谢

3 个答案:

答案 0 :(得分:1)

遇到同样的问题。 但是,这里我们只需要添加国家代码。

            var message = MessageResource.Create(
                body: "Order Placed on BulkyBook. Your Order ID:" + id,
                from: new Twilio.Types.PhoneNumber(_twilloOptions.PhoneNumber),
                to: new Twilio.Types.PhoneNumber("+91" + orderHeader.PhoneNumber)
                );
        

答案 1 :(得分:0)

  

error.moreInfo:'https://www.twilio.com/docs/errors/21211'

     

Twilio accepts phone numbers in E164 format: [+] [country code] [subscriber number including area code]

进一步的格式:

  

What is E.164?

     

示例:+14155552671

更改为:

const client = require('twilio')(config.SId, config.AccesToekn);
// SEND OTP TO USER ACCOUNT
router.post('/sendsms',(req, res, next)=>{
client.messages.create({
     from:'+15204770942', 
     to:"+9199778080", //this must be a verified phone number for twilio trial accounts
     body:'Please user this OPT to verify your number 74536',
 }, function(error, data){
     if(error){
   console.log(error,'error')
    console.log(data,"data")
     }
 })
})

答案 2 :(得分:0)

使用 Twilio 时,请始终使用带有电话号码的国家/地区代码