0
我有一个类中的2种功能的短信发送程序:开发使用Java Swing的
login()
登录到某个网站Send_Sms()
发送短
这里我我正在考虑为这些功能添加2个线程,以便可以以开始发送的方式控制功能Send_Sms
的功能login()
之后的短信已成功完成,否则程序将无法工作。
这是我迄今所做的:
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.logging.Level;
import java.util.logging.Logger;
public class RunThreads extends Thread
{
public void Login(String username,String password)
{
try
{
// creates the batch file for Logging into abc.com server
Writer output = null;
String UserAgent = "Mozilla/5.0 (Windows NT 5.1;KM:10.0.2)";
String postdata = "\"" + "username="+username+ "&password=" + password + "&button=Login" + "\"";
String MainStream = "c:\\wget.exe --output-document=login.html --user-agent=" + "\"" + UserAgent + "\"" + " --max-redirect=10 --cookies=on --keep-session-cookies --save-cookies=cookie.txt --post-data " + postdata + " http://www.abc.com/Login1.action;";
File file = new File("login.bat");
output = new BufferedWriter(new FileWriter(file));
output.write(MainStream);
output.close();
Runtime.getRuntime().exec("cmd /c start login.bat");
}
catch (IOException ex)
{
Logger.getLogger(Save_Credentials.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void SendSms(String mobno,String content) throws IOException
{
Writer output = null;
String UserAgent = "Mozilla/5.0 (Windows NT 5.1;KM:10.0.2)";
String MainStream = "c:\\wget.exe --output-document=quicksms.html --user-agent=" + "\"" + UserAgent + "\"" + " --referer=http://www.abc.com/jsp/SMS.jsp --cookies=on --keep-session-cookies --load-cookies=cookie.txt --save-cookies=cookie.txt --post-data "+"\""+"&HiddenAction=instantsms&catnamedis=Birthday&Action=gstahsbdf5346g&chkall=on&MobNo="+mobno+"&textArea="+content+"\""+" http://www.abc.com/quicksms.action;";
File file = new File("SendSms.bat");
output = new BufferedWriter(new FileWriter(file));
output.write(MainStream);
output.close();
Runtime.getRuntime().exec("cmd /c start SendSms.bat");
}
public static void main(String[] args)
{
}
}