在我的公司,我们需要通过 SMS 网关发送一些警报,我使用了带有 java 的 Nexmo API。它工作得很好,但是我们公司买不到这项服务,所以我在想;有没有免费的短信网关?
您发现有些免费提供商可能会限制您发送一定数量的消息或施加其他限制。然而,许多提供商都支持“电子邮件网关”,您可以使用它来发送消息。例如,如果您有手机号码并且知道提供商(例如 Verizon Wireless),那么您可以向 number@vtext.com
发送电子邮件,该电子邮件将作为 SMS 消息发送到手机。这可能是您可以考虑的替代方案。
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class SendSMS
{
static String SMSApi = "https://site2sms.p.mashape.com/index.php?uid=9095393259&pwd=554182&phone=9751931673&msg=hai";
static String head = "aVi7utR6ZUkGLFkGRwXxd4wLsXz7c1QQ";
public static void main(String[] args)
{
try
{
String url = SMSApi;
String smsApiResponse = sendMySMS(url);
System.out.println(smsApiResponse);
}
catch (Exception e)
{
e.printStackTrace();
}
}
private static String sendMySMS(String url)
{
StringBuilder output = new StringBuilder();
try
{
URL hp = new URL(url);
System.out.println(url);
URLConnection hpCon = hp.openConnection();
hpCon.setRequestProperty("X-Mashape-Authorization", head);
BufferedReader in = new BufferedReader(new InputStreamReader(hpCon.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
output.append(inputLine);
in.close();
}
catch (Exception e)
{
e.printStackTrace();
}
return output.toString();
}
}