2012-04-20 66 views
-1

我想通过短信网关发送使用java的短信。我发现下面的代码通过tomcatserver发送短信。 HERE IS SOURCE CODE。在我的Windows XP的Tomcat在端口8084上运行,当运行Java类,即sendSMS.java我得到如下:通过使用java的tomcat服务器发送短信

D:\>javac sendSMS.java 
D:\>java sendSMS 
phone------>8366xxxx 
message---->SendMsg+via+Now.SMS 
url string->http://localhost:8084/?PhoneNumber=8366xxxx&Text=SendMsg+via+Now.SMS 
Opened Con->sun.net.www.protocol.http.HttpURLConnection:http://localhost:8084/?P 
honeNumber=8366xxxx&Text=SendMsg+via+Now.SMS 
Get Resp ->OK 

In sendSMS.java i just gave my mobile number and changed url from 8800 to 8084

但我在手机号码+ 91xxxxxxxxxx中没有短信。我错在哪里?请帮助

+0

我已经签署了nowsms使用试用版仅 – sujit 2012-04-20 08:03:23

+0

您也可以下载试用版试用,它仅仅是8.4 MB和sendSMS。 java是在那个链接,我已经在我的问题给出,只需向下滚动,并看到该文件 – sujit 2012-04-20 08:05:43

回答

1
  • 第一次尝试从网络界面http://127.0.0.1:8800发送您可以 范围按网页标签和nowsms 的再访问Web界面gateway.You将达发送文本消息的网页给出 在移动数在文本框中输入文本框和消息提交 它将从网关接收消息,并且会向您显示已发送消息的计数 。
+0

你可以指定更多的细节,请你尝试过吗?它在你的终端工作吗? – sujit 2012-05-25 07:46:24

0

的代码将帮助您发送手机短信:

import java.io.BufferedReader; 
import java.io.InputStream; 
import java.io.InputStreamReader; 
import java.net.HttpURLConnection; 
import java.net.URL; 
import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.Map; 
import java.util.Properties; 
import java.util.Random; 

import javax.servlet.ServletContext; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpSession; 

import org.apache.log4j.Logger; 

import qc.dal.DAL; 
import qc.dal.dto.ParameterDTO; 
import qc.los.controller.action.NewProspectAction; 
import qc.sso.util.UserLockingFilter; 

    public class Utils { 
     protected static Logger log = Logger.getLogger(Utils.class); 

     public static void main(String[] args) 
     { 
      Utils Utilss=new Utils(); 
      Utilss.sendVerificationCodeToCustomer("","9811937492","myTestras",true,"properhost","properport"); 
     } 

     public String sendVerificationCodeToCustomer(String prospectId,String mobileNumber, String verificationCode, boolean proxyEnabled, String proxyHost, String proxyPort) 
     { 
      log.info("Start"); 
      Properties systemSettings = System.getProperties(); 
      try 
      { 

       //UPdated by Rahul Tripathi for rbl bank user id password 
       String urlStr ="http://www.unicel.in/SendSMS/sendmsg.php?uname=rahul&pass=rahul&send=Tag&dest="+mobileNumber+"&msg=Your%20verification%20code%20is%20"+verificationCode+"&concat=1"; 
       log.info("urlStr "+urlStr); 
       URL u = new URL (urlStr); 

       log.info("proxyHost and proxyPort "+proxyHost+"  "+proxyPort); 

       if(proxyEnabled) 
       { 
        log.info("proxyEnabled with proxyHost and proxyPort "+proxyHost+"  "+proxyPort); 
        systemSettings.put("proxySet", "true"); 
        systemSettings.put("proxyHost", proxyHost); 
        systemSettings.put("proxyPort", proxyPort); 
       } 

       HttpURLConnection con = (HttpURLConnection) u.openConnection(); 
       con.setDoInput(true); 
       con.setRequestMethod("GET"); 
       log.info("Connection start"); 
       con.connect(); 
       log.info("Connection connected"); 
       InputStream is = con.getInputStream(); 
       BufferedReader rd = new BufferedReader(new InputStreamReader(is)); 
       String line; 
       StringBuffer response = new StringBuffer(); 
       while((line = rd.readLine()) != null) 
       { 
        response.append(line); 
        response.append("<br>"); 
       } 
       rd.close(); 
       log.info("End:Message sucessfull with response "+response.toString()); 
       return response.toString(); 
      } 
      catch(Exception e) 
      { 
       String proxySetting = proxyEnabled + ":" + proxyHost + ":" + proxyPort; 
       e.printStackTrace(); 
       log.error("exception while sending sms:("+proxySetting+")"+"  "+e.getMessage()); 
       return "exception while sending sms:("+proxySetting+")"+e.getMessage(); 
      } 
      finally 
      { 
       if(proxyEnabled) 
       { 
        systemSettings.remove("proxySet"); 
        systemSettings.remove("proxyHost"); 
        systemSettings.remove("proxyPort"); 
       } 
       log.info("End"); 
      } 
     } 
    }