Commit b886149f by 朱海

[add]微信小程序转发项目

0 parents
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.viontech</groupId>
<artifactId>VVAS-Forward</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mybatis-plus.version>3.5.1</mybatis-plus.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.2</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.26</version>
</dependency>
</dependencies>
<build>
<finalName>VVAS-Forward</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file \ No newline at end of file
package com.viontech;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
/**
* Created with IntelliJ IDEA.
*
* @author: zhuhai
* Date: 2023-04-04
* Time: 14:21
*/
@MapperScan("com.viontech.mapper")
@SpringBootApplication
@Configuration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public RestTemplate restTemplate() {
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
factory.setConnectTimeout(60000);
factory.setReadTimeout(20000);
RestTemplate restTemplate = new RestTemplate(factory);
return restTemplate;
}
}
\ No newline at end of file \ No newline at end of file
package com.viontech.controller;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.viontech.model.LoadEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* Created with IntelliJ IDEA.
*
* @author: zhuhai
* Date: 2023-04-04
* Time: 14:24
*/
@RestController
@Slf4j
public class LoadController {
@Resource
private RestTemplate restTemplate;
@PostMapping({"/load"})
public Object load(@RequestBody LoadEntity loadEntity, @RequestHeader(required = false,name = "Authorization") String authorization) throws JsonProcessingException {
String url = loadEntity.getUrl();
String param = loadEntity.getParam();
HttpMethod method = loadEntity.getMethod();
HttpHeaders headers = new HttpHeaders();
headers.set("app-code", "");
if (authorization != null) {
headers.set("Authorization", authorization);
}
if (!method.equals(HttpMethod.GET)) {
headers.setContentType(MediaType.APPLICATION_JSON);
} else if (param != null) {
HashMap<String, Object> hashMap = JSON.parseObject(param, HashMap.class);
StringBuilder sb = (new StringBuilder(url)).append("?");
Iterator iterator = hashMap.entrySet().iterator();
while(iterator.hasNext()) {
Map.Entry<String, Object> entry = (Map.Entry<String, Object>) iterator.next();
sb.append("&").append(entry.getKey()).append("=").append(entry.getValue());
}
url = sb.toString().replaceFirst("&", "");
}
log.info("url : [{}]", url);
HttpEntity<Object> entity = new HttpEntity(param, headers);
ResponseEntity<Object> exchange = this.restTemplate.exchange(url, method, entity, Object.class, new Object[0]);
return exchange.getBody();
}
}
\ No newline at end of file \ No newline at end of file
package com.viontech.controller;
import com.viontech.model.MiniWeChatCode;
import com.viontech.service.MiniWechatCodeService;
import com.viontech.vo.ResultVo;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* Created with IntelliJ IDEA.
*
* @author: zhuhai
* Date: 2023-04-04
* Time: 16:07
*/
@RestController
public class MiniWechatCodeController {
@Resource
private MiniWechatCodeService miniWechatCodeService;
@GetMapping("/getUrl")
public ResultVo getUrlByCode(@RequestParam("code") String code) {
MiniWeChatCode miniWeChatCode = miniWechatCodeService.getByCode(code);
if (miniWeChatCode == null) {
return ResultVo.error("code is not exist");
}
return ResultVo.success(miniWeChatCode.getUrl());
}
}
\ No newline at end of file \ No newline at end of file
package com.viontech.controller;
import com.viontech.vo.ResultVo;
import net.sf.jsqlparser.util.validation.metadata.DatabaseException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
/**
* Created with IntelliJ IDEA.
*
* @author: zhuhai
* Date: 2023-04-04
* Time: 17:36
*/
@RestController
public class StatusController {
@GetMapping("/keepAlive")
public ResultVo keepAlive() {
return ResultVo.success(new Date());
}
}
\ No newline at end of file \ No newline at end of file
package com.viontech.exception;
import com.viontech.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* Created with IntelliJ IDEA.
*
* @author: zhuhai
* Date: 2023-04-04
* Time: 16:22
*/
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
public ResultVo exception(Exception ex) {
log.error("系统异常", ex);
if (ex instanceof ServletRequestBindingException) {
return ResultVo.error("400", "param is error");
}
return ResultVo.error();
}
}
\ No newline at end of file \ No newline at end of file
package com.viontech.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.viontech.model.MiniWeChatCode;
/**
* Created with IntelliJ IDEA.
*
* @author: zhuhai
* Date: 2023-04-04
* Time: 15:43
*/
public interface MiniWechatCodeMapper extends BaseMapper<MiniWeChatCode> {
}
package com.viontech.model;
import lombok.Data;
import org.springframework.http.HttpMethod;
/**
* Created with IntelliJ IDEA.
*
* @author: zhuhai
* Date: 2023-04-04
* Time: 14:26
*/
@Data
public class LoadEntity {
private HttpMethod method;
private String url;
private String param;
}
\ No newline at end of file \ No newline at end of file
package com.viontech.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.util.Date;
/**
* Created with IntelliJ IDEA.
*
* @author: zhuhai
* Date: 2023-04-04
* Time: 15:43
*/
@Data
@TableName("b_mini_wechat_code")
public class MiniWeChatCode {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@TableField(value = "name")
private String name;
@TableField("code")
private String code;
@TableField("url")
private String url;
@TableField("create_time")
private Date createTime;
@TableField("modify_time")
private Date modifyTime;
}
\ No newline at end of file \ No newline at end of file
package com.viontech.service;
import com.viontech.model.MiniWeChatCode;
/**
* Created with IntelliJ IDEA.
*
* @author: zhuhai
* Date: 2023-04-04
* Time: 15:48
*/
public interface MiniWechatCodeService {
public MiniWeChatCode getByCode(String code);
}
\ No newline at end of file \ No newline at end of file
package com.viontech.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.viontech.mapper.MiniWechatCodeMapper;
import com.viontech.model.MiniWeChatCode;
import com.viontech.service.MiniWechatCodeService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* Created with IntelliJ IDEA.
*
* @author: zhuhai
* Date: 2023-04-04
* Time: 15:48
*/
@Service
public class MiniWechatCodeServiceImpl implements MiniWechatCodeService {
@Resource
private MiniWechatCodeMapper miniWechatCodeMapper;
/**
* 根据code获取url
* @param code
* @return
*/
@Override
public MiniWeChatCode getByCode(String code) {
LambdaQueryWrapper<MiniWeChatCode> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(MiniWeChatCode::getCode, code);
MiniWeChatCode miniWeChatCode = miniWechatCodeMapper.selectOne(queryWrapper);
return miniWeChatCode;
}
}
\ No newline at end of file \ No newline at end of file
package com.viontech.vo;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
/**
* Created with IntelliJ IDEA.
*
* @author: zhuhai
* Date: 2023-04-04
* Time: 16:08
*/
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResultVo<T> {
private String code;
private String message;
private T data;
public static ResultVo<Void> success() {
return success("success", null);
}
public static <T> ResultVo<T> success(T data) {
return success("success", data);
}
public static <T> ResultVo<T> success(String message, T data) {
ResultVo<T> resultVo = new ResultVo<>();
resultVo.setCode("200");
resultVo.setMessage(message);
resultVo.setData(data);
return resultVo;
}
public static ResultVo<Void> error() {
return error("System error!");
}
public static ResultVo<Void> error(String code, String message) {
ResultVo<Void> resultVo = new ResultVo<>();
resultVo.setCode(code);
resultVo.setMessage(message);
return resultVo;
}
public static ResultVo<Void> error(String message) {
return error("500", message);
}
}
\ No newline at end of file \ No newline at end of file
spring.datasource.url=jdbc:postgresql://117.133.143.116:5432/VionCountStore
spring.datasource.username=postgres
spring.datasource.password=vion
spring.datasource.druid.initial-size=0
\ No newline at end of file \ No newline at end of file
server:
port: 8080
spring:
aop:
proxy-target-class: true
main:
allow-bean-definition-overriding: true
profiles:
active: dev
datasource:
driver-class-name: org.postgresql.Driver
druid:
initial-size: 5
min-idle: 5
max-active: 20
max-wait: 60000
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
validation-query: null
test-while-idle: true
test-on-borrow: false
test-on-return: false
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
logging:
config: classpath:logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- 日志级别从低到高分为TRACE < DEBUG < INFO < WARN < ERROR < FATAL,如果设置为WARN,则低于WARN的信息都不会输出 -->
<!-- scan:当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true -->
<!-- scanPeriod:设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。 -->
<!-- debug:当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。 -->
<configuration scan="true" scanPeriod="10 seconds">
<!--<include resource="org/springframework/boot/logging/logback/base.xml" />-->
<contextName>logback</contextName>
<!-- name的值是变量的名称,value的值时变量定义的值。通过定义的值会被插入到logger上下文中。定义变量后,可以使“${}”来使用变量。 -->
<property name="log.path" value="logs" />
<property name="pattern" value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] [%thread] %logger{50} - %msg%n" />
<!--输出到控制台-->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息-->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>info</level>
</filter>
<encoder>
<Pattern>${pattern}</Pattern>
<!-- 设置字符集 -->
</encoder>
</appender>
<!--输出到文件-->
<!-- 时间滚动输出 level为 DEBUG 日志 -->
<appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文件的路径及文件名 -->
<file>${log.path}/log_debug.log</file>
<!--日志文件输出格式-->
<encoder>
<Pattern>${pattern}</Pattern>
<charset>UTF-8</charset> <!-- 设置字符集 -->
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志归档 -->
<fileNamePattern>${log.path}/debug/log-debug-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文件保留天数-->
<maxHistory>15</maxHistory>
</rollingPolicy>
<!-- 此日志文件只记录debug级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>debug</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 时间滚动输出 level为 INFO 日志 -->
<appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文件的路径及文件名 -->
<file>${log.path}/log_info.log</file>
<!--日志文件输出格式-->
<encoder>
<Pattern>${pattern}</Pattern>
<charset>UTF-8</charset>
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 每天日志归档路径以及格式 -->
<fileNamePattern>${log.path}/info/log-info-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文件保留天数-->
<maxHistory>15</maxHistory>
</rollingPolicy>
<!-- 此日志文件只记录info级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>info</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>NEUTRAL</onMismatch>
</filter>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>warn</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 时间滚动输出 level为 WARN 日志 -->
<appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文件的路径及文件名 -->
<file>${log.path}/log_warn.log</file>
<!--日志文件输出格式-->
<encoder>
<Pattern>${pattern}</Pattern>
<charset>UTF-8</charset> <!-- 此处设置字符集 -->
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/warn/log-warn-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文件保留天数-->
<maxHistory>5</maxHistory>
</rollingPolicy>
<!-- 此日志文件只记录warn级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>warn</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 时间滚动输出 level为 ERROR 日志 -->
<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文件的路径及文件名 -->
<file>${log.path}/log_error.log</file>
<!--日志文件输出格式-->
<encoder>
<Pattern>${pattern}</Pattern>
<charset>UTF-8</charset> <!-- 此处设置字符集 -->
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/error/log-error-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文件保留天数-->
<maxHistory>15</maxHistory>
</rollingPolicy>
<!-- 此日志文件只记录ERROR级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!--
<logger>用来设置某一个包或者具体的某一个类的日志打印级别、
以及指定<appender>。<logger>仅有一个name属性,
一个可选的level和一个可选的addtivity属性。
name:用来指定受此logger约束的某一个包或者具体的某一个类。
level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF,
还有一个特俗值INHERITED或者同义词NULL,代表强制执行上级的级别。
如果未设置此属性,那么当前logger将会继承上级的级别。
addtivity:是否向上级logger传递打印信息。默认是true。
-->
<!--<logger name="org.springframework.web" level="info"/>-->
<!--<logger name="org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor" level="INFO"/>-->
<!--
使用mybatis的时候,sql语句是debug下才会打印,而这里我们只配置了info,所以想要查看sql语句的话,有以下两种操作:
第一种把<root level="info">改成<root level="DEBUG">这样就会打印sql,不过这样日志那边会出现很多其他消息
第二种就是单独给dao下目录配置debug模式,代码如下,这样配置sql语句会打印,其他还是正常info级别:
-->
<!--
root节点是必选节点,用来指定最基础的日志输出级别,只有一个level属性
level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF,
不能设置为INHERITED或者同义词NULL。默认是DEBUG
可以包含零个或多个元素,标识这个appender将会添加到这个logger。
-->
<!--<logger name="com.viontech" level="debug" additivity="false">
<appender-ref ref="DEBUG_FILE" />
</logger>-->
<root level="info">
<appender-ref ref="CONSOLE" />
<appender-ref ref="INFO_FILE" />
<appender-ref ref="WARN_FILE" />
<appender-ref ref="ERROR_FILE" />
</root>
</configuration>
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!