2012-07-21 56 views
0

我想使用SMSLib從我的Java web應用程序發送短信。我遵循從http://smslib.org/doc/installation/安裝過程。但它不工作。如果有人通過java API的任何代碼或信息來幫助我,我真的很感激。任何簡單可靠的java API比SMSLib發送短信?

public void doIt() throws Exception 
{ 
    OutboundNotification outboundNotification = new OutboundNotification(); 
    System.out.println("Example: Send message from a serial gsm modem."); 
    System.out.println(Library.getLibraryDescription()); 
    System.out.println("Version: " + Library.getLibraryVersion()); 
    SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM4", 9600, "Nokia", "C2-03"); 
    gateway.setInbound(true); 
    gateway.setOutbound(true); 
    gateway.setSimPin("1234"); 

    // Explicit SMSC address set is required for some modems. 
    // Below is for VODAFONE GREECE - be sure to set your own! 
    gateway.setSmscNumber("+8801700000600"); 
    Service.getInstance().setOutboundMessageNotification(outboundNotification); 
    Service.getInstance().addGateway(gateway); 
    Service.getInstance().startService(); 
    System.out.println(); 
    System.out.println("Modem Information:"); 
    System.out.println(" Manufacturer: " + gateway.getManufacturer()); 
    System.out.println(" Model: " + gateway.getModel()); 
    System.out.println(" Serial No: " + gateway.getSerialNo()); 
    System.out.println(" SIM IMSI: " + gateway.getImsi()); 
    System.out.println(" Signal Level: " + gateway.getSignalLevel() + " dBm"); 
    System.out.println(" Battery Level: " + gateway.getBatteryLevel() + "%"); 
    System.out.println(); 
    // Send a message synchronously. 
    OutboundMessage msg = new OutboundMessage("+8801719057995", "call me, sanchoy"); 
    Service.getInstance().sendMessage(msg); 
    System.out.println(msg); 

    System.out.println("Now Sleeping - Hit <enter> to terminate."); 
    System.in.read(); 
    Service.getInstance().stopService(); 
} 
+2

1876 *「Mr。沃森 - 過來 - 我想見你。「* 2012 *」打電話給我,三明治「*事物越多變化越多,他們保持不變;) – 2012-07-21 18:06:37

回答

0

你可以購買一個便宜的150美元的Android手機,註冊並從谷歌Play商店安裝的應用程序Sent.ly,然後使用由Sent.ly http://sent.ly

提供的API,該API基於這樣從你的web應用程序調用它HTTP將是非常簡單的:

import java.net.*; 
import java.io.*; 

public class URLConnectionReader { 
    public static void main(String[] args) throws Exception { 
     String sentlyUsername = "yourusername"; 
     String sentlyPassword = "yourpassword"; 
     String destinationNumber = "+14085616821"; 
     String message = "This is what I want to send"; 
     URL sentlyService = new URL("http://sent.ly/command/sendsms" + 
      "?username=" + sentlyUsername + 
      "&password=" + sentlyPassword + 
      "&to=" + destinationNumber + 
      "&text=" + message); 
     URLConnection yc = sentlyService .openConnection(); 
     BufferedReader in = new BufferedReader(
           new InputStreamReader(
           yc.getInputStream())); 
     String inputLine; 

     while ((inputLine = in.readLine()) != null) 
      System.out.println(inputLine); 
     in.close(); 
    } 
} 

更多的文檔可以在這裏找到: https://docs.google.com/document/d/1MuFXPTWq7zNIChwZdzIrqiQ2-Mb3_rPrWqNlOZXJNws/edit?pli=1