diff --git a/esua-epdc/epdc-commons/epdc-common-clienttoken/pom.xml b/esua-epdc/epdc-commons/epdc-common-clienttoken/pom.xml new file mode 100644 index 000000000..e6c04ec31 --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-common-clienttoken/pom.xml @@ -0,0 +1,120 @@ + + + + + epdc-commons + com.esua.epdc + 1.0.0 + + 4.0.0 + + epdc-common-clienttoken + jar + + epdc-common-clienttoken + http://www.example.com + 客户端token + + + + com.esua.epdc + epdc-commons-tools + ${project.version} + + + + org.springframework.boot + spring-boot-starter-web + provided + + + + org.springframework.boot + spring-boot-starter-aop + provided + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + com.vaadin.external.google + android-json + + + + + + org.springframework.boot + spring-boot-autoconfigure + compile + + + + org.springframework.boot + spring-boot-autoconfigure-processor + compile + true + + + + org.springframework.boot + spring-boot-starter-log4j2 + provided + + + + + ${project.artifactId} + + + + maven-clean-plugin + + + + maven-resources-plugin + + + maven-compiler-plugin + + true + ${maven.compiler.source} + ${maven.compiler.target} + ${project.build.sourceEncoding} + + + + maven-surefire-plugin + + + maven-war-plugin + + + maven-install-plugin + + + maven-deploy-plugin + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + true + + + + + + + ${project.basedir}/src/main/java + + diff --git a/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/annotation/Login.java b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/annotation/Login.java new file mode 100644 index 000000000..3eead233b --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/annotation/Login.java @@ -0,0 +1,31 @@ +/** + * Copyright 2018 人人开源 http://www.renren.io + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.elink.esua.common.token.annotation; + +import java.lang.annotation.*; + +/** + * 登录效验 + * @author chenshun + * @email sunlightcs@gmail.com + * @date 2017/9/23 14:30 + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface Login { +} diff --git a/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/annotation/LoginUser.java b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/annotation/LoginUser.java new file mode 100644 index 000000000..9fdaae4c9 --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/annotation/LoginUser.java @@ -0,0 +1,35 @@ +/** + * Copyright 2018 人人开源 http://www.renren.io + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.elink.esua.common.token.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 登录用户信息 + * + * @author chenshun + * @email sunlightcs@gmail.com + * @date 2017-03-23 20:39 + */ +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +public @interface LoginUser { + +} diff --git a/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/annotation/NeedClientToken.java b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/annotation/NeedClientToken.java new file mode 100644 index 000000000..ff6e5fbe5 --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/annotation/NeedClientToken.java @@ -0,0 +1,13 @@ +package com.elink.esua.common.token.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.CLASS)//生命注释保留时长,这里无需反射使用,使用CLASS级别 +@Target(ElementType.METHOD)//生命可以使用此注解的元素级别类型(如类、方法变量等) +public @interface NeedClientToken { + + boolean value() default true; +} diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/config/WebConfig.java b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/config/WebConfig.java similarity index 84% rename from esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/config/WebConfig.java rename to esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/config/WebConfig.java index 89458d299..254b499fd 100644 --- a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/config/WebConfig.java +++ b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/config/WebConfig.java @@ -1,15 +1,15 @@ /** * Copyright (c) 2018 人人开源 All rights reserved. - * + *

* https://www.renren.io - * + *

* 版权所有,侵权必究! */ -package com.elink.esua.epdc.config; +package com.elink.esua.common.token.config; -import com.elink.esua.epdc.commons.tools.resolver.LoginUserHandlerMethodArgumentResolver; -import com.elink.esua.epdc.interceptor.AuthorizationInterceptor; +import com.elink.esua.common.token.interceptor.AuthorizationInterceptor; +import com.elink.esua.common.token.resolver.LoginUserHandlerMethodArgumentResolver; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.web.method.support.HandlerMethodArgumentResolver; @@ -25,8 +25,10 @@ import java.util.List; */ @Configuration public class WebConfig implements WebMvcConfigurer { + @Autowired private AuthorizationInterceptor authorizationInterceptor; + @Autowired private LoginUserHandlerMethodArgumentResolver loginUserHandlerMethodArgumentResolver; diff --git a/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/dto/TokenDto.java b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/dto/TokenDto.java new file mode 100644 index 000000000..90fe6269a --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/dto/TokenDto.java @@ -0,0 +1,38 @@ +package com.elink.esua.common.token.dto; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 用户token + * + * @author rongchao + * @Date 18-10-31 + */ +@Data +public class TokenDto implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 用户信息 + */ + private UserTokenDto userInfoDto; + + /** + * 令牌 + */ + private String token; + + /** + * 过期时间 + */ + private Date expireTime; + + /** + * 更新时间 + */ + private Date updateTime; +} diff --git a/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/dto/UserTokenDto.java b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/dto/UserTokenDto.java new file mode 100644 index 000000000..0e2478ef1 --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/dto/UserTokenDto.java @@ -0,0 +1,43 @@ +package com.elink.esua.common.token.dto; + +import lombok.Data; + +/** + * 用户信息DTO + * + * @author rongchao + * @Date 18-12-1 + */ +@Data +public class UserTokenDto { + + /** + * 用户ID + */ + private String userId; + + /** + * 昵称 + */ + private String nickName; + + /** + * 用户头像 + */ + private String faceImg; + + /** + * 手机号 + */ + private String mobile; + + /** + * 真是姓名 + */ + private String realName; + + /** + * 网格ID + */ + private String gridId; +} diff --git a/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/enums/ErrorCode.java b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/enums/ErrorCode.java new file mode 100644 index 000000000..0f8a8bc3a --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/enums/ErrorCode.java @@ -0,0 +1,46 @@ +package com.elink.esua.common.token.enums; + +import com.elink.esua.common.token.error.IErrorCode; + +/** + * client token错误码 + * + * @author rongchao + * @Date 18-11-24 + */ +public enum ErrorCode implements IErrorCode { + + SUCCESS(0, "请求成功"), + + ERR10001(10001, "clientToken不合法或者已过期"), + ERR10002(10002, "无法获取当前用户的信息,无法生成clientToken。"), + ERR10003(10003, "clientToken生成失败,请重试。"), + ERR10004(10004, "返回的Object类型不是EsuaResponse,无法添加token!"), + ERR10005(10005, "clentToken不能为空"), + + ERR500(500, "Internal Server Error"), + ERR501(501, "参数绑定异常"), + + ERR(ErrorCode.COMMON_ERR_CODE, "其他异常"); + + private int code; + + private String msg; + + ErrorCode(final int code, final String msg) { + this.code = code; + this.msg = msg; + } + + public static final int COMMON_ERR_CODE = -1; + + @Override + public int getCode() { + return code; + } + + @Override + public String getMsg() { + return msg; + } +} diff --git a/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/error/IErrorCode.java b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/error/IErrorCode.java new file mode 100644 index 000000000..f6a4a8033 --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/error/IErrorCode.java @@ -0,0 +1,11 @@ +package com.elink.esua.common.token.error; + +/** + * @author rongchao + * @Date 18-11-20 + */ +public interface IErrorCode { + int getCode(); + + String getMsg(); +} diff --git a/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/interceptor/AuthorizationInterceptor.java b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/interceptor/AuthorizationInterceptor.java new file mode 100644 index 000000000..4143cb9ea --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/interceptor/AuthorizationInterceptor.java @@ -0,0 +1,83 @@ +/** + * Copyright 2018 人人开源 http://www.renren.io + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.elink.esua.common.token.interceptor; + + +import com.elink.esua.common.token.annotation.Login; +import com.elink.esua.common.token.dto.TokenDto; +import com.elink.esua.common.token.enums.ErrorCode; +import com.elink.esua.common.token.util.TokenUtil; +import com.elink.esua.epdc.commons.tools.constant.Constant; +import com.elink.esua.epdc.commons.tools.exception.RenException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; +import org.springframework.web.method.HandlerMethod; +import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @author rongchao + * @Date 18-11-20 + */ +@Component +public class AuthorizationInterceptor extends HandlerInterceptorAdapter { + + @Autowired + private TokenUtil tokenUtil; + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + Login annotation; + if (handler instanceof HandlerMethod) { + annotation = ((HandlerMethod) handler).getMethodAnnotation(Login.class); + } else { + return true; + } + + if (annotation == null) { + return true; + } + + //从header中获取token + String token = request.getHeader("Authorization"); + //如果header中不存在token,则从参数中获取token + if (StringUtils.isEmpty(token)) { + token = request.getParameter("token"); + } + + //token为空 + if (StringUtils.isEmpty(token)) { + // 表示请求信息中没有携带token,前端需要修改上送数据 + throw new RenException(ErrorCode.ERR10005.getCode(), ErrorCode.ERR10005.getMsg()); + } + + //查询token信息 + TokenDto tokenDto = tokenUtil.getTokenInfo("123"); + if (tokenDto == null || tokenDto.getExpireTime().getTime() < System.currentTimeMillis()) { + // token失效或已被清除,前端需要重新请求获取token的接口,并上送 + throw new RenException(ErrorCode.ERR10001.getCode(), ErrorCode.ERR10001.getMsg()); + } + + //设置userId到request里,后续根据userId,获取用户信息 + request.setAttribute(Constant.APP_USER_KEY, tokenDto); + + return true; + } +} diff --git a/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/property/TokenPropertise.java b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/property/TokenPropertise.java new file mode 100644 index 000000000..06fa24477 --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/property/TokenPropertise.java @@ -0,0 +1,23 @@ +package com.elink.esua.common.token.property; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * @author rongchao + * @Date 18-12-3 + */ +@Component +@ConfigurationProperties(prefix = "token") +public class TokenPropertise { + + private long expire = 7200L; + + public long getExpire() { + return expire; + } + + public void setExpire(long expire) { + this.expire = expire; + } +} diff --git a/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/resolver/LoginUserHandlerMethodArgumentResolver.java b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/resolver/LoginUserHandlerMethodArgumentResolver.java similarity index 97% rename from esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/resolver/LoginUserHandlerMethodArgumentResolver.java rename to esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/resolver/LoginUserHandlerMethodArgumentResolver.java index 4d12e9e46..ec638592a 100644 --- a/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/resolver/LoginUserHandlerMethodArgumentResolver.java +++ b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/resolver/LoginUserHandlerMethodArgumentResolver.java @@ -6,7 +6,7 @@ * 版权所有,侵权必究! */ -package com.elink.esua.epdc.commons.tools.resolver; +package com.elink.esua.common.token.resolver; import com.elink.esua.epdc.commons.tools.annotation.LoginUser; import com.elink.esua.epdc.commons.tools.constant.Constant; diff --git a/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/redis/CpUserDetailRedis.java b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/util/CpUserDetailRedis.java similarity index 50% rename from esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/redis/CpUserDetailRedis.java rename to esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/util/CpUserDetailRedis.java index 6ba73d60b..ce7aa3e21 100644 --- a/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/redis/CpUserDetailRedis.java +++ b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/util/CpUserDetailRedis.java @@ -6,10 +6,13 @@ * 版权所有,侵权必究! */ -package com.elink.esua.epdc.commons.tools.redis; +package com.elink.esua.common.token.util; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.map.MapUtil; +import com.elink.esua.common.token.dto.TokenDto; +import com.elink.esua.epdc.commons.tools.redis.RedisKeys; +import com.elink.esua.epdc.commons.tools.redis.RedisUtils; import com.elink.esua.epdc.commons.tools.security.user.CpUserDetail; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -28,18 +31,24 @@ public class CpUserDetailRedis { @Autowired private RedisUtils redisUtils; - public void set(CpUserDetail user, long expire) { + public void set(TokenDto user, long expire) { if (user == null) { return; } - String key = RedisKeys.getCpUserKey(user.getId()); + String key = RedisKeys.getCpUserKey(user.getUserInfoDto().getUserId()); //bean to map Map map = BeanUtil.beanToMap(user, false, true); redisUtils.hMSet(key, map, expire); } - public CpUserDetail get(String id) { - String key = RedisKeys.getCpUserKey(id); + /** + * 获取token信息 + * + * @param userId + * @return + */ + public TokenDto get(String userId) { + String key = RedisKeys.getCpUserKey(userId); Map map = redisUtils.hGetAll(key); if (MapUtil.isEmpty(map)) { @@ -47,17 +56,28 @@ public class CpUserDetailRedis { } //map to bean - CpUserDetail user = BeanUtil.mapToBean(map, CpUserDetail.class, true); + TokenDto user = BeanUtil.mapToBean(map, TokenDto.class, true); return user; } /** - * 用户退出 + * 删除用户信息 + * + * @param userId + */ + public void logout(String userId) { + redisUtils.delete(RedisKeys.getCpUserKey(userId)); + } + + /** + * 设置redis时间 * - * @param id + * @param userId + * @param expire + * @author rongchao */ - public void logout(String id) { - redisUtils.delete(RedisKeys.getCpUserKey(id)); + public boolean expire(String userId, long expire) { + return redisUtils.expire(RedisKeys.getCpUserKey(userId), expire); } -} \ No newline at end of file +} diff --git a/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/util/TokenUtil.java b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/util/TokenUtil.java new file mode 100644 index 000000000..96aedcaba --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/util/TokenUtil.java @@ -0,0 +1,68 @@ +package com.elink.esua.common.token.util; + +import com.elink.esua.common.token.dto.TokenDto; +import com.elink.esua.common.token.dto.UserTokenDto; +import com.elink.esua.common.token.property.TokenPropertise; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Date; +import java.util.UUID; + +/** + * token服务类 + * + * @author rongchao + * @Date 18-10-31 + */ +@Component +public class TokenUtil { + + private Logger logger = LoggerFactory.getLogger(getClass()); + + @Autowired + private TokenPropertise tokenPropertise; + + @Autowired + private CpUserDetailRedis redisUtils; + + public TokenDto getTokenInfo(String userId) { + TokenDto tokenDto = redisUtils.get(userId); + return tokenDto; + } + + public TokenDto createToken(UserTokenDto user) { + // 当前时间 + Date now = new Date(); + // 过期时间 + Date expireTime = new Date(now.getTime() + tokenPropertise.getExpire() * 1000); + + // 生成token + String token = this.generateToken(); + + // 保存或更新用户token + TokenDto tokenDto = new TokenDto(); + tokenDto.setUserInfoDto(user); + tokenDto.setToken(token); + tokenDto.setUpdateTime(now); + tokenDto.setExpireTime(expireTime); + redisUtils.set(tokenDto, tokenPropertise.getExpire()); + return tokenDto; + } + + public void expireToken(String userId) { + redisUtils.logout(userId); + } + + public boolean delayToken(String token) { + return redisUtils.expire(token, tokenPropertise.getExpire()); + } + + private String generateToken() { + return UUID.randomUUID().toString().replace("-", ""); + } + + +} diff --git a/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/util/UserUtil.java b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/util/UserUtil.java new file mode 100644 index 000000000..c69067be1 --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/common/token/util/UserUtil.java @@ -0,0 +1,56 @@ +package com.elink.esua.common.token.util; + +import com.elink.esua.common.token.dto.TokenDto; +import com.elink.esua.common.token.dto.UserTokenDto; +import com.elink.esua.common.token.interceptor.AuthorizationInterceptor; +import com.elink.esua.epdc.commons.tools.utils.WebUtil; + +/** + * 用户工具类 + * + * @author rongchao + * @Date 18-11-20 + */ +public class UserUtil { + + /** + * 获取当前用户信息 + * + * @return + */ + public static TokenDto getCurrentUser() { + return (TokenDto) WebUtil.getAttributesFromRequest(AuthorizationInterceptor.USER_KEY); + } + + /** + * 获取当前用户信息 + * + * @return com.elink.esua.common.token.dto.UserTokenDto + * @author yujintao + * @date 2018/12/5 9:24 + */ + public static UserTokenDto getCurrentUserInfo() { + TokenDto tokenDto = getCurrentUser(); + if (tokenDto == null || tokenDto.getUserInfoDto() == null) { + return null; + } + return tokenDto.getUserInfoDto(); + } + + /** + * 获取当前用户ID + * + * @return + */ + public static String getCurrentUserId() { + TokenDto tokenDto = getCurrentUser(); + if (tokenDto == null || tokenDto.getUserInfoDto() == null) { + return null; + } + return tokenDto.getUserInfoDto().getUserId(); + } + + public static void setCurrentUser(TokenDto user) { + WebUtil.setAttributesFromRequest(AuthorizationInterceptor.USER_KEY, user); + } +} diff --git a/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/redis/RedisKeys.java b/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/redis/RedisKeys.java index 494c8c448..8e0b10c1d 100644 --- a/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/redis/RedisKeys.java +++ b/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/redis/RedisKeys.java @@ -14,64 +14,69 @@ package com.elink.esua.epdc.commons.tools.redis; */ public class RedisKeys { + /** + * 党建redis前缀 + */ + private static String rootPrefix = "epdc:"; + /** * 系统参数Key */ public static String getSysParamsKey() { - return "sys:params"; + return rootPrefix.concat("sys:params"); } /** * 登录验证码Key */ public static String getLoginCaptchaKey(String uuid) { - return "sys:captcha:" + uuid; + return rootPrefix.concat("sys:captcha:").concat(uuid); } /** * 登录用户Key */ public static String getSecurityUserKey(Long id) { - return "sys:security:user:" + id; + return rootPrefix.concat("sys:security:user:").concat(String.valueOf(id)); } /** * 系统日志Key */ public static String getSysLogKey() { - return "sys:log"; + return rootPrefix.concat("sys:log"); } /** * 系统资源Key */ public static String getSysResourceKey() { - return "sys:resource"; + return rootPrefix.concat("sys:resource"); } /** * 用户菜单导航Key */ public static String getUserMenuNavKey(Long userId, String language) { - return "sys:user:nav:" + userId + "_" + language; + return rootPrefix.concat("sys:user:nav:").concat(String.valueOf(userId)).concat("_").concat(language); } /** * 用户菜单导航Key */ public static String getUserMenuNavKey(Long userId) { - return "sys:user:nav:" + userId + "_*"; + return rootPrefix.concat("sys:user:nav:").concat(String.valueOf(userId)).concat("_*"); } /** * 用户权限标识Key */ public static String getUserPermissionsKey(Long userId) { - return "sys:user:permissions:" + userId; + return rootPrefix.concat("sys:user:permissions:").concat(String.valueOf(userId)); } public static String getCpUserKey(String id) { - return "sys:security:cpuser:" + id; + return rootPrefix.concat("sys:security:cpuser:").concat(id); } /** @@ -83,7 +88,7 @@ public class RedisKeys { * @date 2019/9/3 16:28 */ public static String getSimpleAreaKey(String areaId) { - return "epdc:config:simple:area:" + areaId; + return rootPrefix.concat("config:simple:area:").concat(areaId); } /** @@ -95,6 +100,6 @@ public class RedisKeys { * @date 2019/9/3 16:28 */ public static String getSimpleDictKey(String dictType) { - return "epdc:config:simple:dict:" + dictType; + return rootPrefix.concat("config:simple:dict:").concat(dictType); } } diff --git a/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/redis/RedisUtils.java b/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/redis/RedisUtils.java index f0724efaa..e09629633 100644 --- a/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/redis/RedisUtils.java +++ b/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/redis/RedisUtils.java @@ -1,8 +1,8 @@ /** * Copyright (c) 2018 人人开源 All rights reserved. - * + *

* https://www.renren.io - * + *

* 版权所有,侵权必究! */ @@ -38,20 +38,20 @@ public class RedisUtils { /** 不设置过期时长 */ public final static long NOT_EXPIRE = -1L; - public void set(String key, Object value, long expire){ + public void set(String key, Object value, long expire) { redisTemplate.opsForValue().set(key, value); - if(expire != NOT_EXPIRE){ + if (expire != NOT_EXPIRE) { expire(key, expire); } } - public void set(String key, Object value){ + public void set(String key, Object value) { set(key, value, DEFAULT_EXPIRE); } public Object get(String key, long expire) { Object value = redisTemplate.opsForValue().get(key); - if(expire != NOT_EXPIRE){ + if (expire != NOT_EXPIRE) { expire(key, expire); } return value; @@ -61,7 +61,7 @@ public class RedisUtils { return get(key, NOT_EXPIRE); } - public Set keys(String pattern){ + public Set keys(String pattern) { return redisTemplate.keys(pattern); } @@ -81,19 +81,19 @@ public class RedisUtils { return redisTemplate.opsForHash().get(key, field); } - public Map hGetAll(String key){ + public Map hGetAll(String key) { HashOperations hashOperations = redisTemplate.opsForHash(); return hashOperations.entries(key); } - public void hMSet(String key, Map map){ + public void hMSet(String key, Map map) { hMSet(key, map, DEFAULT_EXPIRE); } - public void hMSet(String key, Map map, long expire){ + public void hMSet(String key, Map map, long expire) { redisTemplate.opsForHash().putAll(key, map); - if(expire != NOT_EXPIRE){ + if (expire != NOT_EXPIRE) { expire(key, expire); } } @@ -105,32 +105,32 @@ public class RedisUtils { public void hSet(String key, String field, Object value, long expire) { redisTemplate.opsForHash().put(key, field, value); - if(expire != NOT_EXPIRE){ + if (expire != NOT_EXPIRE) { expire(key, expire); } } - public void expire(String key, long expire){ - redisTemplate.expire(key, expire, TimeUnit.SECONDS); + public boolean expire(String key, long expire) { + return redisTemplate.expire(key, expire, TimeUnit.SECONDS); } - public void hDel(String key, Object... fields){ + public void hDel(String key, Object... fields) { redisTemplate.opsForHash().delete(key, fields); } - public void leftPush(String key, Object value){ + public void leftPush(String key, Object value) { leftPush(key, value, DEFAULT_EXPIRE); } - public void leftPush(String key, Object value, long expire){ + public void leftPush(String key, Object value, long expire) { redisTemplate.opsForList().leftPush(key, value); - if(expire != NOT_EXPIRE){ + if (expire != NOT_EXPIRE) { expire(key, expire); } } - public Object rightPop(String key){ + public Object rightPop(String key) { return redisTemplate.opsForList().rightPop(key); } } diff --git a/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/utils/WebUtil.java b/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/utils/WebUtil.java new file mode 100644 index 000000000..5cf6c89cc --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/utils/WebUtil.java @@ -0,0 +1,66 @@ +package com.elink.esua.epdc.commons.tools.utils; + +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; + +/** + * Web工具类 + * + * @author rongchao + * @Date 18-11-20 + */ +public class WebUtil { + + public static HttpServletRequest getHttpServletRequest() { + ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + HttpServletRequest request = requestAttributes.getRequest(); + return request; + } + + public static Object getAttributesFromRequest(String paramName) { + ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + return requestAttributes.getAttribute(paramName, RequestAttributes.SCOPE_REQUEST); + } + + public static void setAttributesFromRequest(String paramName, Object obj) { + ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + requestAttributes.setAttribute(paramName, obj, RequestAttributes.SCOPE_REQUEST); + } + + /** + * 获取用户真实IP地址,不使用request.getRemoteAddr();的原因是有可能用户使用了代理软件方式避免真实IP地址, + *

+ * 可是,如果通过了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP值,究竟哪个才是真正的用户端的真实IP呢? + * 答案是取X-Forwarded-For中第一个非unknown的有效IP字符串。 + *

+ * 如:X-Forwarded-For:192.168.1.110, 192.168.1.120, 192.168.1.130, + * 192.168.1.100 + *

+ * 用户真实IP为: 192.168.1.110 + * + * @return + */ + public static String getIpAddress() { + HttpServletRequest request = getHttpServletRequest(); + String ip = request.getHeader("x-forwarded-for"); + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("WL-Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_CLIENT_IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_X_FORWARDED_FOR"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getRemoteAddr(); + } + return ip; + } +} diff --git a/esua-epdc/epdc-commons/epdc-wx/.editorconfig b/esua-epdc/epdc-commons/epdc-wx/.editorconfig new file mode 100644 index 000000000..775be5ba0 --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/.editorconfig @@ -0,0 +1,14 @@ +# EditorConfig: http://editorconfig.org/ + +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/esua-epdc/epdc-commons/epdc-wx/.travis.yml b/esua-epdc/epdc-commons/epdc-wx/.travis.yml new file mode 100644 index 000000000..5d2a7698b --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/.travis.yml @@ -0,0 +1,13 @@ +language: java +jdk: + - openjdk8 + +script: "mvn clean package -Dmaven.test.skip=true" + +branches: + only: + - master + +notifications: + email: + - binarywang@vip.qq.com diff --git a/esua-epdc/epdc-commons/epdc-wx/README.md b/esua-epdc/epdc-commons/epdc-wx/README.md new file mode 100644 index 000000000..790d56ba1 --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/README.md @@ -0,0 +1,58 @@ +[![码云Gitee](https://gitee.com/binary/weixin-java-mp-demo-springboot/badge/star.svg?theme=blue)](https://gitee.com/binary/weixin-java-mp-demo-springboot) +[![Github](http://github-svg-buttons.herokuapp.com/star.svg?user=binarywang&repo=weixin-java-mp-demo-springboot&style=flat&background=1081C1)](https://github.com/binarywang/weixin-java-mp-demo-springboot) +[![Build Status](https://travis-ci.org/binarywang/weixin-java-mp-demo-springboot.svg?branch=master)](https://travis-ci.org/binarywang/weixin-java-mp-demo-springboot) +----------------------- + +### 本Demo基于Spring Boot构建,实现微信公众号后端开发功能。 +### 本项目为WxJava的Demo演示程序,更多Demo请[查阅此处](https://github.com/Wechat-Group/WxJava/blob/master/demo.md)。 +#### 如有问题请[【在此提问】](https://github.com/binarywang/weixin-java-mp-demo-springboot/issues),谢谢配合。 + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +## 使用步骤: +1. 请注意,本demo为简化代码编译时加入了lombok支持,如果不了解lombok的话,请先学习下相关知识,比如可以阅读[此文章](https://mp.weixin.qq.com/s/cUc-bUcprycADfNepnSwZQ); +1. 另外,新手遇到问题,请务必先阅读[【开发文档首页】](https://github.com/Wechat-Group/WxJava/wiki)的常见问题部分,可以少走很多弯路,节省不少时间。 +1. 配置:复制 `/src/main/resources/application.yml.template` 或修改其扩展名生成 `application.yml` 文件,根据自己需要填写相关配置(需要注意的是:yml文件内的属性冒号后面的文字之前需要加空格,可参考已有配置,否则属性会设置不成功); +2. 主要配置说明如下: +``` +wx: + mp: + configs: + - appId: 1111 (一个公众号的appid) + secret: 1111(公众号的appsecret) + token: 111 (接口配置里的Token值) + aesKey: 111 (接口配置里的EncodingAESKey值) + - appId: 2222 (另一个公众号的appid,以下同上) + secret: 1111 + token: 111 + aesKey: 111 +``` +3. 运行Java程序:`WxMpDemoApplication`; +4. 配置微信公众号中的接口地址:http://公网可访问域名/wx/portal/xxxxx (注意,xxxxx为对应公众号的appid值); +5. 根据自己需要修改各个handler的实现,加入自己的业务逻辑。 + diff --git a/esua-epdc/epdc-commons/epdc-wx/pom.xml b/esua-epdc/epdc-commons/epdc-wx/pom.xml new file mode 100644 index 000000000..081d0e49c --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/pom.xml @@ -0,0 +1,61 @@ + + + 4.0.0 + + + com.esua.epdc + epdc-commons + 1.0.0 + + + 1.0.0 + epdc-wx + jar + + Wechat mp demo with Spring Boot and WxJava + 基于 WxJava 和 Spring Boot 实现的微信公众号后端开发演示项目 + + + 3.5.0 + + 1.8 + 1.8 + UTF-8 + UTF-8 + zh_CN + wechat-mp-demo + + + + + com.github.binarywang + weixin-java-mp + ${weixin-java-mp.version} + + + + org.projectlombok + lombok + provided + + + + org.springframework.boot + spring-boot-autoconfigure + compile + + + org.springframework.boot + spring-boot-configuration-processor + compile + true + + + org.springframework.boot + spring-boot-autoconfigure-processor + compile + true + + + diff --git a/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/builder/AbstractBuilder.java b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/builder/AbstractBuilder.java new file mode 100644 index 000000000..dc270da56 --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/builder/AbstractBuilder.java @@ -0,0 +1,17 @@ +package com.elink.esua.epdc.wx.mp.builder; + +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; +import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Binary Wang(https://github.com/binarywang) + */ +public abstract class AbstractBuilder { + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + public abstract WxMpXmlOutMessage build(String content, + WxMpXmlMessage wxMessage, WxMpService service); +} diff --git a/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/builder/ImageBuilder.java b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/builder/ImageBuilder.java new file mode 100644 index 000000000..8daf22d2c --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/builder/ImageBuilder.java @@ -0,0 +1,24 @@ +package com.elink.esua.epdc.wx.mp.builder; + +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; +import me.chanjar.weixin.mp.bean.message.WxMpXmlOutImageMessage; +import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; + +/** + * @author Binary Wang(https://github.com/binarywang) + */ +public class ImageBuilder extends AbstractBuilder { + + @Override + public WxMpXmlOutMessage build(String content, WxMpXmlMessage wxMessage, + WxMpService service) { + + WxMpXmlOutImageMessage m = WxMpXmlOutMessage.IMAGE().mediaId(content) + .fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()) + .build(); + + return m; + } + +} diff --git a/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/builder/TextBuilder.java b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/builder/TextBuilder.java new file mode 100644 index 000000000..93ea48018 --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/builder/TextBuilder.java @@ -0,0 +1,22 @@ +package com.elink.esua.epdc.wx.mp.builder; + +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; +import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; +import me.chanjar.weixin.mp.bean.message.WxMpXmlOutTextMessage; + +/** + * @author Binary Wang(https://github.com/binarywang) + */ +public class TextBuilder extends AbstractBuilder { + + @Override + public WxMpXmlOutMessage build(String content, WxMpXmlMessage wxMessage, + WxMpService service) { + WxMpXmlOutTextMessage m = WxMpXmlOutMessage.TEXT().content(content) + .fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()) + .build(); + return m; + } + +} diff --git a/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/config/WxMpConfiguration.java b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/config/WxMpConfiguration.java new file mode 100644 index 000000000..59a027c9d --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/config/WxMpConfiguration.java @@ -0,0 +1,113 @@ +package com.elink.esua.epdc.wx.mp.config; + +import com.elink.esua.epdc.wx.mp.handler.*; +import lombok.AllArgsConstructor; +import me.chanjar.weixin.mp.api.WxMpMessageRouter; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; +import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.List; +import java.util.stream.Collectors; + +import static me.chanjar.weixin.common.api.WxConsts.EventType; +import static me.chanjar.weixin.common.api.WxConsts.EventType.SUBSCRIBE; +import static me.chanjar.weixin.common.api.WxConsts.EventType.UNSUBSCRIBE; +import static me.chanjar.weixin.common.api.WxConsts.MenuButtonType.CLICK; +import static me.chanjar.weixin.common.api.WxConsts.MenuButtonType.VIEW; +import static me.chanjar.weixin.common.api.WxConsts.XmlMsgType; +import static me.chanjar.weixin.common.api.WxConsts.XmlMsgType.EVENT; +import static me.chanjar.weixin.mp.constant.WxMpEventConstants.CustomerService.*; +import static me.chanjar.weixin.mp.constant.WxMpEventConstants.POI_CHECK_NOTIFY; + +/** + * wechat mp configuration + * + * @author Binary Wang(https://github.com/binarywang) + */ +@AllArgsConstructor +@Configuration +@EnableConfigurationProperties(WxMpProperties.class) +public class WxMpConfiguration { + private final LogHandler logHandler; + private final NullHandler nullHandler; + private final KfSessionHandler kfSessionHandler; + private final StoreCheckNotifyHandler storeCheckNotifyHandler; + private final LocationHandler locationHandler; + private final MenuHandler menuHandler; + private final MsgHandler msgHandler; + private final UnsubscribeHandler unsubscribeHandler; + private final SubscribeHandler subscribeHandler; + private final ScanHandler scanHandler; + private final WxMpProperties properties; + + @Bean + public WxMpService wxMpService() { + // 代码里 getConfigs()处报错的同学,请注意仔细阅读项目说明,你的IDE需要引入lombok插件!!!! + final List configs = this.properties.getConfigs(); + if (configs == null) { + throw new RuntimeException("大哥,拜托先看下项目首页的说明(readme文件),添加下相关配置,注意别配错了!"); + } + + WxMpService service = new WxMpServiceImpl(); + service.setMultiConfigStorages(configs + .stream().map(a -> { + WxMpDefaultConfigImpl configStorage = new WxMpDefaultConfigImpl(); + configStorage.setAppId(a.getAppId()); + configStorage.setSecret(a.getSecret()); + configStorage.setToken(a.getToken()); + configStorage.setAesKey(a.getAesKey()); + return configStorage; + }).collect(Collectors.toMap(WxMpDefaultConfigImpl::getAppId, a -> a, (o, n) -> o))); + return service; + } + + @Bean + public WxMpMessageRouter messageRouter(WxMpService wxMpService) { + final WxMpMessageRouter newRouter = new WxMpMessageRouter(wxMpService); + + // 记录所有事件的日志 (异步执行) + newRouter.rule().handler(this.logHandler).next(); + + // 接收客服会话管理事件 + newRouter.rule().async(false).msgType(EVENT).event(KF_CREATE_SESSION) + .handler(this.kfSessionHandler).end(); + newRouter.rule().async(false).msgType(EVENT).event(KF_CLOSE_SESSION) + .handler(this.kfSessionHandler).end(); + newRouter.rule().async(false).msgType(EVENT).event(KF_SWITCH_SESSION) + .handler(this.kfSessionHandler).end(); + + // 门店审核事件 + newRouter.rule().async(false).msgType(EVENT).event(POI_CHECK_NOTIFY).handler(this.storeCheckNotifyHandler).end(); + + // 自定义菜单事件 + newRouter.rule().async(false).msgType(EVENT).event(CLICK).handler(this.menuHandler).end(); + + // 点击菜单连接事件 + newRouter.rule().async(false).msgType(EVENT).event(VIEW).handler(this.nullHandler).end(); + + // 关注事件 + newRouter.rule().async(false).msgType(EVENT).event(SUBSCRIBE).handler(this.subscribeHandler).end(); + + // 取消关注事件 + newRouter.rule().async(false).msgType(EVENT).event(UNSUBSCRIBE).handler(this.unsubscribeHandler).end(); + + // 上报地理位置事件 + newRouter.rule().async(false).msgType(EVENT).event(EventType.LOCATION).handler(this.locationHandler).end(); + + // 接收地理位置消息 + newRouter.rule().async(false).msgType(XmlMsgType.LOCATION).handler(this.locationHandler).end(); + + // 扫码事件 + newRouter.rule().async(false).msgType(EVENT).event(EventType.SCAN).handler(this.scanHandler).end(); + + // 默认 + newRouter.rule().async(false).handler(this.msgHandler).end(); + + return newRouter; + } + +} diff --git a/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/config/WxMpProperties.java b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/config/WxMpProperties.java new file mode 100644 index 000000000..6a1aa5947 --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/config/WxMpProperties.java @@ -0,0 +1,46 @@ +package com.elink.esua.epdc.wx.mp.config; + +import com.elink.esua.epdc.wx.mp.utils.JsonUtils; +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +import java.util.List; + +/** + * wechat mp properties + * + * @author Binary Wang(https://github.com/binarywang) + */ +@Data +@ConfigurationProperties(prefix = "wx.mp") +public class WxMpProperties { + private List configs; + + @Data + public static class MpConfig { + /** + * 设置微信公众号的appid + */ + private String appId; + + /** + * 设置微信公众号的app secret + */ + private String secret; + + /** + * 设置微信公众号的token + */ + private String token; + + /** + * 设置微信公众号的EncodingAESKey + */ + private String aesKey; + } + + @Override + public String toString() { + return JsonUtils.toJson(this); + } +} diff --git a/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/AbstractHandler.java b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/AbstractHandler.java new file mode 100644 index 000000000..b3a89e72b --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/AbstractHandler.java @@ -0,0 +1,12 @@ +package com.elink.esua.epdc.wx.mp.handler; + +import me.chanjar.weixin.mp.api.WxMpMessageHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Binary Wang(https://github.com/binarywang) + */ +public abstract class AbstractHandler implements WxMpMessageHandler { + protected Logger logger = LoggerFactory.getLogger(getClass()); +} diff --git a/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/KfSessionHandler.java b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/KfSessionHandler.java new file mode 100644 index 000000000..46df4a7a2 --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/KfSessionHandler.java @@ -0,0 +1,25 @@ +package com.elink.esua.epdc.wx.mp.handler; + +import me.chanjar.weixin.common.session.WxSessionManager; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; +import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; +import org.springframework.stereotype.Component; + +import java.util.Map; + +/** + * @author Binary Wang(https://github.com/binarywang) + */ +@Component +public class KfSessionHandler extends AbstractHandler { + + @Override + public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, + Map context, WxMpService wxMpService, + WxSessionManager sessionManager) { + //TODO 对会话做处理 + return null; + } + +} diff --git a/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/LocationHandler.java b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/LocationHandler.java new file mode 100644 index 000000000..9089a15a2 --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/LocationHandler.java @@ -0,0 +1,44 @@ +package com.elink.esua.epdc.wx.mp.handler; + +import com.elink.esua.epdc.wx.mp.builder.TextBuilder; +import me.chanjar.weixin.common.session.WxSessionManager; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; +import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; +import org.springframework.stereotype.Component; + +import java.util.Map; + +import static me.chanjar.weixin.common.api.WxConsts.XmlMsgType; + +/** + * @author Binary Wang(https://github.com/binarywang) + */ +@Component +public class LocationHandler extends AbstractHandler { + + @Override + public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, + Map context, WxMpService wxMpService, + WxSessionManager sessionManager) { + if (wxMessage.getMsgType().equals(XmlMsgType.LOCATION)) { + //TODO 接收处理用户发送的地理位置消息 + try { + String content = "感谢反馈,您的的地理位置已收到!"; + return new TextBuilder().build(content, wxMessage, null); + } catch (Exception e) { + this.logger.error("位置消息接收处理失败", e); + return null; + } + } + + //上报地理位置事件 + this.logger.info("上报地理位置,纬度 : {},经度 : {},精度 : {}", + wxMessage.getLatitude(), wxMessage.getLongitude(), String.valueOf(wxMessage.getPrecision())); + + //TODO 可以将用户地理位置信息保存到本地数据库,以便以后使用 + + return null; + } + +} diff --git a/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/LogHandler.java b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/LogHandler.java new file mode 100644 index 000000000..1ff3ec3de --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/LogHandler.java @@ -0,0 +1,25 @@ +package com.elink.esua.epdc.wx.mp.handler; + +import com.elink.esua.epdc.wx.mp.utils.JsonUtils; +import me.chanjar.weixin.common.session.WxSessionManager; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; +import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; +import org.springframework.stereotype.Component; + +import java.util.Map; + +/** + * @author Binary Wang(https://github.com/binarywang) + */ +@Component +public class LogHandler extends AbstractHandler { + @Override + public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, + Map context, WxMpService wxMpService, + WxSessionManager sessionManager) { + this.logger.info("\n接收到请求消息,内容:{}", JsonUtils.toJson(wxMessage)); + return null; + } + +} diff --git a/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/MenuHandler.java b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/MenuHandler.java new file mode 100644 index 000000000..249d87e3c --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/MenuHandler.java @@ -0,0 +1,36 @@ +package com.elink.esua.epdc.wx.mp.handler; + +import me.chanjar.weixin.common.session.WxSessionManager; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; +import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; +import org.springframework.stereotype.Component; + +import java.util.Map; + +import static me.chanjar.weixin.common.api.WxConsts.MenuButtonType; + +/** + * @author Binary Wang(https://github.com/binarywang) + */ +@Component +public class MenuHandler extends AbstractHandler { + + @Override + public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, + Map context, WxMpService weixinService, + WxSessionManager sessionManager) { + + String msg = String.format("type:%s, event:%s, key:%s", + wxMessage.getMsgType(), wxMessage.getEvent(), + wxMessage.getEventKey()); + if (MenuButtonType.VIEW.equals(wxMessage.getEvent())) { + return null; + } + + return WxMpXmlOutMessage.TEXT().content(msg) + .fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()) + .build(); + } + +} diff --git a/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/MsgHandler.java b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/MsgHandler.java new file mode 100644 index 000000000..21f8b48b2 --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/MsgHandler.java @@ -0,0 +1,52 @@ +package com.elink.esua.epdc.wx.mp.handler; + +import com.elink.esua.epdc.wx.mp.builder.TextBuilder; +import com.elink.esua.epdc.wx.mp.utils.JsonUtils; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.session.WxSessionManager; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; +import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.Map; + +import static me.chanjar.weixin.common.api.WxConsts.XmlMsgType; + +/** + * @author Binary Wang(https://github.com/binarywang) + */ +@Component +public class MsgHandler extends AbstractHandler { + + @Override + public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, + Map context, WxMpService weixinService, + WxSessionManager sessionManager) { + + if (!wxMessage.getMsgType().equals(XmlMsgType.EVENT)) { + //TODO 可以选择将消息保存到本地 + } + + //当用户输入关键词如“你好”,“客服”等,并且有客服在线时,把消息转发给在线客服 + try { + if (StringUtils.startsWithAny(wxMessage.getContent(), "你好", "客服") + && weixinService.getKefuService().kfOnlineList() + .getKfOnlineList().size() > 0) { + return WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE() + .fromUser(wxMessage.getToUser()) + .toUser(wxMessage.getFromUser()).build(); + } + } catch (WxErrorException e) { + e.printStackTrace(); + } + + //TODO 组装回复消息 + String content = "收到信息内容:" + JsonUtils.toJson(wxMessage); + + return new TextBuilder().build(content, wxMessage, weixinService); + + } + +} diff --git a/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/NullHandler.java b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/NullHandler.java new file mode 100644 index 000000000..f76290842 --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/NullHandler.java @@ -0,0 +1,24 @@ +package com.elink.esua.epdc.wx.mp.handler; + +import me.chanjar.weixin.common.session.WxSessionManager; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; +import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; +import org.springframework.stereotype.Component; + +import java.util.Map; + +/** + * @author Binary Wang(https://github.com/binarywang) + */ +@Component +public class NullHandler extends AbstractHandler { + + @Override + public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, + Map context, WxMpService wxMpService, + WxSessionManager sessionManager) { + return null; + } + +} diff --git a/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/ScanHandler.java b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/ScanHandler.java new file mode 100644 index 000000000..407f94676 --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/ScanHandler.java @@ -0,0 +1,25 @@ +package com.elink.esua.epdc.wx.mp.handler; + +import java.util.Map; + +import org.springframework.stereotype.Component; + +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.session.WxSessionManager; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; +import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; + +/** + * @author Binary Wang(https://github.com/binarywang) + */ +@Component +public class ScanHandler extends AbstractHandler { + + @Override + public WxMpXmlOutMessage handle(WxMpXmlMessage wxMpXmlMessage, Map map, + WxMpService wxMpService, WxSessionManager wxSessionManager) throws WxErrorException { + // 扫码事件处理 + return null; + } +} diff --git a/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/StoreCheckNotifyHandler.java b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/StoreCheckNotifyHandler.java new file mode 100644 index 000000000..cd1cd25ed --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/StoreCheckNotifyHandler.java @@ -0,0 +1,27 @@ +package com.elink.esua.epdc.wx.mp.handler; + +import me.chanjar.weixin.common.session.WxSessionManager; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; +import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; +import org.springframework.stereotype.Component; + +import java.util.Map; + +/** + * 门店审核事件处理 + * + * @author Binary Wang(https://github.com/binarywang) + */ +@Component +public class StoreCheckNotifyHandler extends AbstractHandler { + + @Override + public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, + Map context, WxMpService wxMpService, + WxSessionManager sessionManager) { + // TODO 处理门店审核事件 + return null; + } + +} diff --git a/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/SubscribeHandler.java b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/SubscribeHandler.java new file mode 100644 index 000000000..88aac68bd --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/SubscribeHandler.java @@ -0,0 +1,71 @@ +package com.elink.esua.epdc.wx.mp.handler; + +import java.util.Map; + +import com.elink.esua.epdc.wx.mp.builder.TextBuilder; +import org.springframework.stereotype.Component; + +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.session.WxSessionManager; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; +import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; +import me.chanjar.weixin.mp.bean.result.WxMpUser; + +/** + * @author Binary Wang(https://github.com/binarywang) + */ +@Component +public class SubscribeHandler extends AbstractHandler { + + @Override + public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, + Map context, WxMpService weixinService, + WxSessionManager sessionManager) throws WxErrorException { + + this.logger.info("新关注用户 OPENID: " + wxMessage.getFromUser()); + + // 获取微信用户基本信息 + try { + WxMpUser userWxInfo = weixinService.getUserService() + .userInfo(wxMessage.getFromUser(), null); + if (userWxInfo != null) { + // TODO 可以添加关注用户到本地数据库 + } + } catch (WxErrorException e) { + if (e.getError().getErrorCode() == 48001) { + this.logger.info("该公众号没有获取用户信息权限!"); + } + } + + + WxMpXmlOutMessage responseResult = null; + try { + responseResult = this.handleSpecial(wxMessage); + } catch (Exception e) { + this.logger.error(e.getMessage(), e); + } + + if (responseResult != null) { + return responseResult; + } + + try { + return new TextBuilder().build("感谢关注", wxMessage, weixinService); + } catch (Exception e) { + this.logger.error(e.getMessage(), e); + } + + return null; + } + + /** + * 处理特殊请求,比如如果是扫码进来的,可以做相应处理 + */ + private WxMpXmlOutMessage handleSpecial(WxMpXmlMessage wxMessage) + throws Exception { + //TODO + return null; + } + +} diff --git a/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/UnsubscribeHandler.java b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/UnsubscribeHandler.java new file mode 100644 index 000000000..4a4723d45 --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/handler/UnsubscribeHandler.java @@ -0,0 +1,27 @@ +package com.elink.esua.epdc.wx.mp.handler; + +import me.chanjar.weixin.common.session.WxSessionManager; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; +import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; +import org.springframework.stereotype.Component; + +import java.util.Map; + +/** + * @author Binary Wang(https://github.com/binarywang) + */ +@Component +public class UnsubscribeHandler extends AbstractHandler { + + @Override + public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, + Map context, WxMpService wxMpService, + WxSessionManager sessionManager) { + String openId = wxMessage.getFromUser(); + this.logger.info("取消关注用户 OPENID: " + openId); + // TODO 可以更新本地数据库为取消关注状态 + return null; + } + +} diff --git a/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/utils/JsonUtils.java b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/utils/JsonUtils.java new file mode 100644 index 000000000..0c88b1568 --- /dev/null +++ b/esua-epdc/epdc-commons/epdc-wx/src/main/java/com/elink/esua/epdc/wx/mp/utils/JsonUtils.java @@ -0,0 +1,16 @@ +package com.elink.esua.epdc.wx.mp.utils; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +/** + * @author Binary Wang(https://github.com/binarywang) + */ +public class JsonUtils { + public static String toJson(Object obj) { + Gson gson = new GsonBuilder() + .setPrettyPrinting() + .create(); + return gson.toJson(obj); + } +} diff --git a/esua-epdc/epdc-commons/pom.xml b/esua-epdc/epdc-commons/pom.xml index 9709e2771..3eb744925 100644 --- a/esua-epdc/epdc-commons/pom.xml +++ b/esua-epdc/epdc-commons/pom.xml @@ -9,7 +9,6 @@ 1.0.0 - com.esua.epdc epdc-commons pom @@ -19,5 +18,7 @@ epdc-commons-dynamic-datasource epdc-commons-api-version-control epdc-commons-tools-phone + epdc-wx + epdc-common-clienttoken diff --git a/esua-epdc/epdc-gateway/pom.xml b/esua-epdc/epdc-gateway/pom.xml index e65419204..b75f10e3b 100644 --- a/esua-epdc/epdc-gateway/pom.xml +++ b/esua-epdc/epdc-gateway/pom.xml @@ -93,8 +93,8 @@ lb://epdc-message-server lb://epdc-neighbor-server - lb://epdc-news-server - + + http://127.0.0.1:9064 lb://epdc-oss-server lb://epdc-events-server diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-client/pom.xml b/esua-epdc/epdc-module/epdc-api/epdc-api-client/pom.xml index baf672df8..c41c11e02 100644 --- a/esua-epdc/epdc-module/epdc-api/epdc-api-client/pom.xml +++ b/esua-epdc/epdc-module/epdc-api/epdc-api-client/pom.xml @@ -18,6 +18,36 @@ epdc-commons-tools 1.0.0 + + com.esua.epdc + epdc-heart-client + 1.0.0 + + + com.esua.epdc + epdc-neighbor-client + 1.0.0 + + + com.esua.epdc + epdc-news-client + 1.0.0 + + + com.esua.epdc + epdc-events-client + 1.0.0 + + + com.esua.epdc + epdc-services-client + 1.0.0 + + + com.esua.epdc + epdc-user-client + 1.0.0 + diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-server/pom.xml b/esua-epdc/epdc-module/epdc-api/epdc-api-server/pom.xml index 1762d3b84..402037d25 100644 --- a/esua-epdc/epdc-module/epdc-api/epdc-api-server/pom.xml +++ b/esua-epdc/epdc-module/epdc-api/epdc-api-server/pom.xml @@ -12,6 +12,10 @@ epdc-api-server jar + + 3.5.0 + + com.esua.epdc @@ -53,6 +57,13 @@ epdc-commons-api-version-control ${project.version} + + + + com.esua.epdc + epdc-wx + ${project.version} + @@ -76,4 +87,93 @@ + + + dev + + true + + + dev + + 9040 + + 2 + 47.104.224.45 + 6379 + elink@888 + + + + + epdc + elink833066 + + true + 47.104.224.45:8848 + + wx6ff4e50840cf7dfc + caf82e454ae4e2cb9697651194c37784 + 111 + 111 + + + + + test + + test + + 9040 + + 2 + 47.104.224.45 + 6379 + elink@888 + + + + + epdc + elink833066 + + true + 47.104.224.45:8848 + + wx6ff4e50840cf7dfc + caf82e454ae4e2cb9697651194c37784 + 111 + 111 + + + + + prod + + prod + + 9040 + + 2 + 47.104.224.45 + 6379 + elink@888 + + + + + epdc + elink888 + + false + 47.104.224.45:8848 + + wx62aba559696345af + a93c3dd28ce34fb96228830141e51549 + 111 + 111 + + + + diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/ApiApplication.java b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/ApiApplication.java index 6e75e8720..96d647692 100644 --- a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/ApiApplication.java +++ b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/ApiApplication.java @@ -1,8 +1,8 @@ /** * Copyright (c) 2018 人人开源 All rights reserved. - * + *

* https://www.renren.io - * + *

* 版权所有,侵权必究! */ diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/annotation/Login.java b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/annotation/Login.java deleted file mode 100644 index 041820a0d..000000000 --- a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/annotation/Login.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright (c) 2018 人人开源 All rights reserved. - * - * https://www.renren.io - * - * 版权所有,侵权必究! - */ - -package com.elink.esua.epdc.annotation; - -import java.lang.annotation.*; - -/** - * 登录效验 - * @author Mark sunlightcs@gmail.com - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface Login { -} diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/annotation/LoginUser.java b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/annotation/LoginUser.java deleted file mode 100644 index 2c6ce717a..000000000 --- a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/annotation/LoginUser.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2018 人人开源 All rights reserved. - * - * https://www.renren.io - * - * 版权所有,侵权必究! - */ - -package com.elink.esua.epdc.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * 登录用户信息 - * - * @author Mark sunlightcs@gmail.com - */ -@Target(ElementType.PARAMETER) -@Retention(RetentionPolicy.RUNTIME) -public @interface LoginUser { - -} diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/interceptor/AuthorizationInterceptor.java b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/interceptor/AuthorizationInterceptor.java deleted file mode 100644 index a378ad2a1..000000000 --- a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/interceptor/AuthorizationInterceptor.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright (c) 2018 人人开源 All rights reserved. - * - * https://www.renren.io - * - * 版权所有,侵权必究! - */ - -package com.elink.esua.epdc.interceptor; - -import com.elink.esua.epdc.annotation.Login; -import com.elink.esua.epdc.exception.ModuleErrorCode; -import com.elink.esua.epdc.annotation.Login; -import com.elink.esua.epdc.commons.tools.exception.RenException; -import com.elink.esua.epdc.entity.TokenEntity; -import com.elink.esua.epdc.exception.ModuleErrorCode; -import com.elink.esua.epdc.service.TokenService; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.springframework.web.method.HandlerMethod; -import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * 权限(Token)验证 - * - * @author Mark sunlightcs@gmail.com - */ -@Component -public class AuthorizationInterceptor extends HandlerInterceptorAdapter { - @Autowired - private TokenService tokenService; - - public static final String USER_KEY = "userId"; - - @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { - Login annotation; - if(handler instanceof HandlerMethod) { - annotation = ((HandlerMethod) handler).getMethodAnnotation(Login.class); - }else{ - return true; - } - - if(annotation == null){ - return true; - } - - //从header中获取token - String token = request.getHeader("token"); - //如果header中不存在token,则从参数中获取token - if(StringUtils.isBlank(token)){ - token = request.getParameter("token"); - } - - //token为空 - if(StringUtils.isBlank(token)){ - throw new RenException(ModuleErrorCode.TOKEN_NOT_EMPTY); - } - - //查询token信息 - TokenEntity tokenEntity = tokenService.getByToken(token); - if(tokenEntity == null || tokenEntity.getExpireDate().getTime() < System.currentTimeMillis()){ - throw new RenException(ModuleErrorCode.TOKEN_INVALID); - } - - //设置userId到request里,后续根据userId,获取用户信息 - request.setAttribute(USER_KEY, tokenEntity.getUserId()); - - return true; - } -} diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/wx/controller/WxController.java b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/wx/controller/WxController.java new file mode 100644 index 000000000..0357ff904 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/wx/controller/WxController.java @@ -0,0 +1,33 @@ +package com.elink.esua.epdc.wx.controller; + +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.wx.service.WxService; +import me.chanjar.weixin.common.bean.WxJsapiSignature; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 微信Controller + * + * @author rongchao + * @Date 19-9-4 + */ +@RestController +@RequestMapping("wx") +public class WxController { + + @Autowired + private WxService wxService; + + /** + * 获取用户信息 + * + * @return + */ + @GetMapping("getWxConfig") + public Result getWxConfig(String url) { + return wxService.getWxConfig(url); + } +} diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/wx/service/WxService.java b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/wx/service/WxService.java new file mode 100644 index 000000000..17ae1c39a --- /dev/null +++ b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/wx/service/WxService.java @@ -0,0 +1,20 @@ +package com.elink.esua.epdc.wx.service; + +import com.elink.esua.epdc.commons.tools.utils.Result; +import me.chanjar.weixin.common.bean.WxJsapiSignature; + +/** + * 微信接口类 + * + * @author rongchao + * @Date 19-9-4 + */ +public interface WxService { + + /** + * 获取微信jssdk配置信息 + * + * @return + */ + Result getWxConfig(String url); +} diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/wx/service/impl/WxServiceImpl.java b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/wx/service/impl/WxServiceImpl.java new file mode 100644 index 000000000..803e1c31e --- /dev/null +++ b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/wx/service/impl/WxServiceImpl.java @@ -0,0 +1,38 @@ +package com.elink.esua.epdc.wx.service.impl; + +import com.elink.esua.epdc.commons.tools.exception.RenException; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.wx.service.WxService; +import me.chanjar.weixin.common.bean.WxJsapiSignature; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.mp.api.WxMpService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * 微信相关服务实现类 + * + * @author rongchao + * @Date 19-9-4 + */ +@Service +public class WxServiceImpl implements WxService { + + private final Logger log = LoggerFactory.getLogger(getClass()); + + @Autowired + private WxMpService wxMpService; + + @Override + public Result getWxConfig(String url) { + try { + WxJsapiSignature wxJsapiSignature = wxMpService.createJsapiSignature(url); + return new Result().ok(wxJsapiSignature); + } catch (WxErrorException e) { + log.error("获取微信Jssdk相关配置失败"); + throw new RenException("获取微信Jssdk相关配置失败"); + } + } +} diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/resources/application.yml b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/resources/application.yml index a3a7d17a5..94809a5be 100644 --- a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/resources/application.yml +++ b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 8087 + port: @server.port@ servlet: context-path: /api @@ -16,22 +16,22 @@ spring: time-zone: GMT+8 date-format: yyyy-MM-dd HH:mm:ss redis: - database: 0 - host: 47.104.224.45 + database: @spring.redis.index@ + host: @spring.redis.host@ timeout: 30s - port: 6379 - password: elink@888 + port: @spring.redis.port@ + password: @spring.redis.password@ datasource: druid: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://47.104.224.45:3308/epdc_api?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC - username: root - password: shibei@888 + url: @spring.datasource.druid.url@ + username: @spring.datasource.druid.username@ + password: @spring.datasource.druid.password@ cloud: nacos: discovery: - server-addr: 47.104.224.45:8848 - register-enabled: true + server-addr: @nacos.server-addr@ + register-enabled: @nacos.register-enabled@ alibaba: seata: tx-service-group: epdc-api-server-fescar-service-group @@ -65,3 +65,14 @@ mybatis-plus: cache-enabled: false call-setters-on-nulls: true jdbc-type-for-null: 'null' + +wx: + mp: + configs: + - appId: @wx.mp.configs.appId@ + secret: @wx.mp.configs.secret@ + token: @wx.mp.configs.token@ + aesKey: @wx.mp.configs.aesKey@ + +token: + expire: 21600L diff --git a/esua-epdc/epdc-module/epdc-app/epdc-app-client/pom.xml b/esua-epdc/epdc-module/epdc-app/epdc-app-client/pom.xml deleted file mode 100644 index 2b9c90eb5..000000000 --- a/esua-epdc/epdc-module/epdc-app/epdc-app-client/pom.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - epdc-app - com.esua.epdc - 1.0.0 - - 4.0.0 - - epdc-app-client - jar - - - - com.esua.epdc - epdc-commons-tools - 1.0.0 - - - com.esua.epdc - epdc-heart-client - 1.0.0 - - - com.esua.epdc - epdc-neighbor-client - 1.0.0 - - - com.esua.epdc - epdc-news-client - 1.0.0 - - - com.esua.epdc - epdc-events-client - 1.0.0 - - - com.esua.epdc - epdc-services-client - 1.0.0 - - - com.esua.epdc - epdc-user-client - 1.0.0 - - - - diff --git a/esua-epdc/epdc-module/epdc-app/epdc-app-client/src/main/java/com/elink/esua/epdc/epdc.gitkeep b/esua-epdc/epdc-module/epdc-app/epdc-app-client/src/main/java/com/elink/esua/epdc/epdc.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/esua-epdc/epdc-module/epdc-app/epdc-app-server/pom.xml b/esua-epdc/epdc-module/epdc-app/epdc-app-server/pom.xml deleted file mode 100644 index 42ce442e0..000000000 --- a/esua-epdc/epdc-module/epdc-app/epdc-app-server/pom.xml +++ /dev/null @@ -1,146 +0,0 @@ - - - - epdc-app - com.esua.epdc - 1.0.0 - - 4.0.0 - - epdc-app-server - jar - - - - com.esua.epdc - epdc-app-client - 1.0.0 - - - com.esua.epdc - epdc-commons-tools - 1.0.0 - - - com.esua.epdc - epdc-commons-mybatis - 1.0.0 - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework - spring-context-support - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-discovery - - - de.codecentric - spring-boot-admin-starter-client - ${spring.boot.admin.version} - - - - - ${project.artifactId} - - - org.springframework.boot - spring-boot-maven-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - true - - - - com.spotify - docker-maven-plugin - - - - - - - - dev - - true - - - dev - - 9058 - - 2 - 47.104.224.45 - 6379 - elink@888 - - - - - epdc - elink888 - - false - 47.104.224.45:8848 - - - - - test - - test - - 9058 - - 2 - 47.104.224.45 - 6379 - elink@888 - - - - - epdc - elink888 - - false - 47.104.224.45:8848 - - - - - prod - - prod - - 9058 - - 2 - 47.104.224.45 - 6379 - elink@888 - - - - - epdc - elink888 - - false - 47.104.224.45:8848 - - - - - \ No newline at end of file diff --git a/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/java/com/elink/esua/epdc/AppApplication.java b/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/java/com/elink/esua/epdc/AppApplication.java deleted file mode 100644 index 5fa453d6b..000000000 --- a/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/java/com/elink/esua/epdc/AppApplication.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (c) 2018 人人开源 All rights reserved. - *

- * https://www.renren.io - *

- * 版权所有,侵权必究! - */ - -package com.elink.esua.epdc; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.cloud.openfeign.EnableFeignClients; - -/** - * 移动端接口模块 - * - * @author Mark sunlightcs@gmail.com - * @since 1.1.0 - */ -@SpringBootApplication -@EnableDiscoveryClient -@EnableFeignClients -public class AppApplication { - - public static void main(String[] args) { - SpringApplication.run(AppApplication.class, args); - } - -} diff --git a/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/java/com/elink/esua/epdc/config/ModuleConfigImpl.java b/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/java/com/elink/esua/epdc/config/ModuleConfigImpl.java deleted file mode 100644 index 0a6891524..000000000 --- a/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/java/com/elink/esua/epdc/config/ModuleConfigImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2018 人人开源 All rights reserved. - *

- * https://www.renren.io - *

- * 版权所有,侵权必究! - */ - -package com.elink.esua.epdc.config; - -import com.elink.esua.epdc.commons.tools.config.ModuleConfig; -import org.springframework.stereotype.Service; - -/** - * 模块配置信息-移动端接口模块 - * - * @author Mark sunlightcs@gmail.com - * @since 1.0.0 - */ -@Service -public class ModuleConfigImpl implements ModuleConfig { - @Override - public String getName() { - return "app"; - } -} diff --git a/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/java/com/elink/esua/epdc/config/WebConfig.java b/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/java/com/elink/esua/epdc/config/WebConfig.java deleted file mode 100644 index 1ca742ce7..000000000 --- a/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/java/com/elink/esua/epdc/config/WebConfig.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright (c) 2018 人人开源 All rights reserved. - *

- * https://www.renren.io - *

- * 版权所有,侵权必究! - */ - -package com.elink.esua.epdc.config; - -import com.elink.esua.epdc.commons.tools.resolver.LoginUserHandlerMethodArgumentResolver; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.method.support.HandlerMethodArgumentResolver; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -import java.util.List; - -/** - * MVC配置 - * - * @author Mark sunlightcs@gmail.com - */ -@Configuration -public class WebConfig implements WebMvcConfigurer { - - @Autowired - private LoginUserHandlerMethodArgumentResolver loginUserHandlerMethodArgumentResolver; - - @Override - public void addArgumentResolvers(List argumentResolvers) { - argumentResolvers.add(loginUserHandlerMethodArgumentResolver); - } -} \ No newline at end of file diff --git a/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/application.yml b/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/application.yml deleted file mode 100644 index 6d75d4801..000000000 --- a/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/application.yml +++ /dev/null @@ -1,68 +0,0 @@ -server: - port: @server.port@ - servlet: - context-path: /epdc-app - -spring: - application: - name: epdc-app-server - # 环境 dev|test|prod - profiles: - active: @spring.profiles.active@ - messages: - encoding: UTF-8 - basename: i18n/messages,i18n/messages_common - jackson: - time-zone: GMT+8 - date-format: yyyy-MM-dd HH:mm:ss - redis: - database: @spring.redis.index@ - host: @spring.redis.host@ - timeout: 30s - port: @spring.redis.port@ - password: @spring.redis.password@ - cloud: - nacos: - discovery: - server-addr: @nacos.server-addr@ - register-enabled: @nacos.register-enabled@ - alibaba: - seata: - tx-service-group: epdc-app-server-fescar-service-group - datasource: - druid: - driver-class-name: com.mysql.jdbc.Driver - url: @spring.datasource.druid.url@ - username: @spring.datasource.druid.username@ - password: @spring.datasource.druid.password@ - - -management: - endpoints: - web: - exposure: - include: "*" - endpoint: - health: - show-details: ALWAYS - -mybatis-plus: - mapper-locations: classpath:/mapper/**/*.xml - #实体扫描,多个package用逗号或者分号分隔 - typeAliasesPackage: io.renren.entity;com.elink.esua.epdc.entity - global-config: - #数据库相关配置 - db-config: - #主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID"; - id-type: ID_WORKER - #字段策略 IGNORED:"忽略判断",NOT_NULL:"非 NULL 判断"),NOT_EMPTY:"非空判断" - field-strategy: NOT_NULL - #驼峰下划线转换 - column-underline: true - banner: false - #原生配置 - configuration: - map-underscore-to-camel-case: true - cache-enabled: false - call-setters-on-nulls: true - jdbc-type-for-null: 'null' diff --git a/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/i18n/messages.properties b/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/i18n/messages.properties deleted file mode 100644 index e69de29bb..000000000 diff --git a/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/i18n/messages_en_US.properties b/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/i18n/messages_en_US.properties deleted file mode 100644 index e69de29bb..000000000 diff --git a/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/i18n/messages_zh_CN.properties b/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/i18n/messages_zh_CN.properties deleted file mode 100644 index e69de29bb..000000000 diff --git a/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/i18n/messages_zh_TW.properties b/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/i18n/messages_zh_TW.properties deleted file mode 100644 index e69de29bb..000000000 diff --git a/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/i18n/validation.properties b/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/i18n/validation.properties deleted file mode 100644 index e69de29bb..000000000 diff --git a/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/i18n/validation_en_US.properties b/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/i18n/validation_en_US.properties deleted file mode 100644 index e69de29bb..000000000 diff --git a/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/i18n/validation_zh_CN.properties b/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/i18n/validation_zh_CN.properties deleted file mode 100644 index e69de29bb..000000000 diff --git a/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/i18n/validation_zh_TW.properties b/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/i18n/validation_zh_TW.properties deleted file mode 100644 index e69de29bb..000000000 diff --git a/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/logback-spring.xml b/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/logback-spring.xml deleted file mode 100644 index dd5aa1d15..000000000 --- a/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/logback-spring.xml +++ /dev/null @@ -1,159 +0,0 @@ - - - - - - - - - - - - - - debug - - - ${CONSOLE_LOG_PATTERN} - - UTF-8 - - - - - - - - ${log.path}/debug.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n - UTF-8 - - - - - ${log.path}/debug-%d{yyyy-MM-dd}.%i.log - - 100MB - - - 15 - - - - debug - ACCEPT - DENY - - - - - - - ${log.path}/info.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n - UTF-8 - - - - - ${log.path}/info-%d{yyyy-MM-dd}.%i.log - - 100MB - - - 15 - - - - info - ACCEPT - DENY - - - - - - - ${log.path}/warn.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n - UTF-8 - - - - ${log.path}/warn-%d{yyyy-MM-dd}.%i.log - - 100MB - - - 15 - - - - warn - ACCEPT - DENY - - - - - - - ${log.path}/error.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n - UTF-8 - - - - ${log.path}/error-%d{yyyy-MM-dd}.%i.log - - 100MB - - - 15 - - - - ERROR - ACCEPT - DENY - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/registry.conf b/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/registry.conf deleted file mode 100644 index 9cfedf9cc..000000000 --- a/esua-epdc/epdc-module/epdc-app/epdc-app-server/src/main/resources/registry.conf +++ /dev/null @@ -1,21 +0,0 @@ -registry { - # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa - type = "nacos" - - nacos { - serverAddr = "47.104.224.45" - namespace = "public" - cluster = "default" - } -} - -config { - # file、nacos 、apollo、zk、consul、etcd3 - type = "nacos" - - nacos { - serverAddr = "47.104.224.45" - namespace = "public" - cluster = "default" - } -} diff --git a/esua-epdc/epdc-module/epdc-app/pom.xml b/esua-epdc/epdc-module/epdc-app/pom.xml deleted file mode 100644 index cc01eb83b..000000000 --- a/esua-epdc/epdc-module/epdc-app/pom.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - epdc-module - com.esua.epdc - 1.0.0 - - 4.0.0 - - epdc-app - pom - - epdc-app-client - epdc-app-server - - - - \ No newline at end of file diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/NewsCategoryDTO.java b/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/NewsCategoryDTO.java index 316df4ede..d2d70c7b1 100644 --- a/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/NewsCategoryDTO.java +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/NewsCategoryDTO.java @@ -31,36 +31,59 @@ public class NewsCategoryDTO implements Serializable { private static final long serialVersionUID = 1L; - /** - * 类别名称 - */ + /** + * ID + */ + private String id; + + /** + * 类别名称 + */ private String categoryName; - /** - * 类别编码 - */ + /** + * 类别编码 + */ private String categoryCode; - /** - * 描述 - */ + /** + * 描述 + */ private String description; - /** - * 排序 - */ + /** + * 排序 + */ private Integer sort; + /** + * 删除标识 0:未删除,1:已删除 + */ + private String delFlag; + + /** + * 乐观锁 + */ private Integer revision; + /** + * 创建人 + */ private String createdBy; + /** + * 创建时间 + */ private Date createdTime; + /** + * 更新人 + */ private String updatedBy; + /** + * 更新时间 + */ private Date updatedTime; - private String delFlag; - } \ No newline at end of file diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/controller/NewsCategoryController.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/controller/NewsCategoryController.java index 69a21af14..e5c97696b 100644 --- a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/controller/NewsCategoryController.java +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/controller/NewsCategoryController.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package com.elink.esua.epdc.news.controller; +package com.elink.esua.epdc.controller; import com.elink.esua.epdc.commons.tools.page.PageData; import com.elink.esua.epdc.commons.tools.utils.ExcelUtils; @@ -65,6 +65,12 @@ public class NewsCategoryController { public Result save(@RequestBody NewsCategoryDTO dto){ //效验数据 ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + if(newsCategoryService.checkCodeCategory(dto.getCategoryCode(),dto.getId())>0){ + return new Result().error("类别编码已存在"); + } + if(newsCategoryService.checkNameCategory(dto.getCategoryName(),dto.getId())>0){ + return new Result().error("类别名称已存在"); + } newsCategoryService.save(dto); return new Result(); } @@ -73,6 +79,12 @@ public class NewsCategoryController { public Result update(@RequestBody NewsCategoryDTO dto){ //效验数据 ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + if(newsCategoryService.checkCodeCategory(dto.getCategoryCode(),dto.getId())>0){ + return new Result().error("类别编码已存在"); + } + if(newsCategoryService.checkNameCategory(dto.getCategoryName(),dto.getId())>0){ + return new Result().error("类别名称已存在"); + } newsCategoryService.update(dto); return new Result(); } diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/dao/NewsCategoryDao.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/dao/NewsCategoryDao.java index 15d1c1718..4068cfd71 100644 --- a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/dao/NewsCategoryDao.java +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/dao/NewsCategoryDao.java @@ -21,6 +21,8 @@ import com.elink.esua.epdc.commons.mybatis.dao.BaseDao; import com.elink.esua.epdc.entity.NewsCategoryEntity; import org.apache.ibatis.annotations.Mapper; +import java.util.Map; + /** * 新闻类别表 * @@ -29,5 +31,9 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface NewsCategoryDao extends BaseDao { - + + int selectCodeCount(String categoryCode,String id); + + int selectNameCount(String categoryName,String id); + } \ No newline at end of file diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/NewsCategoryService.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/NewsCategoryService.java index 502d49b3a..f87b4ccbe 100644 --- a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/NewsCategoryService.java +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/NewsCategoryService.java @@ -92,4 +92,14 @@ public interface NewsCategoryService extends BaseService { * @date */ void delete(String[] ids); + + /** + * + */ + int checkNameCategory(String categoryName,String id); + + /** + * + */ + int checkCodeCategory(String categoryCode,String id); } \ No newline at end of file diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/impl/NewsCategoryServiceImpl.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/impl/NewsCategoryServiceImpl.java index 5d237b3c2..076efd2dc 100644 --- a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/impl/NewsCategoryServiceImpl.java +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/impl/NewsCategoryServiceImpl.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package com.elink.esua.epdc.news.service.impl; +package com.elink.esua.epdc.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -70,6 +70,7 @@ public class NewsCategoryServiceImpl extends BaseServiceImpl wrapper = new QueryWrapper<>(); wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); + wrapper.orderByDesc("SORT"); return wrapper; } @@ -101,4 +102,14 @@ public class NewsCategoryServiceImpl extends BaseServiceImpl - - + + \ No newline at end of file diff --git a/esua-epdc/epdc-module/pom.xml b/esua-epdc/epdc-module/pom.xml index 68c359200..4abd74cfe 100644 --- a/esua-epdc/epdc-module/pom.xml +++ b/esua-epdc/epdc-module/pom.xml @@ -24,7 +24,6 @@ epdc-events epdc-neighbor epdc-services - epdc-app epdc-user epdc-demo