Browse Source

初始化项目

jaikuai 3 years ago
commit
f7972de685

+ 11 - 0
.gitignore

@@ -0,0 +1,11 @@
+# Created by .ignore support plugin (hsz.mobi)
+### Example user template template
+### Example user template
+
+# IntelliJ project files
+.idea
+*.iml
+out
+gen
+target
+.mvn

+ 228 - 0
pom.xml

@@ -0,0 +1,228 @@
+<?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>
+
+    <groupId>cn.fastfun</groupId>
+    <artifactId>pdms-oss-api</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <name>pdms-oss-api</name>
+    <description>pdms-oss-api for Spring Boot</description>
+
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>2.1.4.RELEASE</version>
+        <relativePath/> <!-- lookup parent from repository -->
+    </parent>
+    
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+        <java.version>1.8</java.version>
+        <spring-cloud.version>Greenwich.SR2</spring-cloud.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-starter-validation</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-jdbc</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-redis</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-websocket</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.java-websocket</groupId>
+            <artifactId>Java-WebSocket</artifactId>
+            <version>1.3.8</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.kafka</groupId>
+            <artifactId>spring-kafka</artifactId>
+        </dependency>
+
+        <!-- commons-pool2 -->
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-pool2</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-aop</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>druid-spring-boot-starter</artifactId>
+            <version>1.1.10</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>3.9</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.auth0</groupId>
+            <artifactId>java-jwt</artifactId>
+            <version>3.8.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.gavaghan</groupId>
+            <artifactId>geodesy</artifactId>
+            <version>1.1.3</version>
+        </dependency>
+
+        <dependency>
+            <groupId>io.jsonwebtoken</groupId>
+            <artifactId>jjwt</artifactId>
+            <version>0.7.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+            <version>2.8.2</version>
+        </dependency>
+
+        <dependency>
+            <groupId>net.coobird</groupId>
+            <artifactId>thumbnailator</artifactId>
+            <version>0.4.8</version>
+        </dependency>
+
+        <dependency>
+            <groupId>commons-codec</groupId>
+            <artifactId>commons-codec</artifactId>
+            <version>1.13</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-configuration-processor</artifactId>
+            <optional>true</optional>
+        </dependency>
+
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>2.6</version>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.46</version>
+        </dependency>
+
+        <!--<dependency>-->
+            <!--<groupId>org.apache.hbase</groupId>-->
+            <!--<artifactId>hbase-client</artifactId>-->
+            <!--<version>2.4.2</version>-->
+        <!--</dependency>-->
+
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <optional>true</optional>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.bridge</groupId>
+            <artifactId>jpa-curd</artifactId>
+            <version>2.3.1</version>
+        </dependency>
+
+    </dependencies>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework.cloud</groupId>
+                <artifactId>spring-cloud-dependencies</artifactId>
+                <version>${spring-cloud.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+
+        <testResources>
+            <testResource>
+                <directory>${project.basedir}/src/test/java</directory>
+            </testResource>
+            <testResource>
+                <directory>${project.basedir}/src/test/resources</directory>
+            </testResource>
+        </testResources>
+    </build>
+
+    <repositories>
+        <repository>
+            <id>nexus</id>
+            <name>Spring Milestones</name>
+            <url>http://nexus.fast-fun.cn:92/repository/maven-public/</url>
+        </repository>
+    </repositories>
+
+    <pluginRepositories>
+        <pluginRepository>
+            <id>nexus</id>
+            <name>nexus</name>
+            <url>http://nexus.fast-fun.cn:92/repository/maven-public/</url>
+            <layout>default</layout>
+        </pluginRepository>
+    </pluginRepositories>
+
+</project>

+ 20 - 0
src/main/java/cn/fastfun/Application.java

@@ -0,0 +1,20 @@
+package cn.fastfun;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.web.servlet.ServletComponentScan;
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
+@SpringBootApplication
+@ServletComponentScan
+@EnableCaching
+@EnableAsync
+@EnableScheduling
+public class Application {
+
+  public static void main(String[] args) {
+    SpringApplication.run(Application.class, args);
+  }
+}

+ 33 - 0
src/main/java/cn/fastfun/config/ApiExceptionHandler.java

@@ -0,0 +1,33 @@
+package cn.fastfun.config;
+
+import com.bridge.dto.ApiDTO;
+import com.bridge.exception.ApiRuntimeException;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * 异常捕获
+ */
+@Slf4j
+@ControllerAdvice
+public class ApiExceptionHandler {
+
+    @ExceptionHandler(value = ApiRuntimeException.class)
+    public @ResponseBody
+    ApiDTO errorHandler(HttpServletRequest request, ApiRuntimeException e) {
+        if(e.getStatus() != 501)
+            log.error("URL:{},异常捕获:{}", request.getRequestURI(), e.getMessage(), e);
+        return ApiDTO.error(e.getStatus(), e.getMessage());
+    }
+
+    @ExceptionHandler(value = RuntimeException.class)
+    public @ResponseBody
+    ApiDTO errorHandler(HttpServletRequest request, Exception e) {
+        log.error("URL:{},异常捕获:{}", request.getRequestURI(), e.getMessage(), e);
+        return ApiDTO.error(e.getMessage());
+    }
+}

+ 58 - 0
src/main/java/cn/fastfun/config/DataSourceConfig.java

@@ -0,0 +1,58 @@
+package cn.fastfun.config;
+
+import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.sql.DataSource;
+
+@Configuration
+public class DataSourceConfig {
+    @Bean
+    @ConfigurationProperties(prefix = "spring.datasource.base")
+    DataSource base() {
+        return DruidDataSourceBuilder.create().build();
+    }
+
+    @Bean
+    @ConfigurationProperties(prefix = "spring.datasource.runtime")
+    DataSource runtime() {
+        return DruidDataSourceBuilder.create().build();
+    }
+
+    @Bean
+    @ConfigurationProperties(prefix = "spring.datasource.report")
+    DataSource report() {
+        return DruidDataSourceBuilder.create().build();
+    }
+
+//    @Bean
+//    @ConfigurationProperties(prefix = "spring.datasource.phoenix")
+//    DataSource phoenix() {
+//        return DruidDataSourceBuilder.create().build();
+//    }
+
+
+    @Bean
+    JdbcTemplate jdbcTemplateBase(@Qualifier("base") DataSource base) {
+        return new JdbcTemplate(base);
+    }
+
+    @Bean
+    JdbcTemplate jdbcTemplateRunTime(@Qualifier("runtime") DataSource runtime) {
+        return new JdbcTemplate(runtime);
+    }
+
+    @Bean
+    JdbcTemplate jdbcTemplateReport(@Qualifier("report") DataSource report) {
+        return new JdbcTemplate(report);
+    }
+
+//    @Bean
+//    JdbcTemplate jdbcTemplatePhoenix(@Qualifier("phoenix") DataSource runtime) {
+//        return new JdbcTemplate(runtime);
+//    }
+}

+ 33 - 0
src/main/java/cn/fastfun/config/GlobalCorsConfig.java

@@ -0,0 +1,33 @@
+package cn.fastfun.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CorsFilter;
+
+@Configuration
+public class GlobalCorsConfig {
+    @Bean
+    public CorsFilter corsFilter() {
+        //1.添加CORS配置信息
+        CorsConfiguration config = new CorsConfiguration();
+        //放行哪些原始域
+        config.addAllowedOrigin("*");
+        //是否发送Cookie信息
+        config.setAllowCredentials(true);
+        //放行哪些原始域(请求方式)
+        config.addAllowedMethod("*");
+        //放行哪些原始域(头部信息)
+        config.addAllowedHeader("*");
+        //暴露哪些头部信息(因为跨域访问默认不能获取全部头部信息)
+//        config.addExposedHeader("*");
+
+        //2.添加映射路径
+        UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
+        configSource.registerCorsConfiguration("/**", config);
+
+        //3.返回新的CorsFilter.
+        return new CorsFilter(configSource);
+    }
+}

+ 41 - 0
src/main/java/cn/fastfun/config/HttpServletRequestReplacedFilter.java

@@ -0,0 +1,41 @@
+package com.bridge.config;
+
+import javax.servlet.*;
+import javax.servlet.annotation.WebFilter;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+
+
+/**
+ * @author rayfoo@qq.com
+ * @version 1.0
+ * <p>创建一个实现Filter的类,重写doFilter方法,将ServletRequest替换为自定义的request类 </p>
+ * @date 2020/8/6 20:53
+ */
+@WebFilter(urlPatterns = "/*", filterName = "requestReplaced")
+public class HttpServletRequestReplacedFilter implements Filter {
+
+    @Override
+    public void destroy() {
+    }
+
+    @Override
+    public void doFilter(ServletRequest request, ServletResponse response,
+                         FilterChain chain) throws IOException, ServletException {
+        ServletRequest requestWrapper = null;
+        if (request instanceof HttpServletRequest) {
+            requestWrapper = new MyHttpServletRequestWrapper((HttpServletRequest) request);
+        }
+        if (requestWrapper == null) {
+            chain.doFilter(request, response);
+        } else {
+            chain.doFilter(requestWrapper, response);
+        }
+    }
+
+
+    @Override
+    public void init(FilterConfig arg0) throws ServletException {
+
+    }
+}

+ 18 - 0
src/main/java/cn/fastfun/config/ProjectBean.java

@@ -0,0 +1,18 @@
+package cn.fastfun.config;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.Map;
+
+@Setter
+@Getter
+@Configuration
+@ConfigurationProperties(prefix = "project")
+public class ProjectBean {
+
+    private String hbaseUrl;
+
+}

+ 52 - 0
src/main/resources/application-dev.yml

@@ -0,0 +1,52 @@
+server:
+  port: 8082
+spring:
+  datasource:
+    base:
+      url: jdbc:mysql://rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com/qixiang_manage?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
+      username: qx_query
+      password: '@Qx_query'
+      driverClassName: com.mysql.cj.jdbc.Driver
+    runtime:
+      url: jdbc:mysql://172.16.121.236:3306/fastfun?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
+      username: readonly
+      password: Fast1234
+      driverClassName: com.mysql.cj.jdbc.Driver
+    report:
+      url: jdbc:mysql://rpi.it5000.com:9306/zhl_boss?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
+      username: root
+      password: 1qaz2wsx
+      driverClassName: com.mysql.cj.jdbc.Driver
+  redis:
+    host: rpi.it5000.com
+    port: 6379
+    password: jaikuai
+#    timeout: 10000
+  kafka:
+    bootstrap-servers: kafka-1.node:9092
+    listener:
+      missing-topics-fatal: false
+      concurrency: 1
+    consumer:
+      auto-offset-reset: earliest
+      enable-auto-commit: true
+      key-deserializer: org.apache.kafka.common.serialization.ByteArrayDeserializer
+      value-deserializer: org.apache.kafka.common.serialization.ByteArrayDeserializer
+      max-poll-records: 10
+
+logging:
+  level:
+    com.bridge: debug
+    root: info
+    io.lettuce.core.protocol: error
+
+# 项目自定义
+project:
+  hbaseUrl: http://172.16.126.13
+#  hbase:
+#    config:
+#      hbase:
+#        zookeeper:
+#          quorum: 192.168.31.222
+#          property:
+#            clientPort: 9181

+ 45 - 0
src/main/resources/application-test.yml

@@ -0,0 +1,45 @@
+server:
+  port: 8082
+spring:
+  datasource:
+    base:
+      url: jdbc:mysql://rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com/qixiang_manage?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
+      username: qx_query
+      password: '@Qx_query'
+      driverClassName: com.mysql.cj.jdbc.Driver
+    runtime:
+      url: jdbc:mysql://172.16.121.236:3306/fastfun?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
+      username: readonly
+      password: Fast1234
+      driverClassName: com.mysql.cj.jdbc.Driver
+    report:
+      url: jdbc:mysql://rpi.it5000.com:9306/zhl_boss?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
+      username: root
+      password: 1qaz2wsx
+      driverClassName: com.mysql.cj.jdbc.Driver
+  redis:
+    host: 172.16.121.240
+    port: 6379
+    password: ZNh69diQ
+#    timeout: 10000
+  kafka:
+    bootstrap-servers: kafka-1.node:9092
+    listener:
+      missing-topics-fatal: false
+      concurrency: 1
+    consumer:
+      auto-offset-reset: earliest
+      enable-auto-commit: true
+      key-deserializer: org.apache.kafka.common.serialization.ByteArrayDeserializer
+      value-deserializer: org.apache.kafka.common.serialization.ByteArrayDeserializer
+      max-poll-records: 10
+
+logging:
+  level:
+    com.bridge: debug
+    root: info
+    io.lettuce.core.protocol: error
+
+# 项目自定义
+project:
+  hbaseUrl: http://172.16.126.13

+ 23 - 0
src/main/resources/application.yml

@@ -0,0 +1,23 @@
+server:
+  port: 8080
+  compression:
+    enabled: true
+    mime-types: ["application/json"]
+logging:
+  level:
+    root: info
+    io.lettuce.core.protocol: error
+
+spring:
+  application:
+    name: ${PRO_NAME:api}
+  profiles:
+    active: ${PRO_ENV:dev}
+  datasource:
+    type: com.alibaba.druid.pool.DruidDataSource
+    driver-class-name: com.mysql.cj.jdbc.Driver
+  task:
+    execution:
+      pool:
+        core-size: 40
+        queue-capacity: 200

+ 127 - 0
src/test/java/com/bridge/AppTest.java

@@ -0,0 +1,127 @@
+package com.bridge;
+
+import com.bridge.service.BatteryNormService;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.time.DateUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.*;
+
+@Slf4j
+@RunWith(SpringRunner.class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+public class AppTest {
+
+    @Resource
+    BatteryNormService normService;
+
+    /**
+     * 初始化头部
+     *
+     * @param post
+     */
+    private void initBaseParam(HttpPost post, Map<String, Object> parameters) throws JsonProcessingException {
+        post.setHeader("appId", "10001");
+        post.setHeader("nonce", "247305b0731d4d59ac18c73fe19ea992");
+        post.setHeader("timestamp", String.valueOf(System.currentTimeMillis()));
+//        post.setHeader("nonce", "645846fc0c274a6fa4b3e3c604c3aaa7");
+//        post.setHeader("timestamp", "1618456212196");
+
+        String sign = SignUtil.signByMD5(parameters, "U19c8qqJ5E6pyM8ohKdWtO8bHguJ3neR");
+        post.setHeader("sign", sign);
+
+        post.setEntity(new StringEntity(new ObjectMapper().writeValueAsString(parameters), Charset.forName("UTF-8")));
+        post.addHeader("Content-type", "application/json; charset=utf-8");
+    }
+
+    @Test
+    public void testMileage() {
+        normService.addBatteryDay(DateUtils.addDays(new Date(), -2), Arrays.asList(new String[]{"PK504B00100004259"}));
+    }
+
+
+    @Test
+    public void testDictAll() throws IOException {
+        HttpPost post = new HttpPost("http://127.0.0.1:8082/api/v1/dict");
+        initBaseParam(post, new HashMap<>());
+        HttpEntity httpEntity = HttpClients.createDefault().execute(post).getEntity();
+        if (httpEntity != null) {
+            log.info("{}", EntityUtils.toString(httpEntity));
+        }
+    }
+
+    /**
+     * 定位数据
+     *
+     * @throws IOException
+     */
+    @Test
+    public void testGps() throws IOException {
+        HttpPost post = new HttpPost("http://127.0.0.1:8082/api/v1/position");
+        HashMap<String, Object> parameters = new HashMap<>();
+        parameters.put("sn", "PK50001A100000563,PK50001A100000192");
+
+        initBaseParam(post, parameters);
+        HttpEntity httpEntity = HttpClients.createDefault().execute(post).getEntity();
+        if (httpEntity != null) {
+            log.info("{}", EntityUtils.toString(httpEntity));
+        }
+    }
+
+    /**
+     * 电池列表
+     *
+     * @throws IOException
+     */
+    @Test
+    public void testBatteryList() throws IOException {
+        HttpPost post = new HttpPost("http://47.111.243.220:8082/api/v1/battery/list");
+        initBaseParam(post, new HashMap<>());
+        HttpEntity httpEntity = HttpClients.createDefault().execute(post).getEntity();
+        if (httpEntity != null) {
+            log.info("{}", EntityUtils.toString(httpEntity));
+        }
+    }
+
+    /**
+     * 电池详细信息
+     *
+     * @throws IOException
+     */
+    @Test
+    public void testBatteryStatus() throws IOException {
+        HttpPost post = new HttpPost("http://47.111.243.220:8082/api/v1/battery/status");
+
+        HashMap<String, Object> parameters = new HashMap<>();
+        parameters.put("sn", "PK50001A100000563,PK50001A100000192");
+        initBaseParam(post, parameters);
+        HttpEntity httpEntity = HttpClients.createDefault().execute(post).getEntity();
+        if (httpEntity != null) {
+            log.info("{}", EntityUtils.toString(httpEntity));
+        }
+    }
+
+    @Test
+    public void testDict() throws IOException {
+        HttpPost post = new HttpPost("http://47.111.243.220:8082/api/v1/dict");
+        initBaseParam(post, new HashMap<>());
+        HttpEntity httpEntity = HttpClients.createDefault().execute(post).getEntity();
+        if (httpEntity != null) {
+            log.info("{}", EntityUtils.toString(httpEntity));
+        }
+    }
+
+}

+ 59 - 0
src/test/java/com/bridge/WebSocketTest.java

@@ -0,0 +1,59 @@
+package com.bridge;
+
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.java_websocket.client.WebSocketClient;
+import org.java_websocket.handshake.ServerHandshake;
+
+import java.net.URI;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+@Slf4j
+public class WebSocketTest {
+
+    public static void main(String[] args) {
+        try {
+            SignUtil.signByMD5(new HashMap<>(), "");
+            String url = "ws://127.0.0.1:8082/v1/ws/10001/battery";
+            URI uri = new URI(url);
+            WebSocketClient mWs = new WebSocketClient(uri) {
+                @SneakyThrows
+                @Override
+                public void onOpen(ServerHandshake serverHandshake) {
+                    log.info(" is Opend");
+                    Map<String, Object> param = new HashMap<>();
+                    param.put("appid", "10001");
+                    param.put("timestamp", new Date().getTime());
+//                    param.put("nonce","123");
+
+                    String sign = SignUtil.signByMD5(param, "U19c8qqJ5E6pyM8ohKdWtO8bHguJ3neR");
+                    param.put("sign", sign);
+                    this.send(new ObjectMapper().writeValueAsString(param));
+                }
+
+                @Override
+                public void onMessage(String s) {
+                    System.out.println(s);
+                }
+
+                @Override
+                public void onClose(int i, String s, boolean b) {
+
+                }
+
+                @Override
+                public void onError(Exception e) {
+
+                }
+            };
+            mWs.connect();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+}