info = new HashMap<>();
22 |
23 | ((DefaultOAuth2AccessToken) oAuth2AccessToken).setAdditionalInformation(info);
24 | return oAuth2AccessToken;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/main.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/SecurityCoreConfig.java:
--------------------------------------------------------------------------------
1 | package com.zq.core;
2 |
3 |
4 | import com.zq.core.properties.SecurityProperties;
5 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
6 | import org.springframework.context.annotation.Configuration;
7 |
8 | @Configuration
9 | @EnableConfigurationProperties(SecurityProperties.class)
10 | public class SecurityCoreConfig {
11 | }
12 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/authentication/AuthenticationBeanConfig.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.zq.core.authentication;
5 |
6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.Configuration;
9 | import org.springframework.security.core.userdetails.UserDetailsService;
10 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
11 | import org.springframework.security.crypto.password.PasswordEncoder;
12 | import org.springframework.social.security.SocialUserDetailsService;
13 |
14 | /**
15 | *
16 | * 认证相关的扩展点配置。配置在这里的bean,业务系统都可以通过声明同类型或同名的bean来覆盖安全
17 | * 模块默认的配置。
18 | *
19 | * @author zhailiang
20 | *
21 | */
22 | @Configuration
23 | public class AuthenticationBeanConfig {
24 |
25 | /**
26 | * 默认密码处理器
27 | * @return
28 | */
29 | @Bean
30 | @ConditionalOnMissingBean(PasswordEncoder.class)
31 | public PasswordEncoder passwordEncoder() {
32 | return new BCryptPasswordEncoder();
33 | }
34 |
35 | /**
36 | * 默认认证器
37 | *
38 | * @return
39 | */
40 | @Bean
41 | @ConditionalOnMissingBean(UserDetailsService.class)
42 | public UserDetailsService userDetailsService() {
43 | return new DefaultUserDetailsService();
44 | }
45 |
46 | /**
47 | * 默认认证器
48 | *
49 | * @return
50 | */
51 | @Bean
52 | @ConditionalOnMissingBean(SocialUserDetailsService.class)
53 | public SocialUserDetailsService socialUserDetailsService() {
54 | return new DefaultSocialUserDetailsService();
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/authentication/DefaultSocialUserDetailsService.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.zq.core.authentication;
5 |
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 | import org.springframework.security.core.userdetails.UsernameNotFoundException;
9 | import org.springframework.social.security.SocialUserDetails;
10 | import org.springframework.social.security.SocialUserDetailsService;
11 |
12 | /**
13 | * 默认的SocialUserDetailsService实现
14 | *
15 | * 不做任何处理,只在控制台打印一句日志,然后抛出异常,提醒业务系统自己配置SocialUserDetailsService。
16 | *
17 | * @author zhailiang
18 | *
19 | */
20 | public class DefaultSocialUserDetailsService implements SocialUserDetailsService {
21 |
22 | private Logger logger = LoggerFactory.getLogger(getClass());
23 |
24 | @Override
25 | public SocialUserDetails loadUserByUserId(String userId) throws UsernameNotFoundException {
26 | logger.warn("请配置 SocialUserDetailsService 接口的实现.");
27 | throw new UsernameNotFoundException(userId);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/authentication/DefaultUserDetailsService.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.zq.core.authentication;
5 |
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 | import org.springframework.security.core.userdetails.UserDetails;
9 | import org.springframework.security.core.userdetails.UserDetailsService;
10 | import org.springframework.security.core.userdetails.UsernameNotFoundException;
11 |
12 | /**
13 | *
14 | * 默认的 UserDetailsService 实现
15 | *
16 | * 不做任何处理,只在控制台打印一句日志,然后抛出异常,提醒业务系统自己配置 UserDetailsService。
17 | *
18 | * @author zhailiang
19 | *
20 | */
21 | public class DefaultUserDetailsService implements UserDetailsService {
22 |
23 | private Logger logger = LoggerFactory.getLogger(getClass());
24 |
25 | /*
26 | * (non-Javadoc)
27 | *
28 | * @see org.springframework.security.core.userdetails.UserDetailsService#
29 | * loadUserByUsername(java.lang.String)
30 | */
31 | @Override
32 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
33 | logger.warn("请配置 UserDetailsService 接口的实现.");
34 | throw new UsernameNotFoundException(username);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/authentication/FormAuthenticationConfig.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.authentication;
2 |
3 | import com.zq.core.properties.SecurityConstants;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6 | import org.springframework.security.web.authentication.AuthenticationFailureHandler;
7 | import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
8 | import org.springframework.stereotype.Component;
9 |
10 | /**
11 | * @Author 张迁-zhangqian
12 | * @Data 2018/4/8 下午2:59
13 | * @Package com.zq.core.authentication
14 | **/
15 |
16 |
17 | @Component
18 | public class FormAuthenticationConfig {
19 |
20 | @Autowired
21 | private AuthenticationFailureHandler zqAuthenticationFailureHandler;
22 |
23 | @Autowired
24 | private AuthenticationSuccessHandler zqAuthenticationSuccessHandler;
25 |
26 | public void configure(HttpSecurity httpSecurity) throws Exception {
27 | httpSecurity.formLogin()
28 | .loginPage(SecurityConstants.DEFAULT_UNAUTHENTICATION_URL)
29 | .loginProcessingUrl(SecurityConstants.DEFAULT_SIGN_IN_PROCESSING_URL_FORM)
30 | .successHandler(zqAuthenticationSuccessHandler)
31 | .failureHandler(zqAuthenticationFailureHandler);
32 |
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/authentication/mobile/SmsCodeAuthenticationToken.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.authentication.mobile;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 | import org.springframework.security.authentication.AbstractAuthenticationToken;
6 | import org.springframework.security.core.GrantedAuthority;
7 |
8 | import java.util.Collection;
9 |
10 | /**
11 | * @Author 张迁-zhangqian
12 | * @Data 2018/4/8 下午2:42
13 | * @Package com.zq.core.authentication.mobile
14 | **/
15 |
16 | @Setter
17 | @Getter
18 | public class SmsCodeAuthenticationToken extends AbstractAuthenticationToken {
19 |
20 |
21 | private Object principal;
22 |
23 | public SmsCodeAuthenticationToken(String mobile) {
24 | super(null);
25 | this.principal = mobile;
26 | setAuthenticated(false);
27 | }
28 |
29 | public SmsCodeAuthenticationToken(Object principal, Collection extends GrantedAuthority> authorities) {
30 | super(authorities);
31 | this.principal = principal;
32 | super.setAuthenticated(true);
33 | }
34 |
35 |
36 | @Override
37 | public Object getCredentials() {
38 | return null;
39 | }
40 |
41 | public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
42 | if (isAuthenticated) {
43 | throw new IllegalArgumentException(
44 | "Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
45 | }
46 |
47 | super.setAuthenticated(false);
48 | }
49 |
50 | @Override
51 | public void eraseCredentials() {
52 | super.eraseCredentials();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/authorize/AuthorizeConfigManager.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.authorize;
2 |
3 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
4 | import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
5 |
6 | /**
7 | * 授权信息管理器
8 | *
9 | * 用于收集系统中所有 AuthorizeConfigProvider 并加载其配置
10 | *
11 | * @Author 张迁-zhangqian
12 | * @Data 2018/4/9 下午2:00
13 | * @Package com.zq.core.authorize
14 | **/
15 |
16 |
17 | public interface AuthorizeConfigManager {
18 |
19 | void config(ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry config);
20 | }
21 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/authorize/AuthorizeConfigProvider.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.authorize;
2 |
3 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
4 | import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
5 |
6 | /**
7 | * 授权配置提供器,各个模块和业务系统可以通过实现此接口向系统添加授权配置。
8 | *
9 | * @Author 张迁-zhangqian
10 | * @Data 2018/4/9 下午2:00
11 | * @Package com.zq.core.authorize
12 | **/
13 |
14 |
15 | public interface AuthorizeConfigProvider {
16 |
17 | /**
18 | * @param config
19 | * @return 返回的boolean表示配置中是否有针对anyRequest的配置。在整个授权配置中,
20 | * 应该有且仅有一个针对anyRequest的配置,如果所有的实现都没有针对anyRequest的配置,
21 | * 系统会自动增加一个anyRequest().authenticated()的配置。如果有多个针对anyRequest
22 | * 的配置,则会抛出异常。
23 | */
24 | boolean config(ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry config);
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/properties/SecurityProperties.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.properties;
2 |
3 | import com.zq.core.properties.browsers.BrowserProperties;
4 | import com.zq.core.properties.oauth2.Oauth2Properties;
5 | import com.zq.core.properties.social.SocialProperties;
6 | import com.zq.core.properties.validate.ValidateCodeProperties;
7 | import lombok.Getter;
8 | import lombok.Setter;
9 | import org.springframework.boot.context.properties.ConfigurationProperties;
10 |
11 | /**
12 | * @Author 张迁-zhangqian
13 | * @Data 2018/4/4 下午4:33
14 | * @Package com.zq.core.properties
15 | **/
16 |
17 | @Getter
18 | @Setter
19 | @ConfigurationProperties(prefix = "zq.security")
20 | public class SecurityProperties {
21 | /**
22 | * 浏览器环境配置
23 | */
24 | private BrowserProperties browserProperties = new BrowserProperties();
25 |
26 | private Oauth2Properties oauth2Properties = new Oauth2Properties();
27 |
28 | private SocialProperties socialProperties = new SocialProperties();
29 |
30 | private ValidateCodeProperties validateCodeProperties = new ValidateCodeProperties();
31 | }
32 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/properties/browsers/BrowserProperties.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.properties.browsers;
2 |
3 | import com.zq.core.properties.SecurityConstants;
4 | import lombok.Getter;
5 | import lombok.Setter;
6 |
7 | /**
8 | * @Author 张迁-zhangqian
9 | * @Data 2018/4/4 下午4:36
10 | * @Package com.zq.core.properties.browsers
11 | **/
12 |
13 |
14 | @Getter
15 | @Setter
16 | public class BrowserProperties {
17 |
18 | /**
19 | * session管理配置项
20 | */
21 | private SessionProperties session = new SessionProperties();
22 | /**
23 | * 登录页面,当引发登录行为的url以html结尾时,会跳到这里配置的url上
24 | */
25 | private String signInPage = SecurityConstants.DEFAULT_SIGN_IN_PAGE_URL;
26 | /**
27 | * '记住我'功能的有效时间,默认1小时
28 | */
29 | private int rememberMeSeconds = 3600;
30 | /**
31 | * 退出成功时跳转的url,如果配置了,则跳到指定的url,如果没配置,则返回json数据。
32 | */
33 | private String signOutUrl;
34 | /**
35 | * 社交登录,如果需要用户注册,跳转的页面
36 | */
37 | private String signUpUrl = "/zq-signUp.html";
38 | /**
39 | * 登录响应的方式,默认是json
40 | */
41 | private LoginResponseType signInResponseType = LoginResponseType.JSON;
42 | /**
43 | * 登录成功后跳转的地址,如果设置了此属性,则登录成功后总是会跳到这个地址上。
44 | *
45 | * 只在signInResponseType为REDIRECT时生效
46 | */
47 | private String signInSuccessUrl;
48 | }
49 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/properties/browsers/LoginResponseType.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.properties.browsers;
2 |
3 | /**
4 | * @Author 张迁-zhangqian
5 | * @Data 2018/4/8 上午10:15
6 | * @Package com.zq.core.properties.browsers
7 | **/
8 |
9 |
10 | public enum LoginResponseType {
11 | JSON,
12 | REDIRECT
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/properties/browsers/SessionProperties.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.properties.browsers;
2 |
3 | import com.zq.core.properties.SecurityConstants;
4 | import lombok.Getter;
5 | import lombok.Setter;
6 |
7 | /**
8 | * @Author 张迁-zhangqian
9 | * @Data 2018/4/8 上午10:15
10 | * @Package com.zq.core.properties.browsers
11 | **/
12 |
13 |
14 | @Getter
15 | @Setter
16 | public class SessionProperties {
17 | /**
18 | * 同一个用户在系统中的最大session数,默认1
19 | */
20 | private int maximumSessions = 1;
21 | /**
22 | * 达到最大session时是否阻止新的登录请求,默认为false,不阻止,新的登录会将老的登录失效掉
23 | */
24 | private boolean maxSessionsPreventsLogin;
25 | /**
26 | * session失效时跳转的地址
27 | */
28 | private String sessionInvalidUrl = SecurityConstants.DEFAULT_SESSION_INVALID_URL;
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/properties/oauth2/OAuth2ClientProperties.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.properties.oauth2;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | /**
7 | * @Author 张迁-zhangqian
8 | * @Data 2018/4/9 下午7:02
9 | * @Package com.zq.core.properties.oauth2
10 | **/
11 |
12 | @Setter
13 | @Getter
14 | public class OAuth2ClientProperties {
15 | /**
16 | * 第三方应用appId
17 | */
18 | private String clientId;
19 | /**
20 | * 第三方应用appSecret
21 | */
22 | private String clientSecret;
23 | /**
24 | * 针对此应用发出的token的有效时间
25 | */
26 | private int accessTokenValidateSeconds = 7200;
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/properties/oauth2/Oauth2Properties.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.properties.oauth2;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | /**
7 | * @Author 张迁-zhangqian
8 | * @Data 2018/4/4 下午4:30
9 | * @Package com.zq.core.properties.oauth2
10 | **/
11 |
12 | @Setter
13 | @Getter
14 | public class Oauth2Properties {
15 |
16 | /**
17 | * 使用jwt时为token签名的秘钥
18 | */
19 | private String jwtSigningKey = "imooc";
20 | /**
21 | * 客户端配置
22 | */
23 | private OAuth2ClientProperties[] clients = {};
24 | }
25 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/properties/social/QQProperties.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.properties.social;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 | import org.springframework.boot.autoconfigure.social.SocialProperties;
6 |
7 | /**
8 | * @Author 张迁-zhangqian
9 | * @Data 2018/4/8 下午8:01
10 | * @Package com.zq.core.properties.social
11 | **/
12 |
13 | @Setter
14 | @Getter
15 | public class QQProperties extends SocialProperties{
16 | /**
17 | * 第三方id,用来决定发起第三方登录的url,默认是 qq。
18 | */
19 | private String providerId = "qq";
20 |
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/properties/social/SocialProperties.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.properties.social;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | /**
7 | * @Author 张迁-zhangqian
8 | * @Data 2018/4/4 下午4:31
9 | * @Package com.zq.core.properties.social
10 | **/
11 |
12 | @Getter
13 | @Setter
14 | public class SocialProperties {
15 |
16 | /**
17 | * 社交登录功能拦截的url
18 | */
19 | private String filterProcessesUrl = "/auth";
20 |
21 | private QQProperties qq = new QQProperties();
22 |
23 | private WeXinProperties wexin = new WeXinProperties();
24 | }
25 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/properties/social/WeXinProperties.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.properties.social;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 | import org.springframework.boot.autoconfigure.social.SocialProperties;
6 |
7 | /**
8 | * @Author 张迁-zhangqian
9 | * @Data 2018/4/8 下午8:01
10 | * @Package com.zq.core.properties.social
11 | **/
12 |
13 |
14 | @Setter
15 | @Getter
16 | public class WeXinProperties extends SocialProperties{
17 | private String providerId = "wexin";
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/properties/validate/ImageCodeProperties.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.properties.validate;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | /**
7 | * @Author 张迁-zhangqian
8 | * @Data 2018/4/8 下午1:06
9 | * @Package com.zq.core.properties.validate
10 | **/
11 |
12 | @Getter
13 | @Setter
14 | public class ImageCodeProperties {
15 |
16 | private int width = 67;
17 | private int height = 23;
18 | private int expireIn =60;
19 | private int length;
20 |
21 |
22 | private String url;
23 |
24 | public ImageCodeProperties() {
25 | setLength(4);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/properties/validate/SmsCodeProperties.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.properties.validate;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | /**
7 | * @Author 张迁-zhangqian
8 | * @Data 2018/4/8 下午1:06
9 | * @Package com.zq.core.properties.validate
10 | **/
11 |
12 |
13 | @Setter
14 | @Getter
15 | public class SmsCodeProperties {
16 |
17 | private int length = 4;
18 | private int expireIn = 60;
19 |
20 | private String url;
21 | }
22 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/properties/validate/ValidateCodeProperties.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.properties.validate;
2 |
3 | /**
4 | * @Author 张迁-zhangqian
5 | * @Data 2018/4/4 下午4:32
6 | * @Package com.zq.core.properties.validate
7 | **/
8 |
9 | import lombok.Getter;
10 | import lombok.Setter;
11 |
12 | /**
13 | * 验证码配置
14 | */
15 | @Setter
16 | @Getter
17 | public class ValidateCodeProperties {
18 |
19 |
20 | /**
21 | * 图片验证码配置
22 | */
23 | private ImageCodeProperties image = new ImageCodeProperties();
24 | /**
25 | * 短信验证码配置
26 | */
27 | private SmsCodeProperties sms = new SmsCodeProperties();
28 | }
29 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/restful/ResponseCode.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.restful;
2 |
3 | /**
4 | * Created by geely
5 | */
6 | public enum ResponseCode {
7 |
8 | SUCCESS(0,"SUCCESS"),
9 | ERROR(1,"ERROR"),
10 | NEED_LOGIN(10,"NEED_LOGIN"),
11 | ILLEGAL_ARGUMENT(2,"ILLEGAL_ARGUMENT");
12 |
13 | private final int code;
14 | private final String desc;
15 |
16 |
17 | ResponseCode(int code,String desc){
18 | this.code = code;
19 | this.desc = desc;
20 | }
21 |
22 | public int getCode(){
23 | return code;
24 | }
25 | public String getDesc(){
26 | return desc;
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/social/SocialController.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.social;
2 |
3 | import com.zq.core.social.support.SocialUserInfo;
4 | import org.springframework.social.connect.Connection;
5 |
6 | /**
7 | * @Author 张迁-zhangqian
8 | * @Data 2018/4/9 上午10:04
9 | * @Package com.zq.core.social
10 | **/
11 |
12 |
13 | public abstract class SocialController {
14 |
15 | /**
16 | * 根据connect内容构建 SocialUserInfo
17 | * @param connection
18 | * @return
19 | */
20 | protected SocialUserInfo buildSocialUserInfo(Connection> connection){
21 |
22 | SocialUserInfo userInfo = new SocialUserInfo();
23 | userInfo.setProviderId(connection.getKey().getProviderId());
24 | userInfo.setProviderUserId(connection.getKey().getProviderUserId());
25 | userInfo.setNickname(connection.getDisplayName());
26 | userInfo.setHeadimg(connection.getImageUrl());
27 | return userInfo;
28 |
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/social/qq/api/QQ.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.social.qq.api;
2 |
3 | /**
4 | * @Author 张迁-zhangqian
5 | * @Data 2018/4/8 下午6:14
6 | * @Package com.zq.core.social.qq.api
7 | **/
8 |
9 |
10 | public interface QQ {
11 | QQUserInfo getUserInfo();
12 | }
13 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/social/qq/config/QQAutoConfig.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.social.qq.config;
2 |
3 | import com.zq.core.properties.SecurityProperties;
4 | import com.zq.core.properties.social.QQProperties;
5 | import com.zq.core.social.qq.connect.QQConnectionFactory;
6 | import lombok.extern.slf4j.Slf4j;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
9 | import org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter;
10 | import org.springframework.context.annotation.Configuration;
11 | import org.springframework.social.connect.ConnectionFactory;
12 |
13 | /**
14 | * @Author 张迁-zhangqian
15 | * @Data 2018/4/8 下午7:40
16 | * @Package com.zq.core.social.qq.config
17 | **/
18 |
19 | @Slf4j
20 | @Configuration
21 | @ConditionalOnProperty(prefix = "zq.security.social-properties.qq", name = "appId")
22 | public class QQAutoConfig extends SocialAutoConfigurerAdapter {
23 |
24 |
25 | @Autowired
26 | private SecurityProperties securityProperties;
27 |
28 | @Override
29 | protected ConnectionFactory> createConnectionFactory() {
30 | log.info("创建QQConnectFactory成功");
31 | QQProperties qq = securityProperties.getSocialProperties().getQq();
32 | return new QQConnectionFactory(qq.getProviderId(), qq.getAppId(), qq.getAppSecret());
33 |
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/social/qq/connect/QQAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.social.qq.connect;
2 |
3 | import com.zq.core.social.qq.api.QQ;
4 | import com.zq.core.social.qq.api.QQUserInfo;
5 | import org.springframework.social.connect.ApiAdapter;
6 | import org.springframework.social.connect.ConnectionValues;
7 | import org.springframework.social.connect.UserProfile;
8 |
9 | /**
10 | * @Author 张迁-zhangqian
11 | * @Data 2018/4/8 下午7:50
12 | * @Package com.zq.core.social.qq.connect
13 | **/
14 |
15 |
16 | public class QQAdapter implements ApiAdapter {
17 | @Override
18 | public boolean test(QQ qq) {
19 | qq.getUserInfo();
20 | return true;
21 | }
22 |
23 | @Override
24 | public void setConnectionValues(QQ api, ConnectionValues connectionValues) {
25 | QQUserInfo userInfo = api.getUserInfo();
26 |
27 | connectionValues.setDisplayName(userInfo.getNickname());
28 | connectionValues.setImageUrl(userInfo.getFigureurl_qq_1());
29 | connectionValues.setProfileUrl(null);
30 | connectionValues.setProviderUserId(userInfo.getOpenId());
31 | }
32 |
33 | @Override
34 | public UserProfile fetchUserProfile(QQ qq) {
35 | return null;
36 | }
37 |
38 | @Override
39 | public void updateStatus(QQ qq, String s) {
40 |
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/social/qq/connect/QQConnectionFactory.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.social.qq.connect;
2 |
3 | import com.zq.core.social.qq.api.QQ;
4 | import org.springframework.social.connect.ApiAdapter;
5 | import org.springframework.social.connect.support.OAuth2ConnectionFactory;
6 | import org.springframework.social.oauth2.OAuth2ServiceProvider;
7 |
8 | /**
9 | * @Author 张迁-zhangqian
10 | * @Data 2018/4/8 下午7:52
11 | * @Package com.zq.core.social.qq.connect
12 | **/
13 |
14 |
15 | public class QQConnectionFactory extends OAuth2ConnectionFactory {
16 | public QQConnectionFactory(String providerId, String appid, String appSecret) {
17 | super(providerId, new QQServiceProvider(appid, appSecret), new QQAdapter());
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/social/qq/connect/QQServiceProvider.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.social.qq.connect;
2 |
3 | import com.zq.core.social.qq.api.QQ;
4 | import com.zq.core.social.qq.api.QQImpl;
5 | import org.springframework.social.oauth2.AbstractOAuth2ServiceProvider;
6 |
7 |
8 | /**
9 | * @Author 张迁-zhangqian
10 | * @Data 2018/4/8 下午7:41
11 | * @Package com.zq.core.social.qq.connect
12 | **/
13 |
14 |
15 | public class QQServiceProvider extends AbstractOAuth2ServiceProvider {
16 |
17 | private String appId;
18 |
19 | private static final String URL_AUTHORIZE = "https://graph.qq.com/oauth2.0/authorize";
20 |
21 | private static final String URL_ACCESS_TOKEN = "https://graph.qq.com/oauth2.0/token";
22 |
23 | public QQServiceProvider(String appId, String appSecret) {
24 | super(new QQOauth2Template(appId, appSecret, URL_AUTHORIZE, URL_ACCESS_TOKEN));
25 | this.appId = appId;
26 | }
27 |
28 |
29 | @Override
30 | public QQ getApi(String accessToken) {
31 | return new QQImpl(accessToken, appId);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/social/support/SocialAuthenticationFilterPostProcessor.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.zq.core.social.support;
5 |
6 | import org.springframework.social.security.SocialAuthenticationFilter;
7 |
8 | /**
9 | * SocialAuthenticationFilter后处理器,用于在不同环境下个性化社交登录的配置
10 | *
11 | * @author zhailiang
12 | */
13 | public interface SocialAuthenticationFilterPostProcessor {
14 |
15 | /**
16 | * @param socialAuthenticationFilter
17 | */
18 | void process(SocialAuthenticationFilter socialAuthenticationFilter);
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/social/support/SocialUserInfo.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.zq.core.social.support;
5 |
6 | import lombok.Getter;
7 | import lombok.Setter;
8 |
9 | /**
10 | * @author zhailiang
11 | */
12 | @Setter
13 | @Getter
14 | public class SocialUserInfo {
15 |
16 | private String providerId;
17 |
18 | private String providerUserId;
19 |
20 | private String nickname;
21 |
22 | private String headimg;
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/social/support/ZqSpringSocialConfigurer.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.zq.core.social.support;
5 |
6 | import lombok.Getter;
7 | import lombok.Setter;
8 | import org.springframework.social.security.SocialAuthenticationFilter;
9 | import org.springframework.social.security.SpringSocialConfigurer;
10 |
11 | /**
12 | * 继承默认的社交登录配置,加入自定义的后处理逻辑
13 | *
14 | * @author zhailiang
15 | *
16 | */
17 | @Getter
18 | @Setter
19 | public class ZqSpringSocialConfigurer extends SpringSocialConfigurer {
20 |
21 | private String filterProcessesUrl;
22 |
23 | private SocialAuthenticationFilterPostProcessor socialAuthenticationFilterPostProcessor;
24 |
25 | public ZqSpringSocialConfigurer(String filterProcessesUrl) {
26 | this.filterProcessesUrl = filterProcessesUrl;
27 | }
28 |
29 | /* (non-Javadoc)
30 | * @see org.springframework.security.config.annotation.SecurityConfigurerAdapter#postProcess(java.lang.Object)
31 | */
32 | @SuppressWarnings("unchecked")
33 | @Override
34 | protected T postProcess(T object) {
35 | SocialAuthenticationFilter filter = (SocialAuthenticationFilter) super.postProcess(object);
36 | filter.setFilterProcessesUrl(filterProcessesUrl);
37 | if (socialAuthenticationFilterPostProcessor != null) {
38 | socialAuthenticationFilterPostProcessor.process(filter);
39 | }
40 | return (T) filter;
41 | }
42 |
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/social/view/ImoocConnectView.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.zq.core.social.view;
5 |
6 | import org.springframework.web.servlet.view.AbstractView;
7 |
8 | import javax.servlet.http.HttpServletRequest;
9 | import javax.servlet.http.HttpServletResponse;
10 | import java.util.Map;
11 |
12 | /**
13 | * 绑定结果视图
14 | * @author zhailiang
15 | *
16 | */
17 | public class ImoocConnectView extends AbstractView {
18 |
19 | /*
20 | * (non-Javadoc)
21 | *
22 | * @see
23 | * org.springframework.web.servlet.view.AbstractView#renderMergedOutputModel
24 | * (java.util.Map, javax.servlet.http.HttpServletRequest,
25 | * javax.servlet.http.HttpServletResponse)
26 | */
27 | @Override
28 | protected void renderMergedOutputModel(Map model, HttpServletRequest request,
29 | HttpServletResponse response) throws Exception {
30 |
31 | response.setContentType("text/html;charset=UTF-8");
32 | if (model.get("connections") == null) {
33 | response.getWriter().write("解绑成功
");
34 | } else {
35 | response.getWriter().write("绑定成功
");
36 | }
37 |
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/social/wexin/api/WeXin.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.social.wexin.api;
2 |
3 | /**
4 | * @Author 张迁-zhangqian
5 | * @Data 2018/4/9 下午12:49
6 | * @Package com.zq.core.social.wexin.api
7 | **/
8 |
9 |
10 | public interface WeXin {
11 |
12 |
13 | WeXinUserInfo getWexinUserInfo(String appId);
14 | }
15 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/social/wexin/api/WeXinUserInfo.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.social.wexin.api;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | /**
7 | * @Author 张迁-zhangqian
8 | * @Data 2018/4/9 下午12:47
9 | * @Package com.zq.core.social.wexin.api
10 | **/
11 |
12 | @Getter
13 | @Setter
14 | public class WeXinUserInfo {
15 | /**
16 | * 普通用户的标识,对当前开发者帐号唯一
17 | */
18 | private String openid;
19 | /**
20 | * 普通用户昵称
21 | */
22 | private String nickname;
23 | /**
24 | * 语言
25 | */
26 | private String language;
27 | /**
28 | * 普通用户性别,1为男性,2为女性
29 | */
30 | private String sex;
31 | /**
32 | * 普通用户个人资料填写的省份
33 | */
34 | private String province;
35 | /**
36 | * 普通用户个人资料填写的城市
37 | */
38 | private String city;
39 | /**
40 | * 国家,如中国为CN
41 | */
42 | private String country;
43 | /**
44 | * 用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空
45 | */
46 | private String headimgurl;
47 | /**
48 | * 用户特权信息,json数组,如微信沃卡用户为(chinaunicom)
49 | */
50 | private String[] privilege;
51 | /**
52 | * 用户统一标识。针对一个微信开放平台帐号下的应用,同一用户的unionid是唯一的。
53 | */
54 | private String unionid;
55 | }
56 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/social/wexin/connect/WeXinAccessGrant.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.social.wexin.connect;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 | import org.springframework.social.oauth2.AccessGrant;
6 |
7 | /**
8 | * @Author 张迁-zhangqian
9 | * @Data 2018/4/9 下午12:59
10 | * @Package com.zq.core.social.wexin.connect
11 | **/
12 |
13 | @Setter
14 | @Getter
15 | public class WeXinAccessGrant extends AccessGrant {
16 | private String openId;
17 |
18 | public WeXinAccessGrant(String accessToken, String scope, String refreshToken, Long expiresIn) {
19 | super(accessToken, scope, refreshToken, expiresIn);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/social/wexin/connect/WeXinAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.social.wexin.connect;
2 |
3 | import com.zq.core.social.wexin.api.WeXin;
4 | import com.zq.core.social.wexin.api.WeXinUserInfo;
5 | import org.springframework.social.connect.ApiAdapter;
6 | import org.springframework.social.connect.ConnectionValues;
7 | import org.springframework.social.connect.UserProfile;
8 |
9 | /**
10 | * 微信 api适配器,将微信 api的数据模型转为spring social的标准模型。
11 | *
12 | * @Author 张迁-zhangqian
13 | * @Data 2018/4/9 下午1:05
14 | * @Package com.zq.core.social.wexin.connect
15 | **/
16 |
17 |
18 | public class WeXinAdapter implements ApiAdapter {
19 | private String openId;
20 |
21 | public WeXinAdapter(String openId) {
22 | this.openId = openId;
23 | }
24 |
25 | @Override
26 | public boolean test(WeXin weXin) {
27 | weXin.getWexinUserInfo(openId);
28 | return true;
29 | }
30 |
31 | @Override
32 | public void setConnectionValues(WeXin weXin, ConnectionValues connectionValues) {
33 | WeXinUserInfo wexinUserInfo = weXin.getWexinUserInfo(openId);
34 | connectionValues.setProviderUserId(wexinUserInfo.getOpenid());
35 | connectionValues.setDisplayName(wexinUserInfo.getNickname());
36 | connectionValues.setImageUrl(wexinUserInfo.getHeadimgurl());
37 | }
38 |
39 | @Override
40 | public UserProfile fetchUserProfile(WeXin weXin) {
41 | return null;
42 | }
43 |
44 | @Override
45 | public void updateStatus(WeXin weXin, String s) {
46 |
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/social/wexin/connect/WeXinServiceProvider.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.social.wexin.connect;
2 |
3 | import com.zq.core.social.wexin.api.WeXin;
4 | import com.zq.core.social.wexin.api.WeXinImpl;
5 | import org.springframework.social.oauth2.AbstractOAuth2ServiceProvider;
6 | import org.springframework.social.oauth2.OAuth2Operations;
7 |
8 | /**
9 | * @Author 张迁-zhangqian
10 | * @Data 2018/4/9 下午1:02
11 | * @Package com.zq.core.social.wexin.connect
12 | **/
13 |
14 |
15 | public class WeXinServiceProvider extends AbstractOAuth2ServiceProvider {
16 |
17 | /**
18 | * 微信获取授权码的url
19 | */
20 | private static final String URL_AUTHORIZE = "https://open.weixin.qq.com/connect/qrconnect";
21 | /**
22 | * 微信获取accessToken的url
23 | */
24 | private static final String URL_ACCESS_TOKEN = "https://api.weixin.qq.com/sns/oauth2/access_token";
25 |
26 |
27 | public WeXinServiceProvider(String appId, String appSecret) {
28 | super(new WeXinOAuth2Template(appId, appSecret, URL_AUTHORIZE, URL_ACCESS_TOKEN));
29 | }
30 |
31 | @Override
32 | public WeXin getApi(String accessToken) {
33 | return new WeXinImpl(accessToken);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/validate/code/ValidateCodeBeanConfig.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.validate.code;
2 |
3 | import com.zq.core.properties.SecurityProperties;
4 | import com.zq.core.validate.code.common.ValidateCodeGenerator;
5 | import com.zq.core.validate.code.image.ImageCodeGenerator;
6 | import com.zq.core.validate.code.sms.DefaultSmsCodeSender;
7 | import com.zq.core.validate.code.sms.SmsCodeSender;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
10 | import org.springframework.context.annotation.Bean;
11 | import org.springframework.context.annotation.Configuration;
12 |
13 | /**
14 | * @Author 张迁-zhangqian
15 | * @Data 2018/4/8 下午2:03
16 | * @Package com.zq.core.validate.code
17 | **/
18 |
19 |
20 | @Configuration
21 | public class ValidateCodeBeanConfig {
22 |
23 | @Autowired
24 | private SecurityProperties securityProperties;
25 |
26 | /**
27 | * 图片验证码图片生成器
28 | * @return
29 | */
30 | @Bean
31 | @ConditionalOnMissingBean(name = "imageValidateCodeGenerator")
32 | public ValidateCodeGenerator imageValidateCodeGenerator() {
33 | ImageCodeGenerator codeGenerator = new ImageCodeGenerator();
34 | codeGenerator.setSecurityProperties(securityProperties);
35 | return codeGenerator;
36 | }
37 |
38 | /**
39 | * 短信验证码发送器
40 | * @return
41 | */
42 | @Bean
43 | @ConditionalOnMissingBean(SmsCodeSender.class)
44 | public SmsCodeSender smsCodeSender() {
45 | return new DefaultSmsCodeSender();
46 | }
47 |
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/validate/code/ValidateCodeController.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.validate.code;
2 |
3 | import com.zq.core.properties.SecurityConstants;
4 | import com.zq.core.restful.ServerResponse;
5 | import com.zq.core.validate.code.common.ValidateCodeProcessorHolder;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.web.bind.annotation.GetMapping;
8 | import org.springframework.web.bind.annotation.PathVariable;
9 | import org.springframework.web.bind.annotation.RestController;
10 | import org.springframework.web.context.request.ServletWebRequest;
11 |
12 | import javax.servlet.http.HttpServletRequest;
13 | import javax.servlet.http.HttpServletResponse;
14 |
15 | /**
16 | * @Author 张迁-zhangqian
17 | * @Data 2018/4/8 下午3:30
18 | * @Package com.zq.core.validate.code
19 | **/
20 |
21 |
22 | @RestController
23 | public class ValidateCodeController {
24 |
25 | @Autowired
26 | private ValidateCodeProcessorHolder validateCodeProcessorHolder;
27 |
28 |
29 | /**
30 | * 创建验证码,根据验证码类型不同,调用不同的 {@link com.zq.core.validate.code.common.ValidateCodeProcessor}接口实现
31 | *
32 | * @param type
33 | * @param request
34 | * @param response
35 | * @throws Exception
36 | */
37 | @GetMapping(SecurityConstants.DEFAULT_VALIDATE_CODE_URL_PREFIX + "/{type}")
38 | public ServerResponse createCode(@PathVariable String type, HttpServletRequest request, HttpServletResponse response) throws Exception {
39 | return validateCodeProcessorHolder.findValidateCodeProcessor(type)
40 | .create(new ServletWebRequest(request, response));
41 |
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/validate/code/ValidateCodeSecurityConfig.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.validate.code;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
7 | import org.springframework.security.web.DefaultSecurityFilterChain;
8 | import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter;
9 | import org.springframework.stereotype.Component;
10 |
11 | import javax.servlet.Filter;
12 |
13 | /**
14 | * @Author 张迁-zhangqian
15 | * @Data 2018/4/8 下午2:00
16 | * @Package com.zq.core.validate.code
17 | **/
18 |
19 | @Configuration("validateCodeSecurityConfig")
20 | public class ValidateCodeSecurityConfig extends SecurityConfigurerAdapter {
21 |
22 |
23 | @Autowired
24 | private Filter validateCodeFilter;
25 |
26 | @Override
27 | public void configure(HttpSecurity builder) throws Exception {
28 | builder.addFilterBefore(validateCodeFilter, AbstractPreAuthenticatedProcessingFilter.class);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/validate/code/common/ValidateCode.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.validate.code.common;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | import java.io.Serializable;
7 | import java.time.LocalDateTime;
8 |
9 | /**
10 | * @Author 张迁-zhangqian
11 | * @Data 2018/4/8 上午11:59
12 | * @Package com.zq.core.validate.code
13 | **/
14 |
15 | @Getter
16 | @Setter
17 | public class ValidateCode implements Serializable {
18 |
19 |
20 | private String code;
21 | private LocalDateTime expireTime;
22 |
23 | public ValidateCode(String code, int expireIn) {
24 | this.code = code;
25 | this.expireTime = LocalDateTime.now().plusSeconds(expireIn);
26 | }
27 |
28 | public ValidateCode(String code, LocalDateTime expireTime) {
29 | this.code = code;
30 | this.expireTime = expireTime;
31 | }
32 |
33 | public boolean isExpried() {
34 | return LocalDateTime.now().isAfter(expireTime);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/validate/code/common/ValidateCodeException.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.zq.core.validate.code.common;
5 |
6 | import org.springframework.security.core.AuthenticationException;
7 |
8 | /**
9 | * @author zhailiang
10 | *
11 | */
12 | public class ValidateCodeException extends AuthenticationException {
13 |
14 | /**
15 | *
16 | */
17 | private static final long serialVersionUID = -7285211528095468156L;
18 |
19 | public ValidateCodeException(String msg) {
20 | super(msg);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/validate/code/common/ValidateCodeGenerator.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.validate.code.common;
2 |
3 | import org.springframework.web.context.request.ServletWebRequest;
4 |
5 | /**
6 | * @Author 张迁-zhangqian
7 | * @Data 2018/4/8 下午1:02
8 | * @Package com.zq.core.validate.code.common
9 | **/
10 |
11 |
12 | public interface ValidateCodeGenerator {
13 |
14 | /**
15 | * 生成验证码
16 | *
17 | * @param servletWebRequest
18 | * @return
19 | */
20 | ValidateCode generate(ServletWebRequest servletWebRequest);
21 | }
22 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/validate/code/common/ValidateCodeProcessor.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.validate.code.common;
2 |
3 | import com.zq.core.restful.ServerResponse;
4 | import org.springframework.web.context.request.ServletWebRequest;
5 |
6 | /**
7 | * @Author 张迁-zhangqian
8 | * @Data 2018/4/8 上午11:52
9 | * @Package com.zq.core.validate.code
10 | **/
11 |
12 |
13 | public interface ValidateCodeProcessor {
14 |
15 | /**
16 | * 创建校验码
17 | *
18 | * @param servletWebRequest
19 | * @throws Exception
20 | */
21 | ServerResponse create(ServletWebRequest servletWebRequest) throws Exception;
22 |
23 | /**
24 | * 验证校验码
25 | *
26 | * @param servletWebRequest
27 | */
28 |
29 | void validate(ServletWebRequest servletWebRequest);
30 |
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/validate/code/common/ValidateCodeProcessorHolder.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.validate.code.common;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.stereotype.Component;
5 | import org.springframework.web.context.request.ServletWebRequest;
6 |
7 | import java.util.Map;
8 |
9 | /**
10 | * @Author 张迁-zhangqian
11 | * @Data 2018/4/8 下午1:49
12 | * @Package com.zq.core.validate.code.common
13 | **/
14 |
15 | @Component
16 | public class ValidateCodeProcessorHolder {
17 |
18 | @Autowired
19 | private Map validateCodeProcessors;
20 |
21 | /**
22 | * @param type
23 | * @return
24 | */
25 | public ValidateCodeProcessor findValidateCodeProcessor(ValidateCodeType type) {
26 | return findValidateCodeProcessor(type.toString().toLowerCase());
27 | }
28 |
29 | /**
30 | * @param type
31 | * @return
32 | */
33 | public ValidateCodeProcessor findValidateCodeProcessor(String type) {
34 | String name = type.toLowerCase() + ValidateCodeProcessor.class.getSimpleName();
35 | ValidateCodeProcessor processor = validateCodeProcessors.get(name);
36 | if (processor == null) {
37 | throw new ValidateCodeException("验证码处理器" + name + "不存在");
38 | }
39 | return processor;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/validate/code/common/ValidateCodeRepository.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.validate.code.common;
2 |
3 | import org.springframework.web.context.request.ServletWebRequest;
4 |
5 | /**
6 | * @Author 张迁-zhangqian
7 | * @Data 2018/4/8 下午1:30
8 | * @Package com.zq.core.validate.code.common
9 | **/
10 |
11 | /**
12 | * 校验码存取器
13 | */
14 | public interface ValidateCodeRepository {
15 | /**
16 | * 保存验证码
17 | *
18 | * @param request
19 | * @param code
20 | * @param validateCodeType
21 | */
22 | void save(ServletWebRequest request, ValidateCode code, ValidateCodeType validateCodeType);
23 |
24 | /**
25 | * 获取验证码
26 | *
27 | * @param request
28 | * @param validateCodeType
29 | * @return
30 | */
31 | ValidateCode get(ServletWebRequest request, ValidateCodeType validateCodeType);
32 |
33 | /**
34 | * 移除验证码
35 | *
36 | * @param request
37 | * @param codeType
38 | */
39 | void remove(ServletWebRequest request, ValidateCodeType codeType);
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/validate/code/common/ValidateCodeType.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.validate.code.common;
2 |
3 | /**
4 | * @Author 张迁-zhangqian
5 | * @Data 2018/4/8 下午1:25
6 | * @Package com.zq.core.validate.code.common
7 | **/
8 |
9 | import com.zq.core.properties.SecurityConstants;
10 |
11 | /**
12 | * 校验码类型
13 | */
14 | public enum ValidateCodeType {
15 |
16 |
17 |
18 | /**
19 | * 短信验证码
20 | */
21 | SMS {
22 | @Override
23 | public String getParamNameOnValidate() {
24 | return SecurityConstants.DEFAULT_PARAMETER_NAME_CODE_SMS;
25 | }
26 | },
27 | /**
28 | * 图片验证码
29 | */
30 | IMAGE {
31 | @Override
32 | public String getParamNameOnValidate() {
33 | return SecurityConstants.DEFAULT_PARAMETER_NAME_CODE_IMAGE;
34 | }
35 | };
36 |
37 | /**
38 | * 校验时从请求中获取的参数的名字
39 | * @return
40 | */
41 | public abstract String getParamNameOnValidate();
42 | }
43 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/validate/code/image/ImageCode.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.validate.code.image;
2 |
3 | import com.zq.core.validate.code.common.ValidateCode;
4 | import lombok.Getter;
5 | import lombok.Setter;
6 |
7 | import java.awt.image.BufferedImage;
8 | import java.time.LocalDateTime;
9 |
10 | /**
11 | * @Author 张迁-zhangqian
12 | * @Data 2018/4/8 下午1:15
13 | * @Package com.zq.core.validate.code.image
14 | **/
15 |
16 |
17 | /**
18 | * 图片验证码
19 | */
20 | @Getter
21 | @Setter
22 | public class ImageCode extends ValidateCode {
23 |
24 | private BufferedImage bufferedImage;
25 |
26 | public ImageCode(BufferedImage bufferedImage, String code, int expireIn) {
27 | super(code, expireIn);
28 | this.bufferedImage = bufferedImage;
29 | }
30 |
31 | public ImageCode(String code, LocalDateTime expireTime, BufferedImage bufferedImage) {
32 | super(code, expireTime);
33 | this.bufferedImage = bufferedImage;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/validate/code/image/ImageCodeProcessor.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.validate.code.image;
2 |
3 |
4 | import com.zq.core.restful.ServerResponse;
5 | import com.zq.core.validate.code.common.AbstractValidateCodeProcessor;
6 | import com.zq.core.validate.code.common.ValidateCode;
7 | import org.springframework.stereotype.Component;
8 | import org.springframework.web.context.request.ServletWebRequest;
9 |
10 | import javax.imageio.ImageIO;
11 |
12 | /**
13 | * @Author 张迁-zhangqian
14 | * @Data 2018/4/8 下午1:21
15 | * @Package com.zq.core.validate.code.image
16 | **/
17 |
18 |
19 | @Component("imageValidateCodeProcessor")
20 | public class ImageCodeProcessor extends AbstractValidateCodeProcessor {
21 |
22 |
23 | @Override
24 | protected ServerResponse send(ServletWebRequest request, ImageCode imageCode) throws Exception {
25 | ImageIO.write(imageCode.getBufferedImage(),"JPEG",request.getResponse().getOutputStream());
26 | return ServerResponse.createBySuccess("生成图片成功");
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/validate/code/sms/DefaultSmsCodeSender.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.validate.code.sms;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 |
5 | /**
6 | * @Author 张迁-zhangqian
7 | * @Data 2018/4/8 下午1:47
8 | * @Package com.zq.core.validate.code.sms
9 | **/
10 |
11 | @Slf4j
12 | public class DefaultSmsCodeSender implements SmsCodeSender {
13 | @Override
14 | public void send(String mobile, String code) {
15 |
16 | log.info("用第三方短信给" + mobile + "发送短信验证码:" + code);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/validate/code/sms/SmsCodeGenerator.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.validate.code.sms;
2 |
3 | import com.zq.core.properties.SecurityProperties;
4 | import com.zq.core.validate.code.common.ValidateCode;
5 | import com.zq.core.validate.code.common.ValidateCodeGenerator;
6 | import lombok.Getter;
7 | import lombok.Setter;
8 | import org.apache.commons.lang.RandomStringUtils;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.stereotype.Component;
11 | import org.springframework.web.context.request.ServletWebRequest;
12 |
13 | /**
14 | * @Author 张迁-zhangqian
15 | * @Data 2018/4/8 下午1:39
16 | * @Package com.zq.core.validate.code.sms
17 | **/
18 |
19 | @Getter
20 | @Setter
21 | @Component("smsValidateCodeGenerator")
22 | public class SmsCodeGenerator implements ValidateCodeGenerator {
23 | @Autowired
24 | private SecurityProperties securityProperties;
25 |
26 | @Override
27 | public ValidateCode generate(ServletWebRequest servletWebRequest) {
28 |
29 | String code = RandomStringUtils.randomNumeric(securityProperties.getValidateCodeProperties().getSms().getLength());
30 | return new ValidateCode(code, securityProperties.getValidateCodeProperties().getSms().getExpireIn());
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/validate/code/sms/SmsCodeProcessor.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.validate.code.sms;
2 |
3 | import com.zq.core.properties.SecurityConstants;
4 | import com.zq.core.restful.ServerResponse;
5 | import com.zq.core.validate.code.common.AbstractValidateCodeProcessor;
6 | import com.zq.core.validate.code.common.ValidateCode;
7 | import lombok.extern.slf4j.Slf4j;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.stereotype.Component;
10 | import org.springframework.web.bind.ServletRequestUtils;
11 | import org.springframework.web.context.request.ServletWebRequest;
12 |
13 | /**
14 | * @Author 张迁-zhangqian
15 | * @Data 2018/4/8 下午1:42
16 | * @Package com.zq.core.validate.code.sms
17 | **/
18 |
19 | @Component("smsValidateCodeProcessor")
20 | public class SmsCodeProcessor extends AbstractValidateCodeProcessor {
21 |
22 | @Autowired
23 | private SmsCodeSender smsCodeSender;
24 |
25 | @Override
26 | protected ServerResponse send(ServletWebRequest request, ValidateCode validateCode) throws Exception {
27 | String paramName = SecurityConstants.DEFAULT_PARAMETER_NAME_MOBILE;
28 | String mobile = ServletRequestUtils.getRequiredStringParameter(request.getRequest(), paramName);
29 |
30 | smsCodeSender.send(mobile, validateCode.getCode());
31 |
32 | return ServerResponse.createBySuccess("发送短信成功 mobile:" + mobile + " code:" + validateCode.getCode());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/core/src/main/java/com/zq/core/validate/code/sms/SmsCodeSender.java:
--------------------------------------------------------------------------------
1 | package com.zq.core.validate.code.sms;
2 |
3 | /**
4 | * @Author 张迁-zhangqian
5 | * @Data 2018/4/8 下午1:45
6 | * @Package com.zq.core.validate.code.sms
7 | **/
8 |
9 |
10 | public interface SmsCodeSender {
11 | void send(String mobile, String code);
12 | }
13 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/ExampleApplication.java:
--------------------------------------------------------------------------------
1 | package com.zq;
2 |
3 | import org.mybatis.spring.annotation.MapperScan;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.transaction.annotation.EnableTransactionManagement;
7 |
8 | @SpringBootApplication
9 | @EnableTransactionManagement//开启事务
10 | @MapperScan(value = "com.zq.shop.web.mappers")//mybatis扫描mapper接口
11 | public class ExampleApplication {
12 |
13 | public static void main(String[] args) {
14 | SpringApplication.run(ExampleApplication.class, args);
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/authtication/ExampleAuthticaitionConfigProvider.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.authtication;
2 |
3 | import com.zq.core.authorize.AuthorizeConfigProvider;
4 | import org.springframework.http.HttpMethod;
5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6 | import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
7 | import org.springframework.stereotype.Component;
8 |
9 | /**
10 | * @Author 张迁-zhangqian
11 | * @Data 2018/4/10 下午7:28
12 | * @Package com.zq.shop.authtication
13 | **/
14 |
15 | @Component
16 | public class ExampleAuthticaitionConfigProvider implements AuthorizeConfigProvider {
17 | @Override
18 | public boolean config(ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry config) {
19 |
20 | config.antMatchers(HttpMethod.POST, "/user/register")
21 | .permitAll()
22 | .antMatchers(HttpMethod.GET, "/fonts/**")
23 | .permitAll()
24 | .antMatchers(HttpMethod.GET, "/v2/api-docs"
25 | , "/swagger-resources/configuration/ui"
26 | , "/swagger-resources"
27 | , "/swagger-resources/configuration/security"
28 | , "/swagger-ui.html"
29 | , "/docs.html")
30 | .permitAll();
31 |
32 | return false;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/exception/ExampleExceptionHandler.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.exception;
2 |
3 | import com.zq.core.restful.ServerResponse;
4 | import org.springframework.http.HttpStatus;
5 | import org.springframework.web.bind.annotation.ControllerAdvice;
6 | import org.springframework.web.bind.annotation.ResponseBody;
7 | import org.springframework.web.bind.annotation.*;
8 | import org.springframework.web.servlet.NoHandlerFoundException;
9 |
10 |
11 | /**
12 | * @Author 张迁-zhangqian
13 | * @Data 2018/4/10 下午9:40
14 | * @Package com.zq.shop.exception
15 | **/
16 | @ResponseBody
17 | @ControllerAdvice
18 | public class ExampleExceptionHandler {
19 |
20 |
21 | @ExceptionHandler(value = Exception.class)
22 | public ServerResponse errorHandler(Exception e) {
23 | e.printStackTrace();
24 | int code;
25 | if (e instanceof NoHandlerFoundException) {
26 | code = HttpStatus.BAD_REQUEST.value();
27 | } else {
28 | code = 500;
29 | }
30 | return ServerResponse.createByErrorCodeMessage(code,
31 |
32 | e.getClass().getSimpleName() + ";\n" +
33 | "local : " + e.getLocalizedMessage() + ";\n" +
34 | "string : " + e.toString() + ";\n" +
35 | "message : " + e.getMessage());
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/exception/FinalExceptionHandler.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.exception;
2 |
3 | import com.zq.core.restful.ServerResponse;
4 | import org.springframework.boot.autoconfigure.web.ErrorController;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 |
7 | import javax.servlet.http.HttpServletRequest;
8 | import javax.servlet.http.HttpServletResponse;
9 |
10 | /**
11 | * @Author 张迁-zhangqian
12 | * @Data 2018/4/10 下午10:01
13 | * @Package com.zq.shop.exception
14 | **/
15 | @Deprecated
16 | //@RestController
17 | public class FinalExceptionHandler implements ErrorController {
18 | @Override
19 | public String getErrorPath() {
20 | return "/error";
21 | }
22 |
23 | @RequestMapping("/error")
24 | public ServerResponse finalError(HttpServletResponse response, HttpServletRequest request) {
25 | return ServerResponse.createByErrorCodeMessage(500, "服务器错误");
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/utils/BigDecimalUtil.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.utils;
2 |
3 | import java.math.BigDecimal;
4 |
5 | /**
6 | * Created by geely
7 | */
8 | public class BigDecimalUtil {
9 |
10 | public static BigDecimal add(double v1, double v2) {
11 | BigDecimal b1 = new BigDecimal(Double.toString(v1));
12 | BigDecimal b2 = new BigDecimal(Double.toString(v2));
13 | return b1.add(b2);
14 | }
15 |
16 | public static BigDecimal sub(double v1, double v2) {
17 | BigDecimal b1 = new BigDecimal(Double.toString(v1));
18 | BigDecimal b2 = new BigDecimal(Double.toString(v2));
19 | return b1.subtract(b2);
20 | }
21 |
22 |
23 | public static BigDecimal mul(double v1, double v2) {
24 | BigDecimal b1 = new BigDecimal(Double.toString(v1));
25 | BigDecimal b2 = new BigDecimal(Double.toString(v2));
26 | return b1.multiply(b2);
27 | }
28 |
29 | public static BigDecimal div(double v1, double v2) {
30 | BigDecimal b1 = new BigDecimal(Double.toString(v1));
31 | BigDecimal b2 = new BigDecimal(Double.toString(v2));
32 | return b1.divide(b2, 2, BigDecimal.ROUND_HALF_UP);//四舍五入,保留2位小数
33 |
34 | }
35 |
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/controller/ManageUser/OrderManageController.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.controller.ManageUser;
2 |
3 | import com.zq.core.restful.ServerResponse;
4 | import com.zq.shop.web.service.IOrderService;
5 | import io.swagger.annotations.Api;
6 | import io.swagger.annotations.ApiOperation;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.web.bind.annotation.PostMapping;
9 | import org.springframework.web.bind.annotation.RequestMapping;
10 | import org.springframework.web.bind.annotation.RestController;
11 |
12 | /**
13 | * @Author 张迁-zhangqian
14 | * @Data 2018/4/23 下午2:42
15 | * @Package com.zq.shop.web.controller.ManageUser
16 | **/
17 |
18 | @Api(tags = "管理员:订单管理")
19 | @RestController
20 | @RequestMapping("/manage/order")
21 | public class OrderManageController {
22 |
23 | @Autowired
24 | private IOrderService iOrderService;
25 |
26 | @ApiOperation("列表")
27 | @PostMapping("/list")
28 | public ServerResponse manageList() {
29 | return iOrderService.manageList(0, 0);
30 | }
31 |
32 | @ApiOperation("订单详情")
33 | @PostMapping("/details")
34 | public ServerResponse manageDetails(Long orderNo) {
35 | return iOrderService.manageDetail(orderNo);
36 | }
37 |
38 | @ApiOperation("发送货物")
39 | @PostMapping("/send_goods")
40 | public ServerResponse manageSendGoods(Long orderNo) {
41 | return iOrderService.manageSendGoods(orderNo);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/controller/NormalUser/RongIMController.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.controller.NormalUser;
2 |
3 | import com.zq.app.server.DefaultUserDetails;
4 | import com.zq.core.restful.ServerResponse;
5 | import com.zq.shop.web.service.IRongIMService;
6 | import io.swagger.annotations.Api;
7 | import io.swagger.annotations.ApiOperation;
8 | import lombok.extern.slf4j.Slf4j;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.security.core.annotation.AuthenticationPrincipal;
11 | import org.springframework.web.bind.annotation.GetMapping;
12 | import org.springframework.web.bind.annotation.RequestMapping;
13 | import org.springframework.web.bind.annotation.RestController;
14 |
15 | /**
16 | * @Author 张迁-zhangqian
17 | * @Data 2018/5/30 上午11:49
18 | * @Package com.zq.shop.web.controller.NormalUser
19 | **/
20 |
21 | @Slf4j
22 | @Api(tags = "融云接口管理")
23 | @RestController
24 | @RequestMapping("/rongim")
25 | public class RongIMController {
26 |
27 | @Autowired
28 | IRongIMService iRongIMService;
29 |
30 | @ApiOperation("获取token")
31 | @GetMapping("/token")
32 | public ServerResponse getUser(@AuthenticationPrincipal DefaultUserDetails defaultUserDetails) {
33 | return iRongIMService.getToken(defaultUserDetails.getUid());
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/mappers/AddressMapper.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.mappers;
2 |
3 | import com.zq.shop.web.bean.Address;
4 | import org.apache.ibatis.annotations.Param;
5 |
6 | import java.util.List;
7 |
8 | public interface AddressMapper {
9 | /**
10 | * This method was generated by MyBatis Generator.
11 | * This method corresponds to the database table zq_address
12 | *
13 | * @mbg.generated
14 | */
15 | int insert(Address record);
16 |
17 | /**
18 | * This method was generated by MyBatis Generator.
19 | * This method corresponds to the database table zq_address
20 | *
21 | * @mbg.generated
22 | */
23 | int insertSelective(Address record);
24 |
25 | List findByLevelAndShengOrDi(@Param("level") String level, @Param("sheng") String sheng, @Param("di") String di);
26 |
27 |
28 | }
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/mappers/IDMapper.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.mappers;
2 |
3 | import org.apache.ibatis.annotations.Param;
4 |
5 | /**
6 | * @Author 张迁-zhangqian
7 | * @Data 2018/4/26 下午3:54
8 | * @Package com.zq.shop.web.mappers
9 | **/
10 |
11 |
12 | public interface IDMapper {
13 | /**
14 | * @param typeId
15 | * @return
16 | */
17 | Integer findId(@Param("type_id") String typeId);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/service/ICartService.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.service;
2 |
3 | import com.zq.core.restful.ServerResponse;
4 |
5 | /**
6 | * @Author 张迁-zhangqian
7 | * @Data 2018/4/22 下午5:42
8 | * @Package com.zq.shop.web.service
9 | **/
10 |
11 |
12 | public interface ICartService {
13 | ServerResponse add(Integer userId, Integer productId, Integer count);
14 |
15 | ServerResponse delete(Integer userId, String productIds);
16 |
17 | ServerResponse updateCount(Integer userId, Integer productId, Integer count);
18 |
19 | ServerResponse list(Integer userId);
20 |
21 | ServerResponse selectOrUnSelect(Integer userId, Integer productId, Integer checked);
22 | }
23 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/service/IFileService.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.service;
2 |
3 | import com.zq.core.restful.ServerResponse;
4 | import org.springframework.web.multipart.MultipartFile;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * @Author 张迁-zhangqian
10 | * @Data 2018/4/21 下午7:05
11 | * @Package com.zq.shop.web.service
12 | **/
13 |
14 |
15 | public interface IFileService {
16 | ServerResponse uploadFile(MultipartFile file, String path);
17 |
18 | ServerResponse> uploadFiles(List files, String path);
19 | }
20 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/service/IMomentsCommentService.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.service;
2 |
3 | import com.zq.core.restful.ServerResponse;
4 | import com.zq.shop.web.bean.MomentsComment;
5 |
6 | /**
7 | * @Author 张迁-zhangqian
8 | * @Data 2018/4/23 下午4:19
9 | * @Package com.zq.shop.web.service
10 | **/
11 |
12 |
13 | public interface IMomentsCommentService {
14 | ServerResponse create(MomentsComment momentsComment);
15 |
16 | ServerResponse findComment(Integer momentsId);
17 | }
18 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/service/IMomentsService.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.service;
2 |
3 | import com.zq.core.restful.ServerResponse;
4 | import com.zq.shop.web.bean.Moments;
5 | import com.zq.shop.web.vo.MomentVo;
6 | import com.zq.shop.web.vo.MomentsListVo;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * @Author 张迁-zhangqian
12 | * @Data 2018/4/23 下午4:08
13 | * @Package com.zq.shop.web.service
14 | **/
15 |
16 |
17 | public interface IMomentsService {
18 | ServerResponse create(Moments moments, Integer uid);
19 |
20 | ServerResponse details(Integer momentId, Integer uid);
21 |
22 | ServerResponse> list(Integer uid, Integer searchUid);
23 |
24 | ServerResponse star(Integer momentId, Integer uid);
25 | }
26 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/service/IOrderService.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.service;
2 |
3 | import com.zq.core.restful.ServerResponse;
4 | import com.zq.shop.web.vo.OrderVo;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * @Author 张迁-zhangqian
10 | * @Data 2018/4/22 下午7:59
11 | * @Package com.zq.shop.web.service
12 | **/
13 |
14 |
15 | public interface IOrderService {
16 | ServerResponse createOrder(Integer userId, Integer shippingId, String productIds);
17 |
18 | ServerResponse cancel(Integer userId, Long orderNo);
19 |
20 | ServerResponse getOrderDetail(Integer userId, Long orderNo);
21 |
22 | ServerResponse> getOrderList(Integer userId, Integer status, int pageNum, int pageSize);
23 |
24 | ServerResponse getOrderCheckedProductList(Integer uid, int i, int i1);
25 |
26 | //manage
27 | ServerResponse> manageList(int pageNum, int pageSize);
28 |
29 | ServerResponse manageDetail(Long orderNo);
30 |
31 | ServerResponse manageSendGoods(Long orderNo);
32 |
33 | ServerResponse preCreateOrder(Integer uid, String productIds);
34 | }
35 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/service/IProductCategoryService.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.service;
2 |
3 | import com.zq.core.restful.ServerResponse;
4 | import com.zq.shop.web.vo.CategoryVo;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * @Author 张迁-zhangqian
10 | * @Data 2018/4/22 下午2:45
11 | * @Package com.zq.shop.web.service
12 | **/
13 |
14 |
15 | public interface IProductCategoryService {
16 | ServerResponse> selectCategoryAndChildrenById(Integer id);
17 |
18 | ServerResponse> getChildrenParallelCategory(Integer categoryId);
19 |
20 | ServerResponse addCategory(String categoryName, Integer parentId);
21 |
22 | ServerResponse updateCategoryName(Integer categoryId, String categoryName);
23 |
24 | ServerResponse updateCategoryStatus(Integer categoryId, Boolean status);
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/service/IProductService.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.service;
2 |
3 | import com.zq.core.restful.ServerResponse;
4 | import com.zq.shop.web.bean.Product;
5 | import com.zq.shop.web.vo.ProductVo;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * @Author 张迁-zhangqian
11 | * @Data 2018/4/22 下午2:05
12 | * @Package com.zq.shop.web.service
13 | **/
14 |
15 |
16 | public interface IProductService {
17 | ServerResponse> getProductListByKeywordCategory(String keyword, Integer categoryId, int pagenum, int pagesize, String orderby);
18 |
19 | ServerResponse details(Integer productId);
20 |
21 | ServerResponse saveOrUpdateProduct(Product product, Integer userId);
22 |
23 | ServerResponse setSaleStatus(Integer productId, Integer status);
24 |
25 |
26 | ServerResponse> getProductList(Integer uid, int pageNum, int pageSize);
27 |
28 | ServerResponse> searchProduct(String productName, Integer productId, int pageNum, int pageSize);
29 |
30 | ServerResponse getProductListByUser(Integer userId, int i, int i1);
31 | }
32 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/service/IRongIMService.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.service;
2 |
3 | import com.zq.core.restful.ServerResponse;
4 |
5 | /**
6 | * @Author 张迁-zhangqian
7 | * @Data 2018/5/31 下午2:19
8 | * @Package com.zq.shop.web.service
9 | **/
10 |
11 |
12 | public interface IRongIMService {
13 |
14 | ServerResponse getToken(Integer userId);
15 | }
16 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/service/IShippingService.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.service;
2 |
3 | import com.zq.core.restful.ServerResponse;
4 | import com.zq.shop.web.bean.Address;
5 | import com.zq.shop.web.bean.Shipping;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * @Author 张迁-zhangqian
11 | * @Data 2018/4/22 下午8:01
12 | * @Package com.zq.shop.web.service
13 | **/
14 |
15 |
16 | public interface IShippingService {
17 | ServerResponse add(Integer userId, Shipping shipping);
18 |
19 | ServerResponse del(Integer userId, Integer shippingId);
20 |
21 | ServerResponse update(Integer userId, Shipping shipping);
22 |
23 | ServerResponse select(Integer userId, Integer shippingId);
24 |
25 | ServerResponse> list(Integer userId, int pageNum, int pageSize);
26 |
27 | ServerResponse> address(Integer uid, String shengcode, String dicode, Integer level);
28 | }
29 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/service/IShopUserService.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.service;
2 |
3 | import com.zq.core.restful.ServerResponse;
4 | import com.zq.shop.web.bean.ShopUser;
5 |
6 | /**
7 | * @Author 张迁-zhangqian
8 | * @Data 2018/4/21 下午2:34
9 | * @Package com.zq.shop.web.service
10 | **/
11 |
12 |
13 | public interface IShopUserService {
14 | ServerResponse register(ShopUser shopUser);
15 |
16 | ServerResponse getUserInfo(String username);
17 |
18 | ServerResponse getUserInfo(Integer userId);
19 |
20 | ServerResponse updateUserImage(String uploadFile, Integer userId);
21 |
22 | ServerResponse updateUserPassword(String password, Integer userId);
23 |
24 | ServerResponse updateInfo(ShopUser username, Integer uid);
25 |
26 | ServerResponse manageList(Integer uid);
27 |
28 | ServerResponse manageUpdateRole(Integer uid, Integer userId, Integer role);
29 | }
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/service/IUserFriendsService.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.service;
2 |
3 | import com.zq.core.restful.ServerResponse;
4 |
5 | /**
6 | * @Author 张迁-zhangqian
7 | * @Data 2018/4/24 下午2:50
8 | * @Package com.zq.shop.web.service
9 | **/
10 |
11 |
12 | public interface IUserFriendsService {
13 |
14 | ServerResponse list(Integer userId);
15 |
16 | ServerResponse create(Integer userId, Integer followId);
17 |
18 | ServerResponse delete(Integer userId, Integer followId);
19 | }
20 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/vo/CartShopVo.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.vo;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * @Author 张迁-zhangqian
10 | * @Data 2018/6/12 下午4:22
11 | * @Package com.zq.shop.web.vo
12 | **/
13 |
14 |
15 | @Getter
16 | @Setter
17 | public class CartShopVo {
18 | private Integer userId;
19 | private String username;
20 | private List cartVos;
21 | }
22 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/vo/CartVo.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.vo;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | /**
7 | * @Author 张迁-zhangqian
8 | * @Data 2018/6/9 下午6:00
9 | * @Package com.zq.shop.web.vo
10 | **/
11 |
12 |
13 | @Getter
14 | @Setter
15 | public class CartVo {
16 | private Integer userId;
17 | private Integer productId;
18 | private Integer quantity;
19 | private Integer checked;
20 | private ProductVo productVo;
21 | }
22 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/vo/CategoryVo.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.vo;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * @Author 张迁-zhangqian
10 | * @Data 2018/5/13 下午12:52
11 | * @Package com.zq.shop.web.vo
12 | **/
13 |
14 | @Setter
15 | @Getter
16 | public class CategoryVo {
17 | private Integer id;
18 | private Integer parentId;
19 | private String name;
20 | private String image;
21 | private Boolean status;
22 | private Integer sortOrder;
23 | private List itemList;
24 | }
25 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/vo/MomentCommentVo.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.vo;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | /**
7 | * @Author 张迁-zhangqian
8 | * @Data 2018/5/14 上午10:58
9 | * @Package com.zq.shop.web.vo
10 | **/
11 |
12 | @Setter
13 | @Getter
14 | public class MomentCommentVo {
15 | private Integer id;
16 | private Integer userId;
17 | private String username;
18 | private String userImage;
19 | private Integer status;
20 | private Integer followId;
21 | private Integer replyUserId;
22 | private String replyUserName;
23 | private Integer momentsId;
24 | private String content;
25 | private String images;
26 | }
27 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/vo/MomentVo.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.vo;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | import java.util.Date;
7 | import java.util.List;
8 |
9 | /**
10 | * @Author 张迁-zhangqian
11 | * @Data 2018/5/14 上午10:53
12 | * @Package com.zq.shop.web.vo
13 | **/
14 |
15 | @Setter
16 | @Getter
17 | public class MomentVo {
18 | private Integer id;
19 | private Integer userId;
20 | private String username;
21 | private String userImage;
22 | private Integer category;
23 | private Integer status;
24 | private Integer type;
25 | private String title;
26 | private String subtitle;
27 | private String details;
28 | private String mainImage;
29 | private String subImages;
30 | private Date lastSeeTime;
31 | private Integer star;
32 | private Integer starEnable;
33 | private Integer seeTimes;
34 | private List momentCommentVoList;
35 | }
36 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/vo/MomentsListVo.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.vo;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * @Author 张迁-zhangqian
10 | * @Data 2018/5/2 下午3:28
11 | * @Package com.zq.shop.web.vo
12 | **/
13 |
14 | @Getter
15 | @Setter
16 | public class MomentsListVo {
17 | private MomentVo momentVo;
18 | private List momentCommentVos;
19 | }
20 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/vo/OrderItemVo.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.vo;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | import java.math.BigDecimal;
7 |
8 | /**
9 | * @Author 张迁-zhangqian
10 | * @Data 2018/6/19 下午10:41
11 | * @Package com.zq.shop.web.vo
12 | **/
13 |
14 | @Getter
15 | @Setter
16 | public class OrderItemVo {
17 | private Long orderNo;
18 | private Integer userId;
19 | private Integer productId;
20 | private String productName;
21 | private String productImage;
22 | private BigDecimal currentUnitPrice;
23 | private Integer quantity;
24 | private BigDecimal totalPrice;
25 | private ProductVo productVo;
26 | }
27 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/vo/OrderSettlementsVo.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.vo;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * @Author 张迁-zhangqian
10 | * @Data 2018/6/21 下午12:48
11 | * @Package com.zq.shop.web.vo
12 | **/
13 |
14 | @Getter
15 | @Setter
16 | public class OrderSettlementsVo {
17 | private Integer id;
18 | private Integer settlementno;
19 | private Integer settlementtype;
20 | private Integer shopid;
21 | private Long settlementmoney;
22 | private Long ordermoney;
23 | private Integer isfinish;
24 | private Long totalcommission;
25 | private List orderVos;
26 | }
27 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/vo/OrderShopVo.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.vo;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * @Author 张迁-zhangqian
10 | * @Data 2018/6/19 下午11:05
11 | * @Package com.zq.shop.web.vo
12 | **/
13 |
14 | @Setter
15 | @Getter
16 | public class OrderShopVo {
17 | private Integer shopId;
18 | private Integer shopSn;
19 | private Integer userId;
20 | private String shopName;
21 | private String shopImg;
22 | private String shopTel;
23 | private List orderItemVos;
24 | }
25 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/vo/OrderVo.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.vo;
2 |
3 | import com.zq.shop.web.bean.Shipping;
4 | import lombok.Getter;
5 | import lombok.Setter;
6 |
7 | import java.math.BigDecimal;
8 | import java.util.Date;
9 |
10 | /**
11 | * @Author 张迁-zhangqian
12 | * @Data 2018/4/22 下午8:41
13 | * @Package com.zq.shop.web
14 | **/
15 |
16 | @Getter
17 | @Setter
18 | public class OrderVo {
19 | private Long orderNo;
20 | private Integer userId;
21 | private Integer shippingId;
22 | private BigDecimal payment;
23 | private Integer paymentType;
24 | private Integer settlementId;
25 | private Integer postage;
26 | private Integer status;
27 | private Date paymentTime;
28 | private Date sendTime;
29 | private Date endTime;
30 | private Date closeTime;
31 | private OrderShopVo orderShopVo;
32 | private Shipping shipping;
33 | }
34 |
--------------------------------------------------------------------------------
/example/src/main/java/com/zq/shop/web/vo/RecommendVo.java:
--------------------------------------------------------------------------------
1 | package com.zq.shop.web.vo;
2 |
3 | import lombok.Getter;
4 | import lombok.Setter;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * @Author 张迁-zhangqian
10 | * @Data 2018/5/11 上午10:39
11 | * @Package com.zq.shop.web.vo
12 | **/
13 | @Getter
14 | @Setter
15 | public class RecommendVo {
16 | private List recommendProducts;
17 | private List recommendImages;
18 | }
19 |
--------------------------------------------------------------------------------
/example/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | profiles:
3 | active: prod
--------------------------------------------------------------------------------
/example/src/main/resources/mappers/IDMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/example/src/test/java/com/zq/ExampleApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.zq;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class ExampleApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/shop.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------