📄 taskmanager.java
字号:
package com.sunnitech.VirtualBank.nts;
import java.io.*;
import javax.microedition.io.Connector;
//import javax.microedition.io.HttpConnection;
import javax.microedition.io.HttpsConnection;
import javax.microedition.io.SecurityInfo;
public class TaskManager {
// security data
private SecurityInfo si = null;
// personal data
private String url = "https://security.sunnitech.com/Bank/do";
private String id = "";
private String pwd = "";
private int taskType = 0;
private String msg = "";
private String historys = "";
private String moneyType = "";
private String moneySum = "";
private int state = 0;
public TaskManager() {
}
public TaskManager(String url) {
setUrl(url);
}
private void init() {
taskType = 0;
msg = "";
historys = "";
moneyType = "";
moneySum = "";
state = 0;
}
public boolean taskLogin(String id, String pwd) throws IOException {
init();
setIdAndPwd(id, pwd);
setTaskType(Task.TASK_LOGIN);
LoginTask t = new LoginTask();
t.setId(this.id);
t.setPwd(this.pwd);
submitForResult(t);
msg = t.getMsg();
return t.getResult();
}
public boolean taskQuery() throws IOException {
init();
setTaskType(Task.TASK_QUERY);
QueryTask t = new QueryTask();
t.setId(this.id);
t.setPwd(this.pwd);
submitForResult(t);
moneyType = t.getMoneyType();
moneySum = t.getMoneySum();
state = t.getState();
msg = t.getMsg();
return t.getResult();
}
public boolean taskHistory(String period) throws IOException {
init();
setTaskType(Task.TASK_HISTORY);
HistoryTask t = new HistoryTask();
t.setId(this.id);
t.setPwd(this.pwd);
t.setPeriod(period);
submitForResult(t);
historys = t.getHistorys();
msg = t.getMsg();
return t.getResult();
}
public boolean taskExchange(String sum, String idTo, String moneyType, String cur_pwd) throws IOException {
init();
setTaskType(Task.TASK_EXCHANGE);
ExchangeTask t = new ExchangeTask();
t.setId(this.id);
t.setPwd(cur_pwd);
t.setSum(sum);
t.setIdNew(idTo);
t.setMoneyType(moneyType);
submitForResult(t);
msg = t.getMsg();
return t.getResult();
}
public boolean taskLoss() throws IOException {
init();
setTaskType(Task.TASK_LOSS);
LossTask t = new LossTask();
t.setId(this.id);
t.setPwd(this.pwd);
submitForResult(t);
msg = t.getMsg();
return t.getResult();
}
public boolean taskNewpwd(String pwdOld, String pwdNew) throws IOException {
init();
setTaskType(Task.TASK_NEW_PWD);
NewpwdTask t = new NewpwdTask();
t.setId(this.id);
t.setPwd(this.pwd);
t.setPwdNew(pwdNew);
submitForResult(t);
msg = t.getMsg();
if(t.getResult()) {
this.pwd = pwdNew;
return true;
} else {
return false;
}
}
public boolean taskLogoff() throws IOException {
init();
setTaskType(Task.TASK_LOGOFF);
LogoffTask t = new LogoffTask();
t.setId(this.id);
t.setPwd(this.pwd);
submitForResult(t);
msg = t.getMsg();
if(t.getResult()) {
clearIdAndPwd();
return true;
} else {
return false;
}
}
public String getHistorys() {
return historys;
}
public String getMoneySum() {
return moneySum;
}
public String getMoneyType() {
return moneyType;
}
public String getMsg() {
return msg;
}
public int getAcountState() {
return state;
}
public void setUrl(String url) {
this.url = url;
}
public void setIdAndPwd(String id, String pwd) {
this.id = id;
this.pwd = pwd;
}
public void clearIdAndPwd() {
this.id = "";
this.pwd = "";
}
private int getTaskType() {
return taskType;
}
private void setTaskType(int taskType) {
this.taskType = taskType;
}
private void submitForResult(Task t) throws IOException {
HttpsConnection conn = null;
DataOutputStream dos = null;
DataInputStream dis = null;
try {
//String CMCC_PROXY = "http://10.0.0.172:80/"; //这个是中国移动的代理
//conn = (HttpsConnection)Connector.open(CMCC_PROXY + "Bank/do");
//conn.setRequestProperty("X-Online-Host", "security.sunnitech.com");
conn = (HttpsConnection)Connector.open(url);
} catch(IOException e1) {
throw (new IOException("网络出错!" + e1.toString()));
}
try {
conn.setRequestMethod(HttpsConnection.POST);
//conn.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
//conn.setRequestProperty("Content-Language", "en-US");
//conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
dos = new DataOutputStream(conn.openOutputStream());
dos.writeInt(getTaskType());
t.serialize(dos);
int status = conn.getResponseCode();
if(status != HttpsConnection.HTTP_OK) {
throw (new Exception("getResponseCode error!"));
} else {
dis = new DataInputStream(conn.openInputStream());
if(dis.readInt() != getTaskType()) {
throw (new Exception("getTaskType error!"));
} else {
t.deserialize(dis);
}
}
} catch(Exception e) {
throw (new IOException("网络出错了!" + e.toString()));
} finally {
if(dis != null) {
dis.close();
}
if(dos != null) {
dos.close();
}
if(conn != null) {
conn.close();
}
}
}
public SecurityInfo getSecurityInfo() throws IOException {
//HttpConnection conn = null;
//if(this.si == null) {
//conn = (HttpConnection)Connector.open(url);
//this.si = conn.getSecurityInfo();
//conn.close();
//}
//return this.si;
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -