???????java???????????????bugfree?????в???????磺???bug id?????bug??????????????壻????????????????bug?б??????????bug?????????bug??bugfree?????
package com.yunos.qa;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
public class BugfreeOperator {
private static final String API_KEY = "";
private static final String bugfreeUrl = "http://bugfree-external.aliyun-inc.com/bugfree/api3.php";
private String sessionId;
private SessionInfo sessionInfo;
public BugfreeOperator() {
}
private SessionInfo getSessionInfo() {
String jsonResult = null;
InputStream is = null;
try {
is = doPost(bugfreeUrl?? "mode=getsid");
jsonResult = getResult(is);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (jsonResult == null) {
return null;
}
SessionInfo sessionInfo = JsonParser.parseSessionInfo(jsonResult);
System.out.println("sessionId: " + sessionInfo.getSessionId());
System.out.println("rand: " + sessionInfo.getRand());
return sessionInfo;
}
/**
*
* ?????
#????????
$auth = md5(md5($username.md5($password)).API_KEY.$rand)
????$username????????$password????????????????$rand?getsid????????rand???
* @param userName
* @param password
* @return
*/
public boolean login(String userName?? String password) {
sessionInfo = getSessionInfo();
if (sessionInfo == null) {
return false;
}
String md5 = MD5.getMD5(password.getBytes());
System.out.println("md5: " + md5);
md5 = userName + md5;
md5 = MD5.getMD5(md5.getBytes());
md5 = md5 + API_KEY + sessionInfo.getRand();
String auth = MD5.getMD5(md5.getBytes());
Map<String?? String> params = new HashMap<String?? String>();
params.put("mode"?? "login");
params.put(sessionInfo.getSessionName()?? sessionInfo.getSessionId());
params.put("username"?? userName);
params.put("auth"?? auth);
String jsonResult = null;
InputStream is = null;
try {
is = doPost(bugfreeUrl?? params);
jsonResult = getResult(is);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (jsonResult == null) {
return false;
}
System.out.println("jsonResult: " + jsonResult);
return JsonParser.parseLoginResult(jsonResult);
}
public void findProducts() {
if (sessionInfo == null) {
return;
}
Map<String?? String> params = new HashMap<String?? String>();
params.put("mode"?? "findproducts");
params.put(sessionInfo.getSessionName()?? sessionInfo.getSessionId());
String jsonResult = null;
InputStream is = null;
try {
is = doPost(bugfreeUrl?? params);
jsonResult = getResult(is);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (jsonResult == null) {
return;
}
System.out.println("[findProducts] jsonResult: " + jsonResult);
return;
}
public void getBug(int id) {
if (sessionInfo == null) {
return;
}
Map<String?? String> params = new HashMap<String?? String>();
params.put("mode"?? "getbug");
params.put(sessionInfo.getSessionName()?? sessionInfo.getSessionId());
params.put("id"?? Integer.toString(id));
String jsonResult = null;
InputStream is = null;
try {
is = doPost(bugfreeUrl?? params);
jsonResult = getResult(is);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (jsonResult == null) {
return;
}
System.out.println("[getBug] jsonResult: " + jsonResult);
return;
}