/**
* SMS SMS Component
* @author Administrator
*
*/
public class Smssender {
Protected Logger Logger=logger.getlogger (Smssender.class);
private static String spcode= "221816";
private static String username= "Admin2";
private static String password= "hrt150605";
Protected static Properties Pro = new properties ();
static {
Properties Pro = new properties ();
Pro.put ("Log4j.rootlogger", "debug,c,r,a");
Pro.put ("Log4j.appender.c", "Org.apache.log4j.ConsoleAppender");
Pro.put ("Log4j.appender.c.threshold", "INFO");
Pro.put ("Log4j.appender.c.layout", "org.apache.log4j.PatternLayout");
Pro.put ("Log4j.appender.c.layout.conversionpattern", "%n%m");
Pro.put ("LOG4J.APPENDER.R", "Org.apache.log4j.RollingFileAppender");
Pro.put ("Log4j.appender.r.file", "D:\\filelog.log");
Pro.put ("Log4j.appender.r.maxfilesize", "10000KB");
Pro.put ("Log4j.appender.r.maxbackupindex", "20");
Pro.put ("Log4j.appender.r.threshold", "INFO");
Pro.put ("Log4j.appender.r.layout", "org.apache.log4j.PatternLayout");
Pro.put ("Log4j.appender.r.layout.conversionpattern", "%n[%d{hh:mm:ss}" [%p]%m ");
Pro.put ("Log4j.appender.a", "Org.apache.log4j.RollingFileAppender");
Pro.put ("Log4j.appender.a.file", "D:\\filelog2.log");
Pro.put ("Log4j.appender.a.maxfilesize", "10000KB");
Pro.put ("Log4j.appender.a.maxbackupindex", "20");
Pro.put ("Log4j.appender.a.threshold", "DEBUG");
Pro.put ("Log4j.appender.a.layout", "org.apache.log4j.PatternLayout");
Pro.put ("Log4j.appender.a.layout.conversionpattern", "%n[%d{hh:mm:ss}" [%p]%m ");
Propertyconfigurator.configure (PRO);
}
public static void Main (string[] args) {
String content= "Your registered phone is {13543498876} benefactor {13543498876} Hello, you have successfully registered why people Hall Creative products website member. Remember your login password. Thank you for your support for the Creative product network. Please continue to follow http:/ /www.who158.com ";
String phone= "13543498876";
String Result=querysmsleavenum ();
String sendresult=sendsms (Content,phone);
String reportresult=querycallbackmsg ();
}
/**
* Send text messages
* @param content
* @return
*/
public static string Sendsms (string content,string target) {
String info = null;
try{
HttpClient HttpClient = new HttpClient ();
Postmethod post = new Postmethod ("http://gd.ums86.com:8899/sms/Api/Send.do");//
Post.getparams (). Setparameter (Httpmethodparams.http_content_charset, "GBK");
Post.addparameter ("Spcode", Spcode);
Post.addparameter ("LoginName", username);
Post.addparameter ("Password", Password);
Post.addparameter ("Messagecontent", content);
Post.addparameter ("Usernumber", target);
Post.addparameter ("SerialNumber", "" ");
Post.addparameter ("Scheduletime", "" ");
Post.addparameter ("Extendaccessnum", "" ");
Post.addparameter ("F", "1");
Httpclient.executemethod (POST);
info = new String (Post.getresponsebody (), "GBK");
SYSTEM.OUT.PRINTLN (info);
return info;
}catch (Exception e) {
E.printstacktrace ();
}
return null;
}
/**
* Query the number of remaining SMS
* @return
*/
public static String Querysmsleavenum ()
{
HttpClient HttpClient = new HttpClient ();
Postmethod post = new Postmethod ("http://gd.ums86.com:8899/sms/Api/SearchNumber.do");//
Post.getparams (). Setparameter (Httpmethodparams.http_content_charset, "GBK");
Post.addparameter ("Spcode", Spcode);
Post.addparameter ("LoginName", username);
Post.addparameter ("Password", Password);
try {
Httpclient.executemethod (POST);
String info = new String (Post.getresponsebody (), "GBK");
SYSTEM.OUT.PRINTLN (info);
return info;
} catch (HttpException e) {
TODO auto-generated Catch block
E.printstacktrace ();
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
return null;
}
/**
*
*/
public static String querycallbackmsg ()
{
HttpClient HttpClient = new HttpClient ();
Postmethod post = new Postmethod ("http://gd.ums86.com:8899/sms/Api/report.do");//
Post.getparams (). Setparameter (Httpmethodparams.http_content_charset, "GBK");
Post.addparameter ("Spcode", Spcode);
Post.addparameter ("LoginName", username);
Post.addparameter ("Password", Password);
try {
Httpclient.executemethod (POST);
String info = new String (Post.getresponsebody (), "GBK");
SYSTEM.OUT.PRINTLN (info);
return info;
} catch (HttpException e) {
TODO auto-generated Catch block
E.printstacktrace ();
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
return null;
}
}
Java Send SMS Tool class