master
chaiyapeng 2024-08-30 09:55:56 +08:00
parent 3417b5a39e
commit 2bc6d35edf
2 changed files with 10 additions and 9 deletions

View File

@ -16,10 +16,9 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class Birthday { public class Birthday {
private String year; private String years;
private String month; private String months;
private String day; private String days;
private String hour;
private String animal; private String animal;
private String imonthcn; private String imonthcn;
private String idaycn; private String idaycn;

View File

@ -39,6 +39,7 @@ public class BirthdayHelper {
map.put("day", birthdayRes.getDay()); map.put("day", birthdayRes.getDay());
map.put("hour", birthdayRes.getHour()); map.put("hour", birthdayRes.getHour());
String urlencode = urlencode(map); String urlencode = urlencode(map);
Birthday birthday1 = new Birthday(); Birthday birthday1 = new Birthday();
String s = doGet(API_URL, urlencode); String s = doGet(API_URL, urlencode);
try { try {
@ -47,9 +48,10 @@ public class BirthdayHelper {
if (error_code == 0){ if (error_code == 0){
System.out.println("调用接口成功"); System.out.println("调用接口成功");
JSONObject result = jsonObject.getJSONObject("result"); JSONObject result = jsonObject.getJSONObject("result");
birthday1.setYear(result.getString("year"));
birthday1.setMonth(result.getString("month")); birthday1.setYears(result.getString("year"));
birthday1.setDay(result.getString("day")); birthday1.setMonths(result.getString("month"));
birthday1.setDays(result.getString("day"));
birthday1.setAnimal(result.getString("Animal")); birthday1.setAnimal(result.getString("Animal"));
birthday1.setImonthcn(result.getString("ImonthCn")); birthday1.setImonthcn(result.getString("ImonthCn"));
birthday1.setIdaycn(result.getString("IDayCn")); birthday1.setIdaycn(result.getString("IDayCn"));
@ -107,7 +109,7 @@ public class BirthdayHelper {
// 通过远程url连接对象打开一个连接强转成httpURLConnection类 // 通过远程url连接对象打开一个连接强转成httpURLConnection类
connection = (HttpURLConnection) url.openConnection(); connection = (HttpURLConnection) url.openConnection();
// 设置连接方式get // 设置连接方式get
connection.setRequestMethod("GET"); connection.setRequestMethod("GET");
// 设置连接主机服务器的超时时间15000毫秒 // 设置连接主机服务器的超时时间15000毫秒
connection.setConnectTimeout(5000); connection.setConnectTimeout(5000);
// 设置读取远程返回的数据时间60000毫秒 // 设置读取远程返回的数据时间60000毫秒
@ -161,7 +163,7 @@ public class BirthdayHelper {
*/ */
public static String urlencode(Map<String, ?> data) { public static String urlencode(Map<String, ?> data) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (Map.Entry<String, ?> i : data.entrySet()) { for (Map.Entry<String, ? > i : data.entrySet()) {
try { try {
sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue() + "", "UTF-8")).append("&"); sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue() + "", "UTF-8")).append("&");
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {