From e2faab2780dc6ad1cf6b336f5847be1492c54854 Mon Sep 17 00:00:00 2001 From: Carol Date: Tue, 16 Jul 2024 13:30:37 +0800 Subject: [PATCH] =?UTF-8?q?change:=20=E5=8F=98=E6=9B=B4=E7=88=B1=E5=8F=91?= =?UTF-8?q?=E7=94=B5API=E5=9C=B0=E5=9D=80=E4=B8=BA=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=A1=AB=E5=86=99=20add:=20=E6=96=B0=E5=A2=9E=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=85=A8=E9=83=A8=E8=B5=9E=E5=8A=A9=E6=96=B9=E6=A1=88?= =?UTF-8?q?=E3=80=81=E5=95=86=E5=93=81=E3=80=81VIP=E6=9C=8D=E5=8A=A1Finder?= =?UTF-8?q?=20add:=20=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E8=B5=9E=E5=8A=A9=E6=96=B9=E6=A1=88=E3=80=81=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=88=97=E8=A1=A8Finder=20add:=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=85=A8=E9=83=A8=E4=BD=9C=E5=93=81=E9=9B=86?= =?UTF-8?q?Finder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../xindu/afdian/config/AfdianRouter.java | 8 +++- .../afdian/config/BaseSettingConfig.java | 2 +- .../afdian/config/ThemeSettingConfig.java | 5 +++ .../xindu/afdian/service/AfdianFinder.java | 19 ++++++++ .../afdian/service/impl/AfdianFinderImpl.java | 30 +++++++++++++ .../service/impl/AfdianServiceImpl.java | 43 ++++++++++++++++--- src/main/resources/extensions/settings.yaml | 15 +++++-- src/main/resources/templates/afdian.html | 4 +- src/main/resources/templates/afdian2.html | 2 +- src/main/resources/templates/afdian3.html | 4 +- 11 files changed, 116 insertions(+), 18 deletions(-) diff --git a/gradle.properties b/gradle.properties index af4708f..2ccaeec 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=1.6.2 +version=1.6.3 diff --git a/src/main/java/site/xindu/afdian/config/AfdianRouter.java b/src/main/java/site/xindu/afdian/config/AfdianRouter.java index 6777b9f..abbaa90 100644 --- a/src/main/java/site/xindu/afdian/config/AfdianRouter.java +++ b/src/main/java/site/xindu/afdian/config/AfdianRouter.java @@ -24,6 +24,7 @@ public class AfdianRouter { private final ReactiveSettingFetcher settingFetcher; private static final String THEME_SETTING = "themeSetting"; + private static final String BASIC = "basic"; @Bean RouterFunction momentRouterFunction() { @@ -50,7 +51,7 @@ private void defaultModel(HashMap model) { Mono sponsorUrl = this.settingFetcher.get(THEME_SETTING).map(setting -> setting.get("sponsorUrl").asText() - ).defaultIfEmpty("https://afdian.net/a/carolcoral"); + ).defaultIfEmpty("https://afdian.com/a/carolcoral"); model.put("sponsorUrl", sponsorUrl); Mono sponsorNumber = this.settingFetcher.get(THEME_SETTING).map(setting -> @@ -61,6 +62,11 @@ private void defaultModel(HashMap model) { setting.get("rewardTopTitle").asText() ).defaultIfEmpty("感谢我的赞赏者们"); model.put("rewardTopTitle", rewardTopTitle); + Mono baseUrl = + this.settingFetcher.get(BASIC).map(setting -> + setting.get("baseUrl").asText() + ).defaultIfEmpty("https://afdian.com"); + model.put("baseUrl", baseUrl); } private void extracted(HashMap model, String theme) { diff --git a/src/main/java/site/xindu/afdian/config/BaseSettingConfig.java b/src/main/java/site/xindu/afdian/config/BaseSettingConfig.java index e9b88e2..e9164ba 100644 --- a/src/main/java/site/xindu/afdian/config/BaseSettingConfig.java +++ b/src/main/java/site/xindu/afdian/config/BaseSettingConfig.java @@ -8,7 +8,7 @@ public class BaseSettingConfig { public static final String CONFIG_MAP_NAME = "plugin-afdian-config"; - public static final String GROUP = "basic"; + public static final String GROUP = "account"; /** * 用户token diff --git a/src/main/java/site/xindu/afdian/config/ThemeSettingConfig.java b/src/main/java/site/xindu/afdian/config/ThemeSettingConfig.java index c1e19ad..c1b117a 100644 --- a/src/main/java/site/xindu/afdian/config/ThemeSettingConfig.java +++ b/src/main/java/site/xindu/afdian/config/ThemeSettingConfig.java @@ -13,6 +13,11 @@ public class ThemeSettingConfig { public static final String CONFIG_MAP_NAME = "plugin-afdian-config"; public static final String GROUP = "themeSetting"; + /** + * 爱发电地址 + */ + private String baseUrl = ""; + /** * 赞助地址 */ diff --git a/src/main/java/site/xindu/afdian/service/AfdianFinder.java b/src/main/java/site/xindu/afdian/service/AfdianFinder.java index 3e902ff..c99ab44 100644 --- a/src/main/java/site/xindu/afdian/service/AfdianFinder.java +++ b/src/main/java/site/xindu/afdian/service/AfdianFinder.java @@ -34,4 +34,23 @@ public interface AfdianFinder { */ Mono getRewardNumber(); + /** + * 获取全部赞助方案、商品、VIP服务 + * @return 全部赞助方案、商品、VIP服务 + */ + Mono listAllSponsorship(); + + + /** + * 获取全部赞助方案、商品列表 + * @return 全部赞助方案、商品列表 + */ + Mono listPlansAndSales(); + + /** + * 获取全部作品集 + * @return 全部作品集 + */ + Mono listAlbum(); + } diff --git a/src/main/java/site/xindu/afdian/service/impl/AfdianFinderImpl.java b/src/main/java/site/xindu/afdian/service/impl/AfdianFinderImpl.java index 70206bd..793fac0 100644 --- a/src/main/java/site/xindu/afdian/service/impl/AfdianFinderImpl.java +++ b/src/main/java/site/xindu/afdian/service/impl/AfdianFinderImpl.java @@ -74,4 +74,34 @@ public Mono getRewardNumber() { ) .defaultIfEmpty(66.0); } + + /** + * 获取全部赞助方案、商品、VIP服务 + * + * @return 全部赞助方案、商品、VIP服务 + */ + @Override + public Mono listAllSponsorship() { + return afdianService.listAllSponsorship(); + } + + /** + * 获取全部赞助方案、商品列表 + * + * @return 全部赞助方案、商品列表 + */ + @Override + public Mono listPlansAndSales() { + return afdianService.listPlansAndSales(); + } + + /** + * 获取全部作品集 + * + * @return 全部作品集 + */ + @Override + public Mono listAlbum() { + return afdianService.listAlbum(); + } } diff --git a/src/main/java/site/xindu/afdian/service/impl/AfdianServiceImpl.java b/src/main/java/site/xindu/afdian/service/impl/AfdianServiceImpl.java index 2dd342c..66991f7 100644 --- a/src/main/java/site/xindu/afdian/service/impl/AfdianServiceImpl.java +++ b/src/main/java/site/xindu/afdian/service/impl/AfdianServiceImpl.java @@ -1,6 +1,7 @@ package site.xindu.afdian.service.impl; import com.fasterxml.jackson.databind.JsonNode; +import jakarta.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; @@ -27,13 +28,13 @@ public class AfdianServiceImpl implements AfdianService { private final String BASIC = "basic"; + // 创建webClient + private WebClient webClient; + public AfdianServiceImpl(ReactiveSettingFetcher settingFetcher) { this.settingFetcher = settingFetcher; } - // 创建webClient - private WebClient webClient = WebClient.builder().baseUrl("https://afdian.net").build(); - /** * 获取token * @@ -41,13 +42,17 @@ public AfdianServiceImpl(ReactiveSettingFetcher settingFetcher) { */ @Override public Mono getAuthToken() { - return this.settingFetcher.get("basic").flatMap(base -> { + return this.settingFetcher.get(BASIC).flatMap(base -> { String username = base.get("username").asText(); String password = base.get("password").asText(); String url = "/api/passport/login"; Map params = new HashMap<>(); params.put("account", username); params.put("password", password); + + String baseUrl = base.get("baseUrl").asText(); + this.webClient = WebClient.builder().baseUrl(baseUrl).build(); + return webClient.post().uri(url).contentType(MediaType.APPLICATION_JSON) // JSON数据类型 .body(BodyInserters.fromValue(params)) // JSON字符串数据 .retrieve() // 获取响应体 @@ -63,7 +68,7 @@ public Mono getAuthToken() { */ @Override public Mono getSponsorList(int pageNumber) { - var mono = this.settingFetcher.get("basic").flatMap(base -> { + var mono = this.settingFetcher.get(BASIC).flatMap(base -> { String token = base.get("token").asText(); String userId = base.get("userId").asText(); String url = "/api/open/query-sponsor"; @@ -80,6 +85,9 @@ public Mono getSponsorList(int pageNumber) { params.put("ts", timeInMillis); params.put("sign", signMd5); + String baseUrl = base.get("baseUrl").asText(); + this.webClient = WebClient.builder().baseUrl(baseUrl).build(); + return webClient.post().uri(url).contentType(MediaType.APPLICATION_JSON) // JSON数据类型 .body(BodyInserters.fromValue(params)) // JSON字符串数据 .retrieve() // 获取响应体 @@ -129,6 +137,13 @@ public Mono listAllSponsorship() { var token = res.get("data").get("auth_token").textValue(); String url = "/api/creator/all-plans"; String cookie = "auth_token=".concat(token); + + this.settingFetcher.get(BASIC).map(base -> { + String baseUrl = base.get("baseUrl").asText(); + this.webClient = WebClient.builder().baseUrl(baseUrl).build(); + return this.webClient; + }); + return webClient.get().uri(url).header("Cookie", cookie) .retrieve() // 获取响应体 .bodyToMono(JsonNode.class); @@ -146,10 +161,17 @@ public Mono listPlansAndSales() { return authToken.flatMap(res -> { var token = res.get("data").get("auth_token").textValue(); String cookie = "auth_token=".concat(token); - return this.settingFetcher.get(BASIC).flatMap(setting->{ + return this.settingFetcher.get(BASIC).flatMap(setting -> { var userId = setting.get("userId").textValue(); String url = "/api/creator/get-plans?user_id="; url = url.concat(userId); + + this.settingFetcher.get(BASIC).map(base -> { + String baseUrl = base.get("baseUrl").asText(); + this.webClient = WebClient.builder().baseUrl(baseUrl).build(); + return this.webClient; + }); + return webClient.get().uri(url).header("Cookie", cookie) .retrieve() // 获取响应体 .bodyToMono(JsonNode.class); @@ -168,10 +190,17 @@ public Mono listAlbum() { return authToken.flatMap(res -> { var token = res.get("data").get("auth_token").textValue(); String cookie = "auth_token=".concat(token); - return this.settingFetcher.get(BASIC).flatMap(setting->{ + return this.settingFetcher.get(BASIC).flatMap(setting -> { var userId = setting.get("userId").textValue(); String url = "/api/user/get-album-list?user_id="; url = url.concat(userId); + + this.settingFetcher.get(BASIC).map(base -> { + String baseUrl = base.get("baseUrl").asText(); + this.webClient = WebClient.builder().baseUrl(baseUrl).build(); + return this.webClient; + }); + return webClient.get().uri(url).header("Cookie", cookie) .retrieve() // 获取响应体 .bodyToMono(JsonNode.class); diff --git a/src/main/resources/extensions/settings.yaml b/src/main/resources/extensions/settings.yaml index a303048..a5c5718 100644 --- a/src/main/resources/extensions/settings.yaml +++ b/src/main/resources/extensions/settings.yaml @@ -7,25 +7,32 @@ spec: - group: basic label: 基本设置 formSchema: + - $formkit: text + name: baseUrl + label: 爱发电访问地址 + placeholder: 请输入爱发电访问地址(末尾不带/) + validation: required + help: 启用后必填 + value: https://afdian.com - $formkit: text name: token label: 用户token placeholder: 请输入用户TOKEN validation: required - help: 启用后必填,在 https://afdian.net/dashboard/dev 中 API TOKEN 获取 + help: 启用后必填,在 https://afdian.com/dashboard/dev 中 API TOKEN 获取 - $formkit: text name: userId label: 用户ID placeholder: 请输入用户ID validation: required - help: 启用后必填,在 https://afdian.net/dashboard/dev 中 user_id 获取 + help: 启用后必填,在 https://afdian.com/dashboard/dev 中 user_id 获取 - $formkit: text name: username label: 用户名 value: username placeholder: 请输入爱发电登录用户名,如果不输入用户名和密码,获取赞助方案等接口会出现异常 help: 如果不输入用户名和密码,获取赞助方案等接口会出现异常 - - $formkit: text + - $formkit: password name: password label: 密码 value: password @@ -42,7 +49,7 @@ spec: - $formkit: text name: sponsorUrl label: 赞助地址 - value: https://afdian.net/a/carolcoral + value: https://afdian.com/a/carolcoral placeholder: 请输入跳转赞助地址 validation: required help: 启用后必填,否则爱发电页面可能会报错 diff --git a/src/main/resources/templates/afdian.html b/src/main/resources/templates/afdian.html index 6cd665d..abdbcd0 100644 --- a/src/main/resources/templates/afdian.html +++ b/src/main/resources/templates/afdian.html @@ -85,7 +85,9 @@
-
+
diff --git a/src/main/resources/templates/afdian2.html b/src/main/resources/templates/afdian2.html index 3206a07..9222cbd 100644 --- a/src/main/resources/templates/afdian2.html +++ b/src/main/resources/templates/afdian2.html @@ -34,7 +34,7 @@