我想制作一个旨在通过网络界面发送短信的网络应用程序。 如何使用 node/express 向指定收件人发送短信(从我的电话号码)? twilio 是唯一的方法吗?
除非您的移动运营商提供一些非常特殊的功能,否则没有什么比
send SMS (from my phone number) ... using node/express
更好的了。
只有安装了您的 SIM 卡的手机才能通过您的号码发送短信。
Sendgrid
和 twillio
我已经使用
Twilio
发送可编程短信,所以对产品了解甚少,您可以创建一个免费试用帐户并尝试Twilio的短信功能。
回答你这个问题-> 如何使用 node/express 向指定收件人发送短信(从我的电话号码)?
-->
您可以购买 Twilio 号码来发送短信/(用于入站或出站呼叫)。 您只需从 Twilio 中选择您最喜欢的号码即可。
Node.js 代码:
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
client.messages
.create({
body: 'This is the ship that made the Kessel Run in fourteen
parsecs?',
from: '+15017122661',
to: '+15558675310'
})
.then(message => console.log(message.sid));
登录 Twilio 后,您将看到 accountSid、authToken。
这里是参考链接:https://www.twilio.com/docs/sms/quickstart/node
首次尝试 Twilio。享受吧:)
Sendgrid
和 twillio
是发送短信的两个主要服务。
Twilio不是唯一的方式,您还可以使用mesente和plivo等服务。这两种服务都提供了一个可以集成到您的代码库(node/express)中的 API,并且最好使用 superface sdk 来处理此功能(它很容易使用和集成多个提供程序,并且代码要少得多)。请按照以下两个步骤操作
npm install @superfaceai/one-sdk
npx @superfaceai/cli install communication/send-sms
const { SuperfaceClient } = require('@superfaceai/one-sdk');
const sdk = new SuperfaceClient();
async function run() {
// Load the installed profile
const profile = await sdk.getProfile('communication/send-sms');
// Use the profile
const result = await profile
.getUseCase('SendMessage')
.perform({
to: '+12127290149',
from: '+4915207955279',
text: 'Your order is ready to be picked up!'
});
return result.unwrap();
}
run();
我正在使用这个非常简单的服务在英国发送短信:https://www.func.live/functions/sms