feat: 微信公众号扫码登录完成
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
package com.schisandra.auth.api;
|
package com.schisandra.auth.api;
|
||||||
|
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
@FeignClient("schisandra-cloud-storage-auth")
|
@FeignClient("schisandra-cloud-storage-auth")
|
||||||
public interface SchisandraAuthFeignService {
|
public interface SchisandraAuthFeignService {
|
||||||
|
@PostMapping("/auth/user/wechatRegister")
|
||||||
|
Boolean wechatRegister(@RequestParam(name = "appId") String appId, @RequestParam(name = "openId") String openId, @RequestParam("clientId") String clientId);
|
||||||
}
|
}
|
||||||
|
@@ -3,11 +3,9 @@ package com.schisandra.auth.application.config;
|
|||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
import com.schisandra.auth.application.interceptor.LoginInterceptor;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -15,7 +13,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* @Classname GlobalConfig
|
* @Classname GlobalConfig
|
||||||
* @BelongsProject: schisandra-cloud-storage
|
* @BelongsProject: schisandra-cloud-storage
|
||||||
* @BelongsPackage: com.schisandra.auth.application.config
|
* @BelongsPackage: com.schisandra.auth.application.common
|
||||||
* @Author: schisandra
|
* @Author: schisandra
|
||||||
* @CreateTime: 2024-02-16 15:57
|
* @CreateTime: 2024-02-16 15:57
|
||||||
* @Description: MVC全局处理
|
* @Description: MVC全局处理
|
||||||
|
@@ -29,7 +29,7 @@ public class SmsInitConfig implements SmartLifecycle {
|
|||||||
@Resource
|
@Resource
|
||||||
RedisUtil redisUtil;
|
RedisUtil redisUtil;
|
||||||
|
|
||||||
private final String smsConfigPrefix="sys.config";
|
private final String smsConfigPrefix="sys.common";
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
ConfigInfo configInfo = configRpc.getConfigInfo(SmsConfigContext.SMS_CONFIG_KEY);
|
ConfigInfo configInfo = configRpc.getConfigInfo(SmsConfigContext.SMS_CONFIG_KEY);
|
||||||
|
@@ -11,7 +11,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* @Classname SmsConfig
|
* @Classname SmsConfig
|
||||||
* @BelongsProject: schisandra-cloud-storage
|
* @BelongsProject: schisandra-cloud-storage
|
||||||
* @BelongsPackage: com.schisandra.auth.common.config
|
* @BelongsPackage: com.schisandra.auth.common.common
|
||||||
* @Author: schisandra
|
* @Author: schisandra
|
||||||
* @CreateTime: 2024-05-08 18:46
|
* @CreateTime: 2024-05-08 18:46
|
||||||
* @Description: 短信配置加载类
|
* @Description: 短信配置加载类
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
package com.schisandra.auth.application.controller;
|
package com.schisandra.auth.application.controller;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.stp.SaTokenInfo;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.schisandra.auth.application.convert.SchisandraAuthRolePermissionDTOConverter;
|
import com.schisandra.auth.application.convert.SchisandraAuthRolePermissionDTOConverter;
|
||||||
@@ -12,9 +14,9 @@ import com.schisandra.auth.application.utils.CheckRouteCaptcha;
|
|||||||
import com.schisandra.auth.common.entity.CaptchaResult;
|
import com.schisandra.auth.common.entity.CaptchaResult;
|
||||||
import com.schisandra.auth.common.entity.Result;
|
import com.schisandra.auth.common.entity.Result;
|
||||||
import com.schisandra.auth.common.enums.UserRoleEnum;
|
import com.schisandra.auth.common.enums.UserRoleEnum;
|
||||||
import com.schisandra.auth.domain.redis.RedisUtil;
|
|
||||||
import com.schisandra.auth.domain.bo.SchisandraAuthRolePermissionBO;
|
import com.schisandra.auth.domain.bo.SchisandraAuthRolePermissionBO;
|
||||||
import com.schisandra.auth.domain.bo.SchisandraAuthUserBO;
|
import com.schisandra.auth.domain.bo.SchisandraAuthUserBO;
|
||||||
|
import com.schisandra.auth.domain.redis.RedisUtil;
|
||||||
import com.schisandra.auth.domain.service.SchisandraAuthPermissionDomainService;
|
import com.schisandra.auth.domain.service.SchisandraAuthPermissionDomainService;
|
||||||
import com.schisandra.auth.domain.service.SchisandraAuthRoleDomainService;
|
import com.schisandra.auth.domain.service.SchisandraAuthRoleDomainService;
|
||||||
import com.schisandra.auth.domain.service.SchisandraAuthRolePermissionDomainService;
|
import com.schisandra.auth.domain.service.SchisandraAuthRolePermissionDomainService;
|
||||||
@@ -22,15 +24,16 @@ import com.schisandra.auth.domain.service.SchisandraAuthUserDomainService;
|
|||||||
import com.schisandra.auth.infra.basic.entity.SchisandraAuthPermission;
|
import com.schisandra.auth.infra.basic.entity.SchisandraAuthPermission;
|
||||||
import com.schisandra.auth.infra.basic.entity.SchisandraAuthRole;
|
import com.schisandra.auth.infra.basic.entity.SchisandraAuthRole;
|
||||||
import com.schisandra.auth.infra.basic.entity.SchisandraAuthUser;
|
import com.schisandra.auth.infra.basic.entity.SchisandraAuthUser;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.LinkedList;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,12 +66,19 @@ public class SchisandraAuthUserController {
|
|||||||
|
|
||||||
private final String AUTH_ROLE_PREFIX = "auth.role";
|
private final String AUTH_ROLE_PREFIX = "auth.role";
|
||||||
|
|
||||||
|
private final String WX_LOGIN_TEMPORARY_CLIENT_ID = "wechat.client.id";
|
||||||
|
|
||||||
|
private final String WX_LOGIN_TOKEN = "wechat.login.token";
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private SchisandraAuthRolePermissionDomainService schisandraAuthRolePermissionDomainService;
|
private SchisandraAuthRolePermissionDomainService schisandraAuthRolePermissionDomainService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private SchisandraAuthPermissionDomainService schisandraAuthPermissionDomainService;
|
private SchisandraAuthPermissionDomainService schisandraAuthPermissionDomainService;
|
||||||
|
|
||||||
|
@Value("${web.url}")
|
||||||
|
private String url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: 注册
|
* @description: 注册
|
||||||
* @param: [schisandraAuthUserDTO]
|
* @param: [schisandraAuthUserDTO]
|
||||||
@@ -298,4 +308,69 @@ public class SchisandraAuthUserController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 微信公众号扫码登录
|
||||||
|
* @param: []
|
||||||
|
* @return: com.schisandra.auth.common.entity.Result
|
||||||
|
* @author: landaiqing
|
||||||
|
* @date: 2024/6/27 下午2:50
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@PostMapping("wechatRegister")
|
||||||
|
public Boolean wechatRegister(@RequestParam(name = "appId") String appId, @RequestParam(name = "openId") String openId, @RequestParam("clientId") String clientId) {
|
||||||
|
Boolean result = schisandraAuthUserDomainService.wechatRegister(appId, openId, clientId);
|
||||||
|
if (result) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 生成客户端id
|
||||||
|
* @param: []
|
||||||
|
* @return: com.schisandra.auth.common.entity.Result<java.lang.String>
|
||||||
|
* @author: landaiqing
|
||||||
|
* @date: 2024/6/27 下午3:43
|
||||||
|
*/
|
||||||
|
@GetMapping("createClientId")
|
||||||
|
public Result<String> createClientId() {
|
||||||
|
String clientId = UUID.randomUUID().toString();
|
||||||
|
String key = redisUtil.buildKey(WX_LOGIN_TEMPORARY_CLIENT_ID, clientId);
|
||||||
|
redisUtil.setNx(key, clientId, 5L, TimeUnit.MINUTES);
|
||||||
|
return Result.ok(clientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 获取客户端id
|
||||||
|
* @param: []
|
||||||
|
* @return: com.schisandra.auth.common.entity.Result<java.lang.String>
|
||||||
|
* @author: landaiqing
|
||||||
|
* @date: 2024/6/27 下午3:43
|
||||||
|
*/
|
||||||
|
@PostMapping("getClientId")
|
||||||
|
public Result<String> getClientId(@RequestParam("clientId") String clientId) {
|
||||||
|
String key = redisUtil.buildKey(WX_LOGIN_TEMPORARY_CLIENT_ID, clientId);
|
||||||
|
String result = redisUtil.get(key);
|
||||||
|
return Result.ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 获取客户端token
|
||||||
|
* @param: [clientId]
|
||||||
|
* @return: com.schisandra.auth.common.entity.Result<java.lang.String>
|
||||||
|
* @author: landaiqing
|
||||||
|
* @date: 2024/6/27 下午5:33
|
||||||
|
*/
|
||||||
|
@PostMapping("getClientToken")
|
||||||
|
public Result getClientToken(String clientId) {
|
||||||
|
String key = redisUtil.buildKey(WX_LOGIN_TOKEN, clientId);
|
||||||
|
String result = redisUtil.get(key);
|
||||||
|
if(StringUtils.isBlank(result)){
|
||||||
|
return Result.fail();
|
||||||
|
}
|
||||||
|
return Result.ok(JSONObject.parseObject(result));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,52 @@
|
|||||||
|
package com.schisandra.auth.application.handler.oauth;
|
||||||
|
|
||||||
|
import com.schisandra.auth.common.enums.OauthType;
|
||||||
|
import com.schisandra.auth.common.utils.AuthStateRedisCache;
|
||||||
|
import com.schisandra.auth.infra.entity.OauthConfigInfo;
|
||||||
|
import com.schisandra.auth.infra.rpc.OauthConfigRpc;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import me.zhyd.oauth.config.AuthConfig;
|
||||||
|
import me.zhyd.oauth.request.AuthOschinaRequest;
|
||||||
|
import me.zhyd.oauth.request.AuthRequest;
|
||||||
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Classname OschinaOauthHandler
|
||||||
|
* @BelongsProject: schisandra-cloud-storage
|
||||||
|
* @BelongsPackage: com.schisandra.auth.application.handler.oauth
|
||||||
|
* @Author: landaiqing
|
||||||
|
* @CreateTime: 2024-06-26 14:21
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class OschinaOauthHandler implements SchisandraOauthTypeHandler {
|
||||||
|
@Resource
|
||||||
|
private OauthConfigRpc oauthConfigRpc;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AuthStateRedisCache stateRedisCache;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OauthType getHandlerType() {
|
||||||
|
return OauthType.OSCHINA;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthRequest getAuthRequest(String type) {
|
||||||
|
OauthConfigInfo oschina = oauthConfigRpc.getOauthConfigInfo(type);
|
||||||
|
if (ObjectUtils.isEmpty(oschina)) {
|
||||||
|
log.error("oschina oauth 配置信息获取失败");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new AuthOschinaRequest(AuthConfig.builder()
|
||||||
|
.clientId(oschina.getClientId())
|
||||||
|
.clientSecret(oschina.getClientSecret())
|
||||||
|
.redirectUri(oschina.getRedirectUri())
|
||||||
|
.build(), stateRedisCache);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,52 @@
|
|||||||
|
package com.schisandra.auth.application.handler.oauth;
|
||||||
|
|
||||||
|
import com.schisandra.auth.common.enums.OauthType;
|
||||||
|
import com.schisandra.auth.common.utils.AuthStateRedisCache;
|
||||||
|
import com.schisandra.auth.infra.entity.OauthConfigInfo;
|
||||||
|
import com.schisandra.auth.infra.rpc.OauthConfigRpc;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import me.zhyd.oauth.config.AuthConfig;
|
||||||
|
import me.zhyd.oauth.request.AuthRequest;
|
||||||
|
import me.zhyd.oauth.request.AuthStackOverflowRequest;
|
||||||
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Classname OschinaOauthHandler
|
||||||
|
* @BelongsProject: schisandra-cloud-storage
|
||||||
|
* @BelongsPackage: com.schisandra.auth.application.handler.oauth
|
||||||
|
* @Author: landaiqing
|
||||||
|
* @CreateTime: 2024-06-26 14:21
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class StackOverFlowOauthHandler implements SchisandraOauthTypeHandler {
|
||||||
|
@Resource
|
||||||
|
private OauthConfigRpc oauthConfigRpc;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AuthStateRedisCache stateRedisCache;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OauthType getHandlerType() {
|
||||||
|
return OauthType.STACK_OVERFLOW;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthRequest getAuthRequest(String type) {
|
||||||
|
OauthConfigInfo STACK_OVERFLOW = oauthConfigRpc.getOauthConfigInfo(type);
|
||||||
|
if (ObjectUtils.isEmpty(STACK_OVERFLOW)) {
|
||||||
|
log.error("STACK_OVERFLOW oauth 配置信息获取失败");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new AuthStackOverflowRequest(AuthConfig.builder()
|
||||||
|
.clientId(STACK_OVERFLOW.getClientId())
|
||||||
|
.clientSecret(STACK_OVERFLOW.getClientSecret())
|
||||||
|
.redirectUri(STACK_OVERFLOW.getRedirectUri())
|
||||||
|
.build(), stateRedisCache);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,54 @@
|
|||||||
|
package com.schisandra.auth.application.handler.oauth;
|
||||||
|
|
||||||
|
import com.schisandra.auth.common.enums.OauthType;
|
||||||
|
import com.schisandra.auth.common.utils.AuthStateRedisCache;
|
||||||
|
import com.schisandra.auth.infra.entity.OauthConfigInfo;
|
||||||
|
import com.schisandra.auth.infra.rpc.OauthConfigRpc;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import me.zhyd.oauth.config.AuthConfig;
|
||||||
|
import me.zhyd.oauth.request.AuthOschinaRequest;
|
||||||
|
import me.zhyd.oauth.request.AuthRequest;
|
||||||
|
import me.zhyd.oauth.request.AuthWeChatEnterpriseThirdQrcodeRequest;
|
||||||
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Classname OschinaOauthHandler
|
||||||
|
* @BelongsProject: schisandra-cloud-storage
|
||||||
|
* @BelongsPackage: com.schisandra.auth.application.handler.oauth
|
||||||
|
* @Author: landaiqing
|
||||||
|
* @CreateTime: 2024-06-26 14:21
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class WechatEnterpriseOauthHandler implements SchisandraOauthTypeHandler {
|
||||||
|
@Resource
|
||||||
|
private OauthConfigRpc oauthConfigRpc;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AuthStateRedisCache stateRedisCache;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OauthType getHandlerType() {
|
||||||
|
return OauthType.WECHAT_ENTERPRISE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthRequest getAuthRequest(String type) {
|
||||||
|
OauthConfigInfo WECHAT_ENTERPRISE = oauthConfigRpc.getOauthConfigInfo(type);
|
||||||
|
if (ObjectUtils.isEmpty(WECHAT_ENTERPRISE)) {
|
||||||
|
log.error("WECHAT_ENTERPRISE oauth 配置信息获取失败");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new AuthWeChatEnterpriseThirdQrcodeRequest(AuthConfig.builder()
|
||||||
|
.clientId(WECHAT_ENTERPRISE.getClientId())
|
||||||
|
.clientSecret(WECHAT_ENTERPRISE.getClientSecret())
|
||||||
|
.redirectUri(WECHAT_ENTERPRISE.getRedirectUri())
|
||||||
|
.agentId(WECHAT_ENTERPRISE.getAgentId())
|
||||||
|
.build(), stateRedisCache);
|
||||||
|
}
|
||||||
|
}
|
@@ -7,7 +7,7 @@ import org.springframework.stereotype.Component;
|
|||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,28 +1,29 @@
|
|||||||
package com.schisandra.auth.application.interceptor;
|
//package com.schisandra.auth.application.interceptor;
|
||||||
|
//
|
||||||
|
//
|
||||||
import com.schisandra.auth.application.context.LoginContextHolder;
|
//import com.schisandra.auth.application.context.LoginContextHolder;
|
||||||
import org.springframework.lang.Nullable;
|
//import jakarta.servlet.http.HttpServletRequest;
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
//import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
//import org.springframework.lang.Nullable;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
//import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
//
|
||||||
|
//
|
||||||
/**
|
//
|
||||||
* @description: 登录拦截器
|
///**
|
||||||
* @author: landaiqing
|
// * @description: 登录拦截器
|
||||||
* @date: 2024/6/2 14:24
|
// * @author: landaiqing
|
||||||
*/
|
// * @date: 2024/6/2 14:24
|
||||||
public class LoginInterceptor implements HandlerInterceptor {
|
// */
|
||||||
@Override
|
//public class LoginInterceptor implements HandlerInterceptor {
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
// @Override
|
||||||
String userId = request.getHeader("userId");
|
// public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||||
LoginContextHolder.set("userId",userId);
|
// String userId = request.getHeader("userId");
|
||||||
return true;
|
// LoginContextHolder.set("userId",userId);
|
||||||
}
|
// return true;
|
||||||
|
// }
|
||||||
@Override
|
//
|
||||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception {
|
// @Override
|
||||||
LoginContextHolder.remove();
|
// public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception {
|
||||||
}
|
// LoginContextHolder.remove();
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
|
@@ -37,7 +37,7 @@ public enum OauthType {
|
|||||||
/**
|
/**
|
||||||
* 企业微信登录
|
* 企业微信登录
|
||||||
*/
|
*/
|
||||||
WORK_WEIXIN("work_weixin"),
|
WECHAT_ENTERPRISE("WECHAT_ENTERPRISE"),
|
||||||
/**
|
/**
|
||||||
* Github
|
* Github
|
||||||
*/
|
*/
|
||||||
@@ -49,7 +49,16 @@ public enum OauthType {
|
|||||||
/**
|
/**
|
||||||
* System
|
* System
|
||||||
*/
|
*/
|
||||||
SYSTEM("SYSTEM");
|
SYSTEM("SYSTEM"),
|
||||||
|
/**
|
||||||
|
* 开源中国
|
||||||
|
*/
|
||||||
|
OSCHINA("OSCHINA"),
|
||||||
|
/**
|
||||||
|
* STACK_OVERFLOW
|
||||||
|
*/
|
||||||
|
STACK_OVERFLOW("STACK_OVERFLOW");
|
||||||
|
|
||||||
|
|
||||||
public String type;
|
public String type;
|
||||||
|
|
||||||
|
@@ -5,6 +5,7 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -53,6 +54,18 @@ public class RedisUtil {
|
|||||||
redisTemplate.opsForValue().set(key, value);
|
redisTemplate.opsForValue().set(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setJson(String key, Object value) {
|
||||||
|
redisTemplate.opsForValue().set(key, value);
|
||||||
|
}
|
||||||
|
public void setJsonNx(String key, Object value, Long time, TimeUnit timeUnit) {
|
||||||
|
redisTemplate.opsForValue().setIfAbsent(key, value, time, timeUnit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, String> getJson(String key) {
|
||||||
|
return (HashMap<String, String>) redisTemplate.opsForValue().get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set(带过期)
|
* set(带过期)
|
||||||
*/
|
*/
|
||||||
|
@@ -1,10 +1,12 @@
|
|||||||
package com.schisandra.auth.domain.service;
|
package com.schisandra.auth.domain.service;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.dev33.satoken.stp.SaTokenInfo;
|
||||||
import com.schisandra.auth.common.entity.Result;
|
import com.schisandra.auth.common.entity.Result;
|
||||||
import com.schisandra.auth.domain.bo.SchisandraAuthUserBO;
|
import com.schisandra.auth.domain.bo.SchisandraAuthUserBO;
|
||||||
import com.schisandra.auth.infra.basic.entity.SchisandraAuthUser;
|
import com.schisandra.auth.infra.basic.entity.SchisandraAuthUser;
|
||||||
import me.zhyd.oauth.model.AuthUser;
|
import me.zhyd.oauth.model.AuthUser;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户领域service
|
* 用户领域service
|
||||||
@@ -93,5 +95,7 @@ public interface SchisandraAuthUserDomainService {
|
|||||||
Object deleteById(Long id);
|
Object deleteById(Long id);
|
||||||
|
|
||||||
SchisandraAuthUser queryByPhone(String phone);
|
SchisandraAuthUser queryByPhone(String phone);
|
||||||
|
|
||||||
|
Boolean wechatRegister(String appId, String openId, String clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,21 +2,19 @@ package com.schisandra.auth.domain.service.impl;
|
|||||||
|
|
||||||
|
|
||||||
import cn.dev33.satoken.stp.SaLoginConfig;
|
import cn.dev33.satoken.stp.SaLoginConfig;
|
||||||
|
import cn.dev33.satoken.stp.SaTokenInfo;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.schisandra.auth.common.entity.Result;
|
import com.schisandra.auth.common.entity.Result;
|
||||||
import com.schisandra.auth.common.enums.IsDeletedFlagEnum;
|
import com.schisandra.auth.common.enums.IsDeletedFlagEnum;
|
||||||
import com.schisandra.auth.common.enums.UserRoleEnum;
|
import com.schisandra.auth.common.enums.UserRoleEnum;
|
||||||
import com.schisandra.auth.domain.redis.RedisUtil;
|
import com.schisandra.auth.domain.bo.*;
|
||||||
import com.schisandra.auth.domain.bo.SchisandraAuthUserBO;
|
|
||||||
import com.schisandra.auth.domain.bo.SchisandraAuthUserRoleBO;
|
|
||||||
import com.schisandra.auth.domain.bo.SchisandraSocialUserAuthBO;
|
|
||||||
import com.schisandra.auth.domain.bo.SchisandraSocialUserBO;
|
|
||||||
import com.schisandra.auth.domain.convert.SchisandraAuthUserBOConverter;
|
import com.schisandra.auth.domain.convert.SchisandraAuthUserBOConverter;
|
||||||
import com.schisandra.auth.domain.convert.SchisandraAuthUserRoleBOConverter;
|
import com.schisandra.auth.domain.convert.SchisandraAuthUserRoleBOConverter;
|
||||||
import com.schisandra.auth.domain.convert.SchisandraSocialUserAuthBOConverter;
|
import com.schisandra.auth.domain.convert.SchisandraSocialUserAuthBOConverter;
|
||||||
import com.schisandra.auth.domain.convert.SchisandraSocialUserBOConverter;
|
import com.schisandra.auth.domain.convert.SchisandraSocialUserBOConverter;
|
||||||
|
import com.schisandra.auth.domain.redis.RedisUtil;
|
||||||
import com.schisandra.auth.domain.service.SchisandraAuthUserDomainService;
|
import com.schisandra.auth.domain.service.SchisandraAuthUserDomainService;
|
||||||
import com.schisandra.auth.infra.basic.entity.*;
|
import com.schisandra.auth.infra.basic.entity.*;
|
||||||
import com.schisandra.auth.infra.basic.service.*;
|
import com.schisandra.auth.infra.basic.service.*;
|
||||||
@@ -30,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -61,6 +60,8 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
|
|||||||
|
|
||||||
private final String AUTH_ROLE_PREFIX = "auth.role";
|
private final String AUTH_ROLE_PREFIX = "auth.role";
|
||||||
|
|
||||||
|
private final String WX_LOGIN_TOKEN = "wechat.login.token";
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
RedisUtil redisUtil;
|
RedisUtil redisUtil;
|
||||||
|
|
||||||
@@ -216,6 +217,88 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
|
|||||||
return schisandraAuthUserService.queryByPhone(phone);
|
return schisandraAuthUserService.queryByPhone(phone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 微信注册
|
||||||
|
* @param: []
|
||||||
|
* @return: com.schisandra.auth.common.entity.Result
|
||||||
|
* @author: landaiqing
|
||||||
|
* @date: 2024/6/27 下午2:58
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean wechatRegister(String appId, String openId,String clientId) {
|
||||||
|
SchisandraSocialUser socialUser = schisandraSocialUserService.selectByOpenId(openId);
|
||||||
|
if (ObjectUtils.isNotEmpty(socialUser)) {
|
||||||
|
Long userId = socialUser.getId();
|
||||||
|
// redis存储用户角色与权限信息
|
||||||
|
userInfoPersistence(userId);
|
||||||
|
StpUtil.login(userId);
|
||||||
|
SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
|
||||||
|
String jsonString = JSONObject.toJSONString(tokenInfo);
|
||||||
|
String key = redisUtil.buildKey(WX_LOGIN_TOKEN, clientId);
|
||||||
|
redisUtil.setJsonNx(key, jsonString,5L, TimeUnit.MINUTES);
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
// 插入社会用户信息表
|
||||||
|
SchisandraSocialUserBO socialUserBO = new SchisandraSocialUserBO();
|
||||||
|
socialUserBO.setOpenId(openId);
|
||||||
|
SchisandraSocialUser schisandraSocialUser = SchisandraSocialUserBOConverter.INSTANCE.convertBOToEntity(socialUserBO);
|
||||||
|
int result = schisandraSocialUserService.insertSocialUser(schisandraSocialUser);
|
||||||
|
if (result <= 0) {
|
||||||
|
if (log.isInfoEnabled()) {
|
||||||
|
log.error("wechatRegister.insertSocialUser fail, param:{}", JSONObject.toJSONString(schisandraSocialUser));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 插入用户信息表
|
||||||
|
SchisandraAuthUserBO authUserBO = new SchisandraAuthUserBO();
|
||||||
|
authUserBO.setUserName(openId);
|
||||||
|
SchisandraAuthUser schisandraAuthUser = SchisandraAuthUserBOConverter.INSTANCE.convertBOToEntity(authUserBO);
|
||||||
|
int insertAuthUser = schisandraAuthUserService.insertAuthUserByOauth(schisandraAuthUser);
|
||||||
|
if (insertAuthUser <= 0) {
|
||||||
|
if (log.isInfoEnabled()) {
|
||||||
|
log.error("wechatRegister.insertAuthUser fail, param:{}", JSONObject.toJSONString(schisandraAuthUser));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Long authUserId = schisandraAuthUser.getId();
|
||||||
|
Long socialUserId = schisandraSocialUser.getId();
|
||||||
|
// 建立社会用户与用户信息映射
|
||||||
|
SchisandraSocialUserAuthBO socialUserAuthBO = new SchisandraSocialUserAuthBO();
|
||||||
|
socialUserAuthBO.setUserId(authUserId);
|
||||||
|
socialUserAuthBO.setSocialUserId(socialUserId);
|
||||||
|
SchisandraSocialUserAuth schisandraSocialUserAuth = SchisandraSocialUserAuthBOConverter.INSTANCE.convertBOToEntity(socialUserAuthBO);
|
||||||
|
int insertMapper = schisandraSocialUserAuthService.insert(schisandraSocialUserAuth);
|
||||||
|
if (insertMapper <= 0) {
|
||||||
|
if (log.isInfoEnabled()) {
|
||||||
|
log.error("wechatRegister.insertAuthUserMapper fail, param:{}", JSONObject.toJSONString(schisandraSocialUserAuth));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 建立用户与角色映射关系
|
||||||
|
SchisandraAuthUserRoleBO schisandraAuthUserRoleBO = new SchisandraAuthUserRoleBO();
|
||||||
|
schisandraAuthUserRoleBO.setUserId(authUserId);
|
||||||
|
schisandraAuthUserRoleBO.setRoleId(UserRoleEnum.NORMAL_USER.getCode());
|
||||||
|
schisandraAuthUserRoleBO.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
|
||||||
|
SchisandraAuthUserRole schisandraAuthUserRole = SchisandraAuthUserRoleBOConverter.INSTANCE.convertBOToEntity(schisandraAuthUserRoleBO);
|
||||||
|
int insert = schisandraAuthUserRoleService.insert(schisandraAuthUserRole);
|
||||||
|
if (insert <= 0) {
|
||||||
|
if (log.isInfoEnabled()) {
|
||||||
|
log.error("wechatRegister.insertUserRole fail, param:{}", JSONObject.toJSONString(schisandraAuthUserRole));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// redis存储用户角色与权限信息
|
||||||
|
userInfoPersistence(authUserId);
|
||||||
|
StpUtil.login(authUserId);
|
||||||
|
SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
|
||||||
|
String jsonString = JSONObject.toJSONString(tokenInfo);
|
||||||
|
String key = redisUtil.buildKey(WX_LOGIN_TOKEN, clientId);
|
||||||
|
redisUtil.setJsonNx(key, jsonString,5L, TimeUnit.MINUTES);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: 根据第三方用户信息添加用户
|
* @description: 根据第三方用户信息添加用户
|
||||||
@@ -287,7 +370,7 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 插入用户信息表
|
// 插入用户信息表
|
||||||
SchisandraAuthUserBO authUserBO=new SchisandraAuthUserBO();
|
SchisandraAuthUserBO authUserBO = new SchisandraAuthUserBO();
|
||||||
authUserBO.setUserName(data.getUsername());
|
authUserBO.setUserName(data.getUsername());
|
||||||
authUserBO.setNickName(data.getNickname());
|
authUserBO.setNickName(data.getNickname());
|
||||||
authUserBO.setAvatar(data.getAvatar());
|
authUserBO.setAvatar(data.getAvatar());
|
||||||
|
@@ -48,4 +48,6 @@ public interface SchisandraSocialUserService {
|
|||||||
int updateById(SchisandraSocialUser schisandraSocialUser);
|
int updateById(SchisandraSocialUser schisandraSocialUser);
|
||||||
|
|
||||||
int insertSocialUser(SchisandraSocialUser schisandraSocialUser);
|
int insertSocialUser(SchisandraSocialUser schisandraSocialUser);
|
||||||
|
|
||||||
|
SchisandraSocialUser selectByOpenId(String openId);
|
||||||
}
|
}
|
||||||
|
@@ -89,10 +89,29 @@ public class SchisandraSocialUserServiceImpl implements SchisandraSocialUserServ
|
|||||||
return schisandraSocialUserDao.update(schisandraSocialUser, true);
|
return schisandraSocialUserDao.update(schisandraSocialUser, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 插入社会用户信息
|
||||||
|
* @param: [schisandraSocialUser]
|
||||||
|
* @return: int
|
||||||
|
* @author: landaiqing
|
||||||
|
* @date: 2024/6/27 下午3:05
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int insertSocialUser(SchisandraSocialUser schisandraSocialUser) {
|
public int insertSocialUser(SchisandraSocialUser schisandraSocialUser) {
|
||||||
return schisandraSocialUserDao.insertSelective(schisandraSocialUser);
|
return schisandraSocialUserDao.insertSelective(schisandraSocialUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 根据appId和openId查询用户
|
||||||
|
* @param: [appId, openId]
|
||||||
|
* @return: com.schisandra.auth.infra.basic.entity.SchisandraSocialUser
|
||||||
|
* @author: landaiqing
|
||||||
|
* @date: 2024/6/27 下午3:05
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public SchisandraSocialUser selectByOpenId(String openId) {
|
||||||
|
return schisandraSocialUserDao.selectOneByCondition(SchisandraSocialUserTableDef.SCHISANDRA_SOCIAL_USER.OPEN_ID.eq(openId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
/**
|
/**
|
||||||
* @Classname MyBatisFlexConfiguration
|
* @Classname MyBatisFlexConfiguration
|
||||||
* @BelongsProject: schisandra-cloud-storage
|
* @BelongsProject: schisandra-cloud-storage
|
||||||
* @BelongsPackage: com.schisandra.oss.infra.config
|
* @BelongsPackage: com.schisandra.oss.infra.common
|
||||||
* @Author: landaiqing
|
* @Author: landaiqing
|
||||||
* @CreateTime: 2024-05-31 16:14
|
* @CreateTime: 2024-05-31 16:14
|
||||||
* @Description: Mybatis flex 配置类
|
* @Description: Mybatis flex 配置类
|
||||||
|
@@ -1,48 +1,48 @@
|
|||||||
package com.schisandra.gateway.filter;
|
//package com.schisandra.gateway.filter;
|
||||||
|
//
|
||||||
import cn.dev33.satoken.stp.SaTokenInfo;
|
//import cn.dev33.satoken.stp.SaTokenInfo;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
//import cn.dev33.satoken.stp.StpUtil;
|
||||||
import lombok.SneakyThrows;
|
//import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
//import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
//import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
//import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||||
import org.springframework.stereotype.Component;
|
//import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.StringUtils;
|
//import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
//import org.springframework.web.server.ServerWebExchange;
|
||||||
import reactor.core.publisher.Mono;
|
//import reactor.core.publisher.Mono;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* @Classname LoginFilter
|
// * @Classname LoginFilter
|
||||||
* @BelongsProject: schisandra-cloud-storage
|
// * @BelongsProject: schisandra-cloud-storage
|
||||||
* @BelongsPackage: com.schisandra.club.gateway.filter
|
// * @BelongsPackage: com.schisandra.club.gateway.filter
|
||||||
* @Author: schisandra
|
// * @Author: schisandra
|
||||||
* @CreateTime: 2024-03-03 17:41
|
// * @CreateTime: 2024-03-03 17:41
|
||||||
* @Description: 登录拦截器
|
// * @Description: 登录拦截器
|
||||||
* @Version: 1.0
|
// * @Version: 1.0
|
||||||
*/
|
// */
|
||||||
@Component
|
//@Component
|
||||||
@Slf4j
|
//@Slf4j
|
||||||
public class LoginFilter implements GlobalFilter {
|
//public class LoginFilter implements GlobalFilter {
|
||||||
@Override
|
// @Override
|
||||||
@SneakyThrows
|
// @SneakyThrows
|
||||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
// public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||||
ServerHttpRequest request = exchange.getRequest();
|
// ServerHttpRequest request = exchange.getRequest();
|
||||||
ServerHttpRequest.Builder mutate = request.mutate();
|
// ServerHttpRequest.Builder mutate = request.mutate();
|
||||||
String url = request.getURI().getPath();
|
// String url = request.getURI().getPath();
|
||||||
log.info("LoginFilter.filter.url:{}", url);
|
// log.info("LoginFilter.filter.url:{}", url);
|
||||||
if (url.equals("/oauth/render/gitee") || url.equals("/oauth/callback/gitee") || url.equals("/auth/user/register") || url.equals("/auth/user/login") || url.equals("/system/getConfigByKey")) {
|
// if (url.equals("/oauth/render/gitee") || url.equals("/oauth/callback/gitee") || url.equals("/auth/user/register") || url.equals("/auth/user/login") || url.equals("/system/getConfigByKey")) {
|
||||||
return chain.filter(exchange);
|
// return chain.filter(exchange);
|
||||||
}
|
// }
|
||||||
SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
|
// SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
|
||||||
String userId = (String) tokenInfo.getLoginId();
|
// String userId = (String) tokenInfo.getLoginId();
|
||||||
System.out.println("userId:" + userId);
|
// System.out.println("userId:" + userId);
|
||||||
if (StringUtils.isEmpty(userId)) {
|
// if (StringUtils.isEmpty(userId)) {
|
||||||
throw new Exception("未获取到用户信息");
|
// throw new Exception("未获取到用户信息");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
mutate.header("userId", userId);
|
// mutate.header("userId", userId);
|
||||||
|
//
|
||||||
return chain.filter(exchange.mutate().request(mutate.build()).build());
|
// return chain.filter(exchange.mutate().request(mutate.build()).build());
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
@@ -22,6 +22,12 @@ spring:
|
|||||||
- Path=/system/**
|
- Path=/system/**
|
||||||
filters:
|
filters:
|
||||||
- StripPrefix=1
|
- StripPrefix=1
|
||||||
|
- id: wechat
|
||||||
|
uri: lb://schisandra-cloud-storage-wechat
|
||||||
|
predicates:
|
||||||
|
- Path=/wechat/**
|
||||||
|
filters:
|
||||||
|
- StripPrefix=1
|
||||||
# redis配置
|
# redis配置
|
||||||
redis:
|
redis:
|
||||||
# Redis数据库索引(默认为0)
|
# Redis数据库索引(默认为0)
|
||||||
|
@@ -13,7 +13,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* @Classname GlobalConfig
|
* @Classname GlobalConfig
|
||||||
* @BelongsProject: schisandra-cloud-storage
|
* @BelongsProject: schisandra-cloud-storage
|
||||||
* @BelongsPackage: com.schisandra.auth.application.config
|
* @BelongsPackage: com.schisandra.auth.application.common
|
||||||
* @Author: schisandra
|
* @Author: schisandra
|
||||||
* @CreateTime: 2024-02-16 15:57
|
* @CreateTime: 2024-02-16 15:57
|
||||||
* @Description: MVC全局处理
|
* @Description: MVC全局处理
|
||||||
|
@@ -55,9 +55,9 @@ public class SchisandraOssMinioController {
|
|||||||
|
|
||||||
Result result = minioOssConfiguration.minioOssClient(userId);
|
Result result = minioOssConfiguration.minioOssClient(userId);
|
||||||
if (result.getSuccess()) {
|
if (result.getSuccess()) {
|
||||||
log.info("用户: " + userId + "-> minio 初始化完成!");
|
log.info("用户: {}-> minio 初始化完成!", userId);
|
||||||
} else {
|
} else {
|
||||||
log.error("用户: " + userId + "-> minio 初始化完成!");
|
log.error("用户: {}-> minio 初始化完成!", userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ public class SchisandraOssMinioController {
|
|||||||
log.error("容器获取失败!");
|
log.error("容器获取失败!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return Result.ok(bean.getBaseInfo(fileName));
|
return Result.ok(bean.getInfo(fileName,true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("getAllMinioInfo")
|
@GetMapping("getAllMinioInfo")
|
||||||
|
@@ -8,7 +8,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
/**
|
/**
|
||||||
* @Classname MyBatisFlexConfiguration
|
* @Classname MyBatisFlexConfiguration
|
||||||
* @BelongsProject: schisandra-cloud-storage
|
* @BelongsProject: schisandra-cloud-storage
|
||||||
* @BelongsPackage: com.schisandra.oss.infra.config
|
* @BelongsPackage: com.schisandra.oss.infra.common
|
||||||
* @Author: landaiqing
|
* @Author: landaiqing
|
||||||
* @CreateTime: 2024-05-31 16:14
|
* @CreateTime: 2024-05-31 16:14
|
||||||
* @Description: Mybatis flex 配置类
|
* @Description: Mybatis flex 配置类
|
||||||
|
@@ -1,21 +1,53 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>com.schisandra.share</groupId>
|
<groupId>com.schisandra.share</groupId>
|
||||||
<artifactId>schisandra-cloud-storage-share</artifactId>
|
<artifactId>schisandra-cloud-storage-share</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>schisandra-cloud-storage-share</name>
|
<name>schisandra-cloud-storage-share</name>
|
||||||
<modules>
|
<modules>
|
||||||
<module>schisandra-cloud-storage-share-api</module>
|
<module>schisandra-cloud-storage-share-api</module>
|
||||||
<module>schisandra-cloud-storage-share-starter</module>
|
<module>schisandra-cloud-storage-share-starter</module>
|
||||||
<module>schisandra-cloud-storage-share-infra</module>
|
<module>schisandra-cloud-storage-share-infra</module>
|
||||||
<module>schisandra-cloud-storage-share-domain</module>
|
<module>schisandra-cloud-storage-share-domain</module>
|
||||||
<module>schisandra-cloud-storage-share-common</module>
|
<module>schisandra-cloud-storage-share-common</module>
|
||||||
<module>schisandra-cloud-storage-share-application</module>
|
<module>schisandra-cloud-storage-share-application</module>
|
||||||
</modules>
|
</modules>
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
</properties>
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
<spring-boot.version>2.4.2</spring-boot.version>
|
||||||
|
<spring-cloud-alibaba.version>2021.1</spring-cloud-alibaba.version>
|
||||||
|
<spring-cloud.version>2020.0.6</spring-cloud.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-dependencies</artifactId>
|
||||||
|
<version>2.4.2</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>central</id>
|
||||||
|
<name>aliyun maven</name>
|
||||||
|
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
||||||
|
<layout>default</layout>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
</project>
|
</project>
|
||||||
|
@@ -14,10 +14,28 @@
|
|||||||
|
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||||
|
<version>3.0.7</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-loadbalancer</artifactId>
|
||||||
|
<version>3.0.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.24</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@@ -13,11 +13,67 @@
|
|||||||
<name>schisandra-cloud-storage-share-application-controller</name>
|
<name>schisandra-cloud-storage-share-application-controller</name>
|
||||||
|
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.13.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.24</version>
|
||||||
|
</path>
|
||||||
|
<!-- 必须要加, 否则生成不了 MapperImpl 实现类 -->
|
||||||
|
<path>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct-processor</artifactId>
|
||||||
|
<version>1.4.2.Final</version>
|
||||||
|
</path>
|
||||||
|
<!-- 如果是 0.1.0 有可能出现生成了maptruct的实现类, 但该类只创建了对象, 没有进行赋值 -->
|
||||||
|
<path>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok-mapstruct-binding</artifactId>
|
||||||
|
<version>0.2.0</version>
|
||||||
|
</path>
|
||||||
|
<path>
|
||||||
|
<groupId>com.mybatis-flex</groupId>
|
||||||
|
<artifactId>mybatis-flex-processor</artifactId>
|
||||||
|
<version>1.9.0</version>
|
||||||
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
<properties>
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
<version>2.4.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.schisandra.share</groupId>
|
||||||
|
<artifactId>schisandra-cloud-storage-share-domain</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.schisandra.share</groupId>
|
||||||
|
<artifactId>schisandra-cloud-storage-share-api</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@@ -12,9 +12,100 @@
|
|||||||
|
|
||||||
<name>schisandra-cloud-storage-share-common</name>
|
<name>schisandra-cloud-storage-share-common</name>
|
||||||
<properties>
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-core</artifactId>
|
||||||
|
<version>2.12.7</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>2.12.7</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>2.8.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.24</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct</artifactId>
|
||||||
|
<version>1.4.2.Final</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct-processor</artifactId>
|
||||||
|
<version>1.4.2.Final</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-log4j2</artifactId>
|
||||||
|
<version>2.4.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>fastjson</artifactId>
|
||||||
|
<version>1.2.79</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
<version>19.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
<version>3.11</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- 提供Redis连接池 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-pool2</artifactId>
|
||||||
|
<version>2.9.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
|
<version>2.5.15</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-extra</artifactId>
|
||||||
|
<version>5.8.27</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.directory.studio</groupId>
|
||||||
|
<artifactId>org.apache.commons.codec</artifactId>
|
||||||
|
<version>1.8</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||||
|
<artifactId>caffeine</artifactId>
|
||||||
|
<version>3.1.8</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
<version>5.1.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@@ -0,0 +1,29 @@
|
|||||||
|
package com.schisandra.share.common.entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页请求实体
|
||||||
|
*
|
||||||
|
* @author: schisandra
|
||||||
|
*/
|
||||||
|
public class PageInfo {
|
||||||
|
|
||||||
|
private Integer pageNo = 1;
|
||||||
|
|
||||||
|
private Integer pageSize = 20;
|
||||||
|
|
||||||
|
public Integer getPageNo() {
|
||||||
|
if (pageNo == null || pageNo < 1) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return pageNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPageSize() {
|
||||||
|
if (pageSize == null || pageSize < 1 || pageSize > Integer.MAX_VALUE) {
|
||||||
|
return 20;
|
||||||
|
}
|
||||||
|
return pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,57 @@
|
|||||||
|
package com.schisandra.share.common.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页返回实体
|
||||||
|
*
|
||||||
|
* @author: schisandra
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class PageResult<T> implements Serializable {
|
||||||
|
|
||||||
|
private Integer pageNo = 1;
|
||||||
|
|
||||||
|
private Integer pageSize = 20;
|
||||||
|
|
||||||
|
private Integer total = 0;
|
||||||
|
|
||||||
|
private Integer totalPages = 0;
|
||||||
|
|
||||||
|
private List<T> result = Collections.emptyList();
|
||||||
|
|
||||||
|
private Integer start = 1;
|
||||||
|
|
||||||
|
private Integer end = 0;
|
||||||
|
|
||||||
|
public void setRecords(List<T> result) {
|
||||||
|
this.result = result;
|
||||||
|
if (result != null && result.size() > 0) {
|
||||||
|
setTotal(result.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotal(Integer total) {
|
||||||
|
this.total = total;
|
||||||
|
if (this.pageSize > 0) {
|
||||||
|
this.totalPages = (total / this.pageSize) + (total % this.pageSize == 0 ? 0 : 1);
|
||||||
|
} else {
|
||||||
|
this.totalPages = 0;
|
||||||
|
}
|
||||||
|
this.start = (this.pageSize > 0 ? (this.pageNo - 1) * this.pageSize : 0) + 1;
|
||||||
|
this.end = (this.start - 1 + this.pageSize * (this.pageNo > 0 ? 1 : 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPageSize(Integer pageSize) {
|
||||||
|
this.pageSize = pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPageNo(Integer pageNo) {
|
||||||
|
this.pageNo = pageNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1,7 +1,14 @@
|
|||||||
package com.schisandra.wechat.entity;
|
package com.schisandra.share.common.entity;
|
||||||
|
|
||||||
|
|
||||||
|
import com.schisandra.share.common.enums.ResultCodeEnum;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 返回结果泛型类
|
||||||
|
* @author: schisandra
|
||||||
|
* @date: 2024/3/22 13:09
|
||||||
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class Result<T> {
|
public class Result<T> {
|
||||||
|
|
||||||
@@ -13,7 +20,7 @@ public class Result<T> {
|
|||||||
|
|
||||||
private T data;
|
private T data;
|
||||||
|
|
||||||
public static Result ok(){
|
public static Result ok() {
|
||||||
Result result = new Result();
|
Result result = new Result();
|
||||||
result.setSuccess(true);
|
result.setSuccess(true);
|
||||||
result.setCode(ResultCodeEnum.SUCCESS.getCode());
|
result.setCode(ResultCodeEnum.SUCCESS.getCode());
|
||||||
@@ -21,7 +28,7 @@ public class Result<T> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> Result ok(T data){
|
public static <T> Result ok(T data) {
|
||||||
Result result = new Result();
|
Result result = new Result();
|
||||||
result.setSuccess(true);
|
result.setSuccess(true);
|
||||||
result.setCode(ResultCodeEnum.SUCCESS.getCode());
|
result.setCode(ResultCodeEnum.SUCCESS.getCode());
|
||||||
@@ -30,7 +37,7 @@ public class Result<T> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Result fail(){
|
public static Result fail() {
|
||||||
Result result = new Result();
|
Result result = new Result();
|
||||||
result.setSuccess(false);
|
result.setSuccess(false);
|
||||||
result.setCode(ResultCodeEnum.FAIL.getCode());
|
result.setCode(ResultCodeEnum.FAIL.getCode());
|
||||||
@@ -38,7 +45,7 @@ public class Result<T> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> Result fail(T data){
|
public static <T> Result fail(T data) {
|
||||||
Result result = new Result();
|
Result result = new Result();
|
||||||
result.setSuccess(false);
|
result.setSuccess(false);
|
||||||
result.setCode(ResultCodeEnum.FAIL.getCode());
|
result.setCode(ResultCodeEnum.FAIL.getCode());
|
@@ -0,0 +1,34 @@
|
|||||||
|
package com.schisandra.share.common.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除状态枚举
|
||||||
|
*
|
||||||
|
* @author: schisandra
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum IsDeletedFlagEnum {
|
||||||
|
|
||||||
|
DELETED(1,"已删除"),
|
||||||
|
UN_DELETED(0,"未删除");
|
||||||
|
|
||||||
|
public int code;
|
||||||
|
|
||||||
|
public String desc;
|
||||||
|
|
||||||
|
IsDeletedFlagEnum(int code, String desc){
|
||||||
|
this.code = code;
|
||||||
|
this.desc = desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IsDeletedFlagEnum getByCode(int codeVal){
|
||||||
|
for(IsDeletedFlagEnum resultCodeEnum : IsDeletedFlagEnum.values()){
|
||||||
|
if(resultCodeEnum.code == codeVal){
|
||||||
|
return resultCodeEnum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,34 @@
|
|||||||
|
package com.schisandra.share.common.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 返回结果状态枚举
|
||||||
|
* @author: schisandra
|
||||||
|
* @date: 2024/3/22 13:10
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum ResultCodeEnum {
|
||||||
|
|
||||||
|
SUCCESS(200, "成功"),
|
||||||
|
FAIL(500, "失败");
|
||||||
|
|
||||||
|
public int code;
|
||||||
|
|
||||||
|
public String desc;
|
||||||
|
|
||||||
|
ResultCodeEnum(int code, String desc) {
|
||||||
|
this.code = code;
|
||||||
|
this.desc = desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResultCodeEnum getByCode(int codeVal) {
|
||||||
|
for (ResultCodeEnum resultCodeEnum : ResultCodeEnum.values()) {
|
||||||
|
if (resultCodeEnum.code == codeVal) {
|
||||||
|
return resultCodeEnum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -12,10 +12,63 @@
|
|||||||
|
|
||||||
<name>schisandra-cloud-storage-share-domain</name>
|
<name>schisandra-cloud-storage-share-domain</name>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.13.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.24</version>
|
||||||
|
</path>
|
||||||
|
<!-- 必须要加, 否则生成不了 MapperImpl 实现类 -->
|
||||||
|
<path>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct-processor</artifactId>
|
||||||
|
<version>1.4.2.Final</version>
|
||||||
|
</path>
|
||||||
|
<!-- 如果是 0.1.0 有可能出现生成了maptruct的实现类, 但该类只创建了对象, 没有进行赋值 -->
|
||||||
|
<path>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok-mapstruct-binding</artifactId>
|
||||||
|
<version>0.2.0</version>
|
||||||
|
</path>
|
||||||
|
<path>
|
||||||
|
<groupId>com.mybatis-flex</groupId>
|
||||||
|
<artifactId>mybatis-flex-processor</artifactId>
|
||||||
|
<version>1.9.0</version>
|
||||||
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.schisandra.share</groupId>
|
||||||
|
<artifactId>schisandra-cloud-storage-share-infra</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.schisandra.share</groupId>
|
||||||
|
<artifactId>schisandra-cloud-storage-share-common</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@@ -13,9 +13,53 @@
|
|||||||
<name>schisandra-cloud-storage-share-infra</name>
|
<name>schisandra-cloud-storage-share-infra</name>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!--jdbcStarter-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||||
|
<version>2.4.2</version>
|
||||||
|
</dependency>
|
||||||
|
<!--druid连接池-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>druid-spring-boot-starter</artifactId>
|
||||||
|
<version>1.1.21</version>
|
||||||
|
</dependency>
|
||||||
|
<!--mysql-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>8.0.33</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mybatis-flex</groupId>
|
||||||
|
<artifactId>mybatis-flex-spring-boot-starter</artifactId>
|
||||||
|
<version>1.9.3</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mybatis-flex</groupId>
|
||||||
|
<artifactId>mybatis-flex-processor</artifactId>
|
||||||
|
<version>1.9.3</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.aspectj</groupId>
|
||||||
|
<artifactId>aspectjweaver</artifactId>
|
||||||
|
<version>1.9.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.schisandra.share</groupId>
|
||||||
|
<artifactId>schisandra-cloud-storage-share-common</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@@ -12,9 +12,137 @@
|
|||||||
|
|
||||||
<name>schisandra-cloud-storage-share-starter</name>
|
<name>schisandra-cloud-storage-share-starter</name>
|
||||||
<properties>
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
<spring-boot.version>2.4.2</spring-boot.version>
|
||||||
|
<spring-cloud-alibaba.version>2021.1</spring-cloud-alibaba.version>
|
||||||
|
<spring-cloud.version>2020.0.6</spring-cloud.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
<version>2.4.2</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>spring-boot-starter-logging</artifactId>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.schisandra.share</groupId>
|
||||||
|
<artifactId>schisandra-cloud-storage-share-infra</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.schisandra.share</groupId>
|
||||||
|
<artifactId>schisandra-cloud-storage-share-application-controller</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-dependencies</artifactId>
|
||||||
|
<version>${spring-cloud.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-dependencies</artifactId>
|
||||||
|
<version>${spring-boot.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||||
|
<version>${spring-cloud-alibaba.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
<build>
|
||||||
|
<finalName>${project.artifactId}</finalName>
|
||||||
|
<!--打包成jar包时的名字-->
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>2.3.0.RELEASE</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<excludes>
|
||||||
|
<!-- 打包的时候忽略lombok,因为lombok值在编译器起作用 -->
|
||||||
|
<exclude>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</exclude>
|
||||||
|
</excludes>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.13.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.24</version>
|
||||||
|
</path>
|
||||||
|
<!-- 必须要加, 否则生成不了 MapperImpl 实现类 -->
|
||||||
|
<path>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct-processor</artifactId>
|
||||||
|
<version>1.4.2.Final</version>
|
||||||
|
</path>
|
||||||
|
<!-- 如果是 0.1.0 有可能出现生成了maptruct的实现类, 但该类只创建了对象, 没有进行赋值 -->
|
||||||
|
<path>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok-mapstruct-binding</artifactId>
|
||||||
|
<version>0.2.0</version>
|
||||||
|
</path>
|
||||||
|
<path>
|
||||||
|
<groupId>com.mybatis-flex</groupId>
|
||||||
|
<artifactId>mybatis-flex-processor</artifactId>
|
||||||
|
<version>1.9.0</version>
|
||||||
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
@@ -1,13 +0,0 @@
|
|||||||
package com.schisandra.share;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hello world!
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class App
|
|
||||||
{
|
|
||||||
public static void main( String[] args )
|
|
||||||
{
|
|
||||||
System.out.println( "Hello World!" );
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,21 @@
|
|||||||
|
package com.schisandra.share;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分享微服务启动类
|
||||||
|
*
|
||||||
|
* @author: schisandra
|
||||||
|
* @date: 2024/3/21
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
@ComponentScan("com.schisandra")
|
||||||
|
@MapperScan("com.schisandra.**.dao")
|
||||||
|
public class ShareApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(ShareApplication.class);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,65 @@
|
|||||||
|
server:
|
||||||
|
port: 6000
|
||||||
|
spring:
|
||||||
|
datasource:
|
||||||
|
username: root
|
||||||
|
password: BZbVbGDBePiA2q8/mt0eMxKNpHniDzxBtOxFadQiAOTDzCDlopC4qOKwwBEi9CAZcuFsCrRJdwn0wP6jwsnzxw==
|
||||||
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
url: jdbc:mysql://1.95.0.111:3306/schisandra-cloud-storage?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=true
|
||||||
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
|
druid:
|
||||||
|
initial-size: 20
|
||||||
|
min-idle: 20
|
||||||
|
max-active: 100
|
||||||
|
max-wait: 60000
|
||||||
|
connectionProperties: config.decrypt=true;config.decrypt.key=${publicKey};
|
||||||
|
stat-view-servlet:
|
||||||
|
enabled: true
|
||||||
|
url-pattern: /druid/*
|
||||||
|
login-username: admin
|
||||||
|
login-password: 123456
|
||||||
|
filter:
|
||||||
|
stat:
|
||||||
|
enabled: true
|
||||||
|
slow-sql-millis: 2000
|
||||||
|
log-slow-sql: true
|
||||||
|
wall:
|
||||||
|
enabled: true
|
||||||
|
config:
|
||||||
|
enabled: true
|
||||||
|
# redis配置
|
||||||
|
redis:
|
||||||
|
# Redis数据库索引(默认为0)
|
||||||
|
database: 1
|
||||||
|
# Redis服务器地址
|
||||||
|
host: 1.95.0.111
|
||||||
|
# Redis服务器连接端口
|
||||||
|
port: 6379
|
||||||
|
# Redis服务器连接密码(默认为空)
|
||||||
|
password: LDQ20020618xxx
|
||||||
|
# 连接超时时间
|
||||||
|
timeout: 2s
|
||||||
|
lettuce:
|
||||||
|
pool:
|
||||||
|
# 连接池最大连接数
|
||||||
|
max-active: 200
|
||||||
|
# 连接池最大阻塞等待时间(使用负值表示没有限制)
|
||||||
|
max-wait: -1ms
|
||||||
|
# 连接池中的最大空闲连接
|
||||||
|
max-idle: 10
|
||||||
|
# 连接池中的最小空闲连接
|
||||||
|
min-idle: 0
|
||||||
|
publicKey: MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANUVxjcrVoirBZaNmDrUqatHEW4FOHbO5ynW6zvhIbRMo6hEFGgglbURkjuHOlgEduxJVz6Xa+sG+FMrxTguOJECAwEAAQ==
|
||||||
|
logging:
|
||||||
|
config: classpath:log4j2-spring.xml
|
||||||
|
mybatis-flex:
|
||||||
|
global-config:
|
||||||
|
print-banner: false
|
||||||
|
key-config:
|
||||||
|
key-type: generator
|
||||||
|
normal-value-of-logic-delete: 0
|
||||||
|
deleted-value-of-logic-delete: 1
|
||||||
|
logic-delete-column: is_deleted
|
||||||
|
mapper-locations:
|
||||||
|
- "classpath*:/mapper/**/*.xml"
|
||||||
|
|
@@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
|
||||||
|
,---,
|
||||||
|
,--.' | ,--, ,---,
|
||||||
|
| | : ,--.'| ,---, ,---.'| __ ,-.
|
||||||
|
.--.--. : : : | |, .--.--. ,-+-. / | | | :,' ,'/ /|
|
||||||
|
/ / ' ,---. : | |,--.`--'_ / / ' ,--.--. ,--.'|' | | | |' | |' | ,--.--.
|
||||||
|
| : /`./ / \ | : ' |,' ,'| | : /`./ / \ | | ,"' | ,--.__| || | ,'/ \
|
||||||
|
| : ;_ / / ' | | /' :' | | | : ;_ .--. .-. | | | / | | / ,' |' : / .--. .-. |
|
||||||
|
\ \ `. . ' / ' : | | || | : \ \ `. \__\/: . . | | | | |. ' / || | ' \__\/: . .
|
||||||
|
`----. \' ; :__ | | ' | :' : |__ `----. \ ," .--.; | | | | |/ ' ; |: |; : | ," .--.; |
|
||||||
|
/ /`--' /' | '.'|| : :_:,'| | '.'| / /`--' // / ,. | | | |--' | | '/ '| , ; / / ,. |
|
||||||
|
'--'. / | : :| | ,' ; : ;'--'. /; : .' \| |/ | : :| ---' ; : .' \
|
||||||
|
`--'---' \ \ / `--'' | , / `--'---' | , .-./'---' \ \ / | , .-./
|
||||||
|
`----' ---`-' `--`---' `----' `--`---'
|
||||||
|
|
||||||
|
Spring Boot: ${spring-boot.formatted-version}
|
||||||
|
五味子云存储
|
@@ -0,0 +1,15 @@
|
|||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: schisandra-cloud-storage-share
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
config:
|
||||||
|
server-addr: 1.95.0.111:8848
|
||||||
|
prefix: ${spring.application.name}
|
||||||
|
group: DEFAULT_GROUP
|
||||||
|
namespace:
|
||||||
|
file-extension: yaml
|
||||||
|
discovery:
|
||||||
|
enabled: true
|
||||||
|
server-addr: 1.95.0.111:8848
|
||||||
|
|
@@ -0,0 +1,87 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--Configuration后面的status,这个用于设置log4j2自身内部的信息输出,可以不设置,当设置成trace时,你会看到log4j2内部各种详细输出-->
|
||||||
|
<!--monitorInterval:Log4j能够自动检测修改配置 文件和重新配置本身,设置间隔秒数-->
|
||||||
|
<configuration status="INFO" monitorInterval="5">
|
||||||
|
<!--日志级别以及优先级排序: OFF > FATAL > ERROR > WARN > INFO > DEBUG > TRACE > ALL -->
|
||||||
|
<!--变量配置-->
|
||||||
|
<Properties>
|
||||||
|
<!-- 格式化输出:%date表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度 %msg:日志消息,%n是换行符-->
|
||||||
|
<!-- %logger{36} 表示 Logger 名字最长36个字符 -->
|
||||||
|
<property name="LOG_PATTERN" value="%clr{%d{yyyy-MM-dd HH:mm:ss.SSS}}{faint} %clr{%5p} %clr{${sys:PID}}{magenta} %clr{---}{faint} %clr{[%thread]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n%xwEx" />
|
||||||
|
<!-- 定义日志存储的路径 -->
|
||||||
|
<property name="FILE_PATH" value="../log" />
|
||||||
|
<property name="FILE_NAME" value="schisandra-cloud-storage-share.log" />
|
||||||
|
</Properties>
|
||||||
|
|
||||||
|
<!--https://logging.apache.org/log4j/2.x/manual/appenders.html-->
|
||||||
|
<appenders>
|
||||||
|
|
||||||
|
<console name="Console" target="SYSTEM_OUT">
|
||||||
|
<!--输出日志的格式-->
|
||||||
|
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||||
|
<!--控制台只输出level及其以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
|
||||||
|
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
|
||||||
|
</console>
|
||||||
|
|
||||||
|
<!--文件会打印出所有信息,这个log每次运行程序会自动清空,由append属性决定,适合临时测试用-->
|
||||||
|
<File name="fileLog" fileName="${FILE_PATH}/temp.log" append="false">
|
||||||
|
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||||
|
</File>
|
||||||
|
|
||||||
|
<!-- 这个会打印出所有的info及以下级别的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
|
||||||
|
<RollingFile name="RollingFileInfo" fileName="${FILE_PATH}/info.log" filePattern="${FILE_PATH}/${FILE_NAME}-INFO-%d{yyyy-MM-dd}_%i.log.gz">
|
||||||
|
<!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
|
||||||
|
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
|
||||||
|
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||||
|
<Policies>
|
||||||
|
<!--interval属性用来指定多久滚动一次,默认是1 hour-->
|
||||||
|
<TimeBasedTriggeringPolicy interval="1"/>
|
||||||
|
<SizeBasedTriggeringPolicy size="10MB"/>
|
||||||
|
</Policies>
|
||||||
|
<!-- DefaultRolloverStrategy属性如不设置,则默认为最多同一文件夹下7个文件开始覆盖-->
|
||||||
|
<DefaultRolloverStrategy max="15"/>
|
||||||
|
</RollingFile>
|
||||||
|
|
||||||
|
<!-- 这个会打印出所有的warn及以下级别的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
|
||||||
|
<RollingFile name="RollingFileWarn" fileName="${FILE_PATH}/warn.log" filePattern="${FILE_PATH}/${FILE_NAME}-WARN-%d{yyyy-MM-dd}_%i.log.gz">
|
||||||
|
<!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
|
||||||
|
<ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="DENY"/>
|
||||||
|
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||||
|
<Policies>
|
||||||
|
<!--interval属性用来指定多久滚动一次,默认是1 hour-->
|
||||||
|
<TimeBasedTriggeringPolicy interval="1"/>
|
||||||
|
<SizeBasedTriggeringPolicy size="10MB"/>
|
||||||
|
</Policies>
|
||||||
|
<!-- DefaultRolloverStrategy属性如不设置,则默认为最多同一文件夹下7个文件开始覆盖-->
|
||||||
|
<DefaultRolloverStrategy max="15"/>
|
||||||
|
</RollingFile>
|
||||||
|
|
||||||
|
<!-- 这个会打印出所有的error及以下级别的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
|
||||||
|
<RollingFile name="RollingFileError" fileName="${FILE_PATH}/error.log" filePattern="${FILE_PATH}/${FILE_NAME}-ERROR-%d{yyyy-MM-dd}_%i.log.gz">
|
||||||
|
<!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
|
||||||
|
<ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
|
||||||
|
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||||
|
<Policies>
|
||||||
|
<!--interval属性用来指定多久滚动一次,默认是1 hour-->
|
||||||
|
<TimeBasedTriggeringPolicy interval="1"/>
|
||||||
|
<SizeBasedTriggeringPolicy size="10MB"/>
|
||||||
|
</Policies>
|
||||||
|
<!-- DefaultRolloverStrategy属性如不设置,则默认为最多同一文件夹下7个文件开始覆盖-->
|
||||||
|
<DefaultRolloverStrategy max="15"/>
|
||||||
|
</RollingFile>
|
||||||
|
|
||||||
|
</appenders>
|
||||||
|
|
||||||
|
<!--Logger节点用来单独指定日志的形式,比如要为指定包下的class指定不同的日志级别等。-->
|
||||||
|
<!--然后定义loggers,只有定义了logger并引入的appender,appender才会生效-->
|
||||||
|
<loggers>
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="Console"/>
|
||||||
|
<appender-ref ref="RollingFileInfo"/>
|
||||||
|
<appender-ref ref="RollingFileWarn"/>
|
||||||
|
<appender-ref ref="RollingFileError"/>
|
||||||
|
<appender-ref ref="fileLog"/>
|
||||||
|
</root>
|
||||||
|
</loggers>
|
||||||
|
|
||||||
|
</configuration>
|
@@ -0,0 +1,3 @@
|
|||||||
|
processor.enable=true
|
||||||
|
processor.allInTables.enable=false
|
||||||
|
processor.allInTables.package=com.schisandra.oss
|
@@ -20,6 +20,10 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.schisandra.system</groupId>
|
||||||
|
<artifactId>schisandra-cloud-storage-system-domain</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@@ -69,5 +69,15 @@
|
|||||||
<artifactId>schisandra-cloud-storage-system-common</artifactId>
|
<artifactId>schisandra-cloud-storage-system-common</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xuxueli</groupId>
|
||||||
|
<artifactId>xxl-job-core</artifactId>
|
||||||
|
<version>2.4.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-context</artifactId>
|
||||||
|
<version>5.3.27</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@@ -0,0 +1,78 @@
|
|||||||
|
package com.schisandra.system.domain.config;
|
||||||
|
|
||||||
|
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xxl-job config
|
||||||
|
*
|
||||||
|
* @author xuxueli 2017-04-28
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class XxlJobConfig {
|
||||||
|
private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);
|
||||||
|
|
||||||
|
@Value("${xxl.job.admin.addresses}")
|
||||||
|
private String adminAddresses;
|
||||||
|
|
||||||
|
@Value("${xxl.job.accessToken}")
|
||||||
|
private String accessToken;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.appname}")
|
||||||
|
private String appname;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.address}")
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.ip}")
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.port}")
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.logpath}")
|
||||||
|
private String logPath;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.logretentiondays}")
|
||||||
|
private int logRetentionDays;
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public XxlJobSpringExecutor xxlJobExecutor() {
|
||||||
|
logger.info(">>>>>>>>>>> xxl-job config init.");
|
||||||
|
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
|
||||||
|
xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
|
||||||
|
xxlJobSpringExecutor.setAppname(appname);
|
||||||
|
xxlJobSpringExecutor.setAddress(address);
|
||||||
|
xxlJobSpringExecutor.setIp(ip);
|
||||||
|
xxlJobSpringExecutor.setPort(port);
|
||||||
|
xxlJobSpringExecutor.setAccessToken(accessToken);
|
||||||
|
xxlJobSpringExecutor.setLogPath(logPath);
|
||||||
|
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
|
||||||
|
|
||||||
|
return xxlJobSpringExecutor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP;
|
||||||
|
*
|
||||||
|
* 1、引入依赖:
|
||||||
|
* <dependency>
|
||||||
|
* <groupId>org.springframework.cloud</groupId>
|
||||||
|
* <artifactId>spring-cloud-commons</artifactId>
|
||||||
|
* <version>${version}</version>
|
||||||
|
* </dependency>
|
||||||
|
*
|
||||||
|
* 2、配置文件,或者容器启动变量
|
||||||
|
* spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.'
|
||||||
|
*
|
||||||
|
* 3、获取IP
|
||||||
|
* String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -8,7 +8,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
/**
|
/**
|
||||||
* @Classname MyBatisFlexConfiguration
|
* @Classname MyBatisFlexConfiguration
|
||||||
* @BelongsProject: schisandra-cloud-storage
|
* @BelongsProject: schisandra-cloud-storage
|
||||||
* @BelongsPackage: com.schisandra.oss.infra.config
|
* @BelongsPackage: com.schisandra.oss.infra.common
|
||||||
* @Author: landaiqing
|
* @Author: landaiqing
|
||||||
* @CreateTime: 2024-05-31 16:14
|
* @CreateTime: 2024-05-31 16:14
|
||||||
* @Description: Mybatis flex 配置类
|
* @Description: Mybatis flex 配置类
|
||||||
|
@@ -58,6 +58,11 @@
|
|||||||
<artifactId>schisandra-cloud-storage-system-infra</artifactId>
|
<artifactId>schisandra-cloud-storage-system-infra</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.schisandra.system</groupId>
|
||||||
|
<artifactId>schisandra-cloud-storage-system-application-job</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
@@ -82,4 +82,17 @@ mybatis-flex:
|
|||||||
mapper-locations:
|
mapper-locations:
|
||||||
- "classpath*:/mapper/**/*.xml"
|
- "classpath*:/mapper/**/*.xml"
|
||||||
|
|
||||||
|
# xxl-job配置
|
||||||
|
xxl:
|
||||||
|
job:
|
||||||
|
admin:
|
||||||
|
addresses: http://1.95.0.111:8088/xxl-job-admin
|
||||||
|
accessToken: default_token
|
||||||
|
executor:
|
||||||
|
appname: schisandra-cloud-storage-system
|
||||||
|
address:
|
||||||
|
ip: 1.95.0.111
|
||||||
|
port: 9999
|
||||||
|
logpath: /data/applogs/xxl-job/jobhandler
|
||||||
|
logretentiondays: 30
|
||||||
|
|
||||||
|
@@ -40,6 +40,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>error_prone_annotations</artifactId>
|
||||||
|
<groupId>com.google.errorprone</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
@@ -67,11 +73,6 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-log4j2</artifactId>
|
<artifactId>spring-boot-starter-log4j2</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.thoughtworks.xstream</groupId>
|
|
||||||
<artifactId>xstream</artifactId>
|
|
||||||
<version>1.4.18</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>com.google.code.gson</groupId>
|
||||||
<artifactId>gson</artifactId>
|
<artifactId>gson</artifactId>
|
||||||
@@ -82,11 +83,6 @@
|
|||||||
<artifactId>dom4j</artifactId>
|
<artifactId>dom4j</artifactId>
|
||||||
<version>2.1.1</version>
|
<version>2.1.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
|
||||||
<artifactId>jackson-core</artifactId>
|
|
||||||
<version>2.12.7</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
@@ -101,6 +97,28 @@
|
|||||||
<artifactId>caffeine</artifactId>
|
<artifactId>caffeine</artifactId>
|
||||||
<version>2.9.3</version>
|
<version>2.9.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||||
|
<artifactId>jackson-dataformat-xml</artifactId>
|
||||||
|
<version>2.11.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||||
|
<version>2.7.4</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xuxueli</groupId>
|
||||||
|
<artifactId>xxl-job-core</artifactId>
|
||||||
|
<version>2.4.0</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.schisandra</groupId>
|
<groupId>com.schisandra</groupId>
|
||||||
<artifactId>schisandra-cloud-storage-auth-api</artifactId>
|
<artifactId>schisandra-cloud-storage-auth-api</artifactId>
|
||||||
|
@@ -0,0 +1,59 @@
|
|||||||
|
package com.schisandra.wechat.aes;
|
||||||
|
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
public class AesException extends Exception {
|
||||||
|
|
||||||
|
public final static int OK = 0;
|
||||||
|
public final static int ValidateSignatureError = -40001;
|
||||||
|
public final static int ParseXmlError = -40002;
|
||||||
|
public final static int ComputeSignatureError = -40003;
|
||||||
|
public final static int IllegalAesKey = -40004;
|
||||||
|
public final static int ValidateAppidError = -40005;
|
||||||
|
public final static int EncryptAESError = -40006;
|
||||||
|
public final static int DecryptAESError = -40007;
|
||||||
|
public final static int IllegalBuffer = -40008;
|
||||||
|
//public final static int EncodeBase64Error = -40009;
|
||||||
|
//public final static int DecodeBase64Error = -40010;
|
||||||
|
//public final static int GenReturnXmlError = -40011;
|
||||||
|
|
||||||
|
private int code;
|
||||||
|
|
||||||
|
private static String getMessage(int code) {
|
||||||
|
switch (code) {
|
||||||
|
case ValidateSignatureError:
|
||||||
|
return "签名验证错误";
|
||||||
|
case ParseXmlError:
|
||||||
|
return "xml解析失败";
|
||||||
|
case ComputeSignatureError:
|
||||||
|
return "sha加密生成签名失败";
|
||||||
|
case IllegalAesKey:
|
||||||
|
return "SymmetricKey非法";
|
||||||
|
case ValidateAppidError:
|
||||||
|
return "appid校验失败";
|
||||||
|
case EncryptAESError:
|
||||||
|
return "aes加密失败";
|
||||||
|
case DecryptAESError:
|
||||||
|
return "aes解密失败";
|
||||||
|
case IllegalBuffer:
|
||||||
|
return "解密后得到的buffer非法";
|
||||||
|
// case EncodeBase64Error:
|
||||||
|
// return "base64加密错误";
|
||||||
|
// case DecodeBase64Error:
|
||||||
|
// return "base64解密错误";
|
||||||
|
// case GenReturnXmlError:
|
||||||
|
// return "xml生成失败";
|
||||||
|
default:
|
||||||
|
return null; // cannot be
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AesException(int code) {
|
||||||
|
super(getMessage(code));
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,58 @@
|
|||||||
|
package com.schisandra.wechat.common.constant;
|
||||||
|
|
||||||
|
public enum ApiResponseCode {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功
|
||||||
|
*/
|
||||||
|
SUCCESS(0, "success"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数错误
|
||||||
|
*/
|
||||||
|
PARAMETER_INVALID(100, "parameter_invalid"),
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业务错误
|
||||||
|
*/
|
||||||
|
BUSINESS_ERROR(200, "业务错误"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录错误
|
||||||
|
*/
|
||||||
|
LOGIN_ERROR(201, "登录失败"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号或密码错误
|
||||||
|
*/
|
||||||
|
ACCOUNT_PASSWORD_ERROR(202, "账号或密码错误"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号错误
|
||||||
|
*/
|
||||||
|
ACCOUNT_ERROR(203, "账号错误"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务异常
|
||||||
|
*/
|
||||||
|
SERVICE_ERROR(500, "service_error");
|
||||||
|
|
||||||
|
private Integer code;
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
private ApiResponseCode(Integer code, String message) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,29 @@
|
|||||||
|
package com.schisandra.wechat.common.constant;
|
||||||
|
|
||||||
|
public class CommonConstant {
|
||||||
|
public static final String TOKEN_CACHE_KEY = "TOKEN:";
|
||||||
|
public static final String USER_CACHE_KEY = "USER:";
|
||||||
|
|
||||||
|
public static final String UTF8 = "UTF-8";
|
||||||
|
public static final String GBK = "GBK";
|
||||||
|
/**
|
||||||
|
* 角色菜单权限
|
||||||
|
*/
|
||||||
|
public static final String ROLE_MENU_PERMISSIONS = "ROLE_MENU_PERMISSIONS:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色资源权限
|
||||||
|
*/
|
||||||
|
public static final String ROLE_RESOURCE_PERMISSIONS = "ROLE_RESOURCE_PERMISSIONS:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理员
|
||||||
|
*/
|
||||||
|
public static final Long ROLE_ADMIN = 1L;
|
||||||
|
/**
|
||||||
|
* 普通会员
|
||||||
|
*/
|
||||||
|
public static final Long ROLE_MEMBER = 2L;
|
||||||
|
public CommonConstant() {
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,57 @@
|
|||||||
|
package com.schisandra.wechat.common.entity;
|
||||||
|
|
||||||
|
|
||||||
|
import com.schisandra.wechat.common.enums.ResultCodeEnum;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 返回结果泛型类
|
||||||
|
* @author: schisandra
|
||||||
|
* @date: 2024/3/22 13:09
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class Result<T> {
|
||||||
|
|
||||||
|
private Boolean success;
|
||||||
|
|
||||||
|
private Integer code;
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
public static Result ok() {
|
||||||
|
Result result = new Result();
|
||||||
|
result.setSuccess(true);
|
||||||
|
result.setCode(ResultCodeEnum.SUCCESS.getCode());
|
||||||
|
result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result ok(T data) {
|
||||||
|
Result result = new Result();
|
||||||
|
result.setSuccess(true);
|
||||||
|
result.setCode(ResultCodeEnum.SUCCESS.getCode());
|
||||||
|
result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
|
||||||
|
result.setData(data);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result fail() {
|
||||||
|
Result result = new Result();
|
||||||
|
result.setSuccess(false);
|
||||||
|
result.setCode(ResultCodeEnum.FAIL.getCode());
|
||||||
|
result.setMessage(ResultCodeEnum.FAIL.getDesc());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result fail(T data) {
|
||||||
|
Result result = new Result();
|
||||||
|
result.setSuccess(false);
|
||||||
|
result.setCode(ResultCodeEnum.FAIL.getCode());
|
||||||
|
result.setMessage(ResultCodeEnum.FAIL.getDesc());
|
||||||
|
result.setData(data);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,34 @@
|
|||||||
|
package com.schisandra.wechat.common.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 返回结果状态枚举
|
||||||
|
* @author: schisandra
|
||||||
|
* @date: 2024/3/22 13:10
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum ResultCodeEnum {
|
||||||
|
|
||||||
|
SUCCESS(200, "成功"),
|
||||||
|
FAIL(500, "失败");
|
||||||
|
|
||||||
|
public int code;
|
||||||
|
|
||||||
|
public String desc;
|
||||||
|
|
||||||
|
ResultCodeEnum(int code, String desc) {
|
||||||
|
this.code = code;
|
||||||
|
this.desc = desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResultCodeEnum getByCode(int codeVal) {
|
||||||
|
for (ResultCodeEnum resultCodeEnum : ResultCodeEnum.values()) {
|
||||||
|
if (resultCodeEnum.code == codeVal) {
|
||||||
|
return resultCodeEnum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,43 @@
|
|||||||
|
package com.schisandra.wechat.common.exception;
|
||||||
|
|
||||||
|
|
||||||
|
import com.schisandra.wechat.common.constant.ApiResponseCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理异常
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class BaseException extends RuntimeException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 2612992235262400823L;
|
||||||
|
|
||||||
|
public Integer getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(Integer code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer code = null;
|
||||||
|
|
||||||
|
public BaseException(String message) {
|
||||||
|
super(message);
|
||||||
|
this.code = ApiResponseCode.SERVICE_ERROR.getCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BaseException(String message, Throwable t) {
|
||||||
|
super(message, t);
|
||||||
|
this.code = ApiResponseCode.SERVICE_ERROR.getCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BaseException(Integer code, String message) {
|
||||||
|
super(message);
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BaseException(Integer code, String message, Throwable t) {
|
||||||
|
super(message, t);
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,46 @@
|
|||||||
|
package com.schisandra.wechat.common.exception;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import com.schisandra.wechat.common.constant.ApiResponseCode;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数异常
|
||||||
|
*/
|
||||||
|
public class ParameterException extends BaseException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Map<String, String> fieldErrors;
|
||||||
|
|
||||||
|
public ParameterException(String message) {
|
||||||
|
super(ApiResponseCode.PARAMETER_INVALID.getCode(), message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParameterException(int code, String message) {
|
||||||
|
super(code, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParameterException(Map<String, String> fieldErrors) {
|
||||||
|
super(ApiResponseCode.PARAMETER_INVALID.getCode(), ApiResponseCode.PARAMETER_INVALID.getMessage());
|
||||||
|
this.fieldErrors = fieldErrors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParameterException(String key, String value) {
|
||||||
|
super(ApiResponseCode.PARAMETER_INVALID.getCode(), ApiResponseCode.PARAMETER_INVALID.getMessage());
|
||||||
|
Map<String, String> fieldErrors = new HashMap<>();
|
||||||
|
fieldErrors.put(key, value);
|
||||||
|
this.fieldErrors = fieldErrors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getFieldErrors() {
|
||||||
|
return fieldErrors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParameterException(String message, Throwable t) {
|
||||||
|
super(message, t);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,4 +1,5 @@
|
|||||||
package com.schisandra.wechat.redis;
|
package com.schisandra.wechat.common.redis;
|
||||||
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
@@ -16,8 +17,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|||||||
/**
|
/**
|
||||||
* Redis的config处理
|
* Redis的config处理
|
||||||
*
|
*
|
||||||
* @author: ChickenWing
|
* @author: schisandra
|
||||||
* @date: 2023/10/28
|
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class RedisConfig {
|
public class RedisConfig {
|
@@ -1,4 +1,5 @@
|
|||||||
package com.schisandra.wechat.redis;
|
package com.schisandra.wechat.common.redis;
|
||||||
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
@@ -13,8 +14,8 @@ import java.util.stream.Stream;
|
|||||||
/**
|
/**
|
||||||
* RedisUtil工具类
|
* RedisUtil工具类
|
||||||
*
|
*
|
||||||
* @author: ChickenWing
|
* @author: schisandra
|
||||||
* @date: 2023/10/28
|
* @date: 2024/2/19
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
@@ -0,0 +1,24 @@
|
|||||||
|
package com.schisandra.wechat.config;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
||||||
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
|
import reactor.netty.http.client.HttpClient;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Slf4j
|
||||||
|
public class WebClientDefaultConfig {
|
||||||
|
@Bean
|
||||||
|
public WebClient webClient() {
|
||||||
|
log.info("WebClientDefaultConfig init start ...");
|
||||||
|
HttpClient httpClient = HttpClient.create();
|
||||||
|
|
||||||
|
WebClient webClient = WebClient.builder()
|
||||||
|
.clientConnector(new ReactorClientHttpConnector(httpClient))
|
||||||
|
.build();
|
||||||
|
log.info("WebClientDefaultConfig init end");
|
||||||
|
return webClient;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,23 @@
|
|||||||
|
package com.schisandra.wechat.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@ConfigurationProperties(
|
||||||
|
prefix = "wx"
|
||||||
|
)
|
||||||
|
@Data
|
||||||
|
public class WxConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公众号配置
|
||||||
|
*/
|
||||||
|
private WxDetailConfig mp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小程序配置
|
||||||
|
*/
|
||||||
|
private WxDetailConfig miniApp;
|
||||||
|
}
|
@@ -0,0 +1,33 @@
|
|||||||
|
package com.schisandra.wechat.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class WxDetailConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* appid
|
||||||
|
*/
|
||||||
|
private String appId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 秘钥
|
||||||
|
*/
|
||||||
|
private String secret;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 二维码过期时间
|
||||||
|
* 默认15分钟
|
||||||
|
*/
|
||||||
|
private Integer codeExpire = 900;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* token
|
||||||
|
*/
|
||||||
|
private String token;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息加密密钥
|
||||||
|
*/
|
||||||
|
private String encodingAESKey;
|
||||||
|
}
|
@@ -0,0 +1,78 @@
|
|||||||
|
package com.schisandra.wechat.config;
|
||||||
|
|
||||||
|
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xxl-job config
|
||||||
|
*
|
||||||
|
* @author xuxueli 2017-04-28
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class XxlJobConfig {
|
||||||
|
private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);
|
||||||
|
|
||||||
|
@Value("${xxl.job.admin.addresses}")
|
||||||
|
private String adminAddresses;
|
||||||
|
|
||||||
|
@Value("${xxl.job.accessToken}")
|
||||||
|
private String accessToken;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.appname}")
|
||||||
|
private String appname;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.address}")
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.ip}")
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.port}")
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.logpath}")
|
||||||
|
private String logPath;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.logretentiondays}")
|
||||||
|
private int logRetentionDays;
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public XxlJobSpringExecutor xxlJobExecutor() {
|
||||||
|
logger.info(">>>>>>>>>>> xxl-job config init.");
|
||||||
|
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
|
||||||
|
xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
|
||||||
|
xxlJobSpringExecutor.setAppname(appname);
|
||||||
|
xxlJobSpringExecutor.setAddress(address);
|
||||||
|
xxlJobSpringExecutor.setIp(ip);
|
||||||
|
xxlJobSpringExecutor.setPort(port);
|
||||||
|
xxlJobSpringExecutor.setAccessToken(accessToken);
|
||||||
|
xxlJobSpringExecutor.setLogPath(logPath);
|
||||||
|
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
|
||||||
|
|
||||||
|
return xxlJobSpringExecutor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP;
|
||||||
|
*
|
||||||
|
* 1、引入依赖:
|
||||||
|
* <dependency>
|
||||||
|
* <groupId>org.springframework.cloud</groupId>
|
||||||
|
* <artifactId>spring-cloud-commons</artifactId>
|
||||||
|
* <version>${version}</version>
|
||||||
|
* </dependency>
|
||||||
|
*
|
||||||
|
* 2、配置文件,或者容器启动变量
|
||||||
|
* spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.'
|
||||||
|
*
|
||||||
|
* 3、获取IP
|
||||||
|
* String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,15 @@
|
|||||||
|
package com.schisandra.wechat.constant;
|
||||||
|
|
||||||
|
public class WXApiConstant {
|
||||||
|
/**
|
||||||
|
* 获取微信token
|
||||||
|
*/
|
||||||
|
public static final String ACCESS_TOKEN_API = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成临时公众号二维码
|
||||||
|
* 文档地址:https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=TOKEN
|
||||||
|
*/
|
||||||
|
public static final String MP_QRCODE_CREATE ="https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=%s";
|
||||||
|
|
||||||
|
}
|
@@ -1,84 +0,0 @@
|
|||||||
package com.schisandra.wechat.controller;
|
|
||||||
|
|
||||||
import com.schisandra.wechat.handler.WeChatMsgFactory;
|
|
||||||
import com.schisandra.wechat.handler.WeChatMsgHandler;
|
|
||||||
import com.schisandra.wechat.utils.MessageUtil;
|
|
||||||
import com.schisandra.wechat.utils.SHA1;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Classname CallBackController
|
|
||||||
* @BelongsProject: schisandra-cloud-storage
|
|
||||||
* @BelongsPackage: com.schisandra.wechat.controller
|
|
||||||
* @Author: schisandra
|
|
||||||
* @CreateTime: 2024-02-21 16:41
|
|
||||||
* @Description: TODO
|
|
||||||
* @Version: 1.0
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@Slf4j
|
|
||||||
public class CallBackController {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private WeChatMsgFactory weChatMsgFactory;
|
|
||||||
@Value("${wechat.token}")
|
|
||||||
private String token;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description: 回调消息校验
|
|
||||||
* @param: [signature, timestamp, nonce, echostr]
|
|
||||||
* @return: java.lang.String
|
|
||||||
* @author schisandra
|
|
||||||
* @date: 2024/2/21 17:16
|
|
||||||
*/
|
|
||||||
@GetMapping("/callback")
|
|
||||||
public String callback(@RequestParam("signature") String signature,
|
|
||||||
@RequestParam("timestamp") String timestamp,
|
|
||||||
@RequestParam("nonce") String nonce,
|
|
||||||
@RequestParam("echostr") String echostr) {
|
|
||||||
log.info("get验签请求参数:signature: {},timestamp: {}, nonce: {},echostr: {}",
|
|
||||||
signature, timestamp, nonce, echostr);
|
|
||||||
|
|
||||||
String shaStr = SHA1.getSHA1(token, timestamp, nonce, "");
|
|
||||||
if (signature.equals(shaStr)) {
|
|
||||||
return echostr;
|
|
||||||
}
|
|
||||||
return "unKnown";
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping(value = "callback", produces = "application/xml;charset=UTF-8")
|
|
||||||
public String callback(
|
|
||||||
@RequestBody String requestBody,
|
|
||||||
@RequestParam("signature") String signature,
|
|
||||||
@RequestParam("timestamp") String timestamp,
|
|
||||||
@RequestParam("nonce") String nonce,
|
|
||||||
@RequestParam(value = "msg_signature", required = false) String msgSignature) {
|
|
||||||
log.info("接收到微信消息:requestBody:{}", requestBody);
|
|
||||||
Map<String, String> messageMap = MessageUtil.parseXml(requestBody);
|
|
||||||
String msgType = messageMap.get("MsgType");
|
|
||||||
String event = messageMap.get("Event") == null ? "" : messageMap.get("Event");
|
|
||||||
log.info("msgType:{},event:{}", msgType, event);
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append(msgType);
|
|
||||||
if (!StringUtils.isEmpty(event)) {
|
|
||||||
sb.append(".");
|
|
||||||
sb.append(event);
|
|
||||||
}
|
|
||||||
String msgTypeKey = sb.toString();
|
|
||||||
WeChatMsgHandler weChatMsgHandler = weChatMsgFactory.getHandlerByMsgType(msgTypeKey);
|
|
||||||
if (Objects.isNull(weChatMsgHandler)) {
|
|
||||||
return "unknown";
|
|
||||||
}
|
|
||||||
String replyContent = weChatMsgHandler.dealMsg(messageMap);
|
|
||||||
log.info("replyContent:{}", replyContent);
|
|
||||||
return replyContent;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,75 @@
|
|||||||
|
package com.schisandra.wechat.controller;
|
||||||
|
|
||||||
|
import com.schisandra.wechat.common.entity.Result;
|
||||||
|
import com.schisandra.wechat.config.WxConfig;
|
||||||
|
import com.schisandra.wechat.dto.AccessTokenResult;
|
||||||
|
import com.schisandra.wechat.dto.MpQrCodeCreateRequest;
|
||||||
|
import com.schisandra.wechat.dto.MpQrCodeCreateResult;
|
||||||
|
import com.schisandra.wechat.service.WXService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.logging.log4j.util.Strings;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Classname WxController
|
||||||
|
* @BelongsProject: schisandra-cloud-storage
|
||||||
|
* @BelongsPackage: com.schisandra.wechat.controller
|
||||||
|
* @Author: landaiqing
|
||||||
|
* @CreateTime: 2024-06-26 16:29
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/wx/")
|
||||||
|
@Slf4j
|
||||||
|
public class WxController {
|
||||||
|
@Resource
|
||||||
|
private WXService wxService;
|
||||||
|
@Resource
|
||||||
|
WxConfig wxConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 获取微信access_token
|
||||||
|
* @param: []
|
||||||
|
* @return: void
|
||||||
|
* @author: landaiqing
|
||||||
|
* @date: 2024/6/27 上午11:34
|
||||||
|
*/
|
||||||
|
@GetMapping("getAccessToken")
|
||||||
|
public Result getAccessToken() {
|
||||||
|
AccessTokenResult accessTokenResult = wxService.getMpAccessToken(wxConfig.getMp().getAppId(), wxConfig.getMp().getSecret());
|
||||||
|
return Result.ok(accessTokenResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 生成微信二维码
|
||||||
|
* @param: []
|
||||||
|
* @return: com.schisandra.wechat.common.entity.Result
|
||||||
|
* @author: landaiqing
|
||||||
|
* @date: 2024/6/27 上午11:34
|
||||||
|
*/
|
||||||
|
@GetMapping("generateQRCode")
|
||||||
|
public Result generateQRCode(@RequestParam("clientId") String clientId) {
|
||||||
|
if (Strings.isBlank(clientId)){
|
||||||
|
return Result.fail("客户端获取失败,请刷新页面!");
|
||||||
|
}
|
||||||
|
String mpAccessTokenByCache = wxService.getMpAccessTokenByCache(wxConfig.getMp().getAppId());
|
||||||
|
if (Strings.isBlank(mpAccessTokenByCache)) {
|
||||||
|
return Result.fail("获取微信access_token失败!");
|
||||||
|
}
|
||||||
|
MpQrCodeCreateRequest request = new MpQrCodeCreateRequest();
|
||||||
|
request.setExpireSeconds(wxConfig.getMp().getCodeExpire());
|
||||||
|
request.setActionName("QR_STR_SCENE");
|
||||||
|
request.setActionInfo(request.new ActionInfo());
|
||||||
|
request.getActionInfo().setScene(request.new scene());
|
||||||
|
request.getActionInfo().getScene().setSceneStr("ScanReg_" + wxConfig.getMp().getAppId() + "_" + clientId);
|
||||||
|
MpQrCodeCreateResult result = wxService.createMpQrcodeCreate(mpAccessTokenByCache, request);
|
||||||
|
return Result.ok(result);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,45 @@
|
|||||||
|
package com.schisandra.wechat.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.schisandra.wechat.aes.AesException;
|
||||||
|
import com.schisandra.wechat.dto.MpCommonRequest;
|
||||||
|
import com.schisandra.wechat.service.WxMpEventService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||||
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
public class WxEventController {
|
||||||
|
@Resource
|
||||||
|
WxMpEventService wxMpEventService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接收微信事件推送
|
||||||
|
* 参考文档:
|
||||||
|
* https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Receiving_event_pushes.html
|
||||||
|
* *
|
||||||
|
*
|
||||||
|
* @param mpCommonRequest
|
||||||
|
* @return
|
||||||
|
* @throws HttpRequestMethodNotSupportedException
|
||||||
|
*/
|
||||||
|
@RequestMapping(value = "/callback",
|
||||||
|
method = {RequestMethod.GET, RequestMethod.POST})
|
||||||
|
public String receiveMpEvent(@Validated @ModelAttribute MpCommonRequest mpCommonRequest, HttpServletRequest httpServletRequest) throws IOException, AesException {
|
||||||
|
return wxMpEventService.receiveMpEvent(mpCommonRequest, httpServletRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,32 @@
|
|||||||
|
package com.schisandra.wechat.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取微信token返回接口实体信息
|
||||||
|
* 参考文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class AccessTokenResult {
|
||||||
|
/**
|
||||||
|
* 获取到的凭证
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "access_token", required = true)
|
||||||
|
private String accessToken;
|
||||||
|
/**
|
||||||
|
* 凭证有效时间,单位:秒。目前是7200秒之内的值。
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "expires_in", required = true)
|
||||||
|
private String expiresIn;
|
||||||
|
/**
|
||||||
|
* 错误码
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "errcode", required = true)
|
||||||
|
private String errCode;
|
||||||
|
/**
|
||||||
|
* 错误信息
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "errmsg", required = true)
|
||||||
|
private String errMsg;
|
||||||
|
}
|
@@ -0,0 +1,82 @@
|
|||||||
|
package com.schisandra.wechat.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接收微信事件推送
|
||||||
|
* 具体参数意思参考文档地址:
|
||||||
|
* https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Receiving_event_pushes.html
|
||||||
|
*/
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
@Data
|
||||||
|
public class MpBaseEventRequest implements Serializable {
|
||||||
|
private static final long serialVersionUID = 9194059022155191588L;
|
||||||
|
/**
|
||||||
|
* 开发者微信号
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "ToUserName")
|
||||||
|
private String toUserName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送方帐号(一个OpenID)
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "FromUserName")
|
||||||
|
private String fromUserName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息创建时间 (整型)
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "CreateTime")
|
||||||
|
private Integer createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息类型,event
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "MsgType")
|
||||||
|
private String msgType;
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 事件类型
|
||||||
|
// * subscribe(订阅/)
|
||||||
|
// * unsubscribe(取消订阅)
|
||||||
|
// * SCAN(用户已关注扫描)
|
||||||
|
// * LOCATION 上报地理位置
|
||||||
|
// * CLICK 菜单点击事件
|
||||||
|
// */
|
||||||
|
// @JsonProperty(value = "Event")
|
||||||
|
// private String event;
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 事件 KEY 值,是一个32位无符号整数,即创建二维码时的二维码scene_id
|
||||||
|
// */
|
||||||
|
// @JsonProperty(value = "EventKey")
|
||||||
|
// private String eventKey;
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 二维码的ticket,可用来换取二维码图片
|
||||||
|
// */
|
||||||
|
// @JsonProperty(value = "Ticket")
|
||||||
|
// private String ticket;
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 地理位置纬度
|
||||||
|
// */
|
||||||
|
// @JsonProperty(value = "Latitude")
|
||||||
|
// private Double latitude;
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 地理位置经度
|
||||||
|
// */
|
||||||
|
// @JsonProperty(value = "Longitude")
|
||||||
|
// private Double longitude;
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 地理位置精度
|
||||||
|
// */
|
||||||
|
// @JsonProperty(value = "Precision")
|
||||||
|
// private Double precision;
|
||||||
|
}
|
@@ -0,0 +1,27 @@
|
|||||||
|
package com.schisandra.wechat.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class MpCommonRequest {
|
||||||
|
/**
|
||||||
|
* 微信加密签名,signature结合了开发者填写的 token 参数和请求中的 timestamp 参数、nonce参数。
|
||||||
|
*/
|
||||||
|
|
||||||
|
private String signature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时间戳
|
||||||
|
*/
|
||||||
|
private String timestamp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 随机数
|
||||||
|
*/
|
||||||
|
private String nonce;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 随机字符串
|
||||||
|
*/
|
||||||
|
private String echostr;
|
||||||
|
}
|
@@ -0,0 +1,46 @@
|
|||||||
|
package com.schisandra.wechat.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class MpQrCodeCreateRequest {
|
||||||
|
/**
|
||||||
|
* 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为60秒。
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "expire_seconds")
|
||||||
|
private Integer expireSeconds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 二维码类型,QR_SCENE为临时的整型参数值,QR_STR_SCENE为临时的字符串参数值,QR_LIMIT_SCENE为永久的整型参数值,QR_LIMIT_STR_SCENE为永久的字符串参数值
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "action_name")
|
||||||
|
private String actionName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 二维码详细信息
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "action_info")
|
||||||
|
private ActionInfo actionInfo;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ActionInfo {
|
||||||
|
private scene scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class scene {
|
||||||
|
/**
|
||||||
|
* 场景值ID,临时二维码时为32位非0整型,永久二维码时最大值为100000(目前参数只支持1--100000)
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "scene_id")
|
||||||
|
private Integer sceneId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 场景值ID(字符串形式的ID),字符串类型,长度限制为1到64
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "scene_str")
|
||||||
|
private String sceneStr;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,41 @@
|
|||||||
|
package com.schisandra.wechat.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class MpQrCodeCreateResult implements Serializable {
|
||||||
|
/**
|
||||||
|
* 获取的二维码ticket,凭借此 ticket 可以在有效时间内换取二维码。
|
||||||
|
*/
|
||||||
|
private String ticket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天)。
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "expire_seconds")
|
||||||
|
private Integer expireSeconds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 二维码图片解析后的地址,开发者可根据该地址自行生成需要的二维码图片
|
||||||
|
*/
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误码
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "errcode")
|
||||||
|
private String errCode;
|
||||||
|
/**
|
||||||
|
* 错误信息
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "errmsg")
|
||||||
|
private String errMsg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 二维码地址
|
||||||
|
*/
|
||||||
|
private String qrCodeUrl;
|
||||||
|
}
|
@@ -0,0 +1,37 @@
|
|||||||
|
package com.schisandra.wechat.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接收微信事件推送
|
||||||
|
* 具体参数意思参考文档地址:
|
||||||
|
* https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Receiving_event_pushes.html
|
||||||
|
*/
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
@Data
|
||||||
|
public class MpSubscribeEventRequest extends MpBaseEventRequest {
|
||||||
|
/**
|
||||||
|
* 事件类型
|
||||||
|
* subscribe(订阅/)
|
||||||
|
* unsubscribe(取消订阅)
|
||||||
|
* SCAN(用户已关注扫描)
|
||||||
|
* LOCATION 上报地理位置
|
||||||
|
* CLICK 菜单点击事件
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "Event")
|
||||||
|
private String event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事件 KEY 值,qrscene_为前缀,后面为二维码的参数值
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "EventKey")
|
||||||
|
private String eventKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 二维码的ticket,可用来换取二维码图片
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "Ticket")
|
||||||
|
private String ticket;
|
||||||
|
}
|
@@ -0,0 +1,18 @@
|
|||||||
|
package com.schisandra.wechat.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接收微信事件推送
|
||||||
|
* 具体参数意思参考文档地址:
|
||||||
|
* https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Receiving_event_pushes.html
|
||||||
|
*/
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
@Data
|
||||||
|
public class MpTextEventRequest extends MpBaseEventRequest {
|
||||||
|
private static final long serialVersionUID = 4209945653336582616L;
|
||||||
|
@JsonProperty(value = "Content")
|
||||||
|
private String content;
|
||||||
|
}
|
@@ -1,29 +0,0 @@
|
|||||||
package com.schisandra.wechat.entity;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public enum ResultCodeEnum {
|
|
||||||
|
|
||||||
SUCCESS(200,"成功"),
|
|
||||||
FAIL(500,"失败");
|
|
||||||
|
|
||||||
public int code;
|
|
||||||
|
|
||||||
public String desc;
|
|
||||||
|
|
||||||
ResultCodeEnum(int code,String desc){
|
|
||||||
this.code = code;
|
|
||||||
this.desc = desc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ResultCodeEnum getByCode(int codeVal){
|
|
||||||
for(ResultCodeEnum resultCodeEnum : ResultCodeEnum.values()){
|
|
||||||
if(resultCodeEnum.code == codeVal){
|
|
||||||
return resultCodeEnum;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,57 +0,0 @@
|
|||||||
package com.schisandra.wechat.handler;
|
|
||||||
|
|
||||||
import com.schisandra.wechat.redis.RedisUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@Slf4j
|
|
||||||
public class ReceiveTextMsgHandler implements WeChatMsgHandler {
|
|
||||||
|
|
||||||
private static final String KEY_WORD = "验证码";
|
|
||||||
private static final String LOGIN_KEY_WORD = "登录";
|
|
||||||
|
|
||||||
private static final String LOGIN_PREFIX = "loginCode";
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private RedisUtil redisUtil;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public WeChatMsgTypeEnum getMsgType() {
|
|
||||||
return WeChatMsgTypeEnum.TEXT_MSG;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String dealMsg(Map<String, String> messageMap) {
|
|
||||||
String content = messageMap.get("Content");
|
|
||||||
String fromUserName = messageMap.get("FromUserName");
|
|
||||||
String toUserName = messageMap.get("ToUserName");
|
|
||||||
|
|
||||||
// 验证码
|
|
||||||
if (KEY_WORD.equals(content)) {
|
|
||||||
|
|
||||||
Random random = new Random();
|
|
||||||
int num = random.nextInt(9000) + 1000;
|
|
||||||
String numKey = redisUtil.buildKey(LOGIN_PREFIX, String.valueOf(num));
|
|
||||||
redisUtil.setNx(numKey, fromUserName, 1L, TimeUnit.MINUTES);
|
|
||||||
String numContent = "您当前的验证码是:【" + num + "】 , 1分钟内有效";
|
|
||||||
String replyContent = "<xml>\n" +
|
|
||||||
" <ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>\n" +
|
|
||||||
" <FromUserName><![CDATA[" + toUserName + "]]></FromUserName>\n" +
|
|
||||||
" <CreateTime>12345678</CreateTime>\n" +
|
|
||||||
" <MsgType><![CDATA[text]]></MsgType>\n" +
|
|
||||||
" <Content><![CDATA[" + numContent + "]]></Content>\n" +
|
|
||||||
"</xml>";
|
|
||||||
|
|
||||||
return replyContent;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,33 +0,0 @@
|
|||||||
package com.schisandra.wechat.handler;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@Slf4j
|
|
||||||
public class SubscribeMsgHandler implements WeChatMsgHandler {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public WeChatMsgTypeEnum getMsgType() {
|
|
||||||
return WeChatMsgTypeEnum.SUBSCRIBE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String dealMsg(Map<String, String> messageMap) {
|
|
||||||
log.info("触发用户关注事件!");
|
|
||||||
String fromUserName = messageMap.get("FromUserName");
|
|
||||||
String toUserName = messageMap.get("ToUserName");
|
|
||||||
String subscribeContent = "感谢您的关注!";
|
|
||||||
String content = "<xml>\n" +
|
|
||||||
" <ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>\n" +
|
|
||||||
" <FromUserName><![CDATA[" + toUserName + "]]></FromUserName>\n" +
|
|
||||||
" <CreateTime>12345678</CreateTime>\n" +
|
|
||||||
" <MsgType><![CDATA[text]]></MsgType>\n" +
|
|
||||||
" <Content><![CDATA[" + subscribeContent + "]]></Content>\n" +
|
|
||||||
"</xml>";
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,31 +0,0 @@
|
|||||||
package com.schisandra.wechat.handler;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class WeChatMsgFactory implements InitializingBean {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private List<WeChatMsgHandler> weChatMsgHandlerList;
|
|
||||||
|
|
||||||
private Map<WeChatMsgTypeEnum, WeChatMsgHandler> handlerMap = new HashMap<>();
|
|
||||||
|
|
||||||
public WeChatMsgHandler getHandlerByMsgType(String msgType) {
|
|
||||||
WeChatMsgTypeEnum msgTypeEnum = WeChatMsgTypeEnum.getByMsgType(msgType);
|
|
||||||
return handlerMap.get(msgTypeEnum);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterPropertiesSet() throws Exception {
|
|
||||||
for (WeChatMsgHandler weChatMsgHandler : weChatMsgHandlerList) {
|
|
||||||
handlerMap.put(weChatMsgHandler.getMsgType(), weChatMsgHandler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,11 +0,0 @@
|
|||||||
package com.schisandra.wechat.handler;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public interface WeChatMsgHandler {
|
|
||||||
|
|
||||||
WeChatMsgTypeEnum getMsgType();
|
|
||||||
|
|
||||||
String dealMsg(Map<String, String> messageMap);
|
|
||||||
|
|
||||||
}
|
|
@@ -1,26 +0,0 @@
|
|||||||
package com.schisandra.wechat.handler;
|
|
||||||
|
|
||||||
public enum WeChatMsgTypeEnum {
|
|
||||||
|
|
||||||
SUBSCRIBE("event.subscribe", "用户关注事件"),
|
|
||||||
TEXT_MSG("text", "接收用户文本消息");
|
|
||||||
|
|
||||||
private String msgType;
|
|
||||||
|
|
||||||
private String desc;
|
|
||||||
|
|
||||||
WeChatMsgTypeEnum(String msgType, String desc) {
|
|
||||||
this.msgType = msgType;
|
|
||||||
this.desc = desc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static WeChatMsgTypeEnum getByMsgType(String msgType) {
|
|
||||||
for (WeChatMsgTypeEnum weChatMsgTypeEnum : WeChatMsgTypeEnum.values()) {
|
|
||||||
if (weChatMsgTypeEnum.msgType.equals(msgType)) {
|
|
||||||
return weChatMsgTypeEnum;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -0,0 +1,38 @@
|
|||||||
|
package com.schisandra.wechat.job;
|
||||||
|
|
||||||
|
import com.schisandra.wechat.config.WxConfig;
|
||||||
|
import com.schisandra.wechat.service.WXService;
|
||||||
|
import com.xxl.job.core.context.XxlJobHelper;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Classname GetAccessTokenJob
|
||||||
|
* @BelongsProject: schisandra-cloud-storage
|
||||||
|
* @BelongsPackage: com.schisandra.auth.application.job
|
||||||
|
* @Author: landaiqing
|
||||||
|
* @CreateTime: 2024-06-26 22:57
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class GenerateAccessTokenJob {
|
||||||
|
@Resource
|
||||||
|
private WXService wxService;
|
||||||
|
@Resource
|
||||||
|
private WxConfig wxConfig;
|
||||||
|
|
||||||
|
@XxlJob("generateAccessTokenJobHandler")
|
||||||
|
public void GenerateAccessTokenJobHandler() throws Exception {
|
||||||
|
XxlJobHelper.log("generateAccessTokenJobHandler.starter");
|
||||||
|
try {
|
||||||
|
wxService.setMpAccessTokenCache(wxConfig.getMp().getAppId(), wxConfig.getMp().getSecret());
|
||||||
|
} catch (Exception e) {
|
||||||
|
XxlJobHelper.log("generateAccessTokenJobHandler.error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,29 @@
|
|||||||
|
package com.schisandra.wechat.rpc;
|
||||||
|
|
||||||
|
import com.schisandra.auth.api.SchisandraAuthFeignService;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Classname AuthUserRpc
|
||||||
|
* @BelongsProject: schisandra-cloud-storage
|
||||||
|
* @BelongsPackage: com.schisandra.wechat.rpc
|
||||||
|
* @Author: landaiqing
|
||||||
|
* @CreateTime: 2024-06-27 17:00
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class AuthUserRpc {
|
||||||
|
@Resource
|
||||||
|
private SchisandraAuthFeignService schisandraAuthFeignService;
|
||||||
|
|
||||||
|
public Boolean wechatRegister(String appId, String openId, String clientId) {
|
||||||
|
Boolean result = schisandraAuthFeignService.wechatRegister(appId, openId, clientId);
|
||||||
|
if (result) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,42 @@
|
|||||||
|
package com.schisandra.wechat.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.schisandra.wechat.dto.AccessTokenResult;
|
||||||
|
import com.schisandra.wechat.dto.MpQrCodeCreateRequest;
|
||||||
|
import com.schisandra.wechat.dto.MpQrCodeCreateResult;
|
||||||
|
|
||||||
|
public interface WXService {
|
||||||
|
/**
|
||||||
|
* 从缓存中获取公众号token
|
||||||
|
* @param appid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String getMpAccessTokenByCache(String appid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置公众号token的redis缓存
|
||||||
|
*
|
||||||
|
* @param appid
|
||||||
|
* @param secret
|
||||||
|
*/
|
||||||
|
void setMpAccessTokenCache(String appid, String secret);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取微信公众号token
|
||||||
|
* 参考接口文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html
|
||||||
|
*
|
||||||
|
* @param appid
|
||||||
|
* @param secret
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
AccessTokenResult getMpAccessToken(String appid, String secret);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成临时公众号二维码
|
||||||
|
* 文档地址:https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=TOKEN
|
||||||
|
* @param token
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
MpQrCodeCreateResult createMpQrcodeCreate(String token, MpQrCodeCreateRequest request);
|
||||||
|
}
|
@@ -0,0 +1,34 @@
|
|||||||
|
package com.schisandra.wechat.service;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import com.schisandra.wechat.aes.AesException;
|
||||||
|
import com.schisandra.wechat.dto.MpCommonRequest;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public interface WxMpEventService {
|
||||||
|
/**
|
||||||
|
* 接收公众号推送的事件
|
||||||
|
*
|
||||||
|
* @param mpCommonRequest
|
||||||
|
* @param httpServletRequest
|
||||||
|
* @return
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
String receiveMpEvent(MpCommonRequest mpCommonRequest, HttpServletRequest httpServletRequest) throws IOException, AesException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用SHA1算法生成安全签名
|
||||||
|
*
|
||||||
|
* @param signature 签名
|
||||||
|
* @param token 票据
|
||||||
|
* @param timestamp 时间戳
|
||||||
|
* @param nonce 随机字符串
|
||||||
|
* @param encrypt 密文
|
||||||
|
* @return 安全签名
|
||||||
|
* @throws AesException
|
||||||
|
*/
|
||||||
|
void checkSignature(String signature, String token, String timestamp, String nonce, String encrypt) throws AesException;
|
||||||
|
}
|
@@ -0,0 +1,100 @@
|
|||||||
|
package com.schisandra.wechat.service.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import com.schisandra.wechat.common.redis.RedisUtil;
|
||||||
|
import com.schisandra.wechat.constant.WXApiConstant;
|
||||||
|
import com.schisandra.wechat.dto.AccessTokenResult;
|
||||||
|
import com.schisandra.wechat.dto.MpQrCodeCreateRequest;
|
||||||
|
import com.schisandra.wechat.dto.MpQrCodeCreateResult;
|
||||||
|
import com.schisandra.wechat.service.WXService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.logging.log4j.util.Strings;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.reactive.function.BodyInserters;
|
||||||
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class WXServiceImpl implements WXService {
|
||||||
|
@Resource
|
||||||
|
WebClient webClient;
|
||||||
|
@Resource
|
||||||
|
RedisTemplate<String, Object> redisTemplate;
|
||||||
|
@Resource
|
||||||
|
RedisUtil redisUtil;
|
||||||
|
|
||||||
|
final String WX_ACCESS_TOKEN_REDIS_KEY = "wx_access_token";
|
||||||
|
//接口重试次数
|
||||||
|
int retry = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从缓存中获取公众号token
|
||||||
|
* @param appid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getMpAccessTokenByCache(String appid) {
|
||||||
|
String key = redisUtil.buildKey(WX_ACCESS_TOKEN_REDIS_KEY, appid);
|
||||||
|
return redisUtil.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置公众号token的redis缓存
|
||||||
|
*
|
||||||
|
* @param appid
|
||||||
|
* @param secret
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setMpAccessTokenCache(String appid, String secret) {
|
||||||
|
AccessTokenResult accessTokenResult = getMpAccessToken(appid, secret);
|
||||||
|
String key = redisUtil.buildKey(WX_ACCESS_TOKEN_REDIS_KEY, appid);
|
||||||
|
redisUtil.setNx(key,accessTokenResult.getAccessToken(), Long.valueOf(accessTokenResult.getExpiresIn()), TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取微信公众号token
|
||||||
|
* 参考接口文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html
|
||||||
|
*
|
||||||
|
* @param appid
|
||||||
|
* @param secret
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public AccessTokenResult getMpAccessToken(String appid, String secret) {
|
||||||
|
String url = String.format(WXApiConstant.ACCESS_TOKEN_API, appid, secret);
|
||||||
|
return webClient.get().uri(url).retrieve().bodyToMono(AccessTokenResult.class)
|
||||||
|
.retry(retry)
|
||||||
|
.block();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成临时公众号二维码
|
||||||
|
* 文档地址:https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=TOKEN
|
||||||
|
*
|
||||||
|
* @param token
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public MpQrCodeCreateResult createMpQrcodeCreate(String token, MpQrCodeCreateRequest request) {
|
||||||
|
String url = String.format(WXApiConstant.MP_QRCODE_CREATE, token);
|
||||||
|
MpQrCodeCreateResult result = webClient.post().uri(url).contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.body(BodyInserters.fromValue(request))
|
||||||
|
.retrieve().bodyToMono(MpQrCodeCreateResult.class).retry(retry)
|
||||||
|
.block();
|
||||||
|
if (result == null || Strings.isBlank(result.getTicket())) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result.setQrCodeUrl("https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + result.getTicket());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,159 @@
|
|||||||
|
package com.schisandra.wechat.service.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||||
|
import com.schisandra.wechat.aes.AesException;
|
||||||
|
import com.schisandra.wechat.common.exception.ParameterException;
|
||||||
|
import com.schisandra.wechat.config.WxConfig;
|
||||||
|
import com.schisandra.wechat.dto.MpBaseEventRequest;
|
||||||
|
import com.schisandra.wechat.dto.MpCommonRequest;
|
||||||
|
import com.schisandra.wechat.dto.MpSubscribeEventRequest;
|
||||||
|
import com.schisandra.wechat.dto.MpTextEventRequest;
|
||||||
|
import com.schisandra.wechat.rpc.AuthUserRpc;
|
||||||
|
import com.schisandra.wechat.service.WxMpEventService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.logging.log4j.util.Strings;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
public class WxMpEventServiceImpl implements WxMpEventService {
|
||||||
|
@Resource
|
||||||
|
ApplicationContext applicationContext;
|
||||||
|
@Resource
|
||||||
|
WxConfig wxConfig;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AuthUserRpc authUserRpc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接收公众号推送的事件
|
||||||
|
*
|
||||||
|
* @param mpCommonRequest
|
||||||
|
* @param httpServletRequest
|
||||||
|
* @return
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String receiveMpEvent(MpCommonRequest mpCommonRequest, HttpServletRequest httpServletRequest) throws IOException, AesException {
|
||||||
|
checkSignature(mpCommonRequest.getSignature(),
|
||||||
|
wxConfig.getMp().getToken(),
|
||||||
|
mpCommonRequest.getTimestamp(),
|
||||||
|
mpCommonRequest.getNonce(),
|
||||||
|
null);
|
||||||
|
if (Strings.isBlank(httpServletRequest.getHeader("content-type"))) {
|
||||||
|
log.info("content-type is null");
|
||||||
|
return mpCommonRequest.getEchostr();
|
||||||
|
}
|
||||||
|
log.info("content-type:" + httpServletRequest.getHeader("content-type"));
|
||||||
|
log.info(mpCommonRequest.toString());
|
||||||
|
|
||||||
|
XmlMapper xmlMapper = new XmlMapper();
|
||||||
|
Object object = xmlMapper.readValue(httpServletRequest.getInputStream(), Object.class);
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
log.info(object.toString());
|
||||||
|
MpBaseEventRequest mpBaseEventRequest = mapper.convertValue(object, MpBaseEventRequest.class);
|
||||||
|
if ("text".equals(mpBaseEventRequest.getMsgType())) {
|
||||||
|
MpTextEventRequest mpTextEventRequest = mapper.convertValue(object, MpTextEventRequest.class);
|
||||||
|
log.info(mpTextEventRequest.toString());
|
||||||
|
log.info("推送消息:MpTextEventRequest...");
|
||||||
|
// applicationContext.publishEvent(mpTextEventRequest);
|
||||||
|
}
|
||||||
|
if ("event".equals(mpBaseEventRequest.getMsgType())) {
|
||||||
|
MpSubscribeEventRequest mpSubscribeEventRequest = mapper.convertValue(object, MpSubscribeEventRequest.class);
|
||||||
|
log.info(mpSubscribeEventRequest.toString());
|
||||||
|
log.info("推送消息:MpSubscribeEventRequest...");
|
||||||
|
// applicationContext.publishEvent(mpSubscribeEventRequest);
|
||||||
|
if ("subscribe".equals(mpSubscribeEventRequest.getEvent())
|
||||||
|
&& Strings.isNotBlank(mpSubscribeEventRequest.getEventKey())) {
|
||||||
|
String[] keys = mpSubscribeEventRequest.getEventKey().split("_");
|
||||||
|
if ("qrscene".equals(keys[0]) && "ScanReg".equals(keys[1])) {
|
||||||
|
log.info("AppId:{},ClientId:{}", keys[2], keys[3]);
|
||||||
|
authUserRpc.wechatRegister(keys[2], mpSubscribeEventRequest.getToUserName(), keys[3]);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("SCAN".equals(mpSubscribeEventRequest.getEvent()) &&
|
||||||
|
Strings.isNotBlank(mpSubscribeEventRequest.getEventKey())) {
|
||||||
|
String[] keys = mpSubscribeEventRequest.getEventKey().split("_");
|
||||||
|
if ("ScanReg".equals(keys[0])) {
|
||||||
|
log.info("AppId:{},ClientId:{}", keys[1], keys[2]);
|
||||||
|
authUserRpc.wechatRegister(keys[1], mpSubscribeEventRequest.getFromUserName(), keys[2]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info("微信公众号推送事件处理完成");
|
||||||
|
return mpCommonRequest.getEchostr();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用SHA1算法生成安全签名
|
||||||
|
*
|
||||||
|
* @param signature 签名
|
||||||
|
* @param token 票据
|
||||||
|
* @param timestamp 时间戳
|
||||||
|
* @param nonce 随机字符串
|
||||||
|
* @param encrypt 密文
|
||||||
|
* @return 安全签名
|
||||||
|
* @throws AesException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void checkSignature(String signature, String token, String timestamp, String nonce, String encrypt) throws AesException {
|
||||||
|
try {
|
||||||
|
if (Strings.isBlank(signature) || Strings.isBlank(token)
|
||||||
|
|| Strings.isBlank(timestamp) || Strings.isBlank(nonce)) {
|
||||||
|
throw new ParameterException("签名参数非法");
|
||||||
|
}
|
||||||
|
String[] array = null;
|
||||||
|
if (Strings.isBlank(encrypt)) {
|
||||||
|
array = new String[]{token, timestamp, nonce};
|
||||||
|
} else {
|
||||||
|
array = new String[]{token, timestamp, nonce, encrypt};
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
// 字符串排序
|
||||||
|
Arrays.sort(array);
|
||||||
|
for (int i = 0; i < array.length; i++) {
|
||||||
|
sb.append(array[i]);
|
||||||
|
}
|
||||||
|
String str = sb.toString();
|
||||||
|
// SHA1签名生成
|
||||||
|
MessageDigest md = MessageDigest.getInstance("SHA-1");
|
||||||
|
md.update(str.getBytes());
|
||||||
|
byte[] digest = md.digest();
|
||||||
|
|
||||||
|
StringBuffer hexstr = new StringBuffer();
|
||||||
|
String shaHex = "";
|
||||||
|
for (int i = 0; i < digest.length; i++) {
|
||||||
|
shaHex = Integer.toHexString(digest[i] & 0xFF);
|
||||||
|
if (shaHex.length() < 2) {
|
||||||
|
hexstr.append(0);
|
||||||
|
}
|
||||||
|
hexstr.append(shaHex);
|
||||||
|
}
|
||||||
|
log.info("wx_signature:{},my_signature:{}", signature, hexstr.toString());
|
||||||
|
if (!Objects.equals(signature, hexstr.toString())) {
|
||||||
|
throw new AesException(AesException.ValidateSignatureError);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new AesException(AesException.ComputeSignatureError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1,47 +0,0 @@
|
|||||||
package com.schisandra.wechat.utils;
|
|
||||||
|
|
||||||
import org.dom4j.Document;
|
|
||||||
import org.dom4j.Element;
|
|
||||||
import org.dom4j.io.SAXReader;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class MessageUtil {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解析微信发来的请求(XML).
|
|
||||||
*
|
|
||||||
* @param msg 消息
|
|
||||||
* @return map
|
|
||||||
*/
|
|
||||||
public static Map<String, String> parseXml(final String msg) {
|
|
||||||
// 将解析结果存储在HashMap中
|
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
|
||||||
|
|
||||||
// 从request中取得输入流
|
|
||||||
try (InputStream inputStream = new ByteArrayInputStream(msg.getBytes(StandardCharsets.UTF_8.name()))) {
|
|
||||||
// 读取输入流
|
|
||||||
SAXReader reader = new SAXReader();
|
|
||||||
Document document = reader.read(inputStream);
|
|
||||||
// 得到xml根元素
|
|
||||||
Element root = document.getRootElement();
|
|
||||||
// 得到根元素的所有子节点
|
|
||||||
List<Element> elementList = root.elements();
|
|
||||||
|
|
||||||
// 遍历所有子节点
|
|
||||||
for (Element e : elementList) {
|
|
||||||
map.put(e.getName(), e.getText());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,56 +0,0 @@
|
|||||||
package com.schisandra.wechat.utils;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* sha1生成签名工具
|
|
||||||
*
|
|
||||||
* @author: schisandra
|
|
||||||
* @date: 2023/11/5
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
public class SHA1 {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用SHA1算法生成安全签名
|
|
||||||
*
|
|
||||||
* @param token 票据
|
|
||||||
* @param timestamp 时间戳
|
|
||||||
* @param nonce 随机字符串
|
|
||||||
* @param encrypt 密文
|
|
||||||
* @return 安全签名
|
|
||||||
*/
|
|
||||||
public static String getSHA1(String token, String timestamp, String nonce, String encrypt) {
|
|
||||||
try {
|
|
||||||
String[] array = new String[]{token, timestamp, nonce, encrypt};
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
// 字符串排序
|
|
||||||
Arrays.sort(array);
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
sb.append(array[i]);
|
|
||||||
}
|
|
||||||
String str = sb.toString();
|
|
||||||
// SHA1签名生成
|
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA-1");
|
|
||||||
md.update(str.getBytes());
|
|
||||||
byte[] digest = md.digest();
|
|
||||||
|
|
||||||
StringBuffer hexStr = new StringBuffer();
|
|
||||||
String shaHex = "";
|
|
||||||
for (int i = 0; i < digest.length; i++) {
|
|
||||||
shaHex = Integer.toHexString(digest[i] & 0xFF);
|
|
||||||
if (shaHex.length() < 2) {
|
|
||||||
hexStr.append(0);
|
|
||||||
}
|
|
||||||
hexStr.append(shaHex);
|
|
||||||
}
|
|
||||||
return hexStr.toString();
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("sha加密生成签名失败:", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -23,5 +23,26 @@ spring:
|
|||||||
max-idle: 10
|
max-idle: 10
|
||||||
# 连接池中的最小空闲连接
|
# 连接池中的最小空闲连接
|
||||||
min-idle: 0
|
min-idle: 0
|
||||||
wechat:
|
|
||||||
token: LDQ20020618xxx
|
# 微信公众号
|
||||||
|
wx:
|
||||||
|
mp:
|
||||||
|
token: LDQ20020618xxx
|
||||||
|
appid: wx55251c2f83b9fc25
|
||||||
|
secret: d511800cd53d248afe1260bb8aeed230
|
||||||
|
codeExpire: 3600
|
||||||
|
encodingAESKey:
|
||||||
|
|
||||||
|
# xxl-job配置
|
||||||
|
xxl:
|
||||||
|
job:
|
||||||
|
admin:
|
||||||
|
addresses: http://127.0.0.1:8081/xxl-job-admin
|
||||||
|
accessToken: default_token
|
||||||
|
executor:
|
||||||
|
appname: schisandra-cloud-storage-wechat
|
||||||
|
address:
|
||||||
|
ip: 127.0.0.1
|
||||||
|
port: 9998
|
||||||
|
logpath: /data/applogs/xxl-job/jobhandler
|
||||||
|
logretentiondays: 30
|
||||||
|
Reference in New Issue
Block a user