Przeglądaj źródła

:sparkles: 添加新特性。微信登录

冷冷 7 lat temu
rodzic
commit
64f8e648ed
19 zmienionych plików z 333 dodań i 22 usunięć
  1. 7 0
      pigx-auth/src/main/java/com/pig4cloud/pigx/auth/PigxAuthApplication.java
  2. 3 3
      pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/WebSecurityConfigurer.java
  3. 59 3
      pigx-auth/src/main/java/com/pig4cloud/pigx/auth/service/PigxUserDetailsServiceImpl.java
  4. 54 0
      pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/EnumLoginType.java
  5. 9 4
      pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileAuthenticationProvider.java
  6. 2 2
      pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileSecurityConfigurer.java
  7. 35 0
      pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/social/QqSocialConfig.java
  8. 35 0
      pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/social/WxSocialConfig.java
  9. 36 0
      pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/util/PigxUserDetailsService.java
  10. 3 1
      pigx-common/pigx-common-security/src/main/resources/META-INF/spring.factories
  11. 10 0
      pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysUser.java
  12. 11 0
      pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/RemoteUserService.java
  13. 14 0
      pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/fallback/RemoteUserServiceFallbackImpl.java
  14. 11 0
      pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/UserVO.java
  15. 5 1
      pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/ResourceServerConfigurer.java
  16. 15 2
      pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java
  17. 3 2
      pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysUserService.java
  18. 11 4
      pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserServiceImpl.java
  19. 10 0
      pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysUserMapper.xml

+ 7 - 0
pigx-auth/src/main/java/com/pig4cloud/pigx/auth/PigxAuthApplication.java

@@ -23,6 +23,8 @@ package com.pig4cloud.pigx.auth;
 import org.springframework.boot.SpringApplication;
 import org.springframework.cloud.client.SpringCloudApplication;
 import org.springframework.cloud.openfeign.EnableFeignClients;
+import org.springframework.context.annotation.Bean;
+import org.springframework.web.client.RestTemplate;
 
 /**
  * @author lengleng
@@ -36,4 +38,9 @@ public class PigxAuthApplication {
 	public static void main(String[] args) {
 		SpringApplication.run(PigxAuthApplication.class, args);
 	}
+
+	@Bean
+	public RestTemplate restTemplate() {
+		return new RestTemplate();
+	}
 }

+ 3 - 3
pigx-auth/src/main/java/com/pig4cloud/pigx/auth/config/WebSecurityConfigurer.java

@@ -22,6 +22,7 @@ package com.pig4cloud.pigx.auth.config;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.pig4cloud.pigx.common.security.mobile.MobileLoginSuccessHandler;
 import com.pig4cloud.pigx.common.security.mobile.MobileSecurityConfigurer;
+import com.pig4cloud.pigx.common.security.util.PigxUserDetailsService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -31,7 +32,6 @@ import org.springframework.core.annotation.Order;
 import org.springframework.security.authentication.AuthenticationManager;
 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
-import org.springframework.security.core.userdetails.UserDetailsService;
 import org.springframework.security.crypto.factory.PasswordEncoderFactories;
 import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.security.oauth2.provider.ClientDetailsService;
@@ -52,7 +52,7 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
 	@Autowired
 	private ClientDetailsService clientDetailsService;
 	@Autowired
-	private UserDetailsService pigxUserDetailsServiceImpl;
+	private PigxUserDetailsService userDetailsService;
 	@Lazy
 	@Autowired
 	private AuthorizationServerTokenServices defaultAuthorizationServerTokenServices;
@@ -88,7 +88,7 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
 	@Bean
 	public MobileSecurityConfigurer mobileSecurityConfigurer() {
 		return new MobileSecurityConfigurer(mobileLoginSuccessHandler()
-			, pigxUserDetailsServiceImpl);
+			, userDetailsService);
 	}
 
 

+ 59 - 3
pigx-auth/src/main/java/com/pig4cloud/pigx/auth/service/PigxUserDetailsServiceImpl.java

@@ -21,21 +21,25 @@ package com.pig4cloud.pigx.auth.service;
 
 import cn.hutool.core.util.ArrayUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
 import com.pig4cloud.pigx.admin.api.dto.UserInfo;
 import com.pig4cloud.pigx.admin.api.entity.SysUser;
 import com.pig4cloud.pigx.admin.api.feign.RemoteUserService;
 import com.pig4cloud.pigx.common.core.constant.CommonConstant;
 import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
+import com.pig4cloud.pigx.common.core.constant.enums.EnumLoginType;
 import com.pig4cloud.pigx.common.core.util.R;
+import com.pig4cloud.pigx.common.security.social.WxSocialConfig;
+import com.pig4cloud.pigx.common.security.util.PigxUserDetailsService;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.authority.AuthorityUtils;
 import org.springframework.security.core.userdetails.User;
 import org.springframework.security.core.userdetails.UserDetails;
-import org.springframework.security.core.userdetails.UserDetailsService;
 import org.springframework.security.core.userdetails.UsernameNotFoundException;
 import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
 
 import java.util.Arrays;
 import java.util.Collection;
@@ -50,13 +54,65 @@ import java.util.Set;
 @Slf4j
 @Service
 @AllArgsConstructor
-public class PigxUserDetailsServiceImpl implements UserDetailsService {
+public class PigxUserDetailsServiceImpl implements PigxUserDetailsService {
+	private static final String WX_AUTHORIZATION_CODE_URL = "https://api.weixin.qq.com/sns/oauth2/access_token" +
+		"?appid=%s&secret=%s&code=%s&grant_type=authorization_code";
+	private static final String REGEX = "@";
+	private final RestTemplate restTemplate;
 	private final RemoteUserService remoteUserService;
+	private final WxSocialConfig wxSocialConfig;
 
+	/**
+	 * 用户密码登录
+	 *
+	 * @param username 用户名
+	 * @return
+	 * @throws UsernameNotFoundException
+	 */
 	@Override
 	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
 		R<UserInfo> result = remoteUserService.info(username, SecurityConstants.FROM_IN);
+		return getUserDetails(result);
+	}
+
+
+	/**
+	 * 根据社交登录code 登录
+	 *
+	 * @param inStr TYPE@CODE
+	 * @return UserDetails
+	 * @throws UsernameNotFoundException
+	 */
+	@Override
+	public UserDetails loadUserBySocial(String inStr) throws UsernameNotFoundException {
+		String[] codeStr = inStr.split(REGEX);
+		String type = codeStr[0];
+		String code = codeStr[1];
+
+		R<UserInfo> userInfo = null;
+		if (EnumLoginType.WECHAT.getType().equals(type)) {
+			String url = String.format(WX_AUTHORIZATION_CODE_URL
+				, wxSocialConfig.getAppid(), wxSocialConfig.getSecret(), code);
+			String result = restTemplate.getForObject(url, String.class);
+			log.debug("微信响应报文:{}", result);
+
+			Object obj = JSONUtil.parseObj(result).get("openid");
+			if (obj != null) {
+				userInfo = remoteUserService.social(EnumLoginType.WECHAT.getType(), obj.toString());
+			} else {
+				throw new UsernameNotFoundException("获取用户openid失败");
+			}
+		}
+		return getUserDetails(userInfo);
+	}
 
+	/**
+	 * 构建userdetails
+	 *
+	 * @param result 用户信息
+	 * @return
+	 */
+	private UserDetails getUserDetails(R<UserInfo> result) {
 		if (result == null || result.getData() == null) {
 			throw new UsernameNotFoundException("用户不存在");
 		}
@@ -75,7 +131,7 @@ public class PigxUserDetailsServiceImpl implements UserDetailsService {
 		SysUser user = info.getSysUser();
 		boolean enabled = StrUtil.equals(user.getDelFlag(), CommonConstant.STATUS_NORMAL);
 		// 构造security用户
-		return new User(username, SecurityConstants.BCRYPT + user.getPassword(), enabled,
+		return new User(info.getSysUser().getUsername(), SecurityConstants.BCRYPT + user.getPassword(), enabled,
 			true, true, true, authorities);
 	}
 }

+ 54 - 0
pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/enums/EnumLoginType.java

@@ -0,0 +1,54 @@
+/*
+ *    Copyright (c) 2018-2025, lengleng All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * Neither the name of the pig4cloud.com developer nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * Author: lengleng (wangiegie@gmail.com)
+ */
+
+package com.pig4cloud.pigx.common.core.constant.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @author lengleng
+ * @date 2018/8/15
+ * 社交登录类型
+ */
+@Getter
+@AllArgsConstructor
+public enum EnumLoginType {
+	/**
+	 * 账号密码登录
+	 */
+	PWD("PWD", "账号密码登录"),
+
+	/**
+	 * QQ登录
+	 */
+	QQ("QQ", "QQ登录"),
+
+	/**
+	 * 微信登录
+	 */
+	WECHAT("WX", "微信登录");
+
+	/**
+	 * 类型
+	 */
+	private final String type;
+	/**
+	 * 描述
+	 */
+	private final String description;
+}

+ 9 - 4
pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileAuthenticationProvider.java

@@ -17,28 +17,33 @@
 
 package com.pig4cloud.pigx.common.security.mobile;
 
+import com.pig4cloud.pigx.common.security.util.PigxUserDetailsService;
 import lombok.Getter;
 import lombok.Setter;
 import org.springframework.security.authentication.AuthenticationProvider;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.AuthenticationException;
 import org.springframework.security.core.userdetails.UserDetails;
-import org.springframework.security.core.userdetails.UserDetailsService;
 
 /**
  * @author lengleng
  * @date 2018/8/5
- * 手机号登录校验逻辑
+ * 手机登录校验逻辑
+ * 验证码登录、社交登录
  */
 public class MobileAuthenticationProvider implements AuthenticationProvider {
 	@Getter
 	@Setter
-	private UserDetailsService userDetailsService;
+	private PigxUserDetailsService userDetailsService;
 
 	@Override
 	public Authentication authenticate(Authentication authentication) throws AuthenticationException {
 		MobileAuthenticationToken mobileAuthenticationToken = (MobileAuthenticationToken) authentication;
-		UserDetails userDetails = userDetailsService.loadUserByUsername("admin");
+
+		String principal = mobileAuthenticationToken.getPrincipal().toString();
+		UserDetails userDetails = userDetailsService.loadUserBySocial(principal);
+
+
 		MobileAuthenticationToken authenticationToken = new MobileAuthenticationToken(userDetails, userDetails.getAuthorities());
 		authenticationToken.setDetails(mobileAuthenticationToken.getDetails());
 		return authenticationToken;

+ 2 - 2
pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/mobile/MobileSecurityConfigurer.java

@@ -17,11 +17,11 @@
 
 package com.pig4cloud.pigx.common.security.mobile;
 
+import com.pig4cloud.pigx.common.security.util.PigxUserDetailsService;
 import lombok.AllArgsConstructor;
 import org.springframework.security.authentication.AuthenticationManager;
 import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.core.userdetails.UserDetailsService;
 import org.springframework.security.web.DefaultSecurityFilterChain;
 import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
 import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
@@ -36,7 +36,7 @@ import org.springframework.stereotype.Component;
 @AllArgsConstructor
 public class MobileSecurityConfigurer extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
 	private AuthenticationSuccessHandler mobileLoginSuccessHandler;
-	private UserDetailsService userDetailsService;
+	private PigxUserDetailsService userDetailsService;
 
 	@Override
 	public void configure(HttpSecurity http) {

+ 35 - 0
pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/social/QqSocialConfig.java

@@ -0,0 +1,35 @@
+/*
+ *    Copyright (c) 2018-2025, lengleng All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * Neither the name of the pig4cloud.com developer nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * Author: lengleng (wangiegie@gmail.com)
+ */
+
+package com.pig4cloud.pigx.common.security.social;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author lengleng
+ * @date 2018/8/16
+ * qq登录配置信息
+ */
+@Data
+@Configuration
+@ConfigurationProperties(prefix = "social.qq")
+public class QqSocialConfig {
+	private String appid;
+	private String secret;
+}

+ 35 - 0
pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/social/WxSocialConfig.java

@@ -0,0 +1,35 @@
+/*
+ *    Copyright (c) 2018-2025, lengleng All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * Neither the name of the pig4cloud.com developer nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * Author: lengleng (wangiegie@gmail.com)
+ */
+
+package com.pig4cloud.pigx.common.security.social;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author lengleng
+ * @date 2018/8/16
+ * 微信登录配置
+ */
+@Data
+@Configuration
+@ConfigurationProperties(prefix = "social.wx")
+public class WxSocialConfig {
+	private String appid;
+	private String secret;
+}

+ 36 - 0
pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/util/PigxUserDetailsService.java

@@ -0,0 +1,36 @@
+/*
+ *    Copyright (c) 2018-2025, lengleng All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * Neither the name of the pig4cloud.com developer nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * Author: lengleng (wangiegie@gmail.com)
+ */package com.pig4cloud.pigx.common.security.util;
+
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+
+/**
+ * @author lengleng
+ * @date 2018/8/15
+ */
+public interface PigxUserDetailsService extends UserDetailsService {
+
+	/**
+	 * 根据社交登录code 登录
+	 *
+	 * @param code TYPE@CODE
+	 * @return UserDetails
+	 * @throws UsernameNotFoundException
+	 */
+	UserDetails loadUserBySocial(String code) throws UsernameNotFoundException;
+}

+ 3 - 1
pigx-common/pigx-common-security/src/main/resources/META-INF/spring.factories

@@ -2,4 +2,6 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
   com.pig4cloud.pigx.common.security.component.PermissionService,\
   com.pig4cloud.pigx.common.security.component.PigAccessDeniedHandler,\
   com.pig4cloud.pigx.common.security.component.ResourceAuthExceptionEntryPoint,\
-  com.pig4cloud.pigx.common.security.feign.PigxFeignClientConfiguration
+  com.pig4cloud.pigx.common.security.feign.PigxFeignClientConfiguration,\
+  com.pig4cloud.pigx.common.security.social.QqSocialConfig,\
+  com.pig4cloud.pigx.common.security.social.WxSocialConfig

+ 10 - 0
pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysUser.java

@@ -87,4 +87,14 @@ public class SysUser implements Serializable {
 	 */
 	private Integer deptId;
 
+	/**
+	 * 微信openid
+	 */
+	private String wxOpenid;
+
+	/**
+	 * QQ openid
+	 */
+	private String qqOpenid;
+
 }

+ 11 - 0
pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/RemoteUserService.java

@@ -44,4 +44,15 @@ public interface RemoteUserService {
 	@GetMapping("/user/info/{username}")
 	R<UserInfo> info(@PathVariable("username") String username
 		, @RequestHeader("from") String from);
+
+	/**
+	 * 通过社交账号查询用户、角色信息
+	 *
+	 * @param type   社交账号类型 (QQ/WX)
+	 * @param openid 账号
+	 * @return
+	 */
+	@GetMapping("/user/social/{type}/{openid}")
+	R<UserInfo> social(@PathVariable("type") String type
+		, @PathVariable("openid") String openid);
 }

+ 14 - 0
pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/fallback/RemoteUserServiceFallbackImpl.java

@@ -44,4 +44,18 @@ public class RemoteUserServiceFallbackImpl implements RemoteUserService {
 		log.error("feign 查询用户信息失败:{}", username);
 		return null;
 	}
+
+	/**
+	 * 通过社交账号查询用户、角色信息
+	 *
+	 * @param type   社交账号类型 (QQ/WX)
+	 * @param openid 账号
+	 * @return
+	 */
+	@Override
+	public R<UserInfo> social(String type, String openid) {
+		log.error("feign 查询用户信息失败:{}", openid);
+		return null;
+	}
+
 }

+ 11 - 0
pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/UserVO.java

@@ -50,6 +50,17 @@ public class UserVO implements Serializable {
 	 * 随机盐
 	 */
 	private String salt;
+
+	/**
+	 * 微信openid
+	 */
+	private String wxOpenid;
+
+	/**
+	 * QQ openid
+	 */
+	private String qqOpenid;
+
 	/**
 	 * 创建时间
 	 */

+ 5 - 1
pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/ResourceServerConfigurer.java

@@ -44,7 +44,11 @@ public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter {
 	@Override
 	public void configure(HttpSecurity http) throws Exception {
 		http.authorizeRequests()
-			.antMatchers("/actuator/**", "/user/info/*", "/log/**", "/v2/api-docs").permitAll()
+			.antMatchers("/actuator/**"
+				, "/user/info/*"
+				, "/user/social/**"
+				, "/log/**"
+				, "/v2/api-docs").permitAll()
 			.anyRequest().authenticated()
 			.and().csrf().disable();
 	}

+ 15 - 2
pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java

@@ -21,7 +21,6 @@ package com.pig4cloud.pigx.admin.controller;
 
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.plugins.Page;
-import com.pig4cloud.pigx.common.core.util.Query;
 import com.pig4cloud.pigx.admin.api.dto.UserDTO;
 import com.pig4cloud.pigx.admin.api.dto.UserInfo;
 import com.pig4cloud.pigx.admin.api.entity.SysUser;
@@ -30,6 +29,8 @@ import com.pig4cloud.pigx.admin.api.vo.UserVO;
 import com.pig4cloud.pigx.admin.service.SysUserService;
 import com.pig4cloud.pigx.common.core.constant.CommonConstant;
 import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
+import com.pig4cloud.pigx.common.core.constant.enums.EnumLoginType;
+import com.pig4cloud.pigx.common.core.util.Query;
 import com.pig4cloud.pigx.common.core.util.R;
 import com.pig4cloud.pigx.common.log.annotation.SysLog;
 import com.pig4cloud.pigx.common.security.util.SecurityUtils;
@@ -75,7 +76,19 @@ public class UserController {
 			username = SecurityUtils.getUser();
 		}
 
-		return new R<>(userService.findUserInfo(username));
+		return new R<>(userService.findUserInfo(EnumLoginType.PWD.getType(), username));
+	}
+
+	/**
+	 * 通过社交账号查询用户、角色信息
+	 *
+	 * @param type   社交账号类型 (QQ/WX)
+	 * @param openid 账号
+	 * @return
+	 */
+	@GetMapping("/social/{type}/{openid}")
+	public R<UserInfo> social(@PathVariable String type, @PathVariable String openid) {
+		return new R<>(userService.findUserInfo(type, openid));
 	}
 
 	/**

+ 3 - 2
pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysUserService.java

@@ -21,11 +21,11 @@ package com.pig4cloud.pigx.admin.service;
 
 import com.baomidou.mybatisplus.plugins.Page;
 import com.baomidou.mybatisplus.service.IService;
-import com.pig4cloud.pigx.common.core.util.Query;
 import com.pig4cloud.pigx.admin.api.dto.UserDTO;
 import com.pig4cloud.pigx.admin.api.dto.UserInfo;
 import com.pig4cloud.pigx.admin.api.entity.SysUser;
 import com.pig4cloud.pigx.admin.api.vo.UserVO;
+import com.pig4cloud.pigx.common.core.util.Query;
 import com.pig4cloud.pigx.common.core.util.R;
 
 /**
@@ -36,10 +36,11 @@ public interface SysUserService extends IService<SysUser> {
 	/**
 	 * 查询用户信息
 	 *
+	 * @param type     类型
 	 * @param username 用户名
 	 * @return userInfo
 	 */
-	UserInfo findUserInfo(String username);
+	UserInfo findUserInfo(String type, String username);
 
 	/**
 	 * 分页查询用户信息(含有角色信息)

+ 11 - 4
pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserServiceImpl.java

@@ -25,7 +25,6 @@ import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.plugins.Page;
 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
-import com.pig4cloud.pigx.common.core.util.Query;
 import com.pig4cloud.pigx.admin.api.dto.UserDTO;
 import com.pig4cloud.pigx.admin.api.dto.UserInfo;
 import com.pig4cloud.pigx.admin.api.entity.SysRole;
@@ -38,6 +37,8 @@ import com.pig4cloud.pigx.admin.service.SysMenuService;
 import com.pig4cloud.pigx.admin.service.SysRoleService;
 import com.pig4cloud.pigx.admin.service.SysUserRoleService;
 import com.pig4cloud.pigx.admin.service.SysUserService;
+import com.pig4cloud.pigx.common.core.constant.enums.EnumLoginType;
+import com.pig4cloud.pigx.common.core.util.Query;
 import com.pig4cloud.pigx.common.core.util.R;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
@@ -79,10 +80,16 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
 	 * @return
 	 */
 	@Override
-	@Cacheable(value = "user_details", key = "#username")
-	public UserInfo findUserInfo(String username) {
+	@Cacheable(value = "user_details", key = "#type +':'+ #username")
+	public UserInfo findUserInfo(String type, String username) {
 		SysUser condition = new SysUser();
-		condition.setUsername(username);
+		if (EnumLoginType.PWD.getType().equals(type)) {
+			condition.setUsername(username);
+		} else if (EnumLoginType.WECHAT.getType().equals(type)) {
+			condition.setWxOpenid(username);
+		} else {
+			condition.setQqOpenid(username);
+		}
 		SysUser sysUser = this.selectOne(new EntityWrapper<>(condition));
 		if (sysUser == null) {
 			return null;

+ 10 - 0
pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysUserMapper.xml

@@ -29,6 +29,8 @@
 		<result column="avatar" property="avatar"/>
 		<result column="salt" property="salt"/>
 		<result column="dept_id" property="deptId"/>
+		<result column="wx_openid" property="wxOpenid"/>
+		<result column="qq_openid" property="qqOpenid"/>
 		<result column="create_time" property="createTime"/>
 		<result column="update_time" property="updateTime"/>
 		<result column="del_flag" property="delFlag"/>
@@ -42,6 +44,8 @@
 		<result column="salt" property="salt"/>
 		<result column="phone" property="phone"/>
 		<result column="avatar" property="avatar"/>
+		<result column="wx_openid" property="wxOpenid"/>
+		<result column="qq_openid" property="qqOpenid"/>
 		<result column="ucreate_time" property="createTime"/>
 		<result column="uupdate_time" property="updateTime"/>
 		<result column="udel_flag" property="delFlag"/>
@@ -65,6 +69,8 @@
             `user`.salt,
             `user`.phone,
             `user`.avatar,
+            `user`.wx_openid,
+            `user`.qq_openid,
             `user`.dept_id,
             `user`.create_time AS ucreate_time,
             `user`.update_time AS uupdate_time,
@@ -95,6 +101,8 @@
             `user`.salt,
             `user`.phone,
             `user`.avatar,
+			`user`.wx_openid,
+            `user`.qq_openid,
             `user`.create_time AS ucreate_time,
             `user`.update_time AS uupdate_time,
             `user`.del_flag AS udel_flag,
@@ -123,6 +131,8 @@
 		`user`.salt,
 		`user`.phone,
 		`user`.avatar,
+		`user`.wx_openid,
+		`user`.qq_openid,
 		`user`.create_time AS ucreate_time,
 		`user`.update_time AS uupdate_time,
 		`user`.del_flag AS udel_flag,