|
@@ -10,6 +10,7 @@ import com.zskk.model.Exams;
|
|
|
import com.zskk.model.PatientInfos;
|
|
|
import com.zskk.model.Report;
|
|
|
import com.zskk.service.ServiceFactory;
|
|
|
+import com.zskk.service.ThreadPoolService;
|
|
|
import com.zskk.service.WeixinService;
|
|
|
|
|
|
import okhttp3.FormBody;
|
|
@@ -26,8 +27,6 @@ import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
public class DataTask implements ITask {
|
|
|
private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
|
|
|
|
|
@@ -35,18 +34,21 @@ public class DataTask implements ITask {
|
|
|
public void run() {
|
|
|
// TODO Auto-generated method stub
|
|
|
try {
|
|
|
- List<Exams> exams = Exams.dao.use("zskk").find("SELECT * FROM pacsonline.exams where exam_status=3 and institution_id=15700002 order by createdAt desc limit 30");
|
|
|
+ List<Exams> exams = Exams.dao.use("zskk").find(
|
|
|
+ "SELECT * FROM pacsonline.exams where exam_status=3 and institution_id=15700002 order by createdAt desc limit 30");
|
|
|
for (Exams exams2 : exams) {
|
|
|
try {
|
|
|
- //Studies studies = Studies.dao.use("zskk").findById(exams2.getStudyId());
|
|
|
- Record record = Db.use("connected").findFirst("select * from zskk where accessionNumber=?",exams2.getAccessionNum());
|
|
|
+ // Studies studies = Studies.dao.use("zskk").findById(exams2.getStudyId());
|
|
|
+ Record record = Db.use("connected").findFirst("select * from zskk where accessionNumber=?",
|
|
|
+ exams2.getAccessionNum());
|
|
|
if (record == null) {
|
|
|
continue;
|
|
|
}
|
|
|
Report report = new Report().use("zskk");
|
|
|
report.setId(creatId());
|
|
|
report.setReportDatetime(parseStringToDate(record.getStr("reportdate")));
|
|
|
- if (record.getStr("impression") == null && record.getStr("description") == null) {
|
|
|
+ if (record.getStr("impression") == null || record.getStr("DESCRIPTION") == null
|
|
|
+ || record.getStr("impression").isBlank() || record.getStr("DESCRIPTION").isBlank()) {
|
|
|
continue;
|
|
|
}
|
|
|
report.setImpression(record.getStr("impression"));
|
|
@@ -65,193 +67,202 @@ public class DataTask implements ITask {
|
|
|
patientInfos.setCardNum(record.getStr("idcard"));
|
|
|
patientInfos.update();
|
|
|
exams2.setExamStatus(9);
|
|
|
- exams2.setClinDoctors(record.getStr("clinicaldoctor"));
|
|
|
- exams2.setApplicationDepartment(record.getStr("department"));
|
|
|
- exams2.setApplicationDoctor(record.getStr("clinicaldoctor"));
|
|
|
- exams2.setClinDiag(record.getStr("diagnosis"));
|
|
|
+ exams2.setClinDoctors(record.getStr("clinicaldoctor"));
|
|
|
+ exams2.setApplicationDepartment(record.getStr("department"));
|
|
|
+ exams2.setApplicationDoctor(record.getStr("clinicaldoctor"));
|
|
|
+ exams2.setClinDiag(record.getStr("diagnosis"));
|
|
|
exams2.update();
|
|
|
- //传云医康 数据
|
|
|
- Map<String, String> data = new HashMap<String, String>();
|
|
|
- //获取data数据
|
|
|
- //医院id
|
|
|
- data.put("hospital_id","15700002");
|
|
|
- //影像所见
|
|
|
- data.put("description",record.getStr("DESCRIPTION"));
|
|
|
- //意见建议
|
|
|
- data.put("impression",record.getStr("impression"));
|
|
|
- //检查id
|
|
|
- data.put("exam_id",exams2.getId());
|
|
|
- data.put("study_id",exams2.getStudyId());
|
|
|
- //患者id
|
|
|
- data.put("patient_id",exams2.getPatientId());
|
|
|
- //患者姓名
|
|
|
- data.put("patient_name",record.getStr("patientname"));
|
|
|
- //患者性别
|
|
|
- data.put("patient_sex",record.getStr("patientsex").equals("女")?"F":"M");
|
|
|
- //身份证号
|
|
|
- data.put("card_num","");
|
|
|
- //手机号
|
|
|
- data.put("phone","");
|
|
|
- //患者生日
|
|
|
- data.put("birthday",returnSecondTimestamp(record.getStr("birthdate")));
|
|
|
- //患者检查时年龄
|
|
|
- data.put("patient_age",record.getStr("patientage"));
|
|
|
- //阴阳性 1阴性 2阳性
|
|
|
- data.put("report_result","");
|
|
|
- //报告时间 10位时间戳
|
|
|
- data.put("report_datetime",returnSecondTimestamp(record.getStr("reportdate")));
|
|
|
- //报告医生id
|
|
|
- data.put("report_doctor_id",record.getStr("reportdoctor"));
|
|
|
- //报告医生姓名
|
|
|
- data.put("report_doctor_name",record.getStr("reportdoctor"));
|
|
|
- //审核时间
|
|
|
- data.put("review_datetime",returnSecondTimestamp(record.getStr("reportdate")));
|
|
|
- //审核医生id
|
|
|
- data.put("review_doctor_id",record.getStr("reviewdoctor"));
|
|
|
- //审核姓名
|
|
|
- data.put("review_doctor_name",record.getStr("reviewdoctor"));
|
|
|
- //确认时间
|
|
|
- data.put("confirm_datetime", returnSecondTimestamp(record.getStr("reportdate")));
|
|
|
- //确认医生id
|
|
|
- data.put("confirm_doctor_id", record.getStr("reviewdoctor"));
|
|
|
- //确认医生姓名
|
|
|
- data.put("confirm_doctor_name",record.getStr("reviewdoctor"));
|
|
|
+ // 传云医康 数据
|
|
|
+ Map<String, String> data = new HashMap<String, String>();
|
|
|
+ // 获取data数据
|
|
|
+ // 医院id
|
|
|
+ data.put("hospital_id", "15700002");
|
|
|
+ // 影像所见
|
|
|
+ data.put("description", record.getStr("DESCRIPTION"));
|
|
|
+ // 意见建议
|
|
|
+ data.put("impression", record.getStr("impression"));
|
|
|
+ // 检查id
|
|
|
+ data.put("exam_id", exams2.getId());
|
|
|
+ data.put("study_id", exams2.getStudyId());
|
|
|
+ // 患者id
|
|
|
+ data.put("patient_id", exams2.getPatientId());
|
|
|
+ // 患者姓名
|
|
|
+ data.put("patient_name", record.getStr("patientname"));
|
|
|
+ // 患者性别
|
|
|
+ data.put("patient_sex", record.getStr("patientsex").equals("女") ? "F" : "M");
|
|
|
+ // 身份证号
|
|
|
+ data.put("card_num", "");
|
|
|
+ // 手机号
|
|
|
+ data.put("phone", "");
|
|
|
+ // 患者生日
|
|
|
+ data.put("birthday", returnSecondTimestamp(record.getStr("birthdate")));
|
|
|
+ // 患者检查时年龄
|
|
|
+ data.put("patient_age", record.getStr("patientage"));
|
|
|
+ // 阴阳性 1阴性 2阳性
|
|
|
+ data.put("report_result", "");
|
|
|
+ // 报告时间 10位时间戳
|
|
|
+ data.put("report_datetime", returnSecondTimestamp(record.getStr("reportdate")));
|
|
|
+ // 报告医生id
|
|
|
+ data.put("report_doctor_id", record.getStr("reportdoctor"));
|
|
|
+ // 报告医生姓名
|
|
|
+ data.put("report_doctor_name", record.getStr("reportdoctor"));
|
|
|
+ // 审核时间
|
|
|
+ data.put("review_datetime", returnSecondTimestamp(record.getStr("reportdate")));
|
|
|
+ // 审核医生id
|
|
|
+ data.put("review_doctor_id", record.getStr("reviewdoctor"));
|
|
|
+ // 审核姓名
|
|
|
+ data.put("review_doctor_name", record.getStr("reviewdoctor"));
|
|
|
+ // 确认时间
|
|
|
+ data.put("confirm_datetime", returnSecondTimestamp(record.getStr("reportdate")));
|
|
|
+ // 确认医生id
|
|
|
+ data.put("confirm_doctor_id", record.getStr("reviewdoctor"));
|
|
|
+ // 确认医生姓名
|
|
|
+ data.put("confirm_doctor_name", record.getStr("reviewdoctor"));
|
|
|
+
|
|
|
+ ThreadPoolService tService = new com.zskk.service.ThreadPoolService();
|
|
|
+ tService.execute(() -> {
|
|
|
+ String dadaString = JSON.toJSONString(data);
|
|
|
+ dadaString = dadaString.replace("\\", "");
|
|
|
+ Map maps = (Map) JSON.parse(dadaString);
|
|
|
+ try {
|
|
|
+ post(null, maps);
|
|
|
+ } catch (IOException e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- String dadaString=JSON.toJSONString(data);
|
|
|
- dadaString = dadaString.replace("\\","");
|
|
|
- Map maps = (Map)JSON.parse(dadaString);
|
|
|
- post(null, maps);
|
|
|
} catch (Exception e) {
|
|
|
// TODO: handle exception
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
// TODO: handle exception
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private static void post(String url, Map<String, String> map) throws IOException {
|
|
|
- RequestBody formBody = new FormBody.Builder()
|
|
|
- .add("timestamp", String.valueOf(getSecondTimestamp(new Date())))
|
|
|
- .add("signature", Ksort(map))
|
|
|
- .add("data", JSON.toJSONString(map))
|
|
|
- .build();
|
|
|
+ RequestBody formBody = new FormBody.Builder().add("timestamp", String.valueOf(getSecondTimestamp(new Date())))
|
|
|
+ .add("signature", Ksort(map)).add("data", JSON.toJSONString(map)).build();
|
|
|
|
|
|
- Request request = new Request.Builder()
|
|
|
- .url("http://39.106.136.96/pacs/zskk/writePatientReport")
|
|
|
- .post(formBody)
|
|
|
- .build();
|
|
|
+ Request request = new Request.Builder().url("http://39.106.136.96/pacs/zskk/writePatientReport").post(formBody)
|
|
|
+ .build();
|
|
|
|
|
|
- try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
|
|
|
- if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
|
|
|
+ try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
|
|
|
+ if (!response.isSuccessful())
|
|
|
+ throw new IOException("Unexpected code " + response);
|
|
|
|
|
|
- System.out.println(response.body().string());
|
|
|
+ System.out.println(response.body().string());
|
|
|
// return response.body().string();
|
|
|
|
|
|
- }
|
|
|
- }
|
|
|
- /**
|
|
|
- *
|
|
|
- * 功能描述: 获取当前时间戳(秒)
|
|
|
- *
|
|
|
- * @param: [date]
|
|
|
- * @return: int
|
|
|
- * @auther: zzp
|
|
|
- * @date: 2019/12/26 18:26
|
|
|
- */
|
|
|
- public static String getSecondTimestamp(Date date) {
|
|
|
- if (null == date) {
|
|
|
- return "参数为空";
|
|
|
- }
|
|
|
- String timestamp = String.valueOf(date.getTime());
|
|
|
- int length = timestamp.length();
|
|
|
- if (length > 3) {
|
|
|
- return String.valueOf(timestamp.substring(0, length - 3));
|
|
|
- } else {
|
|
|
- return "参数不足3位数";
|
|
|
- }
|
|
|
- }
|
|
|
- /**
|
|
|
- *
|
|
|
- * 功能描述: 对数组的值按key排序,生成url的形式(http_build_query)
|
|
|
- *
|
|
|
- * @param: [map]
|
|
|
- * @return: java.lang.String
|
|
|
- * @auther: zzp
|
|
|
- * @date: 2019/12/26 19:21
|
|
|
- */
|
|
|
- public static String Ksort(Map<String, String> map){
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * 功能描述: 获取当前时间戳(秒)
|
|
|
+ *
|
|
|
+ * @param: [date]
|
|
|
+ * @return: int
|
|
|
+ * @auther: zzp
|
|
|
+ * @date: 2019/12/26 18:26
|
|
|
+ */
|
|
|
+ public static String getSecondTimestamp(Date date) {
|
|
|
+ if (null == date) {
|
|
|
+ return "参数为空";
|
|
|
+ }
|
|
|
+ String timestamp = String.valueOf(date.getTime());
|
|
|
+ int length = timestamp.length();
|
|
|
+ if (length > 3) {
|
|
|
+ return String.valueOf(timestamp.substring(0, length - 3));
|
|
|
+ } else {
|
|
|
+ return "参数不足3位数";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * 功能描述: 对数组的值按key排序,生成url的形式(http_build_query)
|
|
|
+ *
|
|
|
+ * @param: [map]
|
|
|
+ * @return: java.lang.String
|
|
|
+ * @auther: zzp
|
|
|
+ * @date: 2019/12/26 19:21
|
|
|
+ */
|
|
|
+ public static String Ksort(Map<String, String> map) {
|
|
|
String sb = "";
|
|
|
String[] key = new String[map.size()];
|
|
|
int index = 0;
|
|
|
for (String k : map.keySet()) {
|
|
|
- key[index] = k;
|
|
|
- index++;
|
|
|
+ key[index] = k;
|
|
|
+ index++;
|
|
|
}
|
|
|
Arrays.sort(key);
|
|
|
|
|
|
for (String s : key) {
|
|
|
- sb += s + "=" + map.get(s) + "&";
|
|
|
+ sb += s + "=" + map.get(s) + "&";
|
|
|
}
|
|
|
sb = sb.substring(0, sb.length() - 1);
|
|
|
try {
|
|
|
- sb = URLEncoder.encode(sb, "UTF-8");
|
|
|
+ sb = URLEncoder.encode(sb, "UTF-8");
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }// 使用常见的UTF-8编码
|
|
|
+ e.printStackTrace();
|
|
|
+ } // 使用常见的UTF-8编码
|
|
|
sb = sb.replace("%3D", "=").replace("%26", "&");
|
|
|
- String resultString = HashKit.md5(sb+"YgpxjVeIx0yoK6Atz413IAj7hU9dygH4");
|
|
|
+ String resultString = HashKit.md5(sb + "YgpxjVeIx0yoK6Atz413IAj7hU9dygH4");
|
|
|
return resultString;
|
|
|
}
|
|
|
- /**
|
|
|
- *
|
|
|
- * 功能描述:生成signature
|
|
|
- *
|
|
|
- * @param: [param, key]
|
|
|
- * @return: java.lang.String
|
|
|
- * @auther: zzp
|
|
|
- * @date: 2019/12/24 15:28
|
|
|
- */
|
|
|
- public static String getSign(Map<String, String> param, String key) {
|
|
|
- return DigestUtils.md5Hex(Ksort(param) + key);
|
|
|
- }
|
|
|
- /**
|
|
|
- *
|
|
|
- * 功能描述: 转时间戳(秒)
|
|
|
- *
|
|
|
- * @param:
|
|
|
- * @return:
|
|
|
- * @auther: zpp
|
|
|
- * @date: 2019/12/26 18:26
|
|
|
- */
|
|
|
- public String returnSecondTimestamp(String data) throws ParseException {
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
- return String.valueOf(sdf.parse(data).getTime()/1000);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * 功能描述:生成signature
|
|
|
+ *
|
|
|
+ * @param: [param, key]
|
|
|
+ * @return: java.lang.String
|
|
|
+ * @auther: zzp
|
|
|
+ * @date: 2019/12/24 15:28
|
|
|
+ */
|
|
|
+ public static String getSign(Map<String, String> param, String key) {
|
|
|
+ return DigestUtils.md5Hex(Ksort(param) + key);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * 功能描述: 转时间戳(秒)
|
|
|
+ *
|
|
|
+ * @param:
|
|
|
+ * @return:
|
|
|
+ * @auther: zpp
|
|
|
+ * @date: 2019/12/26 18:26
|
|
|
+ */
|
|
|
+ public String returnSecondTimestamp(String data) throws ParseException {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
+ return String.valueOf(sdf.parse(data).getTime() / 1000);
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
+ @Override
|
|
|
public void stop() {
|
|
|
// TODO Auto-generated method stub
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private String creatId() {
|
|
|
- UUID id=UUID.randomUUID();
|
|
|
- String[] idd = id.toString().split("-");
|
|
|
- return idd[0]+idd[1]+idd[2];
|
|
|
+ UUID id = UUID.randomUUID();
|
|
|
+ String[] idd = id.toString().split("-");
|
|
|
+ return idd[0] + idd[1] + idd[2];
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private String getDoctorIdByName(String name) {
|
|
|
if (name == null || name.isBlank()) {
|
|
|
return null;
|
|
|
}
|
|
|
name = name.replace(" ", "");
|
|
|
- Doctors doctors = Doctors.dao.use("zskk").findFirst("SELECT * FROM doctors where instr(?,realname) and institution_id=15700002 and realname is not null",name);
|
|
|
+ Doctors doctors = Doctors.dao.use("zskk").findFirst(
|
|
|
+ "SELECT * FROM doctors where instr(?,realname) and institution_id=15700002 and realname <>''", name);
|
|
|
if (doctors == null) {
|
|
|
Doctors newDoctors = new Doctors().use("zskk");
|
|
|
newDoctors.setId(creatId());
|
|
@@ -266,95 +277,89 @@ public class DataTask implements ITask {
|
|
|
}
|
|
|
return doctors.getId();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private Date parseStringToDate(String dateStr) {
|
|
|
if (dateStr == null) {
|
|
|
return new Date();
|
|
|
}
|
|
|
- SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- Date date = null;
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ Date date = null;
|
|
|
try {
|
|
|
date = sdf.parse(dateStr);
|
|
|
} catch (ParseException e) {
|
|
|
// TODO Auto-generated catch block
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- return date;
|
|
|
+ return date;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 发送POST请求
|
|
|
- *
|
|
|
- * @param url 目的地址
|
|
|
- * @param parameters 请求参数,Map类型。
|
|
|
- * @return 远程响应结果
|
|
|
- */
|
|
|
- public static String sendPost(String url, Map<String, String> parameters) {
|
|
|
- String result = "";// 返回的结果
|
|
|
- BufferedReader in = null;// 读取响应输入流
|
|
|
- PrintWriter out = null;
|
|
|
- StringBuffer sb = new StringBuffer();// 处理请求参数
|
|
|
- String params = "";// 编码之后的参数
|
|
|
- try {
|
|
|
- // 编码请求参数
|
|
|
- if (parameters.size() == 1) {
|
|
|
- for (String name : parameters.keySet()) {
|
|
|
- sb.append(name).append("=").append(
|
|
|
- java.net.URLEncoder.encode(parameters.get(name),
|
|
|
- "UTF-8"));
|
|
|
- }
|
|
|
- params = sb.toString();
|
|
|
- } else {
|
|
|
- for (String name : parameters.keySet()) {
|
|
|
- sb.append(name).append("=").append(
|
|
|
- java.net.URLEncoder.encode(parameters.get(name),
|
|
|
- "UTF-8")).append("&");
|
|
|
- }
|
|
|
- String temp_params = sb.toString();
|
|
|
- params = temp_params.substring(0, temp_params.length() - 1);
|
|
|
- }
|
|
|
- // 创建URL对象
|
|
|
- java.net.URL connURL = new java.net.URL(url);
|
|
|
- // 打开URL连接
|
|
|
- java.net.HttpURLConnection httpConn = (java.net.HttpURLConnection) connURL
|
|
|
- .openConnection();
|
|
|
- // 设置通用属性
|
|
|
- httpConn.setRequestProperty("Accept", "*/*");
|
|
|
- httpConn.setRequestProperty("Connection", "Keep-Alive");
|
|
|
- httpConn.setRequestProperty("User-Agent",
|
|
|
- "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
|
|
|
- // 设置POST方式
|
|
|
- httpConn.setDoInput(true);
|
|
|
- httpConn.setDoOutput(true);
|
|
|
- // 获取HttpURLConnection对象对应的输出流
|
|
|
- out = new PrintWriter(httpConn.getOutputStream());
|
|
|
- // 发送请求参数
|
|
|
- out.write(params);
|
|
|
- // flush输出流的缓冲
|
|
|
- out.flush();
|
|
|
- // 定义BufferedReader输入流来读取URL的响应,设置编码方式
|
|
|
- in = new BufferedReader(new InputStreamReader(httpConn
|
|
|
- .getInputStream(), "UTF-8"));
|
|
|
- String line;
|
|
|
- // 读取返回的内容
|
|
|
- while ((line = in.readLine()) != null) {
|
|
|
- result += line;
|
|
|
- }
|
|
|
- System.out.println(result);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- } finally {
|
|
|
- try {
|
|
|
- if (out != null) {
|
|
|
- out.close();
|
|
|
- }
|
|
|
- if (in != null) {
|
|
|
- in.close();
|
|
|
- }
|
|
|
- } catch (IOException ex) {
|
|
|
- ex.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 发送POST请求
|
|
|
+ *
|
|
|
+ * @param url 目的地址
|
|
|
+ * @param parameters 请求参数,Map类型。
|
|
|
+ * @return 远程响应结果
|
|
|
+ */
|
|
|
+ public static String sendPost(String url, Map<String, String> parameters) {
|
|
|
+ String result = "";// 返回的结果
|
|
|
+ BufferedReader in = null;// 读取响应输入流
|
|
|
+ PrintWriter out = null;
|
|
|
+ StringBuffer sb = new StringBuffer();// 处理请求参数
|
|
|
+ String params = "";// 编码之后的参数
|
|
|
+ try {
|
|
|
+ // 编码请求参数
|
|
|
+ if (parameters.size() == 1) {
|
|
|
+ for (String name : parameters.keySet()) {
|
|
|
+ sb.append(name).append("=").append(java.net.URLEncoder.encode(parameters.get(name), "UTF-8"));
|
|
|
+ }
|
|
|
+ params = sb.toString();
|
|
|
+ } else {
|
|
|
+ for (String name : parameters.keySet()) {
|
|
|
+ sb.append(name).append("=").append(java.net.URLEncoder.encode(parameters.get(name), "UTF-8"))
|
|
|
+ .append("&");
|
|
|
+ }
|
|
|
+ String temp_params = sb.toString();
|
|
|
+ params = temp_params.substring(0, temp_params.length() - 1);
|
|
|
+ }
|
|
|
+ // 创建URL对象
|
|
|
+ java.net.URL connURL = new java.net.URL(url);
|
|
|
+ // 打开URL连接
|
|
|
+ java.net.HttpURLConnection httpConn = (java.net.HttpURLConnection) connURL.openConnection();
|
|
|
+ // 设置通用属性
|
|
|
+ httpConn.setRequestProperty("Accept", "*/*");
|
|
|
+ httpConn.setRequestProperty("Connection", "Keep-Alive");
|
|
|
+ httpConn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
|
|
|
+ // 设置POST方式
|
|
|
+ httpConn.setDoInput(true);
|
|
|
+ httpConn.setDoOutput(true);
|
|
|
+ // 获取HttpURLConnection对象对应的输出流
|
|
|
+ out = new PrintWriter(httpConn.getOutputStream());
|
|
|
+ // 发送请求参数
|
|
|
+ out.write(params);
|
|
|
+ // flush输出流的缓冲
|
|
|
+ out.flush();
|
|
|
+ // 定义BufferedReader输入流来读取URL的响应,设置编码方式
|
|
|
+ in = new BufferedReader(new InputStreamReader(httpConn.getInputStream(), "UTF-8"));
|
|
|
+ String line;
|
|
|
+ // 读取返回的内容
|
|
|
+ while ((line = in.readLine()) != null) {
|
|
|
+ result += line;
|
|
|
+ }
|
|
|
+ System.out.println(result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ if (out != null) {
|
|
|
+ out.close();
|
|
|
+ }
|
|
|
+ if (in != null) {
|
|
|
+ in.close();
|
|
|
+ }
|
|
|
+ } catch (IOException ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|