fix:修复bing获取报错问题 #21

Merged
fanxb merged 1 commits from dev into master 2024-05-23 22:08:22 +08:00

View File

@ -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);
} }