Skip to content

Commit

Permalink
初始化网络请求封装并整理基础模块
Browse files Browse the repository at this point in the history
  • Loading branch information
elveahuang committed Jul 10, 2024
1 parent bb2c969 commit 4c7a0a7
Show file tree
Hide file tree
Showing 38 changed files with 580 additions and 76 deletions.
39 changes: 20 additions & 19 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ allprojects {
dependency("io.swagger.core.v3:swagger-annotations-jakarta:2.2.22")
dependency("io.swagger.core.v3:swagger-models:2.2.22")
dependency("io.swagger.core.v3:swagger-models-jakarta:2.2.22")
dependency("org.springdoc:springdoc-openapi-starter-common:2.5.0")
dependency("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0")
dependency("org.springdoc:springdoc-openapi-starter-webflux-ui:2.5.0")
dependency("org.springdoc:springdoc-openapi-starter-common:2.6.0")
dependency("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0")
dependency("org.springdoc:springdoc-openapi-starter-webflux-ui:2.6.0")
// database & nosql
dependency("org.mybatis:mybatis:3.5.16")
dependency("org.mybatis:mybatis-spring:3.0.3")
dependency("org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.3")
dependency("org.mybatis.generator:mybatis-generator-core:1.4.2")
dependency("org.apache.shardingsphere:shardingsphere-jdbc:5.5.0")
dependency("com.github.jsqlparser:jsqlparser:4.9")
dependency("org.redisson:redisson:3.31.0")
dependency("org.redisson:redisson-spring-data-33:3.31.0")
dependency("org.redisson:redisson-spring-boot-starter:3.31.0")
dependency("org.redisson:redisson:3.32.0")
dependency("org.redisson:redisson-spring-data-33:3.32.0")
dependency("org.redisson:redisson-spring-boot-starter:3.32.0")
// others
dependency("com.nimbusds:nimbus-jose-jwt:9.40")
dependency("com.nimbusds:oauth2-oidc-sdk:11.12")
Expand Down Expand Up @@ -132,6 +132,9 @@ allprojects {
dependency("org.jodd:jodd-bean:5.1.6")
dependency("org.jodd:jodd-core:5.3.0")
dependency("org.jodd:jodd-util:6.2.2")
dependency("org.jodd:jodd-http:6.3.0")
dependency("us.codecraft:webmagic-core:0.7.3")
dependency("us.codecraft:webmagic-extension:0.7.3")
// xml & pdf & office & image
dependency("xalan:xalan:2.7.3")
dependency("org.jsoup:jsoup:1.17.2")
Expand All @@ -156,33 +159,30 @@ allprojects {
dependency("org.dom4j:dom4j:2.1.4")
dependency("com.thoughtworks.xstream:xstream:1.4.20")
dependency("org.apache.pdfbox:pdfbox:3.0.2")
dependency("org.dromara.x-easypdf:x-easypdf:3.0.0")
dependency("org.dromara.x-easypdf:x-easypdf-pdfbox:3.0.0")
dependency("org.dromara.x-easypdf:x-easypdf-fop:3.0.0")
// sdks
dependency("io.minio:minio:8.5.10")
dependency("io.minio:minio:8.5.11")
dependency("com.github.binarywang:weixin-java-channel:4.6.0")
dependency("com.github.binarywang:weixin-java-cp:4.6.0")
dependency("com.github.binarywang:weixin-java-miniapp:4.6.0")
dependency("com.github.binarywang:weixin-java-mp:4.6.0")
dependency("com.github.binarywang:weixin-java-open:4.6.0")
dependency("com.github.binarywang:weixin-java-pay:4.6.0")
dependency("com.alibaba:dashscope-sdk-java:2.14.8")
dependency("com.alibaba:dashscope-sdk-java:2.15.1")
dependency("com.aliyun:aliyun-java-sdk-core:4.6.4")
dependency("com.aliyun:tea-openapi:0.3.3")
dependency("com.aliyun:tea-openapi:0.3.4")
dependency("com.aliyun:tea-rpc:0.1.3")
dependency("com.aliyun:tea-rpc-util:0.1.3")
dependency("com.aliyun:dingtalk:2.1.27")
dependency("com.aliyun:dingtalk:2.1.29")
dependency("com.aliyun:imm20170906:1.23.8")
dependency("com.aliyun:facebody20191230:5.1.2")
dependency("com.aliyun:dysmsapi20170525:2.0.24")
dependency("com.aliyun:dysmsapi20170525:3.0.0")
dependency("com.aliyun:alimt20181012:1.3.1")
dependency("com.aliyun.oss:aliyun-sdk-oss:3.17.4")
dependency("com.alipay.sdk:alipay-sdk-java:4.39.110.ALL")
dependency("com.qcloud:cos_api:5.6.218")
dependency("com.tencentcloudapi:tencentcloud-sdk-java-common:3.1.1042")
dependency("com.aliyun.oss:aliyun-sdk-oss:3.18.0")
dependency("com.alipay.sdk:alipay-sdk-java:4.39.123.ALL")
dependency("com.qcloud:cos_api:5.6.219.1")
dependency("com.tencentcloudapi:tencentcloud-sdk-java-common:3.1.1052")
dependency("com.tencentcloudapi:tencentcloud-sdk-java-kms:3.1.977")
dependency("com.tencentcloudapi:tencentcloud-sdk-java-sms:3.1.1024")
dependency("com.tencentcloudapi:tencentcloud-sdk-java-sms:3.1.1043")
dependency("com.tencentcloudapi:tencentcloud-sdk-java-tmt:3.1.1040")
dependency("com.tencentcloudapi:tencentcloud-sdk-java-iai:3.1.978")
dependency("com.tencentcloudapi:tencentcloud-sdk-java-hunyuan:3.1.1041")
Expand Down Expand Up @@ -221,6 +221,7 @@ allprojects {
exclude(module = "junit")
exclude(module = "junit-vintage-engine")
exclude(module = "log4j")
exclude(module = "slf4j-log4j12")
exclude(module = "ehcache")
exclude(module = "poi-ooxml-schemas")
exclude(module = "javax.servlet-api")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package cc.elvea.platform.system.commons.web;

import cc.elvea.platform.commons.annotations.OperationLog;
import cc.elvea.platform.commons.constants.DateTimeConstants;
import cc.elvea.platform.commons.utils.DateTimeUtils;
import cc.elvea.platform.commons.utils.StringUtils;
import cc.elvea.platform.commons.utils.platform.Platform;
import cc.elvea.platform.commons.utils.platform.PlatformHelper;
import cc.elvea.platform.commons.web.controller.AbstractController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.IOException;
import java.time.LocalDateTime;

/**
* @author elvea
Expand All @@ -25,20 +33,33 @@ public class HomeController extends AbstractController {
@ApiResponse(description = "首页")
@GetMapping("/")
@OperationLog("首页")
public String index() {
String page = "";
if (this.context.isProductionMode()) {
Platform platform = PlatformHelper.fromServletRequest();
if (platform.isMobile()) {
page = StringUtils.isNotEmpty(this.context.getHome().getMobile()) ? this.context.getHome().getMobile() : "";
} else {
page = StringUtils.isNotEmpty(this.context.getHome().getWebapp()) ? this.context.getHome().getWebapp() : "";
public void index(@RequestParam("i") String i, HttpServletResponse response) throws IOException {
String page = "/home";
if ("1".equalsIgnoreCase(i)) {
response.addCookie(new Cookie("a", DateTimeUtils.format(LocalDateTime.now(), DateTimeConstants.Pattern.FULL_TIME)));
page = "/about";
} else {
if (this.context.isProductionMode()) {
Platform platform = PlatformHelper.fromServletRequest();
if (platform.isMobile()) {
page = StringUtils.isNotEmpty(this.context.getHome().getMobile()) ? this.context.getHome().getMobile() : "";
} else {
page = StringUtils.isNotEmpty(this.context.getHome().getWebapp()) ? this.context.getHome().getWebapp() : "";
}
}
if (StringUtils.isEmpty(page)) {
page = StringUtils.isNotEmpty(this.context.getHome().getMain()) ? this.context.getHome().getMain() : "about";
}
}
if (StringUtils.isEmpty(page)) {
page = StringUtils.isNotEmpty(this.context.getHome().getMain()) ? this.context.getHome().getMain() : "about";
}
return redirect(page);
response.sendRedirect(page);
}

@Operation(summary = "主页")
@ApiResponse(description = "主页")
@GetMapping("/home")
@OperationLog("主页")
public String home() {
return "index";
}

@Operation(summary = "关于页")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cc.elvea.platform.commons.constants.GlobalConstants;
import cc.elvea.platform.commons.enums.BaseEnum;
import cc.elvea.platform.commons.extensions.template.HtmlTemplateService;
import cc.elvea.platform.commons.template.HtmlTemplateService;
import cc.elvea.platform.commons.utils.*;
import cc.elvea.platform.system.core.model.entity.UserEntity;
import cc.elvea.platform.system.core.service.UserService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cc.elvea.platform.system.message.sender;

import cc.elvea.platform.commons.extensions.mail.MailBody;
import cc.elvea.platform.commons.extensions.mail.MailSender;
import cc.elvea.platform.commons.mail.MailBody;
import cc.elvea.platform.commons.mail.MailSender;
import cc.elvea.platform.commons.utils.ExceptionUtils;
import cc.elvea.platform.system.message.model.dto.SendMessageDto;
import cc.elvea.platform.system.message.service.MessageContentService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ platform:
enabled: true
quartz:
enabled: true
http:
enabled: true
type: okhttp
proxy:
enabled: true
host: 127.0.0.1
port: 7890
oapis:
dingtalk:
enabled: false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package cc.elvea.platform.commons.extensions.http;

import cc.elvea.platform.BaseTests;
import cc.elvea.platform.commons.http.HttpConfig;
import cc.elvea.platform.commons.http.HttpManger;
import cc.elvea.platform.commons.http.HttpType;
import cc.elvea.platform.commons.http.executor.HttpExecutor;
import cc.elvea.platform.commons.http.executor.HttpGetRequestExecutor;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

import java.util.Map;

/**
* @author elvea
* @since 24.1.0
*/
@Slf4j
public class HttpTests extends BaseTests {

@Test
public void baseTest() throws Exception {
HttpExecutor<String, Map<String, String>> executor = HttpGetRequestExecutor.create(HttpManger.getHttp().getConfig());
executor.execute("https://google.com", Maps.newHashMap(), response -> {
log.info("google response: {}", response);
});
}

@Test
public void baseOkHttpTest() throws Exception {
HttpConfig config = HttpConfig.builder().type(HttpType.OKHTTP).build();
HttpExecutor<String, Map<String, String>> executor = HttpGetRequestExecutor.create(config);
executor.execute("https://baidu.com", Maps.newHashMap(), response -> {
log.info("okhttp response: {}", response);
});
}

@Test
public void baseApacheHttpTest() throws Exception {
HttpConfig config = HttpConfig.builder().type(HttpType.APACHE).build();
HttpExecutor<String, Map<String, String>> executor = HttpGetRequestExecutor.create(config);
executor.execute("https://baidu.com", Maps.newHashMap(), response -> {
log.info("apache response: {}", response);
});
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cc.elvea.platform.commons.extensions.mail;

import cc.elvea.platform.BaseTests;
import cc.elvea.platform.commons.mail.MailBody;
import cc.elvea.platform.commons.mail.MailSender;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cc.elvea.platform.commons.extensions.template;

import cc.elvea.platform.BaseTests;
import cc.elvea.platform.commons.template.HtmlTemplateService;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cc.elvea.platform.commons.autoconfigure.http;

import cc.elvea.platform.commons.autoconfigure.http.properties.HttpProperties;
import cc.elvea.platform.commons.http.Http;
import cc.elvea.platform.commons.http.HttpManger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* @author elvea
* @since 24.1.0
*/
@Slf4j
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(prefix = HttpProperties.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true)
@EnableConfigurationProperties({HttpProperties.class})
public class HttpAutoConfiguration {

public HttpAutoConfiguration() {
log.info("HttpAutoConfiguration is enabled.");
}

/**
* @return {@link HttpManger}
*/
@Bean
@ConditionalOnMissingBean
public Http httpManger(HttpProperties properties) {
Http http = new Http();
HttpManger.setHttp(http);
return http;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cc.elvea.platform.commons.autoconfigure.http.properties;

import cc.elvea.platform.commons.http.HttpProxy;
import cc.elvea.platform.commons.http.HttpType;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

/**
* @author elvea
* @since 24.1.0
*/
@Data
@NoArgsConstructor
@ConfigurationProperties(HttpProperties.PREFIX)
public class HttpProperties {

public static final String PREFIX = "platform.http";

private boolean enabled = true;

private HttpType type = HttpType.OKHTTP;

@NestedConfigurationProperty
private HttpProxy proxy = HttpProxy.builder().build();

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cc.elvea.platform.commons.autoconfigure.extensions.mail;
package cc.elvea.platform.commons.autoconfigure.mail;

import cc.elvea.platform.commons.autoconfigure.extensions.mail.properties.MailProperties;
import cc.elvea.platform.commons.extensions.mail.MailSender;
import cc.elvea.platform.commons.extensions.mail.spring.SpringMailSender;
import cc.elvea.platform.commons.autoconfigure.mail.properties.MailProperties;
import cc.elvea.platform.commons.mail.MailSender;
import cc.elvea.platform.commons.mail.spring.SpringMailSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cc.elvea.platform.commons.autoconfigure.extensions.mail.properties;
package cc.elvea.platform.commons.autoconfigure.mail.properties;

import cc.elvea.platform.commons.extensions.mail.MailServer;
import cc.elvea.platform.commons.mail.MailServer;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cc.elvea.platform.commons.autoconfigure.extensions.swagger;
package cc.elvea.platform.commons.autoconfigure.swagger;

import cc.elvea.platform.commons.autoconfigure.extensions.swagger.properties.SwaggerProperties;
import cc.elvea.platform.commons.autoconfigure.swagger.properties.SwaggerProperties;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cc.elvea.platform.commons.autoconfigure.extensions.swagger.properties;
package cc.elvea.platform.commons.autoconfigure.swagger.properties;

import lombok.Data;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cc.elvea.platform.commons.autoconfigure.extensions.template;
package cc.elvea.platform.commons.autoconfigure.template;

import cc.elvea.platform.commons.autoconfigure.extensions.template.properties.TemplateProperties;
import cc.elvea.platform.commons.extensions.template.DefaultHtmlTemplateService;
import cc.elvea.platform.commons.extensions.template.HtmlTemplateService;
import cc.elvea.platform.commons.autoconfigure.template.properties.TemplateProperties;
import cc.elvea.platform.commons.template.DefaultHtmlTemplateService;
import cc.elvea.platform.commons.template.HtmlTemplateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cc.elvea.platform.commons.autoconfigure.extensions.template.properties;
package cc.elvea.platform.commons.autoconfigure.template.properties;

import lombok.Data;
import lombok.NoArgsConstructor;
Expand Down
Loading

0 comments on commit 4c7a0a7

Please sign in to comment.