用java发送免费短信



在我的公司,我们需要通过SMS网关发送一些警报,我使用了带有java的Nexmo API。它运行得很完美,但我们公司买不到这项服务,所以我在想;有免费的短信网关吗?

您找到的一些免费提供程序可能会将您的消息数量限制在一定数量或施加其他限制。然而,许多提供商支持电子邮件网关,您可以使用该网关发送消息。例如,如果你有一个手机号码,并且知道提供商(例如Verizon Wireless),那么你可以向number@vtext.com发送一封电子邮件,它将以短信的形式发送到手机。这可能是一个供您考虑的替代方案。

以下程序用于使用site2sms网关发送短信

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();
}

}

最新更新