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