fix:修复bing获取报错问题 #21
@ -74,14 +74,18 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getBingImg() {
|
private String getBingImg() {
|
||||||
JSONObject bingObj = HttpUtil.getObj(bingHost + bingUrl, null, false);
|
try {
|
||||||
String path = bingObj.getJSONArray("images").getJSONObject(0).getString("url");
|
JSONObject bingObj = HttpUtil.getObj(bingHost + bingUrl, null, false);
|
||||||
String picUrl = bingHost + path;
|
String path = bingObj.getJSONArray("images").getJSONObject(0).getString("url");
|
||||||
Request request = new Request.Builder().url(picUrl).build();
|
String picUrl = bingHost + path;
|
||||||
try (Response res = HttpUtil.getClient(false).newCall(request).execute()) {
|
Request request = new Request.Builder().url(picUrl).build();
|
||||||
byte[] bytes = res.body().bytes();
|
try (Response res = HttpUtil.getClient(false).newCall(request).execute()) {
|
||||||
String filePath = CommonConstant.fileSavePath + "/files/public/bing.jpg";
|
byte[] bytes = res.body().bytes();
|
||||||
FileUtil.writeBytes(bytes, filePath);
|
String filePath = CommonConstant.fileSavePath + "/files/public/bing.jpg";
|
||||||
|
FileUtil.writeBytes(bytes, filePath);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取bing每日一图错误:{}", e.getLocalizedMessage(), e);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("获取bing每日一图错误:{}", e.getLocalizedMessage(), e);
|
log.error("获取bing每日一图错误:{}", e.getLocalizedMessage(), e);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user