|
@@ -1,20 +1,14 @@
|
|
|
package cn.com.qmth.stmms.admin.utils;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
-import java.io.ByteArrayInputStream;
|
|
|
-import java.io.ByteArrayOutputStream;
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.io.OutputStream;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
import java.security.cert.CertificateException;
|
|
|
import java.security.cert.X509Certificate;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import javax.net.ssl.HttpsURLConnection;
|
|
@@ -23,7 +17,6 @@ import javax.net.ssl.SSLSocketFactory;
|
|
|
import javax.net.ssl.TrustManager;
|
|
|
import javax.net.ssl.X509TrustManager;
|
|
|
|
|
|
-import org.apache.commons.io.IOUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
@@ -45,15 +38,18 @@ public class OnlineExamHttpUtil {
|
|
|
|
|
|
public static final String AUTH = "Authorization";
|
|
|
|
|
|
+ protected String host = null;
|
|
|
+
|
|
|
protected String uri = null;
|
|
|
|
|
|
protected String accessKey = null;
|
|
|
|
|
|
protected String accessSecret = null;
|
|
|
|
|
|
- public OnlineExamHttpUtil(String accessKey, String accessSecret, String uri) {
|
|
|
+ public OnlineExamHttpUtil(String accessKey, String accessSecret, String host, String uri) {
|
|
|
this.accessKey = accessKey;
|
|
|
this.accessSecret = accessSecret;
|
|
|
+ this.host = host;
|
|
|
this.uri = uri;
|
|
|
}
|
|
|
|
|
@@ -74,16 +70,16 @@ public class OnlineExamHttpUtil {
|
|
|
try {
|
|
|
|
|
|
// 获取链接
|
|
|
- URL url = new URL(uri);
|
|
|
+ URL url = new URL(host + uri);
|
|
|
conn = (HttpsURLConnection) url.openConnection();
|
|
|
|
|
|
conn.setRequestMethod(METHOD_POST);
|
|
|
conn.setRequestProperty(CONTENT_TYPE, APPLICATION_JSON);
|
|
|
// 设置鉴权
|
|
|
- String signature = SignatureInfo.build(SignatureType.SECRET, METHOD_POST, uri, System.currentTimeMillis(),
|
|
|
- accessKey, accessSecret);
|
|
|
+ long ss = System.currentTimeMillis();
|
|
|
+ String signature = SignatureInfo.build(SignatureType.SECRET, METHOD_POST, uri, ss, accessKey, accessSecret);
|
|
|
conn.setRequestProperty(AUTH, signature);
|
|
|
-
|
|
|
+ conn.setRequestProperty("time", String.valueOf(ss));
|
|
|
// ssl
|
|
|
SSLContext context = SSLContext.getInstance("SSL", "SunJSSE");
|
|
|
TrustManager[] tm = new TrustManager[] { new X509TrustManager() {
|
|
@@ -209,18 +205,23 @@ public class OnlineExamHttpUtil {
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
- Map<String, Object> datas = new HashMap<String, Object>();
|
|
|
- datas.put("examId", "62209205889142784");
|
|
|
- String url = "https://test1.online-exam-test.cn/api/open/exam/course/query";
|
|
|
- OnlineExamHttpUtil subjectHttp = new OnlineExamHttpUtil("123456", "123", url);
|
|
|
- String subjectJson = subjectHttp.httpAction(null, datas);
|
|
|
- System.out.println(subjectJson);
|
|
|
-
|
|
|
- datas.put("courseCode", "A0001");
|
|
|
- url = "https://test1.online-exam-test.cn/api/open/exam/record/need_mark";
|
|
|
- OnlineExamHttpUtil studentHttp = new OnlineExamHttpUtil("123456", "123", url);
|
|
|
- String studentJson = studentHttp.httpAction(null, datas);
|
|
|
- System.out.println(studentJson);
|
|
|
+ // Map<String, Object> datas = new HashMap<String, Object>();
|
|
|
+ // datas.put("examId", "62209205889142784");
|
|
|
+ // datas.put("examId", "71613103238311936");
|
|
|
+ // String url =
|
|
|
+ // "https://test1.online-exam-test.cn/api/open/exam/course/query";
|
|
|
+ // OnlineExamHttpUtil subjectHttp = new OnlineExamHttpUtil("123456",
|
|
|
+ // "123", url);
|
|
|
+ // String subjectJson = subjectHttp.httpAction(null, datas);
|
|
|
+ // System.out.println(subjectJson);
|
|
|
+
|
|
|
+ // datas.put("courseCode", "A0001");
|
|
|
+ // url =
|
|
|
+ // "https://test1.online-exam-test.cn/api/open/exam/record/need_mark";
|
|
|
+ // OnlineExamHttpUtil studentHttp = new OnlineExamHttpUtil("123456",
|
|
|
+ // "123", url);
|
|
|
+ // String studentJson = studentHttp.httpAction(null, datas);
|
|
|
+ // System.out.println(studentJson);
|
|
|
|
|
|
// datas.put("id", "62212585906769920");
|
|
|
// url = "https://test1.online-exam-test.cn/api/open/exam/paper/detail";
|
|
@@ -228,10 +229,9 @@ public class OnlineExamHttpUtil {
|
|
|
// "123", url);
|
|
|
// String paperJson = paperHttp.httpAction(null, datas);
|
|
|
// System.out.println(paperJson);
|
|
|
- //
|
|
|
// ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
|
|
// IOUtils.copy(new
|
|
|
- // ByteArrayInputStream(paperJson.getBytes(StandardCharsets.UTF_8)),
|
|
|
+ // ByteArrayInputStream(subjectJson.getBytes(StandardCharsets.UTF_8)),
|
|
|
// buffer);
|
|
|
// byte[] data = buffer.toByteArray();
|
|
|
// File target = new File("/Users/ting.yin/Desktop/test123.json");
|