.
This commit is contained in:
commit
03d1baaac7
117 files changed
+8048
No files matched your search
@@ -0,0 +1,15 @@
|
||||
package com.mhhy;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
@MapperScan("com.mhhy.mapper")
|
||||
public class MhhyFramworkApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MhhyFramworkApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.mhhy;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Lazy(false)
|
||||
public class SpringContextHolder implements ApplicationContextAware, DisposableBean {
|
||||
|
||||
private static ApplicationContext applicationContext = null;
|
||||
|
||||
|
||||
/**
|
||||
* 取得存储在静态变量中的ApplicationContext.
|
||||
*/
|
||||
public static ApplicationContext getApplicationContext() {
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getBean(String name) {
|
||||
return (T) applicationContext.getBean(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型.
|
||||
*/
|
||||
public static <T> T getBean(Class<T> requiredType) {
|
||||
return applicationContext.getBean(requiredType);
|
||||
}
|
||||
|
||||
public static <T> T getBean(String name, Class<T> clazz) {
|
||||
return getApplicationContext().getBean(name, clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除SpringContextHolder中的ApplicationContext为Null.
|
||||
*/
|
||||
public static void clearHolder() {
|
||||
applicationContext = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 实现ApplicationContextAware接口, 注入Context到静态变量中.
|
||||
*/
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext appContext) {
|
||||
applicationContext = appContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* 实现DisposableBean接口, 在Context关闭时清理静态变量.
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
SpringContextHolder.clearHolder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.mhhy.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 用于标记接口登录、参数解密,标记的非加密接口必须登录
|
||||
*/
|
||||
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface Login {
|
||||
|
||||
//该接口是否加密
|
||||
boolean encrypted() default false;
|
||||
|
||||
//AES解密密钥,在encrypted为true时有效,若不指定,则从当前token中获取
|
||||
String key() default "";
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.mhhy.common;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BasePageReq {
|
||||
|
||||
//最后一条数据的id
|
||||
//private int lastId;
|
||||
|
||||
//分页页码,从1开始
|
||||
@ApiModelProperty(value = "分页页码,从1开始")
|
||||
private int page = 1;
|
||||
|
||||
//分页大小,默认10
|
||||
@ApiModelProperty(value = "分页大小,默认10")
|
||||
private int size = 10;
|
||||
|
||||
//获取page对象,用于mybatis-plus
|
||||
public IPage<?> getIPage() {
|
||||
return new Page<>(page, size).setSearchCount(false);
|
||||
}
|
||||
|
||||
//获取offset,用于手动处理sql
|
||||
public int getOffset() {
|
||||
return page > 1 ? page * size - size : 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.mhhy.common;
|
||||
|
||||
import com.mhhy.util.Aes128Util;
|
||||
import com.mhhy.util.PasswordUtil;
|
||||
import com.mhhy.util.RedisUtil;
|
||||
import com.mhhy.util.RequestUtil;
|
||||
import com.ospn.common.OsnUtils;
|
||||
import lombok.Data;
|
||||
|
||||
import static com.mhhy.service.impl.LoginServiceImpl.conversationFlag;
|
||||
|
||||
@Data
|
||||
//@Builder
|
||||
public class BaseResult<T> {
|
||||
|
||||
private int code = 200;
|
||||
|
||||
private String msg = "Success";
|
||||
|
||||
private long timeMillis = System.currentTimeMillis();
|
||||
|
||||
private Object data;
|
||||
|
||||
public BaseResult() {
|
||||
}
|
||||
|
||||
public BaseResult(Object data) {
|
||||
int mainUserId = RequestUtil.getMainUserId();
|
||||
String conversationId = RedisUtil.get(conversationFlag + mainUserId);
|
||||
byte[] sha256Str = PasswordUtil.getSHA256Str(conversationId);
|
||||
data = Aes128Util.AESEncode(data.toString(), sha256Str);
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public BaseResult(String data, String key) {
|
||||
//byte[] sha256Str = PasswordUtil.decodeBase64(key);
|
||||
System.out.println("[BaseResult success] key:" + key);
|
||||
this.data = OsnUtils.aesEncrypt(data, key);
|
||||
//this.data = Aes128Util.AESEncode(data.toString(), sha256Str);
|
||||
}
|
||||
|
||||
public BaseResult(Object data, String key, int type) {
|
||||
if (type == 1){
|
||||
byte[] sha256Str = PasswordUtil.getSHA256Str(key);
|
||||
this.data = Aes128Util.AESEncode(data.toString(), sha256Str);
|
||||
} else if (type == 0) {
|
||||
byte[] sha256Str = PasswordUtil.decodeBase64(key);
|
||||
this.data = Aes128Util.AESEncode(data.toString(), sha256Str);
|
||||
}
|
||||
}
|
||||
|
||||
public BaseResult(int code, Object data) {
|
||||
this.code = code;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public BaseResult(int code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public static BaseResult<?> success(String msg) {
|
||||
return new BaseResult<>(200, msg);
|
||||
}
|
||||
|
||||
public static BaseResult<?> success(int code, Object msg) {
|
||||
return new BaseResult<>(200, msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static BaseResult<?> success() {
|
||||
return new BaseResult<>(200, "success");
|
||||
}
|
||||
|
||||
|
||||
public static BaseResult<?> err(String msg) {
|
||||
return new BaseResult<>(500, msg);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.mhhy.config.jwt;
|
||||
|
||||
import com.auth0.jwt.algorithms.Algorithm;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
@Configuration
|
||||
public class JwtConfig {
|
||||
|
||||
public static final String JWT_SECRET = "mhhy2022";
|
||||
|
||||
@Bean
|
||||
public Algorithm algorithm() throws UnsupportedEncodingException {
|
||||
return Algorithm.HMAC256(JWT_SECRET);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.mhhy.config.redis;
|
||||
|
||||
import com.mhhy.util.Md5Util;
|
||||
import org.springframework.cache.interceptor.KeyGenerator;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class CacheKeyGenerator implements KeyGenerator {
|
||||
|
||||
@Override
|
||||
public Object generate(Object target, Method method, Object... params) {
|
||||
String className = target.getClass().getName();
|
||||
String methodName = method.getName();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
//builder.append(className).append("&");
|
||||
//builder.append(methodName).append("&");
|
||||
if (params.length > 0) {
|
||||
int i = 0;
|
||||
while (i < params.length) {
|
||||
builder.append(params[i++].toString()).append("&");
|
||||
}
|
||||
}
|
||||
return className + ":" + methodName + ":" + Md5Util.md5(builder.toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.mhhy.config.redis;
|
||||
|
||||
import org.springframework.data.redis.cache.RedisCache;
|
||||
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||
import org.springframework.data.redis.cache.RedisCacheManager;
|
||||
import org.springframework.data.redis.cache.RedisCacheWriter;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
public class OdcCacheManager extends RedisCacheManager {
|
||||
|
||||
private static final String SEPARATOR = "#";
|
||||
|
||||
public OdcCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration config) {
|
||||
super(cacheWriter, config);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RedisCache createRedisCache(String name, RedisCacheConfiguration cacheConfig) {
|
||||
String[] values = name.split(SEPARATOR);
|
||||
if (values.length > 1) {
|
||||
long second = Long.parseLong(values[1]);
|
||||
cacheConfig = cacheConfig.entryTtl(Duration.ofSeconds(second));
|
||||
}
|
||||
return super.createRedisCache(name, cacheConfig);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.mhhy.config.redis;
|
||||
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.interceptor.KeyGenerator;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||
import org.springframework.data.redis.cache.RedisCacheManager;
|
||||
import org.springframework.data.redis.cache.RedisCacheWriter;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
@EnableCaching
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
|
||||
//默认过期时间,1 min
|
||||
private final static int EXPIRATION_SECOND = 20;
|
||||
|
||||
public final static String KEY_GENERATOR_NAME = "odcKeyGenerator";
|
||||
|
||||
public final static String CACHE_KEY = "vexCache";
|
||||
|
||||
@Bean
|
||||
public RedisCacheManager redisCacheManager(RedisConnectionFactory redisConnectionFactory) {
|
||||
RedisSerializationContext.SerializationPair<Object> valuePair =
|
||||
RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
|
||||
RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory);
|
||||
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
|
||||
.entryTtl(Duration.ofSeconds(EXPIRATION_SECOND))
|
||||
.serializeValuesWith(valuePair)
|
||||
.disableCachingNullValues();
|
||||
return new OdcCacheManager(redisCacheWriter, config);
|
||||
}
|
||||
|
||||
@Bean(value = KEY_GENERATOR_NAME)
|
||||
public KeyGenerator keyGenerator() {
|
||||
return new CacheKeyGenerator();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.mhhy.config.redis;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||
|
||||
@Configuration
|
||||
public class RedisListenerConfig {
|
||||
@Bean
|
||||
RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) {
|
||||
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
|
||||
container.setConnectionFactory(connectionFactory);
|
||||
return container;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.mhhy.config.web;
|
||||
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@Configuration
|
||||
public class LocaleConfig {
|
||||
|
||||
@Bean
|
||||
public LocaleResolver localeResolver() {
|
||||
AcceptHeaderLocaleResolver localeResolver = new AcceptHeaderLocaleResolver();
|
||||
localeResolver.setDefaultLocale(Locale.SIMPLIFIED_CHINESE);
|
||||
return localeResolver;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageSource messageSource() {
|
||||
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
|
||||
messageSource.setBasename("classpath:/i18n/messages");
|
||||
messageSource.setDefaultEncoding("UTF-8");
|
||||
messageSource.setCacheSeconds(60);
|
||||
return messageSource;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.mhhy.config.web;
|
||||
|
||||
import com.mhhy.common.BaseResult;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
//@Configuration
|
||||
//@RestControllerAdvice
|
||||
public class OdcResponseBodyAdvice implements ResponseBodyAdvice {
|
||||
@Override
|
||||
public boolean supports(MethodParameter methodParameter, Class aClass) {
|
||||
Method method = methodParameter.getMethod();
|
||||
return method != null
|
||||
&& !method.getDeclaringClass().getPackage().getName().startsWith("springfox");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object beforeBodyWrite(Object body, MethodParameter methodParameter, MediaType mediaType, Class aClass, ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse) {
|
||||
if (body instanceof BaseResult) {
|
||||
return body;
|
||||
}
|
||||
return new BaseResult<>(body);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.mhhy.config.web;
|
||||
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Configuration
|
||||
public class RestTemplateConfig {
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
|
||||
MappingJackson2HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter();
|
||||
jacksonConverter.setSupportedMediaTypes(
|
||||
Arrays.asList(
|
||||
MediaType.APPLICATION_JSON,
|
||||
MediaType.TEXT_HTML
|
||||
));
|
||||
|
||||
RestTemplate restTemplate = restTemplateBuilder.build();
|
||||
restTemplate.getMessageConverters().add(jacksonConverter);
|
||||
return restTemplate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.mhhy.config.web;
|
||||
|
||||
|
||||
|
||||
import com.mhhy.interceptor.AuthInterceptor;
|
||||
import com.mhhy.resolver.DecodeArgumentResolver;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
public class WebConfig extends WebMvcConfigurationSupport {
|
||||
|
||||
@Autowired
|
||||
private AuthInterceptor authInterceptor;
|
||||
|
||||
@Autowired
|
||||
private DecodeArgumentResolver decodeArgumentResolver;
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(authInterceptor).addPathPatterns("/api/**");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HttpMessageConverters httpMessageConverters() {
|
||||
return new HttpMessageConverters(
|
||||
Arrays.asList(
|
||||
new StringHttpMessageConverter(Charset.forName("UTF-8")),
|
||||
//new FastJsonHttpMessageConverter(),
|
||||
new MappingJackson2HttpMessageConverter())
|
||||
);
|
||||
}
|
||||
|
||||
// //不可用
|
||||
// @Bean
|
||||
// public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
|
||||
// return m -> {
|
||||
// m.serializerByType(BaseEnum.class, BaseEnumSerializer.getInstance());
|
||||
// m.serializerByType(BigDecimal.class, CoinNumSerializer.getInstance());
|
||||
// };
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
|
||||
argumentResolvers.add(decodeArgumentResolver);
|
||||
}
|
||||
|
||||
//@Override
|
||||
//protected void addFormatters(FormatterRegistry registry) {
|
||||
// //super.addFormatters(registry);
|
||||
// registry.addConverterFactory(new EnumTypeConverterFactory());
|
||||
//}
|
||||
|
||||
@Override
|
||||
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/static/**")
|
||||
.addResourceLocations("classpath:/static/");
|
||||
registry.addResourceHandler("doc.html")
|
||||
.addResourceLocations("classpath:/META-INF/resources/");
|
||||
registry.addResourceHandler("/webjars/**")
|
||||
.addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
super.addResourceHandlers(registry);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,315 @@
|
||||
package com.mhhy.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mhhy.common.BaseResult;
|
||||
import com.mhhy.enums.UserStateEnum;
|
||||
import com.mhhy.enums.UserTypeEnum;
|
||||
import com.mhhy.model.entity.AdminEntity;
|
||||
import com.mhhy.model.entity.UserEntity;
|
||||
import com.mhhy.model.req.*;
|
||||
import com.mhhy.model.resp.LoginResp;
|
||||
import com.mhhy.model.struct.LoginResult;
|
||||
import com.mhhy.service.*;
|
||||
import com.mhhy.util.RandomUtil;
|
||||
import com.mhhy.util.RedisUtil;
|
||||
import com.mhhy.util.RequestUtil;
|
||||
import com.mhhy.util.token.JwtUtil;
|
||||
import com.ospn.command.CmdReDappLogin;
|
||||
import com.ospn.data.DappData;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api/admin")
|
||||
@CrossOrigin(origins = "*")
|
||||
@Setter(value = AccessLevel.PRIVATE, onMethod_ = @Autowired)
|
||||
public class AdminController {
|
||||
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@Autowired
|
||||
AdminService adminService;
|
||||
|
||||
@Autowired
|
||||
LoginService loginService;
|
||||
|
||||
@Autowired
|
||||
LtpServer ltpServer;
|
||||
|
||||
|
||||
@PostMapping("/register")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "注册", response = RegisterReq.class)
|
||||
public BaseResult register(@RequestBody RegisterReq req) {
|
||||
|
||||
|
||||
String username = req.getUsername();
|
||||
String password = req.getPassword();
|
||||
int level = req.getLevel();
|
||||
|
||||
UserEntity userEntity = userService.findAdmin(username);
|
||||
|
||||
if (userEntity != null) {
|
||||
return BaseResult.err("user existed.");
|
||||
}
|
||||
|
||||
userEntity = new UserEntity();
|
||||
userEntity.setState(level);
|
||||
userEntity.setUsername(username);
|
||||
userEntity.setPassword(password);
|
||||
|
||||
// 存入db
|
||||
boolean result = false;
|
||||
|
||||
/*if (level == 1) {
|
||||
result = adminService.createAdmin(username, password);
|
||||
} else if (level == 2) {
|
||||
result = adminService.createCustomer(username, password);
|
||||
}*/
|
||||
result = userService.save(userEntity);
|
||||
|
||||
if (result) {
|
||||
return BaseResult.success(200, "success.");
|
||||
} else {
|
||||
return BaseResult.err("register error.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/login")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "登录", response = LoginResp.class)
|
||||
public BaseResult login(@RequestBody LoginReq req) {
|
||||
|
||||
//RequestUtil.getMainUser();
|
||||
|
||||
String username = req.getUsername();
|
||||
|
||||
UserEntity userEntity = userService.getOne(
|
||||
new LambdaQueryWrapper<UserEntity>()
|
||||
.eq(UserEntity::getUsername, username));
|
||||
if (userEntity == null) {
|
||||
return BaseResult.err("no user");
|
||||
}
|
||||
|
||||
if (!userEntity.getPassword().equalsIgnoreCase(req.getPassword())) {
|
||||
return BaseResult.err("password error.");
|
||||
}
|
||||
|
||||
//LoginResult result = new LoginResult(userEntity, loginService.getConfig(), ltpServer.getAppId());
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("level", userEntity.getState());
|
||||
return BaseResult.success(200, result);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/modifyAdminPwd")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "modify admin password", response = RegisterReq.class)
|
||||
public BaseResult modifyAdminPwd(@RequestBody RegisterReq req) {
|
||||
|
||||
String username = req.getUsername();
|
||||
String password = req.getPassword();
|
||||
|
||||
UserEntity adminEntity = userService.findAdmin(username);
|
||||
if (adminEntity == null) {
|
||||
return BaseResult.err("user not exist.");
|
||||
}
|
||||
adminEntity.setPassword(password);
|
||||
|
||||
if (!userService.updateById(adminEntity)) {
|
||||
return BaseResult.err("update password failed.");
|
||||
}
|
||||
|
||||
return BaseResult.success(200, "success.");
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/listAdmin")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "登录", response = LoginResp.class)
|
||||
public BaseResult listAdmin(@RequestBody FindUserReq req) {
|
||||
|
||||
int page = req.getPage();
|
||||
int limit = req.getLimit();
|
||||
|
||||
|
||||
List<UserEntity> list = userService.listAdmin(page, limit);
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("list", list);
|
||||
|
||||
int count = userService.count(new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getState, 2));
|
||||
result.put("count", count);
|
||||
/*int fixPage = 0;
|
||||
if (count%limit > 0) {
|
||||
fixPage ++;
|
||||
}
|
||||
result.put("page", count/limit + fixPage);*/
|
||||
result.put("page", page);
|
||||
|
||||
return BaseResult.success(200, result);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/listUser")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "登录", response = LoginResp.class)
|
||||
public BaseResult listUser(@RequestBody FindUserReq req) {
|
||||
|
||||
int page = req.getPage();
|
||||
int limit = req.getLimit();
|
||||
String project = req.getProject();
|
||||
|
||||
List<UserEntity> list = userService.listUser(page, limit, project);
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("list", list);
|
||||
|
||||
int count = userService.count(new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getProject, project));
|
||||
result.put("count", count);
|
||||
/*int fixPage = 0;
|
||||
if (count%limit > 0) {
|
||||
fixPage ++;
|
||||
}
|
||||
result.put("page", count/limit + fixPage);*/
|
||||
result.put("page", page);
|
||||
|
||||
return BaseResult.success(200, result);
|
||||
}
|
||||
|
||||
@PostMapping("/disableUser")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "登录", response = LoginResp.class)
|
||||
public BaseResult disableUser(@RequestBody FindUserReq req) {
|
||||
|
||||
String username = req.getOsnId();
|
||||
|
||||
if (loginService.disableOrEnableUser(username, false)) {
|
||||
UserEntity userEntity = userService.getUser(username);
|
||||
if (userEntity != null) {
|
||||
userEntity.setState(0);
|
||||
userService.updateById(userEntity);
|
||||
}
|
||||
return BaseResult.success(200, "success.");
|
||||
}
|
||||
|
||||
return BaseResult.err("failed.");
|
||||
}
|
||||
|
||||
@PostMapping("/enableUser")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "登录", response = LoginResp.class)
|
||||
public BaseResult enableUser(@RequestBody FindUserReq req) {
|
||||
|
||||
String username = req.getOsnId();
|
||||
|
||||
if (loginService.disableOrEnableUser(username, true)) {
|
||||
UserEntity userEntity = userService.getUser(username);
|
||||
if (userEntity != null) {
|
||||
userEntity.setState(1);
|
||||
userService.updateById(userEntity);
|
||||
}
|
||||
return BaseResult.success(200, "success.");
|
||||
}
|
||||
|
||||
return BaseResult.err("failed.");
|
||||
}
|
||||
|
||||
@PostMapping("/query")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "登录", response = LoginResp.class)
|
||||
public BaseResult query(@RequestBody FindUserReq req) {
|
||||
|
||||
String username = req.getOsnId();
|
||||
JSONObject result = new JSONObject();
|
||||
UserEntity userEntity = userService.getUser(username);
|
||||
if (userEntity != null) {
|
||||
List<UserEntity> list = new ArrayList<>();
|
||||
list.add(userEntity);
|
||||
|
||||
result.put("list", list);
|
||||
result.put("count", 1);
|
||||
result.put("page", 1);
|
||||
|
||||
return BaseResult.success(200, result);
|
||||
}
|
||||
|
||||
return BaseResult.err("failed.");
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/genDappInfo")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "登录", response = LoginResp.class)
|
||||
public BaseResult genDappInfo(@RequestBody ReqBase req) {
|
||||
|
||||
|
||||
DappData dappData = new DappData();
|
||||
dappData.url = req.getUrl();
|
||||
dappData.name = ltpServer.ltpData.dappInfo.name;
|
||||
dappData.portrait = ltpServer.ltpData.dappInfo.portrait;
|
||||
dappData.theme = ltpServer.ltpData.dappInfo.theme;
|
||||
dappData.osnID = ltpServer.ltpData.apps.osnID;
|
||||
|
||||
JSONObject result = dappData.toClientJsonNoParam(ltpServer.ltpData.apps.osnKey);
|
||||
|
||||
return BaseResult.success(200, result);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/flushUser")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "登录", response = LoginResp.class)
|
||||
public BaseResult flushUser(@RequestBody FindUserReq req) {
|
||||
|
||||
String osnId = req.getOsnId();
|
||||
if (osnId == null) {
|
||||
return BaseResult.err("failed.");
|
||||
}
|
||||
|
||||
ltpServer.getUserInfo(osnId);
|
||||
|
||||
return BaseResult.success();
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/flushGroup")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "登录", response = LoginResp.class)
|
||||
public BaseResult flushGroup(@RequestBody FindUserReq req) {
|
||||
|
||||
String osnId = req.getOsnId();
|
||||
if (osnId == null) {
|
||||
return BaseResult.err("failed.");
|
||||
}
|
||||
|
||||
ltpServer.getGroupInfo(osnId);
|
||||
|
||||
return BaseResult.success();
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/delete-user")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "代理商删除", response = LoginResp.class)
|
||||
public BaseResult deleteUser(@RequestBody UserEntity user) {
|
||||
UserEntity userEntity = userService.getOne(new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getUsername, user.getUsername()));
|
||||
if (userEntity != null) {
|
||||
if (!userService.removeById(userEntity.getId())) {
|
||||
return BaseResult.err("delete failed.");
|
||||
}
|
||||
}
|
||||
return BaseResult.success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.mhhy.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.mhhy.common.BaseResult;
|
||||
import com.mhhy.model.entity.AppVersionEntity;
|
||||
import com.mhhy.model.req.FindAppVersionReq;
|
||||
import com.mhhy.model.resp.LoginResp;
|
||||
import com.mhhy.service.AppVersionEntityService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api/im")
|
||||
@CrossOrigin(origins = "*")
|
||||
@Setter(value = AccessLevel.PRIVATE, onMethod_ = @Autowired)
|
||||
public class AppVersionEntityController {
|
||||
|
||||
AppVersionEntityService appVersionEntityService;
|
||||
|
||||
@PostMapping("/list")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "版本信息分页查询", response = LoginResp.class)
|
||||
public BaseResult list(@RequestBody FindAppVersionReq req) {
|
||||
|
||||
int page = req.getPage();
|
||||
int limit = req.getLimit();
|
||||
|
||||
|
||||
List<AppVersionEntity> list = appVersionEntityService.listAppVersion(page, limit);
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("list", list);
|
||||
|
||||
int count = appVersionEntityService.count();
|
||||
result.put("count", count);
|
||||
result.put("page", page);
|
||||
|
||||
return BaseResult.success(200, result);
|
||||
}
|
||||
|
||||
@PostMapping("/list-version")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "版本信息条件分页查询", response = LoginResp.class)
|
||||
public BaseResult listVersion(@RequestBody FindAppVersionReq req) {
|
||||
|
||||
int page = req.getPage();
|
||||
int limit = req.getLimit();
|
||||
|
||||
|
||||
List<AppVersionEntity> list = appVersionEntityService.listAppVersionUser(page, limit, req.getUser());
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("list", list);
|
||||
|
||||
int count = appVersionEntityService.count();
|
||||
result.put("count", count);
|
||||
result.put("page", page);
|
||||
|
||||
return BaseResult.success(200, result);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/all")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "查询全部版本信息", response = LoginResp.class)
|
||||
public BaseResult allVersion() {
|
||||
|
||||
List<AppVersionEntity> list = appVersionEntityService.listAppVersionAll();
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("data", list);
|
||||
|
||||
return BaseResult.success(200, result);
|
||||
}
|
||||
|
||||
@PostMapping("/get-app-version")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "查询user版本信息", response = LoginResp.class)
|
||||
public BaseResult getVersionUser() {
|
||||
|
||||
AppVersionEntity list = appVersionEntityService.getUser();
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("data", list);
|
||||
|
||||
return BaseResult.success(200, result);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/delete")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "删除user版本信息", response = LoginResp.class)
|
||||
public BaseResult delete(@RequestBody FindAppVersionReq req) {
|
||||
|
||||
AppVersionEntity appVersionEntity = appVersionEntityService.getById(req.getId());
|
||||
appVersionEntity.setIsShow(1);
|
||||
appVersionEntityService.save(appVersionEntity);
|
||||
return BaseResult.success();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/update")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "更新user版本信息", response = LoginResp.class)
|
||||
public BaseResult update(@RequestBody AppVersionEntity req) {
|
||||
|
||||
AppVersionEntity appVersionEntity = appVersionEntityService.getById(req.getId());
|
||||
appVersionEntity.setIsShow(1);
|
||||
req.setUpdateTime(new Date());
|
||||
appVersionEntityService.save(appVersionEntity);
|
||||
return BaseResult.success();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/add")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "新增user版本信息", response = LoginResp.class)
|
||||
public BaseResult add(@RequestBody AppVersionEntity req) {
|
||||
|
||||
req.setCreateTime(new Date());
|
||||
req.setUpdateTime(new Date());
|
||||
req.setState(2);
|
||||
req.setIsShow(0);
|
||||
if (!appVersionEntityService.save(req)){
|
||||
return BaseResult.err("add failed.");
|
||||
}
|
||||
return BaseResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.mhhy.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.mhhy.common.BaseResult;
|
||||
import com.mhhy.model.entity.UserEntity;
|
||||
import com.mhhy.model.req.CustomerReq;
|
||||
import com.mhhy.model.req.LoginReq;
|
||||
import com.mhhy.model.resp.LoginResp;
|
||||
import com.mhhy.service.CustomerService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api/customer")
|
||||
@CrossOrigin(origins = "*")
|
||||
@Setter(value = AccessLevel.PRIVATE, onMethod_ = @Autowired)
|
||||
public class CustomerController {
|
||||
|
||||
@Autowired
|
||||
CustomerService customerService;
|
||||
|
||||
@PostMapping("/add")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "add", response = LoginResp.class)
|
||||
public BaseResult add(@RequestBody CustomerReq req) {
|
||||
|
||||
if (!customerService.addObj(req.getName(), req.getPortrait(), req.getOsnId(), req.getProject()) ) {
|
||||
return BaseResult.err("failed.");
|
||||
}
|
||||
|
||||
return BaseResult.success(200, "success.");
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "list", response = LoginResp.class)
|
||||
public BaseResult list(@RequestBody CustomerReq req) {
|
||||
|
||||
List list = customerService.listByProject(req.getProject());
|
||||
|
||||
return BaseResult.success(200, list);
|
||||
}
|
||||
|
||||
@PostMapping("/del")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "del", response = LoginResp.class)
|
||||
public BaseResult del(@RequestBody CustomerReq req) {
|
||||
|
||||
if (!customerService.deleteObj(req.getOsnId(), req.getProject())){
|
||||
return BaseResult.err("failed.");
|
||||
}
|
||||
|
||||
return BaseResult.success(200, "login success.");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.mhhy.controller;
|
||||
|
||||
|
||||
import com.mhhy.common.BaseResult;
|
||||
import com.mhhy.model.req.CustomerReq;
|
||||
import com.mhhy.model.resp.LoginResp;
|
||||
import com.mhhy.service.GroupService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api/group")
|
||||
@CrossOrigin(origins = "*")
|
||||
@Setter(value = AccessLevel.PRIVATE, onMethod_ = @Autowired)
|
||||
public class GroupController {
|
||||
|
||||
@Autowired
|
||||
GroupService groupService;
|
||||
|
||||
@PostMapping("/add")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "add", response = LoginResp.class)
|
||||
public BaseResult add(@RequestBody CustomerReq req) {
|
||||
|
||||
if (!groupService.addObj(req.getName(), req.getPortrait(), req.getOsnId(), req.getProject()) ) {
|
||||
return BaseResult.err("failed.");
|
||||
}
|
||||
|
||||
return BaseResult.success(200, "success.");
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "list", response = LoginResp.class)
|
||||
public BaseResult list(@RequestBody CustomerReq req) {
|
||||
|
||||
List list = groupService.listByProject(req.getProject());
|
||||
|
||||
return BaseResult.success(200, list);
|
||||
}
|
||||
|
||||
@PostMapping("/del")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "del", response = LoginResp.class)
|
||||
public BaseResult del(@RequestBody CustomerReq req) {
|
||||
|
||||
if (!groupService.deleteObj(req.getOsnId(), req.getProject())){
|
||||
return BaseResult.err("failed.");
|
||||
}
|
||||
|
||||
return BaseResult.success(200, "login success.");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.mhhy.controller;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api/im")
|
||||
@Setter(value = AccessLevel.PRIVATE, onMethod_ = @Autowired)
|
||||
public class ImController {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,465 @@
|
||||
package com.mhhy.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mhhy.common.BaseResult;
|
||||
import com.mhhy.enums.UserStateEnum;
|
||||
import com.mhhy.enums.UserTypeEnum;
|
||||
import com.mhhy.model.entity.UserEntity;
|
||||
import com.mhhy.model.req.DappRequest;
|
||||
import com.mhhy.model.req.LoginReq;
|
||||
import com.mhhy.model.req.RegisterReq;
|
||||
import com.mhhy.model.req.UpdatePasswdReq;
|
||||
import com.mhhy.model.resp.LoginResp;
|
||||
import com.mhhy.model.struct.LoginResult;
|
||||
import com.mhhy.service.LoginService;
|
||||
import com.mhhy.service.LtpServer;
|
||||
import com.mhhy.service.ProjectConfigService;
|
||||
import com.mhhy.service.UserService;
|
||||
import com.mhhy.util.RandomUtil;
|
||||
import com.mhhy.util.RedisUtil;
|
||||
import com.mhhy.util.token.JwtUtil;
|
||||
import com.ospn.command.CmdReDappLogin;
|
||||
import com.ospn.common.ECUtils;
|
||||
import com.ospn.data.DappData;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(origins = "*")
|
||||
@RequestMapping("api/login")
|
||||
@Setter(value = AccessLevel.PRIVATE, onMethod_ = @Autowired)
|
||||
public class LoginController {
|
||||
|
||||
@Autowired
|
||||
LoginService loginService;
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@Autowired
|
||||
ProjectConfigService configService;
|
||||
|
||||
|
||||
@Autowired
|
||||
LtpServer ltpServer;
|
||||
|
||||
|
||||
|
||||
@PostMapping("/login")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "登录", response = LoginResp.class)
|
||||
public BaseResult login(@RequestBody LoginReq req){
|
||||
return loginService.login(req);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ApiOperation("dapp login")
|
||||
@CrossOrigin(origins = "*")
|
||||
@PostMapping("/dappLogin")
|
||||
public JSONObject dappLogin(@RequestBody DappRequest cmd) {
|
||||
//log.info("传递的参数是:{}", cmd);
|
||||
|
||||
JSONObject ret = null;
|
||||
if (cmd.command.equalsIgnoreCase("GetServerInfo")) {
|
||||
|
||||
// key: dapp_session_user
|
||||
String session = RedisUtil.get("dapp_session_" + cmd.user);
|
||||
|
||||
if (session != null) {
|
||||
// 返回数据
|
||||
ret = ltpServer.ltpData.getServerInfo(cmd.getCmdGetServerInfo(session));
|
||||
} else {
|
||||
ret = ltpServer.ltpData.getServerInfo(cmd.getCmdGetServerInfo());
|
||||
session = ret.getString("session");
|
||||
RedisUtil.setEx("dapp_session_" + cmd.user, session, 60);
|
||||
}
|
||||
|
||||
} else if (cmd.command.equalsIgnoreCase("Login")) {
|
||||
|
||||
CmdReDappLogin cmdRe = null;
|
||||
try {
|
||||
|
||||
UserEntity userEntity = userService.getOne(
|
||||
new QueryWrapper<UserEntity>()
|
||||
.eq("im_id", cmd.user)
|
||||
);
|
||||
if (userEntity != null){
|
||||
cmdRe.setError("1007:no user");
|
||||
return cmdRe.toJson();
|
||||
}
|
||||
|
||||
String session = RedisUtil.get("dapp_session_" + cmd.user);
|
||||
if (session == null) {
|
||||
// 没有session,返回错误信息
|
||||
cmdRe = new CmdReDappLogin();
|
||||
cmdRe.setError("1001:need session");
|
||||
return cmdRe.toJson();
|
||||
}
|
||||
|
||||
|
||||
cmdRe = ltpServer.ltpData.login(cmd.getCmdDappLogin(session));
|
||||
|
||||
if (cmdRe.errCode.equalsIgnoreCase("0:success")) {
|
||||
|
||||
// 增加sessionKey
|
||||
// 生成jwtToken
|
||||
|
||||
|
||||
String randomToInviteCode = RandomUtil.getRandomToInviteCode(16);
|
||||
String token = JwtUtil.createJwtToken(userEntity.getId(), 315360000L);
|
||||
//把之前的token移除
|
||||
JwtUtil.removeTokenByUserId(userEntity.getId());
|
||||
//把token存入redis
|
||||
JwtUtil.putTokenToRedis(userEntity.getId(), token);
|
||||
JSONObject tokenJson = new JSONObject();
|
||||
// TODO 生成通讯密钥拼接在token后面用中竖线隔开,小程序端需要用中划线分割出token
|
||||
tokenJson.put("token", token);
|
||||
tokenJson.put("communicationKey", randomToInviteCode);
|
||||
// log.info("-------token-------" + tokenJson.get("token"));
|
||||
//将通讯密钥存入redis
|
||||
RedisUtil.set("Communicationkey:"+cmd.user, randomToInviteCode);
|
||||
|
||||
cmdRe.addSessionKey(cmd.user, tokenJson.toString().getBytes());
|
||||
|
||||
return cmdRe.toJson();
|
||||
|
||||
} else {
|
||||
ret = cmdRe.toJson();
|
||||
}
|
||||
|
||||
|
||||
return cmdRe.toJson();
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
cmdRe.setError("1006:exception");
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@PostMapping("/register2")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "注册", response = LoginResp.class)
|
||||
public BaseResult register2(@RequestBody RegisterReq req){
|
||||
|
||||
String key = req.getKey();
|
||||
if (!loginService.getRegisterKey().equals(key)) {
|
||||
return BaseResult.err("register key error.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
String username = req.getAccount();
|
||||
String password = req.getPassword();
|
||||
|
||||
String osnId1 = userService.findUser(username);
|
||||
|
||||
if (osnId1 != null) {
|
||||
return BaseResult.err("user existed.");
|
||||
}
|
||||
|
||||
String[] keyPair =loginService.createAccount();
|
||||
String privateKey = "VER2-" + keyPair[1] + "-" + keyPair[2];
|
||||
|
||||
// 存入db
|
||||
UserEntity userEntity = new UserEntity();
|
||||
userEntity.setUsername(username);
|
||||
userEntity.setPassword(password);
|
||||
userEntity.setType(UserTypeEnum.NORMAL.getCode());
|
||||
userEntity.setState(UserStateEnum.NORMAL.getCode());
|
||||
userEntity.setCreateTime(new Date());
|
||||
userEntity.setImNode(loginService.getHostIp());
|
||||
userEntity.setImId(keyPair[0]);
|
||||
userEntity.setImUsername(keyPair[0]);
|
||||
userEntity.setImPwd(privateKey);
|
||||
userEntity.setProject(req.getProject());
|
||||
try {
|
||||
userService.save(userEntity);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return BaseResult.err("exception.");
|
||||
}
|
||||
|
||||
// 返回成功
|
||||
return BaseResult.success(200,"success.");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/getChallenge")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "获取登录的随机数", response = LoginResp.class)
|
||||
public BaseResult getChallenge(@RequestBody RegisterReq req){
|
||||
return loginService.getChallenge(req.getUsername());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private JSONObject createAccount() {
|
||||
|
||||
try {
|
||||
String username = UUID.randomUUID().toString().replace("-", "").substring(2, 22);
|
||||
String password = UUID.randomUUID().toString().replace("-", "").substring(2, 22);
|
||||
|
||||
RegisterReq req1 = new RegisterReq();
|
||||
req1.setUsername(username);
|
||||
req1.setPassword(password);
|
||||
|
||||
JSONObject result = loginService.register3(req1);
|
||||
if (result != null) {
|
||||
result.put("username", username);
|
||||
result.put("password", password);
|
||||
return result;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@PostMapping("/login3")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "登录", response = LoginResp.class)
|
||||
public BaseResult loginByMnemonic(@RequestBody LoginReq req){
|
||||
|
||||
try {
|
||||
System.out.print("[loginByMnemonic] login begin.\n");
|
||||
System.out.print("[loginByMnemonic] req : " + req);
|
||||
|
||||
String project = req.getInvite();
|
||||
if (project == null) {
|
||||
return BaseResult.err("no project");
|
||||
}
|
||||
JSONObject config = configService.getConfig(project);
|
||||
if (config == null) {
|
||||
return BaseResult.err("no config");
|
||||
}
|
||||
|
||||
String user = req.getUser();
|
||||
|
||||
// 从user 表中查找
|
||||
UserEntity userEntity = userService.getUser(user);
|
||||
if (userEntity == null) {
|
||||
// 进入注册环节
|
||||
userEntity = loginService.register6(user, null, project);
|
||||
}
|
||||
|
||||
if (userEntity == null) {
|
||||
System.out.print("[loginByMnemonic] login failed.");
|
||||
return BaseResult.err("create user failed.");
|
||||
}
|
||||
|
||||
// 返回数据
|
||||
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
//result.put("osn_node", config.getString("HOST_IP"));
|
||||
|
||||
String token = JwtUtil.createJwtToken(userEntity.getId(), 315360000L);
|
||||
//把之前的token移除
|
||||
JwtUtil.removeTokenByUserId(userEntity.getId());
|
||||
//把token存入redis
|
||||
JwtUtil.putTokenToRedis(userEntity.getId(), token);
|
||||
|
||||
result.put("token", token);
|
||||
result.put("language", "en");
|
||||
// 新增修复
|
||||
config = configService.getConfig(userEntity.getProject());
|
||||
result.put("json", config);
|
||||
result.put("osn_node", userEntity.getImNode());
|
||||
|
||||
|
||||
return BaseResult.success(200, result);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return BaseResult.err("Exception.");
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/loginByMnemonic2")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "登录", response = LoginResp.class)
|
||||
public BaseResult loginByMnemonic2(@RequestBody LoginReq req){
|
||||
|
||||
System.out.print("[loginByMnemonic2] login begin.");
|
||||
|
||||
JSONObject config = loginService.getConfig();
|
||||
if (config == null) {
|
||||
return BaseResult.err("no config");
|
||||
}
|
||||
|
||||
String user = req.getUser();
|
||||
|
||||
// 从user 表中查找
|
||||
UserEntity userEntity = userService.getUser(user);
|
||||
if (userEntity == null) {
|
||||
// 进入注册环节
|
||||
userEntity = loginService.register6(user, null, null);
|
||||
}
|
||||
|
||||
if (userEntity == null) {
|
||||
System.out.print("[loginByMnemonic] login failed.");
|
||||
return BaseResult.err("");
|
||||
}
|
||||
|
||||
// 返回数据
|
||||
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("osn_node", config.getString("HOST_IP"));
|
||||
|
||||
String token = JwtUtil.createJwtToken(userEntity.getId(), 315360000L);
|
||||
//把之前的token移除
|
||||
JwtUtil.removeTokenByUserId(userEntity.getId());
|
||||
//把token存入redis
|
||||
JwtUtil.putTokenToRedis(userEntity.getId(), token);
|
||||
|
||||
result.put("token", token);
|
||||
result.put("language", "en");
|
||||
result.put("json", config);
|
||||
|
||||
|
||||
return BaseResult.success(200, result);
|
||||
}
|
||||
|
||||
@PostMapping("/login2")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "登录", response = LoginResp.class)
|
||||
public BaseResult login2(@RequestBody LoginReq req){
|
||||
|
||||
String username = req.getAccount();
|
||||
|
||||
UserEntity userEntity = userService.getOne(
|
||||
new LambdaQueryWrapper<UserEntity>()
|
||||
.eq(UserEntity::getUsername, username));
|
||||
if (userEntity == null) {
|
||||
return BaseResult.err("no user");
|
||||
}
|
||||
|
||||
if (!userEntity.getPassword().equalsIgnoreCase(req.getPassword())) {
|
||||
return BaseResult.err("password error.");
|
||||
}
|
||||
|
||||
LoginResult result = new LoginResult(userEntity, loginService.getConfig(), ltpServer.getAppId());
|
||||
|
||||
return BaseResult.success(200, result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/generateDappInfo")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "登录", response = LoginResp.class)
|
||||
public JSONObject generateDappInfo(@RequestBody LoginReq req){
|
||||
|
||||
String url = req.getUrl();
|
||||
return generateDappInfo(url, null, null);
|
||||
}
|
||||
|
||||
private JSONObject generateDappInfo(String url, String name, String portrait) {
|
||||
|
||||
try {
|
||||
String[] keyPair = ECUtils.createOsnID("service");
|
||||
|
||||
DappData dappData = new DappData();
|
||||
dappData.url = url;
|
||||
dappData.osnID = keyPair[0];
|
||||
dappData.name = name;
|
||||
dappData.portrait = portrait;
|
||||
|
||||
return dappData.toClientJsonNoParam(keyPair[1]);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/createConfigInfo")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "登录", response = LoginResp.class)
|
||||
public BaseResult createConfigInfo(@RequestBody LoginReq req){
|
||||
|
||||
String url = req.getUrl();
|
||||
String project = req.getProject();
|
||||
|
||||
/**
|
||||
* config 格式
|
||||
* json
|
||||
* HOST_IP: 8.219.11.57
|
||||
* ENDPOINT: https://oss-ap-southeast-1.aliyuncs.com
|
||||
* AccessKeyId: LTAI5tE1VjrLkUhQisYmYJEc
|
||||
* AccessKeySecret: FxAfo6vhJCcyQ4RHKz9hGG97RVL9Ta
|
||||
* BUCKETNAME: imx1-default
|
||||
* UserPortraitDirectory: portrait/
|
||||
* GroupPortraitDirectory: portrait/
|
||||
* TempDirectory: temp/
|
||||
* WEBRTCBASE: webrtc://103.163.46.118:1985/live/android/
|
||||
* WEBRTCHOST: http://103.163.46.118:1985
|
||||
* */
|
||||
|
||||
try {
|
||||
JSONObject config = loginService.getConfig();
|
||||
|
||||
JSONObject mainDapp = generateDappInfo(url, null, null);
|
||||
String base64Str = Base64.getEncoder().encodeToString(mainDapp.toJSONString().getBytes());
|
||||
config.put("MainDapp", base64Str);
|
||||
|
||||
String configString = Base64.getEncoder().encodeToString(config.toJSONString().getBytes());
|
||||
|
||||
// 将config 存入数据库
|
||||
if (configService.getConfig(project) == null) {
|
||||
configService.setConfig(project, configString);
|
||||
} else {
|
||||
// update
|
||||
configService.updateConfig(project, configString);
|
||||
}
|
||||
return BaseResult.success(200, config);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return BaseResult.err("error.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/updatePass")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "修改密码", response = UpdatePasswdReq.class)
|
||||
public BaseResult updatePass(@RequestBody UpdatePasswdReq req){
|
||||
return BaseResult.success(200, userService.updatePassword(req.getUsername(), req.getPassword(), req.getOldPassword()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
package com.mhhy.controller;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.mhhy.common.BaseResult;
|
||||
import com.mhhy.model.entity.ProjectConfigEntity;
|
||||
import com.mhhy.model.entity.UserEntity;
|
||||
import com.mhhy.model.req.CustomerReq;
|
||||
import com.mhhy.model.req.FindUserReq;
|
||||
import com.mhhy.model.req.ProjectReq;
|
||||
import com.mhhy.model.resp.LoginResp;
|
||||
import com.mhhy.service.GroupService;
|
||||
import com.mhhy.service.ProjectConfigService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api/project")
|
||||
@CrossOrigin(origins = "*")
|
||||
@Setter(value = AccessLevel.PRIVATE, onMethod_ = @Autowired)
|
||||
public class ProjectController {
|
||||
|
||||
@Autowired
|
||||
ProjectConfigService projectService;
|
||||
|
||||
@PostMapping("/add")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "add", response = LoginResp.class)
|
||||
public BaseResult add(@RequestBody ProjectReq req) {
|
||||
|
||||
if (!projectService.setConfig(req.getProject(), req.getConfig(), req.getConfig2()) ) {
|
||||
return BaseResult.err("failed.");
|
||||
}
|
||||
|
||||
return BaseResult.success(200, "success.");
|
||||
}
|
||||
|
||||
// @PostMapping("/list")
|
||||
// @CrossOrigin(origins = "*")
|
||||
// @ApiOperation(value = "list", response = LoginResp.class)
|
||||
// public BaseResult list(@RequestBody ProjectReq req) {
|
||||
//
|
||||
// List list = projectService.listConfig();
|
||||
//
|
||||
// return BaseResult.success(200, list);
|
||||
// }
|
||||
|
||||
@PostMapping("/list")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "list", response = LoginResp.class)
|
||||
public BaseResult list(@RequestBody FindUserReq req) {
|
||||
|
||||
int page = req.getPage();
|
||||
int limit = req.getLimit();
|
||||
|
||||
List<ProjectConfigEntity> list = projectService.listProject(page, limit);
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("list", list);
|
||||
|
||||
int count = projectService.count();
|
||||
result.put("count", count);
|
||||
/*int fixPage = 0;
|
||||
if (count%limit > 0) {
|
||||
fixPage ++;
|
||||
}
|
||||
result.put("page", count/limit + fixPage);*/
|
||||
result.put("page", page);
|
||||
|
||||
return BaseResult.success(200, result);
|
||||
}
|
||||
|
||||
@PostMapping("/update1")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "del", response = LoginResp.class)
|
||||
public BaseResult updateConfig1(@RequestBody ProjectReq req) {
|
||||
|
||||
if (!projectService.updateConfig(req.getProject(), req.getConfig())){
|
||||
return BaseResult.err("failed.");
|
||||
}
|
||||
|
||||
return BaseResult.success(200, "login success.");
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/update2")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "del", response = LoginResp.class)
|
||||
public BaseResult updateConfig2(@RequestBody ProjectReq req) {
|
||||
|
||||
if (!projectService.updateConfig2(req.getProject(), req.getConfig())){
|
||||
return BaseResult.err("failed.");
|
||||
}
|
||||
|
||||
return BaseResult.success(200, "login success.");
|
||||
}
|
||||
|
||||
@PostMapping("/del")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "del", response = LoginResp.class)
|
||||
public BaseResult deleteConfig(@RequestBody ProjectReq req) {
|
||||
|
||||
if (!projectService.deleteConfig(req.getProject())) {
|
||||
return BaseResult.err("failed.");
|
||||
}
|
||||
|
||||
return BaseResult.success(200, "delete success.");
|
||||
}
|
||||
|
||||
@PostMapping("/getDapp")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "getDapp", response = LoginResp.class)
|
||||
public BaseResult getDapp(@RequestBody ProjectReq req) {
|
||||
|
||||
String dappInfo = projectService.getDappInfo(req.getProject());
|
||||
if (dappInfo == null) {
|
||||
return BaseResult.err("failed.");
|
||||
}
|
||||
|
||||
return BaseResult.success(200, dappInfo);
|
||||
}
|
||||
|
||||
@PostMapping("/query-config")
|
||||
@CrossOrigin(origins = "*")
|
||||
@ApiOperation(value = "queryConfig", response = LoginResp.class)
|
||||
public BaseResult queryConfig(@RequestBody ProjectReq req) {
|
||||
List<ProjectConfigEntity> projectConfigEntities;
|
||||
if (!StringUtils.isEmpty(req.getProject())){
|
||||
projectConfigEntities = projectService.listProjectConfig(req.getProject());
|
||||
}else {
|
||||
return BaseResult.err("project not exist.");
|
||||
}
|
||||
if (projectConfigEntities == null) {
|
||||
return BaseResult.err("failed.");
|
||||
}
|
||||
|
||||
return BaseResult.success(200, projectConfigEntities);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.mhhy.enums;
|
||||
|
||||
public interface BaseEnum {
|
||||
|
||||
int getEnumCode();
|
||||
|
||||
//BaseEnum valueOf(int enumCode);
|
||||
|
||||
default String i18nKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.mhhy.enums;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.converter.ConverterFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class EnumTypeConverterFactory implements ConverterFactory<String, BaseEnum> {
|
||||
|
||||
private static final Map<Class, Converter> converterMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public <T extends BaseEnum> Converter<String, T> getConverter(Class<T> targetType) {
|
||||
Converter result = converterMap.get(targetType);
|
||||
if (result == null) {
|
||||
result = new IntegerStrToEnum<T>(targetType);
|
||||
converterMap.put(targetType, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private class IntegerStrToEnum<T extends BaseEnum> implements Converter<String, T> {
|
||||
private final Class<T> enumType;
|
||||
private Map<String, T> enumMap = new HashMap<>();
|
||||
|
||||
public IntegerStrToEnum(Class<T> enumType) {
|
||||
this.enumType = enumType;
|
||||
T[] enums = enumType.getEnumConstants();
|
||||
for (T e : enums) {
|
||||
enumMap.put(e.getEnumCode() + "", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T convert(String source) {
|
||||
T result = enumMap.get(source);
|
||||
if (result == null) {
|
||||
//throw new IllegalArgumentException("No element matches " + source);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.mhhy.enums;
|
||||
|
||||
public enum ResultCodeEnum {
|
||||
|
||||
SUCCESS(0, "success"),//请求成功
|
||||
BAD_REQUEST(400, "错误请求"),//错误请求
|
||||
UN_AUTHORIZATION(401, "请登录"),//该钱包已在其他设备登录
|
||||
NOT_REPEAT_SEND_SMS(402, "请勿重发短信"),
|
||||
SERVER_EXCEPTION(500, "网络异常"),//网络异常
|
||||
BALANCE_NOT_ENOUGH(600, "余额不足"),//网络异常
|
||||
PAY_ORDER(700, "支付失败"),//网络异常
|
||||
DATA_ORDER(800, "数据异常"),//网络异常
|
||||
|
||||
ACCOUNT_ALREADY(1000, "user already exist"),
|
||||
PASSWORD_ERROR(1001, "wrong password"),
|
||||
ACCOUNT_NOT_EXIST(1002, "User not exist"),
|
||||
IM_REGISTER_FAILED(1003, "register im account failed."),
|
||||
DB_ERROR(1004, "db error."),
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
private final int code;
|
||||
private final String remark;
|
||||
|
||||
ResultCodeEnum(int code, String remark) {
|
||||
this.code = code;
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.mhhy.enums;
|
||||
|
||||
public enum UserStateEnum {
|
||||
|
||||
ENABLE(0, "未启用"),
|
||||
NORMAL(1, "正常"),
|
||||
DISABLE(2, "禁用")
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
private final int code;
|
||||
private final String remark;
|
||||
|
||||
UserStateEnum(int code, String remark) {
|
||||
this.code = code;
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.mhhy.enums;
|
||||
|
||||
public enum UserTypeEnum {
|
||||
|
||||
ADMIN(1, "管理员"),
|
||||
CUSTOMER(2, "客服"),
|
||||
NORMAL(3, "普通用户")
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
private final int code;
|
||||
private final String remark;
|
||||
|
||||
UserTypeEnum(int code, String remark) {
|
||||
this.code = code;
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.mhhy.exception;
|
||||
|
||||
public class CheckException extends RuntimeException {
|
||||
public CheckException() {
|
||||
}
|
||||
|
||||
public CheckException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public CheckException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public CheckException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public CheckException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.mhhy.exception;
|
||||
|
||||
|
||||
|
||||
import com.mhhy.common.BaseResult;
|
||||
import com.mhhy.enums.ResultCodeEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@ControllerAdvice
|
||||
public class ErrorHandler {
|
||||
|
||||
@ResponseBody
|
||||
@ExceptionHandler(RuntimeException.class)
|
||||
public BaseResult<?> handleRuntimeException(RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
ResultCodeEnum resultCodeEnum = ResultCodeEnum.SERVER_EXCEPTION;
|
||||
return new BaseResult<>(resultCodeEnum.getCode(), resultCodeEnum.getRemark());
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@ExceptionHandler(OdcException.class)
|
||||
public BaseResult<?> handleException(OdcException e) {
|
||||
//log.debug("{}: {}, {}", e.getCode(), e.getResultCodeEnum().getRemark(), e.getOtherInfo());
|
||||
//String resultEnumMsg = MessageUtil.getResultMsg(e.getCode());
|
||||
BaseResult<Map<String, ?>> result = new BaseResult<>(e.getCode(), e.getMessage());
|
||||
result.setData(e.getOtherInfo());
|
||||
return result;
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@ExceptionHandler(IllegalArgumentException.class)
|
||||
public BaseResult<?> handleException(IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
int code = ResultCodeEnum.BAD_REQUEST.getCode();
|
||||
return new BaseResult<>(code, e.getMessage());
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
public BaseResult<?> handleException(MethodArgumentNotValidException e) {
|
||||
e.printStackTrace();
|
||||
int code = ResultCodeEnum.BAD_REQUEST.getCode();
|
||||
return new BaseResult<>(code, e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.mhhy.exception;
|
||||
|
||||
import com.mhhy.enums.ResultCodeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class OdcException extends RuntimeException {
|
||||
|
||||
private int code;
|
||||
|
||||
private ResultCodeEnum resultCodeEnum;
|
||||
|
||||
private Map<String, ?> otherInfo;
|
||||
|
||||
public OdcException(ResultCodeEnum codeEnum) {
|
||||
super(codeEnum.getRemark());
|
||||
code = codeEnum.getCode();
|
||||
resultCodeEnum = codeEnum;
|
||||
}
|
||||
|
||||
public OdcException(ResultCodeEnum codeEnum, Map<String, ?> otherInfo) {
|
||||
super(codeEnum.getRemark());
|
||||
this.code = codeEnum.getCode();
|
||||
this.otherInfo = otherInfo;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public ResultCodeEnum getResultCodeEnum() {
|
||||
return resultCodeEnum;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.mhhy.interceptor;
|
||||
|
||||
|
||||
|
||||
import com.mhhy.annotation.Login;
|
||||
import com.mhhy.util.RedisUtil;
|
||||
import com.mhhy.util.RequestUtil;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author zcw
|
||||
* @version 1.0
|
||||
* @date 2019/11/21 21:53
|
||||
* @description 授权认证
|
||||
*/
|
||||
@Log4j2
|
||||
@Configuration
|
||||
@Component(value = "authInterceptor")
|
||||
public class AuthInterceptor extends HandlerInterceptorAdapter {
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
|
||||
if (!(handler instanceof HandlerMethod)) {
|
||||
return true;
|
||||
}
|
||||
Login login = ((HandlerMethod) handler).getMethodAnnotation(Login.class);
|
||||
if (login == null) {
|
||||
return true;
|
||||
}
|
||||
if (login.encrypted()) {
|
||||
return true;
|
||||
}
|
||||
//已登录的接口,限制同一个接口,每两秒最多只能调一次
|
||||
int userId = RequestUtil.getMainUserId();
|
||||
String path = request.getServletPath();
|
||||
String method = request.getMethod();
|
||||
if ("GET".equalsIgnoreCase(method)) {
|
||||
return true;
|
||||
}
|
||||
String cacheKey = String.format("vex:apiLimit:%d-%s-%s", userId, method, path);
|
||||
if (RedisUtil.setNx(cacheKey, "0")) {
|
||||
RedisUtil.expire(cacheKey, 2);
|
||||
return true;
|
||||
}
|
||||
throw new IllegalArgumentException("请勿重复点击");//请勿重复点击 Please do not click repeatedly
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.mhhy.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.mhhy.model.entity.AdminEntity;
|
||||
|
||||
|
||||
public interface AdminMapper extends BaseMapper<AdminEntity> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.mhhy.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.mhhy.model.entity.AppVersionEntity;
|
||||
|
||||
public interface AppVersionEntityMapper extends BaseMapper<AppVersionEntity> {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.mhhy.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.mhhy.model.entity.CustomerEntity;
|
||||
import com.mhhy.model.entity.ProjectConfigEntity;
|
||||
|
||||
public interface CustomerMapper extends BaseMapper<CustomerEntity> {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.mhhy.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.mhhy.model.entity.CustomerEntity;
|
||||
import com.mhhy.model.entity.GroupEntity;
|
||||
|
||||
public interface GroupMapper extends BaseMapper<GroupEntity> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.mhhy.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.mhhy.model.entity.ProjectConfigEntity;
|
||||
|
||||
public interface ProjectConfigMapper extends BaseMapper<ProjectConfigEntity> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.mhhy.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.mhhy.model.entity.UserEntity;
|
||||
|
||||
public interface UserMapper extends BaseMapper<UserEntity> {
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.mhhy.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@TableName("t_admin")
|
||||
public class AdminEntity {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
private String username;
|
||||
|
||||
private String password;
|
||||
|
||||
private int level;
|
||||
|
||||
private int state;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.mhhy.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@TableName("t_app_version")
|
||||
public class AppVersionEntity {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty("apk下载链接")
|
||||
private String apkUrl;
|
||||
|
||||
@ApiModelProperty("是否强制更新e否1是")
|
||||
private Integer updateVersion;
|
||||
|
||||
@ApiModelProperty("安卓版本号")
|
||||
private Integer androidCode;
|
||||
|
||||
@ApiModelProperty("android版本号名称")
|
||||
private String androidVersion;
|
||||
|
||||
@ApiModelProperty("ios版本号")
|
||||
private Integer iosCode;
|
||||
|
||||
@ApiModelProperty("描述")
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty("ios版本号名称")
|
||||
private String iosVersion;
|
||||
|
||||
@ApiModelProperty("代理商用户==username")
|
||||
private String user;
|
||||
|
||||
@ApiModelProperty("1:管理员\\r\\n2:代理商\\r\\n3:普通用户")
|
||||
private Integer state;
|
||||
|
||||
@ApiModelProperty("0:正常\\r\\n1:禁用")
|
||||
private Integer isShow;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
private Date updateTime;
|
||||
|
||||
@ApiModelProperty("ios下载链接")
|
||||
private String iosUrl;
|
||||
@ApiModelProperty("安卓是否显示更新")
|
||||
private Integer androidShow;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.mhhy.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@TableName("t_customer")
|
||||
public class CustomerEntity {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String osnId;
|
||||
|
||||
private String portrait;
|
||||
|
||||
private String project;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.mhhy.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@TableName("t_group")
|
||||
public class GroupEntity {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String osnId;
|
||||
|
||||
private String portrait;
|
||||
|
||||
private String project;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.mhhy.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@TableName("t_config")
|
||||
public class ProjectConfigEntity {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
private String project;
|
||||
|
||||
private String config;
|
||||
|
||||
private String config2;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.mhhy.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@TableName("t_user")
|
||||
public class UserEntity {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty("用户名")
|
||||
private String username;
|
||||
|
||||
@ApiModelProperty("密码")
|
||||
private String password;
|
||||
|
||||
@ApiModelProperty("im id")
|
||||
private String imId;
|
||||
|
||||
@ApiModelProperty("im用户名")
|
||||
private String imUsername;
|
||||
|
||||
@ApiModelProperty("im密码")
|
||||
private String imPwd;
|
||||
|
||||
@ApiModelProperty("im node")
|
||||
private String imNode;
|
||||
|
||||
@ApiModelProperty("nick name")
|
||||
private String nickName;
|
||||
|
||||
@ApiModelProperty("1:管理员\\r\\n2:代理商\\r\\n3:普通用户")
|
||||
private Integer state;
|
||||
|
||||
@ApiModelProperty("0:未启用\\r\\n1:正常\\r\\n2:禁用")
|
||||
private Integer type;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
private String project;
|
||||
|
||||
private String portrait;
|
||||
|
||||
|
||||
public boolean isSetPassword() {
|
||||
if (password == null) {
|
||||
return false;
|
||||
}
|
||||
if (password.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.mhhy.model.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreateGroupReq {
|
||||
String user;
|
||||
String phoneOrEmail;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.mhhy.model.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CustomerReq {
|
||||
|
||||
private String project;
|
||||
|
||||
private String name;
|
||||
|
||||
private String osnId;
|
||||
|
||||
private String portrait;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.mhhy.model.req;
|
||||
|
||||
import com.ospn.command.CmdDappLogin;
|
||||
import com.ospn.command.CmdGetServerInfo;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DappRequest {
|
||||
public String command;
|
||||
public String user;
|
||||
public String sign;
|
||||
public String hash;
|
||||
public long random;
|
||||
|
||||
public CmdDappLogin getCmdDappLogin(String session){
|
||||
CmdDappLogin cmd = new CmdDappLogin();
|
||||
cmd.command = command;
|
||||
cmd.user = user;
|
||||
cmd.sign = sign;
|
||||
cmd.hash = hash;
|
||||
cmd.session = session;
|
||||
return cmd;
|
||||
}
|
||||
|
||||
public CmdGetServerInfo getCmdGetServerInfo(String session){
|
||||
CmdGetServerInfo cmd = new CmdGetServerInfo();
|
||||
cmd.command = command;
|
||||
cmd.user = user;
|
||||
cmd.random = random;
|
||||
cmd.session = session;
|
||||
return cmd;
|
||||
}
|
||||
public CmdGetServerInfo getCmdGetServerInfo(){
|
||||
CmdGetServerInfo cmd = new CmdGetServerInfo();
|
||||
cmd.command = command;
|
||||
cmd.user = user;
|
||||
cmd.random = random;
|
||||
cmd.session = null;
|
||||
return cmd;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.mhhy.model.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class FindAppVersionReq {
|
||||
|
||||
private int page;
|
||||
|
||||
private int limit;
|
||||
|
||||
private String user;
|
||||
|
||||
private Integer id;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.mhhy.model.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class FindUserReq {
|
||||
|
||||
private int page;
|
||||
|
||||
private int limit;
|
||||
|
||||
private String osnId;
|
||||
|
||||
private String project;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.mhhy.model.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GroupReq {
|
||||
|
||||
private String project;
|
||||
|
||||
private String name;
|
||||
|
||||
private String osnId;
|
||||
|
||||
private String portrait;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.mhhy.model.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LoginReq {
|
||||
|
||||
private String username;
|
||||
|
||||
private String account;
|
||||
|
||||
private String password;
|
||||
|
||||
private String nickName;
|
||||
|
||||
private String smsCode;
|
||||
|
||||
private String picCode;
|
||||
|
||||
private String data;
|
||||
|
||||
private String user;
|
||||
|
||||
private String project;
|
||||
|
||||
private String invite;
|
||||
|
||||
private String url;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.mhhy.model.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class NodeRegisterReq {
|
||||
|
||||
private String data;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.mhhy.model.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ProjectReq {
|
||||
|
||||
private String project;
|
||||
|
||||
private String config;
|
||||
|
||||
private String config2;
|
||||
|
||||
private String portrait;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.mhhy.model.req;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RegisterReq {
|
||||
|
||||
private String username;
|
||||
|
||||
private String account;
|
||||
|
||||
private String password;
|
||||
|
||||
private String nickName;
|
||||
|
||||
private String smsCode;
|
||||
|
||||
private String picCode;
|
||||
|
||||
private String data;
|
||||
|
||||
private String key;
|
||||
|
||||
private int level;
|
||||
private String project;
|
||||
|
||||
public RegisterReq() {
|
||||
|
||||
}
|
||||
|
||||
public RegisterReq(String param) {
|
||||
try {
|
||||
JSONObject json = JSONObject.parseObject(param);
|
||||
username = json.getString("username");
|
||||
password = json.getString("password");
|
||||
nickName = json.getString("nickName");
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.mhhy.model.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ReqBase {
|
||||
private String data;
|
||||
private String url;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.mhhy.model.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UpdatePasswdReq {
|
||||
private String username;
|
||||
|
||||
private String password;
|
||||
private String oldPassword;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.mhhy.model.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LoginResp {
|
||||
|
||||
private String token;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.mhhy.model.struct;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.mhhy.model.entity.UserEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ImInfoVer2 {
|
||||
|
||||
public List<OsnUser> osn_users;
|
||||
public String service_id;
|
||||
public boolean password = true;
|
||||
public JSONObject json;
|
||||
|
||||
public ImInfoVer2(UserEntity user, JSONObject jsonObject, String sid) {
|
||||
json = jsonObject;
|
||||
service_id = sid;
|
||||
osn_users = new ArrayList<>();
|
||||
OsnUser osnUser = new OsnUser(user);
|
||||
osn_users.add(osnUser);
|
||||
}
|
||||
|
||||
/*"Token": "b568c30a-7751-4d64-934a-2286ca1139b1",
|
||||
"Expires": "1694164789",
|
||||
"Refresh_Token": "OXiVGJp5eCQlZlb0kI6451Au3SMzVfXH",
|
||||
"Refresh_Token_Expires": "1699348789",
|
||||
|
||||
"UserInfo"
|
||||
|
||||
"ImInfo":*/
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.mhhy.model.struct;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.mhhy.model.entity.UserEntity;
|
||||
|
||||
public class LoginResult {
|
||||
|
||||
public String Token = "b568c30a-7751-4d64-934a-2286ca1139b1";
|
||||
public String Expires = "1694164789";
|
||||
public String Refresh_Token = "OXiVGJp5eCQlZlb0kI6451Au3SMzVfXH";
|
||||
public String Refresh_Token_Expires = "1699348789";
|
||||
public UserInfoVer2 UserInfo;
|
||||
public ImInfoVer2 ImInfo;
|
||||
|
||||
public LoginResult(UserEntity user, JSONObject config, String sid) {
|
||||
UserInfo = new UserInfoVer2(user);
|
||||
ImInfo = new ImInfoVer2(user, config, sid);
|
||||
}
|
||||
|
||||
public JSONObject toJson() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("Token", Token);
|
||||
json.put("Expires", Expires);
|
||||
json.put("Refresh_Token", Refresh_Token);
|
||||
json.put("Refresh_Token_Expires", Refresh_Token_Expires);
|
||||
json.put("UserInfo", UserInfo);
|
||||
json.put("ImInfo", ImInfo);
|
||||
|
||||
return json;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.mhhy.model.struct;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class NodeGetUserData {
|
||||
private String user;
|
||||
|
||||
public NodeGetUserData(JSONObject json){
|
||||
user = json.getString("user");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.mhhy.model.struct;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
public class NodeRegisterData {
|
||||
public String IP;
|
||||
public String region;
|
||||
|
||||
public NodeRegisterData(JSONObject json){
|
||||
IP = json.getString("IP");
|
||||
region = json.getString("region");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.mhhy.model.struct;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
@Data
|
||||
public class NodeSetUsingData {
|
||||
private String user;
|
||||
private String node;
|
||||
private int state = 0;
|
||||
|
||||
public NodeSetUsingData(JSONObject json){
|
||||
user = json.getString("user");
|
||||
node = json.getString("node");
|
||||
state = json.getIntValue("state");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.mhhy.model.struct;
|
||||
|
||||
import com.mhhy.model.entity.UserEntity;
|
||||
|
||||
public class OsnUser {
|
||||
public String osn_id; //: "OSNUiHLZ1XaDcV6MjarXvQUoo6hSzJYBFGUbJ6AXbW3vb8uNDL9LLtgk72c9cidF9V152q3BjwG4YN",
|
||||
public String osn_username; //: "bd9a4aa9774220ad4c0c",
|
||||
public String osn_password; //: "VER2-VK0MHcCAQEEIAABdS7Igb/rV9A+NiHujrpgl900yQ25SPGuYHDRqde/oAoGCCqGSM49AwEHoUQDQgAE1fPNCotCuh49lYrjHLqnMhx3d6f3IG+eM0WEIwNVrjszmG2ARcCPXOGt7PFXdZQdEwxQdfHbspIiYpNH86in+Q==-MHcCAQEEIE3B3LONlmxLjMy3ofwAo4qpcdCHzyMbL6+XndTEoBrMoAoGCCqGSM49AwEHoUQDQgAEKbtW4NBM64a68V48Jp9fR85WNzVebo7o3ldrV1hGRBoX4qO+DPulHxjKDKNbQOqHH+ihU/+yrFh1PQa+XcE5ng==",
|
||||
public String userId; //: "f3739c0075e0d176bce405f017eec587",
|
||||
public String corpName; //: null,
|
||||
public boolean admin = false; //: false,
|
||||
public String osn_node; //: "39.100.133.144",
|
||||
public String nickName; //: null,
|
||||
public String cornet; //: null,
|
||||
public String headUrl; //": null,
|
||||
public boolean def = true; //: true
|
||||
|
||||
public OsnUser(UserEntity user) {
|
||||
osn_id = user.getImId();
|
||||
osn_username = user.getUsername();
|
||||
osn_password = user.getImPwd();
|
||||
userId = user.getId().toString();
|
||||
osn_node = user.getImNode();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.mhhy.model.struct;
|
||||
|
||||
import lombok.Data;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class ServiceInfo {
|
||||
int id;
|
||||
|
||||
String iconUrl;
|
||||
|
||||
String serviceName;
|
||||
|
||||
String url;
|
||||
|
||||
String serviceRemark;
|
||||
|
||||
String appRemark;
|
||||
|
||||
String appIntroduction;
|
||||
|
||||
String createTime;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.mhhy.model.struct;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserCreateOrderData {
|
||||
int lifecycle;
|
||||
String pay_id;
|
||||
|
||||
public UserCreateOrderData(JSONObject json){
|
||||
lifecycle = json.getIntValue("lifecycle");
|
||||
pay_id = json.getString("payId");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.mhhy.model.struct;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.mhhy.model.entity.UserEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class UserInfoVer2 {
|
||||
|
||||
public String F_UserId;
|
||||
public String F_Account;
|
||||
public String F_EnCode; //": null,
|
||||
public String F_RealName; //": null,
|
||||
public String F_HeadIcon; //": null,
|
||||
public String F_Mobile = ""; //
|
||||
public String F_Email; //": null,
|
||||
public String F_WeChat; //": null,
|
||||
public String F_Gender; //": null,
|
||||
public String F_Description; //": null,
|
||||
public String F_Company; //": null,
|
||||
public List<String> F_Department = new ArrayList<>(); //": [],
|
||||
public List<String> F_Role = new ArrayList<>(); //": []
|
||||
|
||||
public UserInfoVer2(UserEntity user) {
|
||||
F_UserId = user.getId().toString();
|
||||
F_Account = user.getUsername();
|
||||
}
|
||||
|
||||
public JSONObject toJson() {
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("F_UserId", F_UserId);
|
||||
json.put("F_Account", F_Account);
|
||||
json.put("F_EnCode", F_EnCode);
|
||||
json.put("F_RealName", F_RealName);
|
||||
json.put("F_HeadIcon", F_HeadIcon);
|
||||
json.put("F_Mobile", F_Mobile);
|
||||
json.put("F_Email", F_Email);
|
||||
json.put("F_WeChat", F_WeChat);
|
||||
json.put("F_Gender", F_Gender);
|
||||
json.put("F_Description", F_Description);
|
||||
json.put("F_Company", F_Company);
|
||||
json.put("F_Department", F_Department);
|
||||
json.put("F_Role", F_Role);
|
||||
|
||||
return json;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.mhhy.model.struct;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserQueryOrderData {
|
||||
String orderNo;
|
||||
String user;
|
||||
|
||||
public UserQueryOrderData(JSONObject json) {
|
||||
|
||||
orderNo = json.getString("orderNo");
|
||||
user = json.getString("user");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.mhhy.model.struct;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserQueryProductData {
|
||||
String user;
|
||||
|
||||
public UserQueryProductData(JSONObject json) {
|
||||
user = json.getString("user");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.mhhy.resolver;
|
||||
|
||||
|
||||
import com.mhhy.annotation.Login;
|
||||
import com.mhhy.util.CodecUtil;
|
||||
import com.mhhy.util.JsonUtil;
|
||||
import com.mhhy.util.StreamUtil;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.support.WebDataBinderFactory;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.context.request.ServletWebRequest;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
|
||||
@Component
|
||||
public class DecodeArgumentResolver implements HandlerMethodArgumentResolver {
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
Login login = parameter.getMethod().getAnnotation(Login.class);
|
||||
return login != null && login.encrypted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
|
||||
Class<?>[] params = parameter.getMethod().getParameterTypes();
|
||||
if (params.length != 1) {
|
||||
throw new RuntimeException("后台接口参数异常");
|
||||
}
|
||||
Class<?> targetClass = params[0];
|
||||
String body = CodecUtil.decodeURL(StreamUtil.getString(((ServletWebRequest) webRequest).getRequest().getInputStream()));
|
||||
if (body == null || body.trim().length() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//todo aes解密
|
||||
return JsonUtil.fromJson(body, targetClass);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.mhhy.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.mhhy.common.BaseResult;
|
||||
import com.mhhy.model.entity.AdminEntity;
|
||||
import com.mhhy.model.entity.UserEntity;
|
||||
|
||||
public interface AdminService extends IService<AdminEntity> {
|
||||
|
||||
boolean createAdmin(String username, String password);
|
||||
|
||||
boolean createCustomer(String username, String password);
|
||||
|
||||
AdminEntity findUser(String username);
|
||||
|
||||
boolean updatePassword(String username, String password);
|
||||
|
||||
boolean updateState(String username, int state);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.mhhy.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.mhhy.model.entity.AppVersionEntity;
|
||||
import com.mhhy.model.entity.UserEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AppVersionEntityService extends IService<AppVersionEntity> {
|
||||
|
||||
|
||||
List<AppVersionEntity> listAppVersionAll();
|
||||
|
||||
AppVersionEntity getUser();
|
||||
|
||||
boolean updateAppVersion(AppVersionEntity appVersionEntity);
|
||||
|
||||
List<AppVersionEntity> listAppVersion(int page, int limit);
|
||||
|
||||
List<AppVersionEntity> listAppVersionUser(int page, int limit, String user);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.mhhy.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.mhhy.model.entity.CustomerEntity;
|
||||
import com.mhhy.model.entity.ProjectConfigEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CustomerService extends IService<CustomerEntity> {
|
||||
|
||||
// 增
|
||||
boolean addObj(String name, String portrait, String osnId, String project);
|
||||
|
||||
// 查
|
||||
List<CustomerEntity> listAll();
|
||||
List<CustomerEntity> listByProject(String project);
|
||||
|
||||
// 改
|
||||
|
||||
// 删
|
||||
boolean deleteObj(String osnId, String project);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.mhhy.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.mhhy.model.entity.CustomerEntity;
|
||||
import com.mhhy.model.entity.GroupEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface GroupService extends IService<GroupEntity> {
|
||||
|
||||
// 增
|
||||
boolean addObj(String name, String portrait, String osnId, String project);
|
||||
|
||||
// 查
|
||||
List<GroupEntity> listAll();
|
||||
List<GroupEntity> listByProject(String project);
|
||||
|
||||
// 改
|
||||
|
||||
// 删
|
||||
boolean deleteObj(String osnId, String project);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.mhhy.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.mhhy.common.BaseResult;
|
||||
import com.mhhy.model.entity.UserEntity;
|
||||
import com.mhhy.model.req.LoginReq;
|
||||
import com.mhhy.model.req.RegisterReq;
|
||||
import com.mhhy.model.resp.LoginResp;
|
||||
|
||||
public interface LoginService {
|
||||
|
||||
BaseResult register(RegisterReq registerReq);
|
||||
BaseResult register2(RegisterReq registerReq);
|
||||
BaseResult register4(RegisterReq registerReq, String key);
|
||||
BaseResult register5(RegisterReq registerReq, String key, String UserPwd, String owner2);
|
||||
|
||||
String[] createAccount();
|
||||
|
||||
JSONObject register3(RegisterReq registerReq);
|
||||
UserEntity register6(String imId, String owner2, String project);
|
||||
|
||||
BaseResult login(LoginReq loginReq);
|
||||
|
||||
BaseResult getChallenge(String userName);
|
||||
|
||||
JSONObject getConfig();
|
||||
|
||||
String createGroup(String groupName, String owner);
|
||||
|
||||
String getHostIp();
|
||||
|
||||
boolean disableOrEnableUser(String osnId, boolean enable);
|
||||
|
||||
String getRegisterKey();
|
||||
}
|
||||
@@ -0,0 +1,686 @@
|
||||
package com.mhhy.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.mhhy.model.entity.CustomerEntity;
|
||||
import com.mhhy.model.entity.GroupEntity;
|
||||
import com.mhhy.model.entity.UserEntity;
|
||||
import com.ospn.command.CmdDappLogin;
|
||||
import com.ospn.command.CmdReDappLogin;
|
||||
import com.ospn.common.OsnServer;
|
||||
import com.ospn.common.OsnUtils;
|
||||
import com.ospn.core.ILTPEvent;
|
||||
import com.ospn.core.LTPData;
|
||||
import com.ospn.utils.CryptUtils;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import static com.ospn.utils.CryptUtils.makeMessage;
|
||||
import static com.ospn.utils.CryptUtils.takeMessage;
|
||||
|
||||
@Service
|
||||
public class LtpServer extends OsnServer implements ILTPEvent {
|
||||
|
||||
//@Autowired
|
||||
//public IDeviceService deviceService;
|
||||
//@Autowired
|
||||
//private MyJPushClient myJPushClient;
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@Autowired
|
||||
GroupService groupService;
|
||||
|
||||
@Autowired
|
||||
CustomerService customerService;
|
||||
|
||||
|
||||
public static LTPData ltpData;
|
||||
|
||||
public static String custormer;
|
||||
|
||||
static RunnerThread runner;
|
||||
|
||||
private ConcurrentHashMap<String, List<String>> pushDataMap = new ConcurrentHashMap<>();
|
||||
|
||||
static String password="password123";
|
||||
|
||||
|
||||
public LtpServer(){
|
||||
init();
|
||||
}
|
||||
|
||||
void init(){
|
||||
|
||||
if (ltpData != null){
|
||||
return;
|
||||
}
|
||||
ltpData = new LTPData();
|
||||
|
||||
try {
|
||||
|
||||
InputStream in = new FileInputStream("ospn.properties");
|
||||
Properties prop = new Properties();
|
||||
prop.load(in);
|
||||
|
||||
custormer = prop.getProperty("customer");
|
||||
System.out.println("[custormer]" + custormer);
|
||||
|
||||
ltpData.init(prop, password,this);
|
||||
in.close();
|
||||
|
||||
prop.put("appID", ltpData.apps.osnID);
|
||||
String encPrivateKey = OsnUtils.aesEncrypt(ltpData.apps.osnKey, password);
|
||||
prop.put("appKey", encPrivateKey);
|
||||
|
||||
FileOutputStream oFile = new FileOutputStream("ospn.properties", false);
|
||||
prop.store(oFile, "Comments");
|
||||
|
||||
oFile.close();
|
||||
|
||||
}catch (Exception e){
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getAppId(){
|
||||
if (ltpData == null){
|
||||
init();
|
||||
}
|
||||
if (ltpData == null){
|
||||
return null;
|
||||
}
|
||||
return ltpData.apps.osnID;
|
||||
}
|
||||
|
||||
public JSONObject makeResult(String to, JSONObject data){
|
||||
|
||||
try {
|
||||
JSONObject json = CryptUtils.makeMessage(
|
||||
"Message",
|
||||
ltpData.apps.osnID,
|
||||
to,
|
||||
data,
|
||||
ltpData.apps.osnKey,
|
||||
(JSONObject)null);
|
||||
return json;
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
return new JSONObject();
|
||||
}
|
||||
|
||||
public void sendCommand(String command, String groupID, JSONObject json){
|
||||
|
||||
// 先扔队列里
|
||||
if (command.equalsIgnoreCase("SystemNotify")) {
|
||||
SendCommandInfo info = new SendCommandInfo(command, groupID, json);
|
||||
push(info);
|
||||
} else {
|
||||
if (ltpData != null){
|
||||
ltpData.sendJson(command, groupID, json);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void sendMessage(String to, JSONObject json){
|
||||
if (ltpData != null){
|
||||
ltpData.sendMessage(to, json);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendNotice2UserByAddBalance(String to, long balance, String txid, JSONObject json){
|
||||
|
||||
JSONObject content = new JSONObject();
|
||||
content.put("type", "text");
|
||||
float bal1 = balance;
|
||||
bal1 = bal1 / 100;
|
||||
|
||||
String coin = "";
|
||||
if (json != null) {
|
||||
if (json.containsKey("coinType")) {
|
||||
coin = json.getString("coinType") + " ";
|
||||
}
|
||||
}
|
||||
|
||||
String text = "[DM wallet test system notice]\r\n" +
|
||||
"Account balance changes, receive " + coin +
|
||||
String.format("%.2f.\r\n", bal1) +
|
||||
"txid:" + txid;
|
||||
content.put("data", text);
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("content", content);
|
||||
|
||||
// 扔队列里去
|
||||
SendCommandInfo info = new SendCommandInfo("Message", to, data);
|
||||
push(info);
|
||||
|
||||
/*if (ltpData != null){
|
||||
ltpData.sendMessage(to, data);
|
||||
}*/
|
||||
}
|
||||
|
||||
public void sendNotice2UserBySubBalance(String to, long balance, String txid, JSONObject json){
|
||||
|
||||
JSONObject content = new JSONObject();
|
||||
content.put("type", "text");
|
||||
float bal1 = balance;
|
||||
bal1 = bal1 / 100;
|
||||
|
||||
String coin = "";
|
||||
if (json != null) {
|
||||
if (json.containsKey("coinType")) {
|
||||
coin = json.getString("coinType") + " ";
|
||||
}
|
||||
}
|
||||
|
||||
String text = "[DM wallet test system notice]\r\n" +
|
||||
"Account balance changes, send " + coin +
|
||||
String.format("%.2f.\r\n", bal1) +
|
||||
"txid:" + txid;
|
||||
content.put("data", text);
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("content", content);
|
||||
|
||||
// 扔队列里去
|
||||
SendCommandInfo info = new SendCommandInfo("Message", to, data);
|
||||
push(info);
|
||||
|
||||
/*if (ltpData != null){
|
||||
ltpData.sendMessage(to, data);
|
||||
}*/
|
||||
}
|
||||
|
||||
public void sendNotice2UserByWithdrawal(String to){
|
||||
|
||||
JSONObject content = new JSONObject();
|
||||
content.put("type", "text");
|
||||
String text = "[J-Talking system notice]\r\n" +
|
||||
"Withdrawal success.";
|
||||
content.put("data", text);
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("content", content);
|
||||
|
||||
if (ltpData != null){
|
||||
ltpData.sendMessage(to, data);
|
||||
}
|
||||
}
|
||||
|
||||
public void getUserInfo(String osnID) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("command", "GetUserInfo");
|
||||
json.put("from", this.ltpData.apps.osnID);
|
||||
json.put("to", osnID);
|
||||
//System.out.println(json.toString()+"JSONsend");
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
// 扔队列里去
|
||||
SendCommandInfo info = new SendCommandInfo("GetUserInfo", osnID, data);
|
||||
push(info);
|
||||
|
||||
// ltpData.sendJson(json);
|
||||
}
|
||||
|
||||
public void getGroupInfo(String osnID) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("command", "GetUserInfo");
|
||||
json.put("from", this.ltpData.apps.osnID);
|
||||
json.put("to", osnID);
|
||||
|
||||
//System.out.println(json.toString()+"JSONsend");
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
// 扔队列里去
|
||||
SendCommandInfo info = new SendCommandInfo("GetGroupInfo", osnID, data);
|
||||
push(info);
|
||||
|
||||
// ltpData.sendJson(json);
|
||||
}
|
||||
|
||||
public boolean login(CmdDappLogin cmd){
|
||||
CmdReDappLogin cmdRe = ltpData.login(cmd);
|
||||
|
||||
if (cmdRe.errCode == null){
|
||||
return false;
|
||||
}
|
||||
if (!cmdRe.errCode.equalsIgnoreCase("0:success")){
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getDappInfo(){
|
||||
JSONObject content = ltpData.dappInfo.toClientJson(ltpData.apps.osnKey);
|
||||
if (content == null){
|
||||
return "";
|
||||
}
|
||||
return content.toString();
|
||||
}
|
||||
|
||||
public void push(SendCommandInfo data){
|
||||
if (runner == null) {
|
||||
runner = new RunnerThread();
|
||||
runner.start();
|
||||
}
|
||||
runner.push(data);
|
||||
}
|
||||
|
||||
void sendNotice(JSONObject json){
|
||||
System.out.println("[sendNotice] send notice : " + json);
|
||||
String groupId = json.getString("groupID");
|
||||
if (groupId == null){
|
||||
return;
|
||||
}
|
||||
System.out.println("[sendNotice] sendCommand");
|
||||
sendCommand("SystemNotify", groupId, json);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleMessage(ChannelHandlerContext channelHandlerContext, JSONObject jsonObject) {
|
||||
|
||||
//System.out.println("[LtpServer::handleMessage] begin. " + jsonObject);
|
||||
|
||||
System.out.println("----------------handleMessage---------------------:"+jsonObject);
|
||||
// 处理收到的消息
|
||||
if (jsonObject == null){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
String command = jsonObject.getString("command");
|
||||
String to = jsonObject.getString("to");
|
||||
if (command == null || to == null){
|
||||
return;
|
||||
}
|
||||
|
||||
if (!to.equalsIgnoreCase(ltpData.apps.osnID)){
|
||||
System.out.println("[LtpServer::handleMessage] error, to is " + to);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//System.out.println("[handleMessage] begin!!!!!!");
|
||||
|
||||
if(command.equalsIgnoreCase("UserInfo")){
|
||||
|
||||
handleUserInfo(jsonObject);
|
||||
|
||||
} else if(command.equalsIgnoreCase("GroupInfo")){
|
||||
|
||||
handleGroupInfo(jsonObject);
|
||||
|
||||
} else if(command.equalsIgnoreCase("Message")){
|
||||
|
||||
JSONObject data = takeMessage(jsonObject);
|
||||
if(data == null) {
|
||||
return;
|
||||
}
|
||||
String command2 = data.getString("command");
|
||||
if (command2 != null) {
|
||||
if (command2.equalsIgnoreCase("PushInfo")) {
|
||||
|
||||
String user = data.getString("user");
|
||||
String type = data.getString("type");
|
||||
|
||||
List<String> cmdList = pushDataMap.get(user);
|
||||
if (cmdList == null) {
|
||||
cmdList = new ArrayList<>();
|
||||
pushDataMap.put(user, cmdList);
|
||||
}
|
||||
cmdList.add(type);
|
||||
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String commandID = data.getString("commandID");
|
||||
if (commandID == null){
|
||||
return;
|
||||
}
|
||||
System.out.println("commandID : " + commandID);
|
||||
String result = data.getString("result");
|
||||
if (result == null){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else if (command.equalsIgnoreCase("GetServiceInfo")){
|
||||
|
||||
String from = jsonObject.getString("from");
|
||||
if (from == null){
|
||||
return;
|
||||
}
|
||||
|
||||
JSONObject content = ltpData.dappInfo.toClientJson(ltpData.apps.osnKey);
|
||||
|
||||
System.out.println("[LtpServer::HandleMessage] dapp content : " + content);
|
||||
|
||||
JSONObject original = new JSONObject();
|
||||
original.put("id", jsonObject.getString("id"));
|
||||
|
||||
System.out.println("[LtpServer::HandleMessage] original id : " + original);
|
||||
|
||||
JSONObject returnData = makeMessage(
|
||||
"ServiceInfo",
|
||||
ltpData.apps.osnID,
|
||||
from,
|
||||
content,
|
||||
ltpData.apps.osnKey,
|
||||
original);
|
||||
|
||||
ltpData.sendJson(returnData);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void pushWorker(){
|
||||
|
||||
ConcurrentHashMap<String, List<String>> tempPushMap = pushDataMap;
|
||||
System.out.println("push data map size : " + tempPushMap.size());
|
||||
|
||||
pushDataMap = new ConcurrentHashMap<>();
|
||||
|
||||
System.out.println("push data map size : " + tempPushMap.size());
|
||||
Iterator<ConcurrentHashMap.Entry<String, List<String>>> iter = tempPushMap.entrySet().iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
ConcurrentHashMap.Entry<String, List<String>> entry = iter.next();
|
||||
// pushMessage(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void handleUserInfo(JSONObject json){
|
||||
|
||||
try {
|
||||
|
||||
System.out.println("[handleUserInfo] : "+json);
|
||||
json = JSONObject.parseObject(json.getString("content"));
|
||||
/**
|
||||
* TODO : 这里处理接收到的user info 信息
|
||||
* "userID" : osn id
|
||||
* "displayName" : 昵称
|
||||
* "describes"
|
||||
* "portrait" : 头像url
|
||||
* "urlSpace" :
|
||||
* **/
|
||||
|
||||
String displayName = json.getString("displayName");
|
||||
String portrait = json.getString("portrait");
|
||||
String userId = json.getString("userID");
|
||||
|
||||
UserEntity user = userService.getUser(userId);
|
||||
if (user != null) {
|
||||
user.setNickName(displayName);
|
||||
user.setPortrait(portrait);
|
||||
|
||||
userService.updateById(user);
|
||||
}
|
||||
|
||||
CustomerEntity customerEntity = customerService.getOne(new LambdaQueryWrapper<CustomerEntity>()
|
||||
.eq(CustomerEntity::getOsnId, userId)
|
||||
);
|
||||
if (customerEntity != null) {
|
||||
customerEntity.setName( displayName );
|
||||
customerEntity.setPortrait(portrait);
|
||||
customerService.updateById(customerEntity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void handleGroupInfo(JSONObject json){
|
||||
|
||||
try {
|
||||
|
||||
System.out.println("[handleUserInfo] : "+json);
|
||||
json = JSONObject.parseObject(json.getString("content"));
|
||||
/**
|
||||
* TODO : 这里处理接收到的user info 信息
|
||||
* "userID" : osn id
|
||||
* "displayName" : 昵称
|
||||
* "describes"
|
||||
* "portrait" : 头像url
|
||||
* "urlSpace" :
|
||||
* **/
|
||||
|
||||
String name = json.getString("name");
|
||||
String portrait = json.getString("portrait");
|
||||
String groupId = json.getString("groupID");
|
||||
|
||||
GroupEntity groupEntity = groupService.getOne(new LambdaQueryWrapper<GroupEntity>().eq(GroupEntity::getOsnId, groupId));
|
||||
if (groupEntity != null) {
|
||||
groupEntity.setName(name);
|
||||
groupEntity.setPortrait(portrait);
|
||||
|
||||
groupService.updateById(groupEntity);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//public void pushMessage(String user, List<String> cmdList){
|
||||
//
|
||||
// // 根据device表中的vendor决定使用什么推送
|
||||
// // iphone
|
||||
// // Xiaomi 使用小米推送
|
||||
// // huawei
|
||||
// // OPPO
|
||||
// // vivo
|
||||
// // FCM 使用极光
|
||||
//
|
||||
// System.out.println("推送开始------");
|
||||
//
|
||||
// String content = "You have " +cmdList.size()+ " new message.";
|
||||
// String alias = genAlias(user);
|
||||
//
|
||||
// Device device = deviceService.getByOsnId(user);
|
||||
// if (device != null) {
|
||||
// String vendor = device.getVendor();
|
||||
// switch (vendor) {
|
||||
//
|
||||
// case "Xiaomi":
|
||||
// pushToXiaomi(alias, "new message", content);
|
||||
// break;
|
||||
//
|
||||
// case "apple":
|
||||
// pushJiguangToId(device.getDevice(), "new message", content);
|
||||
// break;
|
||||
//
|
||||
// //default:
|
||||
// // pushJiguang(alias, "new message", content);
|
||||
// // break;
|
||||
// default:
|
||||
// firebase(device.getDevice(), "new message", content);
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
||||
//void firebase(String device, String title, String content){
|
||||
// myJPushClient.sendMsgFirebase(device, title, content);
|
||||
//}
|
||||
//
|
||||
//void pushToXiaomi(String alias, String title, String content){
|
||||
//
|
||||
// Constants.useOfficial();
|
||||
// Sender sender = new Sender("6jzbNMq0oMzsXQFCuSIeYA==");
|
||||
// String messagePayload = "This is a message";
|
||||
// String description = content;
|
||||
// com.xiaomi.xmpush.server.Message message = new com.xiaomi.xmpush.server.Message.Builder()
|
||||
// .title(title)
|
||||
// .description(description).payload(messagePayload)
|
||||
// .restrictedPackageName("cn.net.shuting.sns.weiliao")
|
||||
// .notifyType(2) // 使用默认提示音提示
|
||||
// .extra(Constants.EXTRA_PARAM_NOTIFY_EFFECT, Constants.NOTIFY_LAUNCHER_ACTIVITY)
|
||||
// .build();
|
||||
//
|
||||
//
|
||||
// try {
|
||||
// Result result = sender.sendToAlias(message, alias, 3);
|
||||
// /*Log.v("Server response: ", "MessageId: " + result.getMessageId()
|
||||
// + " ErrorCode: " + result.getErrorCode().toString()
|
||||
// + " Reason: " + result.getReason());*/
|
||||
// } catch (Exception e) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
//
|
||||
//void pushJiguang(String alias, String title, String content){
|
||||
// // 推送数据
|
||||
// Message message = new Message();
|
||||
//
|
||||
// System.out.println("push alias : " + alias);
|
||||
//
|
||||
// message.setUserId(alias);
|
||||
//
|
||||
// message.setMessageContent(content);
|
||||
//
|
||||
// myJPushClient.sendMsg(message);
|
||||
//}
|
||||
//
|
||||
//void pushJiguangToId(String registerId, String title, String content){
|
||||
// // 推送数据
|
||||
// Message message = new Message();
|
||||
//
|
||||
// System.out.println("push alias : " + registerId);
|
||||
//
|
||||
// message.setUserId(registerId);
|
||||
//
|
||||
// message.setMessageContent(content);
|
||||
//
|
||||
// myJPushClient.sendMsgToId(message);
|
||||
//}
|
||||
|
||||
static byte[] ToMD5(String str) {
|
||||
// 加密后的16进制字符串
|
||||
String hexStr = "";
|
||||
try {
|
||||
// 此 MessageDigest 类为应用程序提供信息摘要算法的功能
|
||||
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
||||
// 转换为MD5码
|
||||
byte[] digest = md5.digest(str.getBytes("utf-8"));
|
||||
return digest;
|
||||
//hexStr = ByteUtils.toHexString(digest);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static String genAlias(String user) {
|
||||
String alias = Base64.getUrlEncoder().encodeToString(ToMD5(user));
|
||||
return alias;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Data
|
||||
class SendCommandInfo{
|
||||
String command;
|
||||
String groupID;
|
||||
JSONObject json;
|
||||
long createTime;
|
||||
|
||||
public SendCommandInfo(String command, String to, JSONObject json){
|
||||
this.command = command;
|
||||
this.groupID = to;
|
||||
this.json = json;
|
||||
createTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class RunnerThread extends Thread {
|
||||
|
||||
final ConcurrentLinkedQueue<SendCommandInfo> dataList = new ConcurrentLinkedQueue<>();
|
||||
|
||||
public RunnerThread(){
|
||||
}
|
||||
|
||||
public void push(SendCommandInfo data) {
|
||||
|
||||
dataList.offer(data);
|
||||
synchronized (dataList){
|
||||
dataList.notify();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(){
|
||||
|
||||
while(true){
|
||||
try{
|
||||
if(dataList.isEmpty()){
|
||||
synchronized (dataList){
|
||||
dataList.wait();
|
||||
}
|
||||
}
|
||||
SendCommandInfo data = dataList.poll();
|
||||
|
||||
try {
|
||||
long createTime = data.getCreateTime();
|
||||
if (createTime + 5000 > System.currentTimeMillis()) {
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
|
||||
if (ltpData != null){
|
||||
ltpData.sendJson(data.getCommand(), data.getGroupID(), data.getJson());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
//logError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.mhhy.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.mhhy.common.BaseResult;
|
||||
import com.mhhy.model.entity.ProjectConfigEntity;
|
||||
import com.mhhy.model.entity.UserEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ProjectConfigService extends IService<ProjectConfigEntity> {
|
||||
|
||||
JSONObject getConfig(String project);
|
||||
String getDappInfo(String project);
|
||||
|
||||
List<ProjectConfigEntity> listProjectConfig(String project);
|
||||
boolean setConfig(String project, String config);
|
||||
boolean setConfig(String project, String config, String config2);
|
||||
|
||||
List<ProjectConfigEntity> listConfig();
|
||||
|
||||
boolean updateConfig(String project, String config);
|
||||
boolean updateConfig2(String project, String config);
|
||||
|
||||
boolean deleteConfig(String project);
|
||||
|
||||
List<ProjectConfigEntity> listProject(int page, int limit);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.mhhy.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.mhhy.common.BaseResult;
|
||||
import com.mhhy.model.entity.UserEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserService extends IService<UserEntity> {
|
||||
BaseResult updatePassword(String data);
|
||||
boolean updatePassword(String username, String password, String oldPassword);
|
||||
String findUser(String username);
|
||||
UserEntity findAdmin(String username);
|
||||
UserEntity getUser(String osnId);
|
||||
|
||||
UserEntity getById(Integer id);
|
||||
|
||||
List<UserEntity> listAdmin(int page, int limit);
|
||||
List<UserEntity> listUser(int page, int limit, String project);
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.mhhy.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mhhy.common.BaseResult;
|
||||
import com.mhhy.mapper.AdminMapper;
|
||||
import com.mhhy.mapper.UserMapper;
|
||||
import com.mhhy.model.entity.AdminEntity;
|
||||
import com.mhhy.model.entity.UserEntity;
|
||||
import com.mhhy.service.AdminService;
|
||||
import com.mhhy.service.UserService;
|
||||
import com.mhhy.util.PasswordUtil;
|
||||
import com.mhhy.util.RedisUtil;
|
||||
import com.mhhy.util.RequestUtil;
|
||||
import com.ospn.common.OsnUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service("adminServer")
|
||||
public class AdminServiceImpl extends ServiceImpl<AdminMapper, AdminEntity> implements AdminService {
|
||||
|
||||
public boolean createAdmin(String username, String password) {
|
||||
AdminEntity adminEntity = findUser(username) ;
|
||||
if (adminEntity != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
adminEntity = new AdminEntity();
|
||||
adminEntity.setUsername(username);
|
||||
adminEntity.setPassword(password);
|
||||
adminEntity.setState(1);
|
||||
adminEntity.setLevel(1);
|
||||
return this.save(adminEntity);
|
||||
}
|
||||
|
||||
public boolean createCustomer(String username, String password) {
|
||||
AdminEntity adminEntity = findUser(username) ;
|
||||
if (adminEntity != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
adminEntity = new AdminEntity();
|
||||
adminEntity.setUsername(username);
|
||||
adminEntity.setPassword(password);
|
||||
adminEntity.setState(1);
|
||||
adminEntity.setLevel(2);
|
||||
return this.save(adminEntity);
|
||||
}
|
||||
|
||||
public AdminEntity findUser(String username) {
|
||||
AdminEntity user = this.getOne(new LambdaQueryWrapper<AdminEntity>()
|
||||
.eq(AdminEntity::getUsername, username));
|
||||
if (user != null) {
|
||||
return user;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean updatePassword(String username, String password) {
|
||||
try {
|
||||
|
||||
AdminEntity adminEntity = findUser(username);
|
||||
if (adminEntity == null) {
|
||||
return false;
|
||||
}
|
||||
adminEntity.setPassword(password);
|
||||
return this.updateById(adminEntity);
|
||||
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateState(String username, int state) {
|
||||
try {
|
||||
|
||||
AdminEntity adminEntity = findUser(username);
|
||||
if (adminEntity == null) {
|
||||
return false;
|
||||
}
|
||||
adminEntity.setState(state);
|
||||
return this.updateById(adminEntity);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.mhhy.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mhhy.mapper.AppVersionEntityMapper;
|
||||
import com.mhhy.model.entity.AppVersionEntity;
|
||||
import com.mhhy.model.entity.UserEntity;
|
||||
import com.mhhy.service.AppVersionEntityService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class AppVersionEntityServiceImpl extends ServiceImpl<AppVersionEntityMapper, AppVersionEntity> implements AppVersionEntityService {
|
||||
|
||||
|
||||
public List<AppVersionEntity> listAppVersionAll() {
|
||||
List<AppVersionEntity> list = this.list();
|
||||
return list;
|
||||
}
|
||||
|
||||
public AppVersionEntity getUser() {
|
||||
String last = " ORDER BY id DESC LIMIT 1";
|
||||
List<AppVersionEntity> list = this.list(new LambdaQueryWrapper<AppVersionEntity>()
|
||||
.last(last));
|
||||
AppVersionEntity appVersionEntity = new AppVersionEntity();
|
||||
if (list.size()>0){
|
||||
appVersionEntity = list.get(0);
|
||||
}
|
||||
return appVersionEntity;
|
||||
}
|
||||
|
||||
public boolean updateAppVersion(AppVersionEntity appVersionEntity) {
|
||||
boolean save = this.save(appVersionEntity);
|
||||
return save;
|
||||
}
|
||||
|
||||
public List<AppVersionEntity> listAppVersion(int page, int limit) {
|
||||
String last = " limit " + (page - 1)*limit + "," + limit;
|
||||
List<AppVersionEntity> list = this.list(new LambdaQueryWrapper<AppVersionEntity>()
|
||||
.eq(AppVersionEntity::getState, 2)
|
||||
.last(last));
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<AppVersionEntity> listAppVersionUser(int page, int limit, String user) {
|
||||
String last = " limit " + (page - 1)*limit + "," + limit;
|
||||
List<AppVersionEntity> list = this.list(new LambdaQueryWrapper<AppVersionEntity>()
|
||||
.eq(AppVersionEntity::getState, 2)
|
||||
.eq(AppVersionEntity::getUser,user)
|
||||
.last(last));
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.mhhy.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mhhy.mapper.CustomerMapper;
|
||||
import com.mhhy.model.entity.CustomerEntity;
|
||||
import com.mhhy.service.CustomerService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CustomerServiceImpl
|
||||
extends ServiceImpl<CustomerMapper, CustomerEntity>
|
||||
implements CustomerService{
|
||||
|
||||
// 增
|
||||
public boolean addObj(String name, String portrait, String osnId, String project) {
|
||||
|
||||
CustomerEntity entity = new CustomerEntity();
|
||||
entity.setProject(project);
|
||||
entity.setName(name);
|
||||
entity.setOsnId(osnId);
|
||||
entity.setPortrait(portrait);
|
||||
return this.save(entity);
|
||||
}
|
||||
|
||||
// 查
|
||||
public List<CustomerEntity> listAll() {
|
||||
return this.list();
|
||||
}
|
||||
|
||||
public List<CustomerEntity> listByProject(String project) {
|
||||
|
||||
try {
|
||||
|
||||
return this.list(new LambdaQueryWrapper<CustomerEntity>().eq(CustomerEntity::getProject, project));
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// 改
|
||||
|
||||
// 删
|
||||
public boolean deleteObj(String osnId, String project) {
|
||||
return this.remove(new LambdaQueryWrapper<CustomerEntity>()
|
||||
.eq(CustomerEntity::getOsnId, osnId)
|
||||
.eq(CustomerEntity::getProject, project));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.mhhy.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mhhy.mapper.GroupMapper;
|
||||
import com.mhhy.model.entity.CustomerEntity;
|
||||
import com.mhhy.model.entity.GroupEntity;
|
||||
import com.mhhy.service.GroupService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class GroupServiceImpl
|
||||
extends ServiceImpl<GroupMapper, GroupEntity>
|
||||
implements GroupService{
|
||||
|
||||
// 增
|
||||
public boolean addObj(String name, String portrait, String osnId, String project) {
|
||||
|
||||
GroupEntity entity = new GroupEntity();
|
||||
entity.setProject(project);
|
||||
entity.setName(name);
|
||||
entity.setOsnId(osnId);
|
||||
entity.setPortrait(portrait);
|
||||
return this.save(entity);
|
||||
}
|
||||
|
||||
// 查
|
||||
public List<GroupEntity> listAll() {
|
||||
return this.list();
|
||||
}
|
||||
|
||||
public List<GroupEntity> listByProject(String project) {
|
||||
|
||||
try {
|
||||
|
||||
return this.list(new LambdaQueryWrapper<GroupEntity>().eq(GroupEntity::getProject, project));
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// 改
|
||||
|
||||
// 删
|
||||
public boolean deleteObj(String osnId, String project) {
|
||||
return this.remove(new LambdaQueryWrapper<GroupEntity>()
|
||||
.eq(GroupEntity::getOsnId, osnId)
|
||||
.eq(GroupEntity::getProject, project));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,149 @@
|
||||
package com.mhhy.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mhhy.common.BaseResult;
|
||||
import com.mhhy.enums.ResultCodeEnum;
|
||||
import com.mhhy.enums.UserStateEnum;
|
||||
import com.mhhy.enums.UserTypeEnum;
|
||||
import com.mhhy.mapper.ProjectConfigMapper;
|
||||
import com.mhhy.mapper.UserMapper;
|
||||
import com.mhhy.model.entity.ProjectConfigEntity;
|
||||
import com.mhhy.model.entity.UserEntity;
|
||||
import com.mhhy.model.req.LoginReq;
|
||||
import com.mhhy.model.req.RegisterReq;
|
||||
import com.mhhy.service.LoginService;
|
||||
import com.mhhy.service.LtpServer;
|
||||
import com.mhhy.service.ProjectConfigService;
|
||||
import com.mhhy.service.UserService;
|
||||
import com.mhhy.util.PasswordUtil;
|
||||
import com.mhhy.util.RandomUtil;
|
||||
import com.mhhy.util.RedisUtil;
|
||||
import com.mhhy.util.token.JwtUtil;
|
||||
import com.mysql.cj.util.Base64Decoder;
|
||||
import com.ospn.common.ECUtils;
|
||||
import com.ospn.common.OsnUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class ProjectConfigServiceImpl
|
||||
extends ServiceImpl<ProjectConfigMapper, ProjectConfigEntity>
|
||||
implements ProjectConfigService{
|
||||
|
||||
public JSONObject getConfig(String project){
|
||||
|
||||
ProjectConfigEntity entity = this.getOne(new LambdaQueryWrapper<ProjectConfigEntity>()
|
||||
.eq(ProjectConfigEntity::getProject, project));
|
||||
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
String temp = new String(Base64.getDecoder().decode(entity.getConfig()));
|
||||
if (temp == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
JSONObject json = JSONObject.parseObject(temp);
|
||||
return json;
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ProjectConfigEntity> listProjectConfig(String project){
|
||||
List<ProjectConfigEntity> list = this.list(new LambdaQueryWrapper<ProjectConfigEntity>()
|
||||
.eq(ProjectConfigEntity::getProject, project)
|
||||
);
|
||||
return list;
|
||||
}
|
||||
|
||||
// 增
|
||||
public boolean setConfig(String project, String config) {
|
||||
|
||||
ProjectConfigEntity entity = new ProjectConfigEntity();
|
||||
entity.setProject(project);
|
||||
entity.setConfig(config);
|
||||
|
||||
return this.save(entity);
|
||||
}
|
||||
|
||||
public boolean setConfig(String project, String config, String config2) {
|
||||
|
||||
ProjectConfigEntity entity = new ProjectConfigEntity();
|
||||
entity.setProject(project);
|
||||
entity.setConfig(config);
|
||||
entity.setConfig2(config2);
|
||||
|
||||
return this.save(entity);
|
||||
}
|
||||
|
||||
// 查
|
||||
public List<ProjectConfigEntity> listConfig() {
|
||||
return this.list();
|
||||
}
|
||||
|
||||
public String getDappInfo(String project) {
|
||||
|
||||
ProjectConfigEntity entity =
|
||||
this.getOne(new LambdaQueryWrapper<ProjectConfigEntity>()
|
||||
.eq(ProjectConfigEntity::getProject, project)
|
||||
);
|
||||
|
||||
if (entity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return entity.getConfig2();
|
||||
}
|
||||
|
||||
// 改
|
||||
public boolean updateConfig(String project, String config) {
|
||||
return this.update(new LambdaUpdateWrapper<ProjectConfigEntity>()
|
||||
.eq(ProjectConfigEntity::getProject,project)
|
||||
.set(ProjectConfigEntity::getConfig, config));
|
||||
}
|
||||
|
||||
public boolean updateConfig2(String project, String config) {
|
||||
return this.update(new LambdaUpdateWrapper<ProjectConfigEntity>()
|
||||
.eq(ProjectConfigEntity::getProject,project)
|
||||
.set(ProjectConfigEntity::getConfig2, config));
|
||||
}
|
||||
|
||||
// 删
|
||||
public boolean deleteConfig(String project) {
|
||||
return this.remove(new LambdaQueryWrapper<ProjectConfigEntity>().eq(ProjectConfigEntity::getProject, project));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProjectConfigEntity> listProject(int page, int limit) {
|
||||
String last = " limit " + (page - 1)*limit + "," + limit;
|
||||
List<ProjectConfigEntity> list = this.list(new LambdaQueryWrapper<ProjectConfigEntity>()
|
||||
.last(last));
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package com.mhhy.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mhhy.common.BaseResult;
|
||||
import com.mhhy.mapper.UserMapper;
|
||||
import com.mhhy.model.entity.UserEntity;
|
||||
import com.mhhy.service.UserService;
|
||||
import com.mhhy.util.*;
|
||||
import com.ospn.common.OsnUtils;
|
||||
import org.apache.catalina.User;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service("userService")
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> implements UserService {
|
||||
@Override
|
||||
public BaseResult updatePassword(String data) {
|
||||
try {
|
||||
UserEntity user = RequestUtil.getMainUser();
|
||||
if (user == null) {
|
||||
return BaseResult.err("user not login.");
|
||||
}
|
||||
|
||||
// 获取解密key
|
||||
// 解密data
|
||||
String plaintext = getPlaintext(data, user);
|
||||
if (plaintext == null) {
|
||||
|
||||
return BaseResult.err("Communication key error.");
|
||||
}
|
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject(plaintext);
|
||||
if (user == null) {
|
||||
return BaseResult.err("get password error.");
|
||||
}
|
||||
|
||||
// 如果有密码,还需要输入原始密码
|
||||
if (user.isSetPassword()) {
|
||||
String oldPwd = jsonObject.getString("oldPassword");
|
||||
if (!user.getPassword().equalsIgnoreCase(oldPwd)) {
|
||||
return BaseResult.err("old password error.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
//对新密码进行加密
|
||||
byte[] sha256Str = PasswordUtil.getSHA256Str(password);
|
||||
String newPassword = PasswordUtil.encoderBase64(sha256Str);
|
||||
user.setPassword(newPassword);
|
||||
this.updateById(user);
|
||||
|
||||
return BaseResult.success();
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
return BaseResult.err("I do not known.");
|
||||
}
|
||||
|
||||
private String getPlaintext(String encData, UserEntity user) {
|
||||
|
||||
try {
|
||||
String key = RedisUtil.get("Communicationkey:"+user.getImId());
|
||||
System.out.println("[getPlaintext] encData:" + encData);
|
||||
System.out.println("[getPlaintext] user:" + user.getImId());
|
||||
System.out.println("[getPlaintext] key:" + key);
|
||||
String plaint = OsnUtils.aesDecrypt(encData, key);
|
||||
System.out.println("[getPlaintext] plaint:" + plaint);
|
||||
return plaint;
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String findUser(String username) {
|
||||
UserEntity user = this.getOne(new LambdaQueryWrapper<UserEntity>()
|
||||
.eq(UserEntity::getUsername, username));
|
||||
if (user != null) {
|
||||
return user.getImId();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public UserEntity findAdmin(String username) {
|
||||
UserEntity user = this.getOne(new LambdaQueryWrapper<UserEntity>()
|
||||
.eq(UserEntity::getUsername, username)
|
||||
.eq(UserEntity::getState, 2)
|
||||
);
|
||||
|
||||
return user;
|
||||
|
||||
}
|
||||
|
||||
public UserEntity getUser(String osnId) {
|
||||
UserEntity user = this.getOne(new LambdaQueryWrapper<UserEntity>()
|
||||
.eq(UserEntity::getImId, osnId));
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
public UserEntity getById(Integer id) {
|
||||
UserEntity userEntity = this.getById(id);
|
||||
return userEntity;
|
||||
}
|
||||
|
||||
public List<UserEntity> listUser(int page, int limit, String project) {
|
||||
String last = " limit " + (page - 1)*limit + "," + limit;
|
||||
List<UserEntity> list = this.list(new LambdaQueryWrapper<UserEntity>()
|
||||
.eq(UserEntity::getProject, project)
|
||||
.last(last));
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<UserEntity> listAdmin(int page, int limit) {
|
||||
String last = " limit " + (page - 1)*limit + "," + limit;
|
||||
List<UserEntity> list = this.list(new LambdaQueryWrapper<UserEntity>()
|
||||
.eq(UserEntity::getState, 2)
|
||||
.last(last));
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updatePassword(String username, String password, String oldPassword) {
|
||||
UserEntity userEntity = new UserEntity();
|
||||
userEntity.setPassword(password);
|
||||
return this.update(userEntity, new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getUsername, username).eq(UserEntity::getPassword, oldPassword));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.mhhy.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.lang.reflect.Array;
|
||||
import java.security.Key;
|
||||
import java.security.Security;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
|
||||
@Slf4j
|
||||
public class Aes128Util {
|
||||
|
||||
/**
|
||||
* 加密 模式:AES/CBC/PKCS7Padding
|
||||
* @param content 明文
|
||||
* @return 密文
|
||||
*/
|
||||
public static String AESEncode(String content, byte[] keyByte) {
|
||||
|
||||
if (keyByte.length != 32){
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] salt = new byte[keyByte.length / 2];
|
||||
byte[] encryptKey = new byte[keyByte.length / 2];
|
||||
// keybyte 分成2个128字节的byte[]
|
||||
// 前一个作为salt
|
||||
// 后一个作为key
|
||||
System.arraycopy(keyByte,0, salt, 0, keyByte.length / 2);
|
||||
System.arraycopy(keyByte,keyByte.length / 2, encryptKey, 0, keyByte.length / 2);
|
||||
|
||||
// 初始化
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
// 转化成JAVA的密钥格式
|
||||
Key key = new SecretKeySpec(encryptKey, "AES");
|
||||
try {
|
||||
// 初始化cipher
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(salt));
|
||||
byte[] encryptedText = cipher.doFinal(content.getBytes());
|
||||
|
||||
return Base64.getEncoder().encodeToString(encryptedText);
|
||||
|
||||
//return new String(Hex.encodeHex(encryptedText)).replaceAll("\r\n", "");
|
||||
} catch (Exception e) {
|
||||
log.info("AESEncode error", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密
|
||||
* @param content 密文
|
||||
* @return 铭文
|
||||
*/
|
||||
public static String AESDecode(String content, byte[] keyByte) {
|
||||
|
||||
if (keyByte.length != 32){
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] salt = new byte[keyByte.length / 2];
|
||||
byte[] encryptKey = new byte[keyByte.length / 2];
|
||||
// keybyte 分成2个128字节的byte[]
|
||||
// 前一个作为salt
|
||||
// 后一个作为key
|
||||
System.arraycopy(keyByte,0, salt, 0, keyByte.length / 2);
|
||||
System.arraycopy(keyByte,keyByte.length / 2, encryptKey, 0, keyByte.length / 2);
|
||||
try {
|
||||
//byte[] raw = key.getBytes(StandardCharsets.UTF_8);
|
||||
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
|
||||
SecretKeySpec skeySpec = new SecretKeySpec(encryptKey, "AES");
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");
|
||||
IvParameterSpec ivParameter = new IvParameterSpec(salt);
|
||||
cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivParameter);
|
||||
try {
|
||||
//byte[] encrypted1 = Hex.decodeHex(content);// 先用base64解密
|
||||
byte[] encrypted1 = Base64.getDecoder().decode(content);
|
||||
byte[] original = cipher.doFinal(encrypted1);
|
||||
return new String(original);
|
||||
} catch (Exception e) {
|
||||
log.info(e.toString());
|
||||
return null;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.info(ex.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
//sha256加密
|
||||
byte[] sha256Str = PasswordUtil.getSHA256Str("123456");
|
||||
//AES加密
|
||||
String encrypt = Aes128Util.AESEncode("9121184", sha256Str);
|
||||
|
||||
System.out.println(encrypt);
|
||||
|
||||
String s = Aes128Util.AESDecode(encrypt, sha256Str);
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.mhhy.util;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
public final class CodecUtil {
|
||||
|
||||
/**
|
||||
* 将url编码
|
||||
*/
|
||||
public static String encodeURL(String source) {
|
||||
try {
|
||||
return URLEncoder.encode(source, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将url解码
|
||||
*/
|
||||
public static String decodeURL(String source) {
|
||||
try {
|
||||
return URLDecoder.decode(source, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.mhhy.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import static com.mhhy.service.impl.LoginServiceImpl.conversationFlag;
|
||||
|
||||
public class JsonUtil {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* 将 POJO 转为 JSON
|
||||
*/
|
||||
public static <T> String toJson(T obj) {
|
||||
String json;
|
||||
try {
|
||||
json = OBJECT_MAPPER.writeValueAsString(obj);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 JSON 转为 POJO
|
||||
*/
|
||||
public static <T> T fromJson(String json, Class<T> type) {
|
||||
T pojo;
|
||||
try {
|
||||
pojo = OBJECT_MAPPER.readValue(json, type);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return pojo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密并返回具体类型
|
||||
* @param data
|
||||
* @param userId
|
||||
* @param obj
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> T getResult(String data, int userId, Class<T> obj) {
|
||||
T pojo = null;
|
||||
try {
|
||||
//获取会话密钥
|
||||
String conversationId = RedisUtil.get(conversationFlag + userId);
|
||||
if (conversationId == null) {
|
||||
System.out.println("conversationId is null.");
|
||||
return null;
|
||||
}
|
||||
//对数据进行解密
|
||||
System.out.println("conversationId : " + conversationId);
|
||||
System.out.println("data : " + data);
|
||||
|
||||
byte[] bytes = PasswordUtil.getSHA256Str(conversationId);
|
||||
String result = Aes128Util.AESDecode(data, bytes);
|
||||
|
||||
System.out.println("result : " + result);
|
||||
|
||||
pojo = JsonUtil.fromJson(result, obj);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return pojo;
|
||||
}
|
||||
|
||||
public static String genResult(JSONObject json, int userId) {
|
||||
try {
|
||||
//获取会话密钥
|
||||
String conversationId = RedisUtil.get(conversationFlag + userId);
|
||||
//对数据进行解密
|
||||
byte[] bytes = PasswordUtil.getSHA256Str(conversationId);
|
||||
String result = Aes128Util.AESEncode(json.toString(), bytes);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.mhhy.util;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public class MD5 {
|
||||
|
||||
//十六进制下数字到字符的映射数组
|
||||
private final static String[] hexDigits = {"0", "1", "2", "3", "4",
|
||||
"5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* md5加密算法
|
||||
* @param originString
|
||||
* @return
|
||||
*/
|
||||
public static String encodeByMD5(String originString){
|
||||
if (originString != null){
|
||||
try{
|
||||
//创建具有指定算法名称的信息摘要
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
//使用指定的字节数组对摘要进行最后更新,然后完成摘要计算
|
||||
byte[] results = md.digest(originString.getBytes());
|
||||
//将得到的字节数组变成字符串返回
|
||||
String resultString = byteArrayToHexString(results);
|
||||
return resultString.toUpperCase();
|
||||
} catch(Exception ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static String encodeByMD5NoTUpperCase(String originString){
|
||||
StringBuffer sb = new StringBuffer(32);
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] array = md.digest(originString.getBytes("utf-8"));
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).toUpperCase().substring(1, 3));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
/**
|
||||
* 转换字节数组为十六进制字符串
|
||||
* @param
|
||||
* @return 十六进制字符串
|
||||
*/
|
||||
private static String byteArrayToHexString(byte[] b){
|
||||
StringBuffer resultSb = new StringBuffer();
|
||||
for (int i = 0; i < b.length; i++){
|
||||
resultSb.append(byteToHexString(b[i]));
|
||||
}
|
||||
return resultSb.toString();
|
||||
}
|
||||
|
||||
/** 将一个字节转化成十六进制形式的字符串 */
|
||||
private static String byteToHexString(byte b){
|
||||
int n = b;
|
||||
if (n < 0)
|
||||
n = 256 + n;
|
||||
int d1 = n / 16;
|
||||
int d2 = n % 16;
|
||||
return hexDigits[d1] + hexDigits[d2];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
|
||||
package com.mhhy.util;
|
||||
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
/**
|
||||
* @author zcw
|
||||
* @version 1.0
|
||||
* @date 2020/1/6 17:03
|
||||
* @description md5工具类
|
||||
*/
|
||||
public class Md5Util {
|
||||
|
||||
public static String md5(String str) {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
return DigestUtils.md5DigestAsHex(str.getBytes());
|
||||
}
|
||||
|
||||
public static String MD5(String data) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] array = md.digest(data.getBytes("UTF-8"));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte item : array) {
|
||||
sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));
|
||||
}
|
||||
return sb.toString().toUpperCase();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.mhhy.util;
|
||||
|
||||
import sun.misc.BASE64Decoder;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.file.Path;
|
||||
import java.security.Key;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
public class PasswordUtil {
|
||||
/**平台加密算法
|
||||
* //前端获取服务端随机数
|
||||
* //前端使用 用户密码+sha256加密 对随机数进行加密
|
||||
* //后端生成密文流程:用户登录密码+sha256+base64--入库
|
||||
* //后端解析前端密文:拿数据库数据进行base64反解密--对前端传递过来的密钥解密--结果是一个服务端生产的随机数。
|
||||
* //随机数去比对缓存里面的随机数
|
||||
* //随机数设置过期时间 5分钟
|
||||
*/
|
||||
|
||||
//sha256加密
|
||||
public static byte[] getSHA256Str(String str){
|
||||
MessageDigest messageDigest;
|
||||
String encdeStr = "";
|
||||
try {
|
||||
messageDigest = MessageDigest.getInstance("SHA-256");
|
||||
byte[] hash = messageDigest.digest(str.getBytes("UTF-8"));
|
||||
return hash;
|
||||
//encdeStr = Hex.encodeHexString(hash);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//base64编码
|
||||
public static String encoderBase64(byte[] sha256){
|
||||
return java.util.Base64.getEncoder().encodeToString(sha256);
|
||||
}
|
||||
|
||||
//base64 解码
|
||||
public static byte[] decodeBase64(String encoderBase64){
|
||||
return java.util.Base64.getDecoder().decode(encoderBase64);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
//sha256加密
|
||||
byte[] sha256Str = PasswordUtil.getSHA256Str("111111");
|
||||
//AES加密
|
||||
String encrypt = Aes128Util.AESEncode("10908325", sha256Str);
|
||||
|
||||
System.out.println(encrypt);
|
||||
String str = "bHCrPMT2MFqhbXdjh_fCRwNQkGruSOU2nk4ZHmRB02H4DLOxzIcpbVOJSZmMPpMMa5HLTPq7PGweInFL9p1YE5sSmlgpUWWl5Kfb_Cstay0Gb4U7HkcS5rNxpiFj45C1SsGxQhG7qEJ7qSxId3Ho_Qgs-T7XTfYM8b_9MM26Yz9-g5EXVoItwXWUlfGEf2dbruFH1jFn4_6wGYawb4SsehIPqmSoTx8oaVRABZcq9Xo=";
|
||||
String s = Aes128Util.AESDecode(str, sha256Str);
|
||||
String[] mhhy2022s = s.split("MHHY2022");
|
||||
System.out.println("token:" + mhhy2022s[0]);
|
||||
System.out.println("会话id:" + mhhy2022s[1]);
|
||||
|
||||
String data = "{\"password\": \"111111\"}";
|
||||
String result = Aes128Util.AESEncode(data, PasswordUtil.getSHA256Str(mhhy2022s[1]));
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.mhhy.util;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class RandomUtil {
|
||||
|
||||
//传入list数组后随机排列
|
||||
public static int[] getSequence(List<Integer> list) {
|
||||
int[] sequence = new int[list.size()];
|
||||
for(int i = 0; i < list.size(); i++){
|
||||
sequence[i] = list.get(i);
|
||||
}
|
||||
Random random = new Random();
|
||||
for(int i = 0; i < list.size(); i++){
|
||||
int p = random.nextInt(list.size());
|
||||
int tmp = sequence[i];
|
||||
sequence[i] = sequence[p];
|
||||
sequence[p] = tmp;
|
||||
}
|
||||
return sequence;
|
||||
}
|
||||
|
||||
//获取某个范围内的随机数
|
||||
public static int getRandomArea(int i){
|
||||
Random random = new Random();
|
||||
return random.nextInt(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取随机数
|
||||
* @param j 随机数的位数
|
||||
* @return
|
||||
*/
|
||||
public static String getRandomToNum(int j){
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
int str[] = {1,2,3,4,5,6,7,8,9,0};
|
||||
for (int i = 0; i < j; i ++){
|
||||
double num = Math.random();
|
||||
int a = (int) (num * 10);
|
||||
buffer.append(a);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
//获取随机数
|
||||
public static String getRandom(){
|
||||
Random random = new Random();
|
||||
int rand = 1000000 + random.nextInt(10000000);
|
||||
return "" + rand;
|
||||
}
|
||||
|
||||
//获取邀请码 6位数
|
||||
public static String getRandomToInviteCode(int number){
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
String str[] = {"1","2","3","4","5","6","7","8","9","0","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
|
||||
for (int i = 0; i < number; i ++){
|
||||
double num = Math.random();
|
||||
int a = (int) (num * str.length);
|
||||
buffer.append(str[a]);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 邀请码
|
||||
* @param j 需要邀请码的位数
|
||||
* @return
|
||||
*/
|
||||
public static String getRandomToInviteCodeToNum(int j){
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
String str[] = {"1","2","3","4","5","6","7","8","9","0","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
|
||||
for (int i = 0; i < j; i ++){
|
||||
double num = Math.random();
|
||||
int a = (int) (num * str.length);
|
||||
buffer.append(str[a]);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static String getRandomHeadUrl(){
|
||||
String str[] = {"https://www.cnqhcs.com/java/head/1.png", "https://www.cnqhcs.com/java/head/2.png"};
|
||||
double num = Math.random();
|
||||
Random random = new Random();
|
||||
int i = random.nextInt(str.length);
|
||||
return str[i];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,395 @@
|
||||
package com.mhhy.util;
|
||||
|
||||
import com.mhhy.SpringContextHolder;
|
||||
import org.springframework.data.redis.core.HashOperations;
|
||||
import org.springframework.data.redis.core.ListOperations;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* redis工具类
|
||||
*/
|
||||
public class RedisUtil {
|
||||
|
||||
private final static StringRedisTemplate stringRedisTemplate = SpringContextHolder.getBean("stringRedisTemplate");
|
||||
|
||||
/**
|
||||
* 匹配key
|
||||
*/
|
||||
public static Set<String> keys(String pattern) {
|
||||
return stringRedisTemplate.keys(pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一个key
|
||||
*/
|
||||
public static void del(String key) {
|
||||
stringRedisTemplate.delete(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除key
|
||||
*/
|
||||
public static void delByPattern(String pattern) {
|
||||
Set<String> keySet = keys(pattern);
|
||||
stringRedisTemplate.delete(keySet);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置过期时间,单位为秒
|
||||
*/
|
||||
public static boolean expire(String key, long seconds) {
|
||||
return stringRedisTemplate.expire(key, seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取自动过期时间
|
||||
*/
|
||||
public static long ttl(String key) {
|
||||
return stringRedisTemplate.getExpire(key, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除过期时间
|
||||
*/
|
||||
public static boolean persist(String key) {
|
||||
return stringRedisTemplate.persist(key);
|
||||
}
|
||||
|
||||
/////// String 操作
|
||||
|
||||
/**
|
||||
* 给key赋值
|
||||
*/
|
||||
public static void set(String key, String value) {
|
||||
ValueOperations<String, String> op = stringRedisTemplate.opsForValue();
|
||||
op.set(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给key赋值,并设置过期时间,单位为秒
|
||||
*/
|
||||
public static void setEx(String key, String value, long seconds) {
|
||||
set(key, value);
|
||||
expire(key, seconds);
|
||||
}
|
||||
|
||||
public static boolean setNewNx(String key,String value,long seconds ){
|
||||
ValueOperations<String, String> op = stringRedisTemplate.opsForValue();
|
||||
return op.setIfAbsent(key, value,Duration.ofSeconds(seconds));
|
||||
}
|
||||
public static boolean setNx(String key, String value) {
|
||||
ValueOperations<String, String> op = stringRedisTemplate.opsForValue();
|
||||
return op.setIfAbsent(key, value);
|
||||
}
|
||||
|
||||
public static void getLock(String key){
|
||||
getLock(key, 2L);
|
||||
}
|
||||
|
||||
public static void getLock(String key, long expireSecond) {
|
||||
if (expireSecond > 10) {
|
||||
expireSecond = 2;
|
||||
}
|
||||
String md5Key = "vexLock:" + key + ":" + Md5Util.md5(key);
|
||||
String value = "0";
|
||||
while (!setNx(md5Key, value)) {
|
||||
sleep(20);
|
||||
}
|
||||
expire(md5Key, expireSecond);
|
||||
}
|
||||
|
||||
public static void unLock(String key) {
|
||||
String md5Key = "vexLock:" + key + ":" + Md5Util.md5(key);
|
||||
del(md5Key);
|
||||
}
|
||||
|
||||
public static void sleep(int timeMills) {
|
||||
try {
|
||||
Thread.sleep(timeMills);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将key的值加num
|
||||
*/
|
||||
public static long incrBy(String key, long num) {
|
||||
ValueOperations<String, String> op = stringRedisTemplate.opsForValue();
|
||||
return op.increment(key, num);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取key的值
|
||||
*/
|
||||
public static String get(String key) {
|
||||
ValueOperations<String, String> op = stringRedisTemplate.opsForValue();
|
||||
return op.get(key);
|
||||
}
|
||||
|
||||
/////// list操作
|
||||
|
||||
/**
|
||||
* 插入到表头
|
||||
*/
|
||||
public static void lPush(String key, String... values) {
|
||||
ListOperations<String, String> listOp = stringRedisTemplate.opsForList();
|
||||
listOp.leftPushAll(key, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除第一个
|
||||
*/
|
||||
public static String rPop(String key) {
|
||||
ListOperations<String, String> listOp = stringRedisTemplate.opsForList();
|
||||
return listOp.rightPop(key);
|
||||
}
|
||||
|
||||
public static int lLen(String key) {
|
||||
ListOperations<String, String> opsForList = stringRedisTemplate.opsForList();
|
||||
return opsForList.size(key).intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取list所有
|
||||
*
|
||||
* @param key
|
||||
* @param start
|
||||
* @param end
|
||||
* @return
|
||||
*/
|
||||
public static List<String> lRange(String key, int start, int end) {
|
||||
ListOperations<String, String> opsForList = stringRedisTemplate.opsForList();
|
||||
return opsForList.range(key, start, end);
|
||||
}
|
||||
|
||||
/////// hash
|
||||
|
||||
/*
|
||||
* public static void hset(String key,String hashKey,String value){
|
||||
* HashOperations<String,String,String> opsForHash =
|
||||
* stringRedisTemplate.opsForHash(); opsForHash.put(key, hashKey, value); }
|
||||
*/
|
||||
/////// set
|
||||
/////// sorted set
|
||||
|
||||
/**
|
||||
* 存放list
|
||||
* @param key
|
||||
* @param list
|
||||
*/
|
||||
public static void setList(String key, List<String> list){
|
||||
ListOperations<String, String> opsForList = stringRedisTemplate.opsForList();
|
||||
opsForList.leftPushAll(key, list);
|
||||
}
|
||||
|
||||
/**
|
||||
* HashGet
|
||||
* @param key 键 不能为null
|
||||
* @param item 项 不能为null
|
||||
* @return 值
|
||||
*/
|
||||
public static String hGet(String key, String item) {
|
||||
HashOperations<String, String, String> mapOp = stringRedisTemplate.opsForHash();
|
||||
return mapOp.get(key, item);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取hashKey对应的所有键值
|
||||
* @param key 键
|
||||
* @return 对应的多个键值
|
||||
*/
|
||||
public static Map<String, String> hmGet(String key) {
|
||||
HashOperations<String, String, String> mapOp = stringRedisTemplate.opsForHash();
|
||||
return mapOp.entries(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* HashSet
|
||||
* @param key 键
|
||||
* @param map 对应多个键值
|
||||
* @return true 成功 false 失败
|
||||
*/
|
||||
public static boolean hmSet(String key, Map<String,String> map){
|
||||
try {
|
||||
HashOperations<String, String, String> mapOp = stringRedisTemplate.opsForHash();
|
||||
mapOp.putAll(key, map);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* HashSet 并设置时间
|
||||
* @param key 键
|
||||
* @param map 对应多个键值
|
||||
* @param time 时间(秒)
|
||||
* @return true成功 false失败
|
||||
*/
|
||||
public static boolean hmset(String key, Map<String, String> map, long time) {
|
||||
try {
|
||||
HashOperations<String, String, String> mapOp = stringRedisTemplate.opsForHash();
|
||||
mapOp.putAll(key, map);
|
||||
if (time > 0) {
|
||||
expire(key, time);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 向一张hash表中放入数据,如果不存在将创建
|
||||
* @param key 键
|
||||
* @param item 项
|
||||
* @param value 值
|
||||
* @return true 成功 false失败
|
||||
*/
|
||||
public static boolean hset(String key, String item, String value) {
|
||||
try {
|
||||
HashOperations<String, String, String> mapOp = stringRedisTemplate.opsForHash();
|
||||
mapOp.put(key, item, value);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 向一张hash表中放入数据,如果不存在将创建
|
||||
* @param key 键
|
||||
* @param item 项
|
||||
* @param value 值
|
||||
* @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间
|
||||
* @return true 成功 false失败
|
||||
*/
|
||||
public static boolean hset(String key,String item,Object value,long time) {
|
||||
try {
|
||||
HashOperations<String, Object, Object> mapOp = stringRedisTemplate.opsForHash();
|
||||
mapOp.put(key, item, value);
|
||||
if(time>0){
|
||||
expire(key, time);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除hash表中的值
|
||||
* @param key 键 不能为null
|
||||
* @param item 项 可以使多个 不能为null
|
||||
*/
|
||||
public static void hdel(String key, Object... item){
|
||||
HashOperations<String, Object, Object> mapOp = stringRedisTemplate.opsForHash();
|
||||
|
||||
mapOp.delete(key,item);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断hash表中是否有该项的值
|
||||
* @param key 键 不能为null
|
||||
* @param item 项 不能为null
|
||||
* @return true 存在 false不存在
|
||||
*/
|
||||
public static boolean hHasKey(String key, String item){
|
||||
HashOperations<String, Object, Object> mapOp = stringRedisTemplate.opsForHash();
|
||||
|
||||
return mapOp.hasKey(key, item);
|
||||
}
|
||||
|
||||
/**
|
||||
* hash递增 如果不存在,就会创建一个 并把新增后的值返回
|
||||
* @param key 键
|
||||
* @param item 项
|
||||
* @param by 要增加几(大于0)
|
||||
* @return
|
||||
*/
|
||||
public static double hincr(String key, String item,double by){
|
||||
HashOperations<String, Object, Object> mapOp = stringRedisTemplate.opsForHash();
|
||||
|
||||
return mapOp.increment(key, item, by);
|
||||
}
|
||||
|
||||
/**
|
||||
* hash递减
|
||||
* @param key 键
|
||||
* @param item 项
|
||||
* @param by 要减少记(小于0)
|
||||
* @return
|
||||
*/
|
||||
public static double hdecr(String key, String item,double by){
|
||||
HashOperations<String, Object, Object> mapOp = stringRedisTemplate.opsForHash();
|
||||
|
||||
return mapOp.increment(key, item,-by);
|
||||
}
|
||||
|
||||
/**
|
||||
* set中增加元素,支持一次增加多个元素,逗号分隔即可,结果返回添加的个数
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static Long addSet(String key, String... value) {
|
||||
Long size = null;
|
||||
try {
|
||||
size = stringRedisTemplate.opsForSet().add(key, value);
|
||||
} catch (Exception e) {
|
||||
//log.error("[RedisUtils.addSet] [error]", e);
|
||||
return size;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
/**
|
||||
* set中移除指定元素
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static Long removeSet(String key, Object value) {
|
||||
Long size = null;
|
||||
try {
|
||||
size = stringRedisTemplate.opsForSet().remove(key, value);
|
||||
} catch (Exception e) {
|
||||
//log.error("[RedisUtils.removeSet] [error]", e);
|
||||
return size;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取key下的所有元素
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public static Set<String> members(String key) {
|
||||
Set<String> result = null;
|
||||
try {
|
||||
result = stringRedisTemplate.opsForSet().members(key);
|
||||
} catch (Exception e) {
|
||||
//log.error("[RedisUtils.members] [error]", e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.mhhy.util;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public enum RegexEnum {
|
||||
|
||||
PHONE("^1\\d{10}$"),
|
||||
EMAIL("^([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)*@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\\.][A-Za-z]{2,3}([\\.][A-Za-z]{2})?$"),
|
||||
// 密码长度8-20位且至少包含大写字母、小写字母、数字或特殊符号中的任意三种
|
||||
PASSWORD("^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\\W_]+$)(?![a-z0-9]+$)(?![a-z\\W_]+$)(?![0-9\\W_]+$)[a-zA-Z0-9\\W_]{8,20}$");
|
||||
|
||||
private String regx;
|
||||
|
||||
RegexEnum(String regx) {
|
||||
this.regx = regx;
|
||||
}
|
||||
|
||||
public boolean isMatcher(String val){
|
||||
Pattern p = Pattern.compile(regx);
|
||||
Matcher m = p.matcher(val);
|
||||
return m.matches();
|
||||
}
|
||||
|
||||
public String getRegx() {
|
||||
return regx;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.mhhy.util;
|
||||
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.mhhy.SpringContextHolder;
|
||||
import com.mhhy.model.entity.AdminEntity;
|
||||
import com.mhhy.model.entity.UserEntity;
|
||||
import com.mhhy.service.impl.AdminServiceImpl;
|
||||
import com.mhhy.service.impl.UserServiceImpl;
|
||||
import com.mhhy.util.token.JwtUtil;
|
||||
import com.mhhy.util.token.OdcProperties;
|
||||
import com.ospn.common.OsnUtils;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author zcw
|
||||
* @version 1.0
|
||||
* @date 2020/1/14 00:19
|
||||
* @description 请求工具
|
||||
*/
|
||||
@Log4j2
|
||||
public class RequestUtil {
|
||||
|
||||
private final static UserServiceImpl userService = SpringContextHolder.getBean("userService", UserServiceImpl.class);
|
||||
|
||||
private final static AdminServiceImpl adminService = SpringContextHolder.getBean("adminService", AdminServiceImpl.class);
|
||||
|
||||
private final static OdcProperties properties = SpringContextHolder.getBean("odcProperties");
|
||||
|
||||
private static HttpServletRequest getRequest() {
|
||||
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
}
|
||||
|
||||
public static String getIp() {
|
||||
HttpServletRequest request = getRequest();
|
||||
String clientIp = request.getHeader("x-forwarded-for");
|
||||
if (clientIp == null || clientIp.length() == 0 || "unknown".equalsIgnoreCase(clientIp)) {
|
||||
clientIp = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (clientIp == null || clientIp.length() == 0 || "unknown".equalsIgnoreCase(clientIp)) {
|
||||
clientIp = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (clientIp == null || clientIp.length() == 0 || "unknown".equalsIgnoreCase(clientIp)) {
|
||||
clientIp = request.getRemoteAddr();
|
||||
}
|
||||
return clientIp;
|
||||
}
|
||||
|
||||
public static String getRequestURI() {
|
||||
HttpServletRequest request = getRequest();
|
||||
return request.getRequestURI();
|
||||
}
|
||||
|
||||
public static String getHeader(String name) {
|
||||
HttpServletRequest request = getRequest();
|
||||
return request.getHeader(name);
|
||||
}
|
||||
|
||||
public static String getParameter(String name) {
|
||||
HttpServletRequest request = getRequest();
|
||||
return request.getParameter(name);
|
||||
}
|
||||
|
||||
public static String getDevice(){
|
||||
HttpServletRequest request = getRequest();
|
||||
return request.getHeader("device");
|
||||
}
|
||||
|
||||
public static String getUserAgent() {
|
||||
HttpServletRequest request = getRequest();
|
||||
return request.getHeader("User-Agent");
|
||||
}
|
||||
|
||||
public static String getToken() {
|
||||
String token = getHeader(properties.getConfig().getTokenHeader());
|
||||
if (token == null) {
|
||||
token = getParameter("token");
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
public static boolean isLogined() {
|
||||
String token = getToken();
|
||||
if (token == null || token.trim().length() == 0) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return getCurUserId() > 0;
|
||||
} catch (Exception e) {
|
||||
log.debug(e.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//获取token中的用户id
|
||||
public static int getMainUserId() {
|
||||
int userId = JwtUtil.verifyToken(getToken());
|
||||
//int userId = 1;
|
||||
//int userId = Integer.parseInt(RequestUtil.getHeader("userId"));
|
||||
UserEntity userEntity = userService.getById(userId);
|
||||
//AssertUtil.notNull(userEntity, ResultCodeEnum.DATA_ORDER);
|
||||
//AssertUtil.isTrue(userEntity.getStatus() == 1, ResultCodeEnum.ACCOUNT_DISABLED);
|
||||
return userId;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
//获取请求头的用户id
|
||||
public static int getCurUserId() {
|
||||
int userId = JwtUtil.verifyToken(getToken());
|
||||
//int userId = Integer.parseInt(RequestUtil.getHeader("userId"));
|
||||
UserEntity userEntity = userService.getById(userId);
|
||||
//AssertUtil.notNull(userEntity, ResultCodeEnum.WALLET_BAD_PARAM);
|
||||
//AssertUtil.isTrue(userEntity.getStatus() == 1, ResultCodeEnum.ACCOUNT_DISABLED);
|
||||
return userId;
|
||||
}
|
||||
|
||||
public static UserEntity getCurUser() {
|
||||
return userService.getById(getCurUserId());
|
||||
}
|
||||
|
||||
//获取当前主账号
|
||||
public static UserEntity getMainUser() {
|
||||
return userService.getById(getMainUserId());
|
||||
}
|
||||
|
||||
//获取当前主账号
|
||||
public static AdminEntity getAdminUser() {
|
||||
return adminService.getById(getMainUserId());
|
||||
}
|
||||
|
||||
public static JSONObject getParam(String user, String data) {
|
||||
|
||||
try {
|
||||
String communicationKey = RedisUtil.get("Communicationkey:"+user);
|
||||
System.out.println("Communicationkey:"+ communicationKey);
|
||||
return JSONObject.parseObject(OsnUtils.aesDecrypt(data, communicationKey));
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.mhhy.util;
|
||||
|
||||
import com.ospn.common.OsnUtils;
|
||||
|
||||
public class ResponseUtil {
|
||||
|
||||
public static String createResponse(String user, String data) {
|
||||
|
||||
try {
|
||||
String communicationKey = RedisUtil.get("Communicationkey:"+user);
|
||||
return OsnUtils.aesEncrypt(data, communicationKey);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.mhhy.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public final class StreamUtil {
|
||||
|
||||
/**
|
||||
* 从输入流中获取字符串
|
||||
*/
|
||||
public static String getString(InputStream is) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将输入流复制到输出流
|
||||
*/
|
||||
public static void copyStream(InputStream inputStream, OutputStream outputStream) {
|
||||
try {
|
||||
int length;
|
||||
byte[] buffer = new byte[4 * 1024];
|
||||
while ((length = inputStream.read(buffer, 0, buffer.length)) != -1) {
|
||||
outputStream.write(buffer, 0, length);
|
||||
}
|
||||
outputStream.flush();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
inputStream.close();
|
||||
outputStream.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.mhhy.util.token;
|
||||
|
||||
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.auth0.jwt.algorithms.Algorithm;
|
||||
|
||||
import com.mhhy.SpringContextHolder;
|
||||
import com.mhhy.enums.ResultCodeEnum;
|
||||
import com.mhhy.exception.OdcException;
|
||||
import com.mhhy.util.RedisUtil;
|
||||
import com.mhhy.util.RequestUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author zcw
|
||||
* @version 1.0
|
||||
* @date 2019/11/23 11:06
|
||||
* @description jwt工具类
|
||||
*/
|
||||
@Slf4j
|
||||
public class JwtUtil {
|
||||
|
||||
private final static Algorithm algorithm = SpringContextHolder.getBean("algorithm", Algorithm.class);
|
||||
|
||||
private final static OdcProperties properties = SpringContextHolder.getBean("odcProperties", OdcProperties.class);
|
||||
|
||||
/**
|
||||
* 创建token
|
||||
*
|
||||
* @param userId;
|
||||
* @param timeout; 单位是秒
|
||||
*/
|
||||
public static String createJwtToken(int userId, long timeout) {
|
||||
return JWT.create()
|
||||
.withClaim("member", userId)
|
||||
.withExpiresAt(new Date(System.currentTimeMillis() + timeout * 1000))
|
||||
.sign(algorithm);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* token正确且有效,则返回userId
|
||||
*/
|
||||
public static int verifyToken(String token) {
|
||||
Map<String, String> extraMap = Collections.singletonMap("uri", RequestUtil.getRequestURI());
|
||||
if (token == null || token.trim().length() == 0) {
|
||||
throw new OdcException(ResultCodeEnum.UN_AUTHORIZATION);
|
||||
}
|
||||
try {
|
||||
String noBearerToken = token.replaceFirst("Bearer ", "");
|
||||
Integer userId = JWT.require(algorithm)
|
||||
.build()
|
||||
.verify(noBearerToken)
|
||||
.getClaim("member")
|
||||
.asInt();
|
||||
if (RedisUtil.get(getRedisKey(userId, noBearerToken)) != null) {
|
||||
return userId;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new OdcException(ResultCodeEnum.UN_AUTHORIZATION, extraMap);
|
||||
}
|
||||
throw new OdcException(ResultCodeEnum.UN_AUTHORIZATION, extraMap);
|
||||
}
|
||||
|
||||
public static String getRedisKey(Integer userId, String token) {
|
||||
return String.format(properties.getConfig().getTokenRedisKeyFormat(), userId, token);
|
||||
}
|
||||
|
||||
public static void putTokenToRedis(Integer userId, String token) {
|
||||
RedisUtil.setEx(getRedisKey(userId, token), "0", properties.getConfig().getTokenExpireSeconds());
|
||||
}
|
||||
|
||||
public static void removeTokenByUserId(Integer userId) {
|
||||
Set<String> tokenSet = RedisUtil.keys(getRedisKey(userId, "*"));
|
||||
for (String key : tokenSet) {
|
||||
log.info("删除token, {}, {}", userId, key);
|
||||
RedisUtil.del(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.mhhy.util.token;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "com.mhhy", ignoreUnknownFields = true)
|
||||
public class OdcProperties {
|
||||
|
||||
private Oss oss = new Oss();
|
||||
|
||||
private Async async = new Async();
|
||||
|
||||
private Config config = new Config();
|
||||
|
||||
@Data
|
||||
public static class Oss {
|
||||
private String endpoint;
|
||||
private String accessKeyId;
|
||||
private String accessKeySecret;
|
||||
private String bucketName;
|
||||
private String prefixUrl;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Async {
|
||||
private int corePoolSize = 10;
|
||||
private int maxPoolSize = 40;
|
||||
private int queueCapacity = 20;
|
||||
private int keepAliveSeconds = 30;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Config {
|
||||
|
||||
private String tokenHeader = "Authorization";
|
||||
|
||||
//登录token,redis key格式
|
||||
private String tokenRedisKeyFormat = "mhhy:token:%d:%s";
|
||||
|
||||
//token有效期,10年
|
||||
private long tokenExpireSeconds = 315360000L;
|
||||
|
||||
//限制只能登录一个
|
||||
private boolean limitLoginOneOnly = true;
|
||||
|
||||
private String userPasswordKey = "mhhy2022";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/user?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8&allowMultiQueries=true
|
||||
username: app
|
||||
password: Asd4356*$
|
||||
|
||||
redis:
|
||||
host: 127.0.0.1
|
||||
database: 1
|
||||
password: pass1234
|
||||
lettuce:
|
||||
pool:
|
||||
max-active: 20
|
||||
max-idle: 16
|
||||
max-wait: 1000ms
|
||||
min-idle: 10
|
||||
|
||||
logging:
|
||||
level:
|
||||
root: ERROR
|
||||
com.mhhy: INFO
|
||||
com.mhhy.mapper: DEBUG
|
||||
@@ -0,0 +1,23 @@
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/user?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8&allowMultiQueries=true
|
||||
username: root
|
||||
password:
|
||||
|
||||
redis:
|
||||
host: 127.0.0.1
|
||||
database: 1
|
||||
password:
|
||||
lettuce:
|
||||
pool:
|
||||
max-active: 20
|
||||
max-idle: 16
|
||||
max-wait: 1000ms
|
||||
min-idle: 10
|
||||
|
||||
logging:
|
||||
level:
|
||||
root: ERROR
|
||||
com.mhhy: INFO
|
||||
com.mhhy.mapper: DEBUG
|
||||
@@ -0,0 +1,23 @@
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/user?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8&allowMultiQueries=true
|
||||
username: root
|
||||
password: GaMz12-SZJF
|
||||
|
||||
redis:
|
||||
host: 127.0.0.1
|
||||
database: 1
|
||||
password: 258Red7@#$
|
||||
lettuce:
|
||||
pool:
|
||||
max-active: 20
|
||||
max-idle: 16
|
||||
max-wait: 1000ms
|
||||
min-idle: 10
|
||||
|
||||
logging:
|
||||
level:
|
||||
root: ERROR
|
||||
com.mhhy: INFO
|
||||
com.mhhy.mapper: DEBUG
|
||||
@@ -0,0 +1,23 @@
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://39.100.133.144:3306/user144?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8&allowMultiQueries=true
|
||||
username: root
|
||||
password: ap*ThR7q0
|
||||
|
||||
redis:
|
||||
host: 127.0.0.1
|
||||
database: 1
|
||||
password: pass1234
|
||||
lettuce:
|
||||
pool:
|
||||
max-active: 20
|
||||
max-idle: 16
|
||||
max-wait: 1000ms
|
||||
min-idle: 10
|
||||
|
||||
logging:
|
||||
level:
|
||||
root: ERROR
|
||||
com.mhhy: INFO
|
||||
com.mhhy.mapper: DEBUG
|
||||
Loaded 100 of 117 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user