Skip to content

Commit a09488f

Browse files
committed
new token
1 parent 8c3f9fc commit a09488f

File tree

3 files changed

+47
-28
lines changed

3 files changed

+47
-28
lines changed

src/main/java/com/luna/commons/http/HttpUtils.java

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
package com.luna.commons.http;
22

3-
import java.io.*;
4-
import java.net.HttpURLConnection;
5-
import java.net.URL;
6-
import java.net.URLEncoder;
7-
import java.nio.charset.Charset;
8-
import java.util.HashMap;
9-
import java.util.List;
10-
import java.util.Map;
11-
12-
import javax.net.ssl.SSLContext;
13-
3+
import com.alibaba.fastjson.JSON;
144
import com.alibaba.fastjson.JSONException;
155
import com.alibaba.fastjson.JSONObject;
6+
import com.google.common.collect.Lists;
167
import com.luna.commons.dto.constant.ResultCode;
178
import com.luna.commons.exception.base.BaseException;
189
import org.apache.commons.collections4.MapUtils;
@@ -40,7 +31,15 @@
4031
import org.apache.http.ssl.SSLContextBuilder;
4132
import org.apache.http.util.EntityUtils;
4233

43-
import com.google.common.collect.Lists;
34+
import javax.net.ssl.SSLContext;
35+
import java.io.*;
36+
import java.net.HttpURLConnection;
37+
import java.net.URL;
38+
import java.net.URLEncoder;
39+
import java.nio.charset.Charset;
40+
import java.util.HashMap;
41+
import java.util.List;
42+
import java.util.Map;
4443

4544
/**
4645
* @author Tony
@@ -354,6 +353,24 @@ public static JSONObject getResponse(HttpResponse httpResponse) {
354353
}
355354
}
356355

356+
/**
357+
* 解析返回JSON数组
358+
*
359+
* @param httpResponse
360+
* @return
361+
*/
362+
public static List<JSONObject> getResponseToArray(HttpResponse httpResponse) {
363+
try {
364+
BufferedReader reader =
365+
new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
366+
String jsonText = readAll(reader);
367+
List<JSONObject> datas = JSON.parseArray(jsonText, JSONObject.class);
368+
return datas;
369+
} catch (IOException e) {
370+
throw new BaseException(ResultCode.ERROR_SYSTEM_EXCEPTION, "读取失败,请检查网络连接后重试" + e);
371+
}
372+
}
373+
357374
/**
358375
* 读取
359376
*

src/main/java/com/luna/commons/xuexiaoyi/XueXiaoYi.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
package com.luna.commons.xuexiaoyi;
22

3+
import com.alibaba.fastjson.JSON;
4+
import com.alibaba.fastjson.JSONObject;
5+
import com.luna.commons.http.HttpUtils;
6+
import com.luna.commons.http.HttpUtilsConstant;
7+
import org.apache.http.HttpResponse;
8+
39
import java.io.IOException;
410
import java.util.HashMap;
511
import java.util.List;
612
import java.util.Map;
713
import java.util.Scanner;
814

9-
import com.luna.commons.http.HttpUtilsConstant;
10-
import org.apache.http.HttpResponse;
11-
12-
import com.alibaba.fastjson.JSON;
13-
import com.alibaba.fastjson.JSONObject;
14-
import com.luna.commons.http.HttpUtils;
15-
1615
/**
1716
* @author Luna@win10
1817
* @date 2020/4/28 11:30
@@ -33,11 +32,11 @@ public static JSONObject getAnswer(String key, String language) throws IOExcepti
3332
Map<String, String> map = new HashMap<>();
3433
map.put("Content-Type", HttpUtilsConstant.JSON);
3534
map.put("Accept-Language", language);
36-
map.put("token", XueXiaoYiConstant.TOKEN);
37-
map.put("t", "1589445251850");
35+
map.put("token", XueXiaoYiConstant.NEW_TOKEN);
36+
map.put("t", "1592575114331");
3837
map.put("app-version", "null");
39-
map.put("device", "26908752fd5dfa3a5444c8d7fa2e351cac25f32838cf2f3c008f0a4926c2a844");
40-
map.put("s", "2a8b885209846ee116eb4d7fcd989235");
38+
map.put("device", "c5a0c5e3e113aac2583a203f696a63a16faf1d7b254db7d8d1914faccfc8a36b");
39+
map.put("s", "c88602c7632a9cfcb499ca506fd48f00");
4140
HttpResponse httpResponse =
4241
HttpUtils.doPost(XueXiaoYiConstant.HOST, XueXiaoYiConstant.PATH, map, null, s);
4342
return HttpUtils.getResponse(httpResponse);
@@ -66,6 +65,7 @@ public static void main(String[] args) throws IOException {
6665
Scanner scanner = new Scanner(System.in);
6766
String word = scanner.nextLine();
6867
JSONObject answer1 = getAnswer(word, XueXiaoYiConstant.EN_US);
68+
System.out.println(answer1);
6969
String answer = getWord(answer1);
7070
System.out.println(answer);
7171
}

src/main/java/com/luna/commons/xuexiaoyi/XueXiaoYiConstant.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
*/
77
public interface XueXiaoYiConstant {
88

9-
String HOST = "http://app.51xuexiaoyi.com";
9+
String HOST = "http://app.51xuexiaoyi.com";
1010

11-
String PATH = "/api/v1/searchQuestion";
11+
String PATH = "/api/v1/searchQuestion";
1212

13-
String TOKEN = "bM1kRmsY64qC8CPxbqgEOnB90cxFh6zy6wmFzY7PTiLKSAk0RfIGPPCEOoIP";
13+
String TOKEN = "bM1kRmsY64qC8CPxbqgEOnB90cxFh6zy6wmFzY7PTiLKSAk0RfIGPPCEOoIP";
1414

15-
String ZH_CN = "zh-cn";
15+
String NEW_TOKEN = "dxTLVcO5Qs4oJDABe4BGbA4EAPq7Qz9zGuDFhDfo5AeGVPBs8WKup0YGvpSi";
1616

17-
String EN_US = "en-us";
17+
String ZH_CN = "zh-cn";
18+
19+
String EN_US = "en-us";
1820
}

0 commit comments

Comments
 (0)