API, Sails.js 如何给多个号码发送多条短信?

API, Sails.js How to send multiples of sms to many number?

我正在尝试一次向多个号码发送一条消息,以在用户在网站上执行某些操作时提醒管理员,但当我发送时,它只发送给管理员2。

request.post({
            form: { method: 'send',
                    username: 'max13',
                    password: '****',
                    from: '0000',
                    to:  admin1,
                    message: 'user '+ user_name +' has sent a job'
                                },
                    url: 'http://www.thsms.com/api/rest',

            form: {method: 'send',
                    username: 'max13',
                    password: '****',
                    from: '0000',
                    to:  admin2,
                    message: 'user '+ user_name +' has sent a job'},

                    url: 'http://www.thsms.com/api/rest',

你需要用到 callback/promise。因此,当短信发送到 admin1 时,它只会移动到 admin2。

现在发生的事情是它没有等待 api 响应而是转移到另一个 api 这就是为什么只有一个管理员收到短信的原因。

试试这个:

.then(function(){
    return //your sms api code for admin1  
  })
.then(function(){
    return //your sms api code for admin2  
  })
.fail(function(){
     log error if any of above then block get failed
  })