Browse Source

修改小程序接口

baolei 9 months ago
parent
commit
d345e17ba9
19 changed files with 579 additions and 240 deletions
  1. 0 29
      08.src/Xingxi/.idea/dataSources.xml
  2. 16 0
      08.src/Xingxi/xingxi-common/src/main/java/com/xingxi/common/core/domain/entity/SysUser.java
  3. 31 0
      08.src/Xingxi/xingxi-common/src/main/java/com/xingxi/common/enums/EUserType.java
  4. 5 10
      08.src/Xingxi/xingxi-miniprogram-api/pom.xml
  5. 71 0
      08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/common/JWTUtils.java
  6. 0 1
      08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/common/ResponseDTO.java
  7. 56 0
      08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/configuration/security/JwtAuthenticationConverter.java
  8. 40 0
      08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/configuration/security/JwtAuthenticationFilter.java
  9. 51 0
      08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/configuration/security/JwtAuthenticationManager.java
  10. 22 0
      08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/configuration/security/WxAccessDeniedHandler.java
  11. 21 0
      08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/configuration/security/WxAuthenticationEntryPoint.java
  12. 31 0
      08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/configuration/security/WxAuthenticationFailureHandler.java
  13. 58 0
      08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/configuration/security/WxAuthenticationSuccessHandler.java
  14. 76 0
      08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/configuration/security/WxLoginAuthenticationManager.java
  15. 68 0
      08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/configuration/security/WxLoginAuthenticationProcessingFilter.java
  16. 8 5
      08.src/Xingxi/xingxi-miniprogram-api/src/main/resources/application-local.yml
  17. 1 188
      08.src/Xingxi/xingxi-miniprogram-api/xingxi-miniprogram-api.iml
  18. 8 0
      08.src/Xingxi/xingxi-system/src/main/java/com/xingxi/system/mapper/SysUserMapper.java
  19. 16 7
      08.src/Xingxi/xingxi-system/src/main/resources/mapper/system/SysUserMapper.xml

+ 0 - 29
08.src/Xingxi/.idea/dataSources.xml

@@ -1,35 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="DataSourceManagerImpl" format="xml" multifile-model="true">
-    <data-source source="LOCAL" name="mysql" uuid="9e70433d-c946-46b4-a902-4c37a2ee0793">
-      <driver-ref>mysql.8</driver-ref>
-      <synchronize>true</synchronize>
-      <imported>true</imported>
-      <remarks>$PROJECT_DIR$/xingxi-admin/src/main/resources/application-local.yml</remarks>
-      <jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
-      <jdbc-url>jdbc:mysql://localhost:3306</jdbc-url>
-      <jdbc-additional-properties>
-        <property name="com.intellij.clouds.kubernetes.db.host.port" />
-        <property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
-        <property name="com.intellij.clouds.kubernetes.db.resource.type" value="Deployment" />
-        <property name="com.intellij.clouds.kubernetes.db.container.port" />
-      </jdbc-additional-properties>
-      <working-dir>$ProjectFileDir$</working-dir>
-    </data-source>
-    <data-source source="LOCAL" name="mysql" uuid="2dd55947-c3ac-4d65-b163-2268910ac998">
-      <driver-ref>mysql.8</driver-ref>
-      <synchronize>true</synchronize>
-      <imported>true</imported>
-      <remarks>$PROJECT_DIR$/xingxi-mq-server/src/main/resources/config/application-local.yml</remarks>
-      <jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
-      <jdbc-url>jdbc:mysql://localhost:3306</jdbc-url>
-      <jdbc-additional-properties>
-        <property name="com.intellij.clouds.kubernetes.db.host.port" />
-        <property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
-        <property name="com.intellij.clouds.kubernetes.db.container.port" />
-      </jdbc-additional-properties>
-      <working-dir>$ProjectFileDir$</working-dir>
-    </data-source>
     <data-source source="LOCAL" name="empress@47.98.144.243" uuid="7542ebbe-4f2d-467f-b61d-5cf128f14e17">
       <driver-ref>mysql.8</driver-ref>
       <synchronize>true</synchronize>

+ 16 - 0
08.src/Xingxi/xingxi-common/src/main/java/com/xingxi/common/core/domain/entity/SysUser.java

@@ -120,6 +120,22 @@ public class SysUser extends BaseEntity {
     // 密码最后更新时间
     private Date pwdUpdateDate;
 
+    public String getWxOpenId() {
+        return wxOpenId;
+    }
+
+    public void setWxOpenId(String wxOpenId) {
+        this.wxOpenId = wxOpenId;
+    }
+
+    public String getWxUnionId() {
+        return wxUnionId;
+    }
+
+    public void setWxUnionId(String wxUnionId) {
+        this.wxUnionId = wxUnionId;
+    }
+
     // 微信openId
     private String wxOpenId;
 

+ 31 - 0
08.src/Xingxi/xingxi-common/src/main/java/com/xingxi/common/enums/EUserType.java

@@ -0,0 +1,31 @@
+package com.xingxi.common.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @program: gululuq
+ * @description: 用户分类
+ * @author: bao
+ * @create: 2022-02-14
+ */
+@AllArgsConstructor
+@Getter
+public enum EUserType {
+    ORDINARY("00", "系统用户"),// 后台系统用户
+    REGISTER("01", "注册用户"),// 后台注册用户
+    WECHAT("10", "微信用户"); // 微信用户
+
+    private String val;
+    private String desc;
+
+    // 解析
+    public static EUserType parseByVal(String val) {
+        for (EUserType type : EUserType.values()) {
+            if (type.getVal().equalsIgnoreCase(val)) {
+                return type;
+            }
+        }
+        return EUserType.ORDINARY;
+    }
+}

+ 5 - 10
08.src/Xingxi/xingxi-miniprogram-api/pom.xml

@@ -19,6 +19,10 @@
             <artifactId>xingxi-system</artifactId>
         </dependency>
         <dependency>
+            <groupId>com.xingxi</groupId>
+            <artifactId>xingxi-common</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-security</artifactId>
         </dependency>
@@ -39,6 +43,7 @@
             <version>0.11.2</version>
             <scope>runtime</scope>
         </dependency>
+        <!-- RabbitMq -->
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-amqp</artifactId>
@@ -57,16 +62,6 @@
             <artifactId>druid-spring-boot-starter</artifactId>
         </dependency>
         <dependency>
-            <groupId>com.jhlabs</groupId>
-            <artifactId>filters</artifactId>
-            <version>2.0.235-1</version>
-        </dependency>
-        <dependency>
-            <groupId>net.coobird</groupId>
-            <artifactId>thumbnailator</artifactId>
-            <version>0.4.16</version>
-        </dependency>
-        <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
         </dependency>

+ 71 - 0
08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/common/JWTUtils.java

@@ -0,0 +1,71 @@
+package com.xingxi.store.common;
+
+import com.xingxi.common.utils.DateUtils;
+import io.jsonwebtoken.*;
+import io.jsonwebtoken.io.Decoders;
+import io.jsonwebtoken.io.Encoders;
+import io.jsonwebtoken.security.Keys;
+
+import javax.crypto.SecretKey;
+import java.security.Key;
+import java.util.Date;
+import java.util.UUID;
+
+public final class JWTUtils {
+    private static final String SECRET_KEY_STRING = "9YIGtSIjKI2cGGz7TuPNQFtk2WmphzESAp98zicd6AI=";
+    private JWTUtils(){
+        throw new RuntimeException();
+    }
+
+
+    public static String generateSecretKeyString(){
+        Key key = Keys.secretKeyFor(SignatureAlgorithm.HS256);
+        return Encoders.BASE64.encode(key.getEncoded());
+    }
+
+
+    public static String generateJwtString(String openid, Date issuedAt){
+        SecretKey secretKey = Keys.hmacShaKeyFor(Decoders.BASE64.decode(SECRET_KEY_STRING));
+        return Jwts.builder()
+                .setHeaderParam("typ", "JWT")
+                .setId(UUID.randomUUID().toString()) // jti
+                .setSubject(openid) // sub 主题
+                .setExpiration(DateUtils.addHours(new Date(), 4)) //过期时间
+                .setIssuedAt(issuedAt) // 发布时间
+                .setIssuer("Biandan_wx_") // 发布者
+//                .claim("test", "1231333")
+                .signWith(secretKey)
+                .compact();
+    }
+
+
+    public static Jws<Claims> parseJwt(String compactJws){
+        try {
+            Jws<Claims> claimsJws = Jwts.parserBuilder()
+                    .setSigningKey(SECRET_KEY_STRING)
+                    .build().parseClaimsJws(compactJws);
+            Claims body = claimsJws.getBody();
+            JwsHeader header = claimsJws.getHeader();
+            System.out.println(body);
+            System.out.println(header);
+            //OK, we can trust this JWT
+            return claimsJws;
+        } catch (JwtException e) {
+            //don't trust the JWT!
+            e.printStackTrace();
+            throw new RuntimeException();
+        }
+    }
+
+    public static void main(String[] args) {
+//        String secretString = generateSecretKeyString();
+//        System.out.println(secretString);
+//        String test = generateJwtString(new HashMap<String, String>(){{
+//            put("test", "1213");
+//        }});
+//        System.out.println(test);
+//        parseJwt(test);
+    }
+
+
+}

+ 0 - 1
08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/common/ResponseDTO.java

@@ -1,6 +1,5 @@
 package com.xingxi.store.common;
 
-
 import java.io.Serializable;
 import java.time.LocalDateTime;
 

+ 56 - 0
08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/configuration/security/JwtAuthenticationConverter.java

@@ -0,0 +1,56 @@
+package com.xingxi.store.configuration.security;
+
+import com.xingxi.common.core.domain.entity.SysUser;
+import com.xingxi.store.common.JWTUtils;
+import io.jsonwebtoken.Claims;
+import io.jsonwebtoken.Jws;
+import org.springframework.http.HttpHeaders;
+import org.springframework.security.authentication.BadCredentialsException;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.web.authentication.AuthenticationConverter;
+import org.springframework.util.StringUtils;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Date;
+
+class JwtAuthenticationConverter implements AuthenticationConverter {
+    public static final String AUTHENTICATION_SCHEME_BEARER = "Bearer";
+
+    public JwtAuthenticationConverter() {
+    }
+
+    @Override
+    public UsernamePasswordAuthenticationToken convert(HttpServletRequest request) {
+        String header = request.getHeader(HttpHeaders.AUTHORIZATION);
+        if (header == null) {
+            return null;
+        }
+
+        header = header.trim();
+        if (!StringUtils.startsWithIgnoreCase(header, AUTHENTICATION_SCHEME_BEARER)) {
+            return null;
+        }
+
+        if (header.equalsIgnoreCase(AUTHENTICATION_SCHEME_BEARER)) {
+            throw new BadCredentialsException("Empty bearer authentication token");
+        }
+
+        String bearerToken = header.substring(7);
+        SysUser sysUser = new SysUser();
+
+        try {
+            Jws<Claims> claimsJws = JWTUtils.parseJwt(bearerToken);
+            Claims claimsJwsBody = claimsJws.getBody();
+            String openid = claimsJwsBody.getSubject();
+            Date issuedAt = claimsJwsBody.getIssuedAt();
+            sysUser.setLoginDate(issuedAt);
+            sysUser.setWxOpenId(openid);
+        } catch (Exception e){
+            e.printStackTrace();
+            return null;
+        }
+
+        return new UsernamePasswordAuthenticationToken(sysUser, "");
+    }
+
+}

+ 40 - 0
08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/configuration/security/JwtAuthenticationFilter.java

@@ -0,0 +1,40 @@
+package com.xingxi.store.configuration.security;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+@Slf4j
+@RequiredArgsConstructor
+class JwtAuthenticationFilter extends OncePerRequestFilter {
+    private final JwtAuthenticationConverter authenticationConverter = new JwtAuthenticationConverter();
+    private final JwtAuthenticationManager jwtAuthenticationManager;
+
+    @Override
+    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
+        log.debug("JwtAuthenticationFilter.doFilterInternal()...");
+        try {
+            UsernamePasswordAuthenticationToken authRequest = this.authenticationConverter.convert(request);
+            if (authRequest != null) {
+                Authentication authResult = jwtAuthenticationManager.authenticate(authRequest);
+                SecurityContextHolder.getContext().setAuthentication(authResult);
+            }
+        } catch (Exception e){
+//            e.printStackTrace();
+            log.error(e.getMessage());
+            SecurityContextHolder.clearContext();
+        }
+
+        filterChain.doFilter(request, response);
+    }
+
+}

+ 51 - 0
08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/configuration/security/JwtAuthenticationManager.java

@@ -0,0 +1,51 @@
+package com.xingxi.store.configuration.security;
+
+import com.xingxi.common.core.domain.entity.SysUser;
+import com.xingxi.common.utils.DateUtils;
+import com.xingxi.store.common.UserContext;
+import com.xingxi.system.mapper.SysDeptMapper;
+import com.xingxi.system.mapper.SysUserMapper;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.stereotype.Component;
+import org.springframework.util.ObjectUtils;
+
+import java.util.ArrayList;
+import java.util.Date;
+
+@Slf4j
+@RequiredArgsConstructor
+@Component("JwtAuthenticationManager")
+class JwtAuthenticationManager implements AuthenticationManager {
+    private final SysUserMapper sysUserMapper;
+
+    @Override
+    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
+        log.debug("JwtAuthenticationManager.authenticate()....");
+        Date now = DateUtils.getNowDate();
+
+        SysUser loginSysUser = (SysUser) authentication.getPrincipal();
+        String wxOpenId = loginSysUser.getWxOpenId();
+        Date loginDate = loginSysUser.getLoginDate();
+
+        SysUser sysUser = sysUserMapper.selectUserByOpenId(wxOpenId);
+        if (ObjectUtils.isEmpty(sysUser)) {
+            log.debug("用户openid[" + wxOpenId + "]不存在");
+            throw new RuntimeException("用户不存在");
+        }
+
+        if (!DateUtils.isSameInstant(loginDate, sysUser.getLoginDate())) {
+            log.debug("token发行时间[" + loginDate + "],当前数据库登录时间[" + sysUser.getLoginDate() + "]");
+            throw new RuntimeException("token过期");
+        }
+
+        UserContext userContext = new UserContext(sysUser);
+
+        return new UsernamePasswordAuthenticationToken(userContext, null, new ArrayList<>());
+    }
+
+}

+ 22 - 0
08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/configuration/security/WxAccessDeniedHandler.java

@@ -0,0 +1,22 @@
+package com.xingxi.store.configuration.security;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.HttpStatus;
+import org.springframework.security.access.AccessDeniedException;
+import org.springframework.security.web.access.AccessDeniedHandler;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+@Slf4j
+@Component
+class WxAccessDeniedHandler implements AccessDeniedHandler {
+    @Override
+    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
+        // Set the 403 status code.
+        response.setStatus(HttpStatus.FORBIDDEN.value());
+    }
+}

+ 21 - 0
08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/configuration/security/WxAuthenticationEntryPoint.java

@@ -0,0 +1,21 @@
+package com.xingxi.store.configuration.security;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.HttpStatus;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.web.AuthenticationEntryPoint;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+@Slf4j
+@Component
+class WxAuthenticationEntryPoint implements AuthenticationEntryPoint {
+    @Override
+    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
+        response.sendError(HttpStatus.UNAUTHORIZED.value(), HttpStatus.UNAUTHORIZED.getReasonPhrase());
+    }
+}

+ 31 - 0
08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/configuration/security/WxAuthenticationFailureHandler.java

@@ -0,0 +1,31 @@
+package com.xingxi.store.configuration.security;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.xingxi.store.common.ResponseDTO;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.web.authentication.AuthenticationFailureHandler;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+@Slf4j
+@Component
+@RequiredArgsConstructor
+class WxAuthenticationFailureHandler implements AuthenticationFailureHandler {
+    private final ObjectMapper objectMapper;
+    @Override
+    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
+        String message = StringUtils.hasLength(exception.getMessage()) ? exception.getMessage() : "登录失败";
+        ResponseDTO<Void> responseDTO = new ResponseDTO<>(401);
+        responseDTO.setMessage(message);
+        response.setStatus(401);
+        response.setCharacterEncoding("utf-8");
+        response.getWriter().write(objectMapper.writeValueAsString(responseDTO));
+    }
+}

+ 58 - 0
08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/configuration/security/WxAuthenticationSuccessHandler.java

@@ -0,0 +1,58 @@
+package com.xingxi.store.configuration.security;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.xingxi.common.core.domain.entity.SysUser;
+import com.xingxi.store.common.ResponseDTO;
+import com.xingxi.store.common.AccessTokenDTO;
+import com.xingxi.store.common.JWTUtils;
+import com.xingxi.store.data.domain.UserProfileDTO;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Slf4j
+@Component
+@RequiredArgsConstructor
+class WxAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
+    private final ObjectMapper objectMapper;
+
+    @Override
+    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
+        log.debug("WxAuthenticationSuccessHandler.onAuthenticationSuccess()...");
+
+        SysUser sysUser = (SysUser) authentication.getPrincipal();
+
+        UserProfileDTO userProfileDTO = new UserProfileDTO();
+        userProfileDTO.setUserType(sysUser.getUserType());
+        userProfileDTO.setUserId(sysUser.getUserId() + "");
+        userProfileDTO.setPhoneNumber(sysUser.getPhonenumber());
+        userProfileDTO.setNickName(sysUser.getUserName());
+        userProfileDTO.setAvatarUrl(sysUser.getAvatar());
+        userProfileDTO.setGender(sysUser.getSex());
+
+        String accessToken = JWTUtils.generateJwtString(sysUser.getWxOpenId(), sysUser.getLoginDate());
+        String requestId = (String) request.getAttribute("X-REQUEST-ID");
+
+        ResponseDTO<Map<String, Object>> responseDTO = new ResponseDTO<>(200);
+        responseDTO.setRequestId(requestId);
+        responseDTO.setData(new HashMap<String, Object>(){{
+            put("userProfileDTO", userProfileDTO);
+            put("accessTokenDTO", new AccessTokenDTO(accessToken, 14400L));
+        }});
+
+        response.setStatus(200);
+        response.setCharacterEncoding("utf-8");
+        response.getWriter().write(objectMapper.writeValueAsString(responseDTO));
+
+    }
+}

+ 76 - 0
08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/configuration/security/WxLoginAuthenticationManager.java

@@ -0,0 +1,76 @@
+package com.xingxi.store.configuration.security;
+
+import com.xingxi.common.core.domain.entity.SysUser;
+import com.xingxi.common.enums.EUserType;
+import com.xingxi.system.mapper.SysConfigMapper;
+import com.xingxi.system.mapper.SysUserMapper;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.annotation.Primary;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.ObjectUtils;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+
+@Slf4j
+@RequiredArgsConstructor
+@Component("WxLoginAuthenticationManager")
+@Primary
+public class WxLoginAuthenticationManager implements AuthenticationManager {
+    private final SysUserMapper sysUserMapper;
+    private final SysConfigMapper configMapper;
+//    private final WxaStoreMerchantMapper wxaStoreMerchantMapper;
+
+    @Transactional
+    @Override
+    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
+        log.debug("WxLoginAuthenticationManager.authenticate()....");
+
+        SysUser loginSysUser = (SysUser) authentication.getPrincipal();
+        String wxOpenId = loginSysUser.getWxOpenId();
+        String wxSessionKey = loginSysUser.getWxSessionKey();
+
+        SysUser dbUser = sysUserMapper.selectUserByOpenId(wxOpenId);
+        if (ObjectUtils.isEmpty(dbUser)) {
+
+            dbUser = new SysUser();
+            dbUser.setLoginName("wx_user");
+            dbUser.setDeptId(100L);
+            dbUser.setWxOpenId(wxOpenId);
+            dbUser.setWxSessionKey(wxSessionKey);
+            dbUser.setUserType(EUserType.WECHAT.getVal());
+            dbUser.setLoginDate(getLoginDate());
+            dbUser.setCreateUser(wxOpenId);
+            dbUser.setCreateTime(new Date());
+            sysUserMapper.insertUser(dbUser);
+
+        } else {
+            SysUser updateSysUser = new SysUser();
+            updateSysUser.setUserId(dbUser.getUserId());
+            updateSysUser.setWxSessionKey(wxSessionKey);
+            updateSysUser.setLoginDate(getLoginDate());
+            updateSysUser.setUpdateUser(wxOpenId);
+            updateSysUser.setUpdateTime(new Date());
+            sysUserMapper.updateUser(updateSysUser);
+
+            // 后续使用
+            dbUser.setLoginDate(updateSysUser.getLoginDate());
+        }
+
+        return new UsernamePasswordAuthenticationToken(dbUser, null, new ArrayList<>());
+    }
+
+    private Date getLoginDate() {
+        Calendar instance = Calendar.getInstance();
+        instance.set(Calendar.MILLISECOND, 0);
+        return instance.getTime();
+    }
+
+}

+ 68 - 0
08.src/Xingxi/xingxi-miniprogram-api/src/main/java/com/xingxi/store/configuration/security/WxLoginAuthenticationProcessingFilter.java

@@ -0,0 +1,68 @@
+package com.xingxi.store.configuration.security;
+
+import cn.binarywang.wx.miniapp.api.WxMaService;
+import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
+import com.xingxi.common.core.domain.entity.SysUser;
+import com.xingxi.store.common.ApiException;
+import lombok.extern.slf4j.Slf4j;
+import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.mp.api.WxMpService;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
+import org.springframework.util.Assert;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+@Slf4j
+public class WxLoginAuthenticationProcessingFilter extends UsernamePasswordAuthenticationFilter {
+    private final WxLoginAuthenticationManager authenticationManager;
+    private final WxMaService wxMaService;
+    private final WxMpService wxMpService;
+
+    public WxLoginAuthenticationProcessingFilter(final WxLoginAuthenticationManager authenticationManager, final WxMaService wxMaService, WxMpService wxMpService) {
+        this.authenticationManager = authenticationManager;
+        this.wxMaService = wxMaService;
+        this.wxMpService = wxMpService;
+        setAuthenticationManager(authenticationManager);
+        setFilterProcessesUrl("/api/store/wxlogin");
+    }
+
+    @Override
+    public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
+        log.debug("WxLoginAuthenticationProcessingFilter.attemptAuthentication()....");
+
+        String jsCode = request.getParameter("jsCode");
+        Assert.hasText(jsCode, "jsCode不能为空");
+
+        log.debug("jsCode = " + jsCode);
+        WxMaJscode2SessionResult result = null;
+        WxOAuth2AccessToken accessToken = null;
+        try {
+            accessToken = wxMpService.getOAuth2Service().getAccessToken(jsCode);
+//            result = wxMaService.jsCode2SessionInfo(jsCode);
+        } catch (WxErrorException e) {
+            e.printStackTrace();
+            log.debug("微信登录失败");
+            throw new ApiException("wxlogin.error");
+        }
+
+        String sessionKey = "";
+//        sessionKey = result.getSessionKey();
+        String openid = "";
+//        openid = result.getOpenid();
+
+        openid = accessToken.getOpenId();
+
+        SysUser sysUser = new SysUser();
+        sysUser.setWxOpenId(openid);
+        sysUser.setWxSessionKey(sessionKey);
+
+        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(sysUser, sessionKey);
+        return authenticationManager.authenticate(token);
+    }
+
+}

+ 8 - 5
08.src/Xingxi/xingxi-miniprogram-api/src/main/resources/application-local.yml

@@ -21,16 +21,19 @@ spring:
     cors:
       pathPattern: "/api/store/**"
       allowedMethods: "GET,POST"
-      allowedHeaders: "authorization,x-requested-with,x-store-id,content-type"
+      allowedHeaders: "authorization,x-requested-with,content-type"
       allowedOrigins: "*,https://bdapi.njnet.co"
   datasource:
     type: com.alibaba.druid.pool.DruidDataSource
     driver-class-name: com.mysql.cj.jdbc.Driver
 #    url: "jdbc:mysql://47.98.241.144:3306/biandan_test?useSSL=false&useTimezone=true&serverTimezone=GMT%2B8"
-    url: "jdbc:mysql://47.98.144.243:3306/empress?useSSL=false&useTimezone=true&serverTimezone=GMT%2B8"
-    username: "root"
+    url: "jdbc:mysql://47.99.85.139:3306/GoodsMarket?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8"
+    username: gululuq
+    password: f^*n%QfvekP!0Rur
+#    url: "jdbc:mysql://47.98.144.243:3306/empress?useSSL=false&useTimezone=true&serverTimezone=GMT%2B8"
+#    username: "root"
     #password: $TyH69i4EEG^om!!
-    password: X8IGlcnhdUcDGawphPHww8z7Xu4a800fhPr9Y6FGquTAAjSsrfhz1+VWYjGyO7pr4Ef5rs4QGpLPA4//mq2gNA==
+#    password: X8IGlcnhdUcDGawphPHww8z7Xu4a800fhPr9Y6FGquTAAjSsrfhz1+VWYjGyO7pr4Ef5rs4QGpLPA4//mq2gNA==
     druid:
       publickey: MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJuY2YFPanMmwVxHazZdOZ/y/LZr1+ZmyzAhstDZ0lCn4Vc3DI7Iw10+w4XJVGD3fnLjFMbPL1ip9eclpTAu6G0CAwEAAQ==
       connectionProperties: config.decrypt=true;config.decrypt.key=${spring.datasource.druid.publickey}
@@ -81,7 +84,7 @@ mybatis:
 logging:
   config: classpath:logback-local.xml
   level:
-    cn.com.wingxi.biandan: debug
+    cn.com.xingxi.biandan: debug
     org.springframework: warn
     org.apache.http: info
 wx:

+ 1 - 188
08.src/Xingxi/xingxi-miniprogram-api/xingxi-miniprogram-api.iml

@@ -1,195 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
+<module version="4">
   <component name="FacetManager">
-    <facet type="web" name="Web">
-      <configuration>
-        <webroots />
-        <sourceRoots>
-          <root url="file://$MODULE_DIR$/src/main/java" />
-          <root url="file://$MODULE_DIR$/src/main/resources" />
-        </sourceRoots>
-      </configuration>
-    </facet>
     <facet type="Spring" name="Spring">
       <configuration />
     </facet>
   </component>
-  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
-    <output url="file://$MODULE_DIR$/target/classes" />
-    <output-test url="file://$MODULE_DIR$/target/test-classes" />
-    <content url="file://$MODULE_DIR$">
-      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
-      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
-      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
-      <sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
-      <excludeFolder url="file://$MODULE_DIR$/target" />
-    </content>
-    <orderEntry type="inheritedJdk" />
-    <orderEntry type="sourceFolder" forTests="false" />
-    <orderEntry type="module" module-name="xingxi-system" />
-    <orderEntry type="module" module-name="xingxi-common" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-context-support:5.3.39" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.shiro:shiro-core:1.13.0" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.shiro:shiro-lang:1.13.0" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.shiro:shiro-cache:1.13.0" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.shiro:shiro-crypto-hash:1.13.0" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.shiro:shiro-crypto-core:1.13.0" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.shiro:shiro-crypto-cipher:1.13.0" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.shiro:shiro-config-core:1.13.0" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.shiro:shiro-config-ogdl:1.13.0" level="project" />
-    <orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils:1.9.4" level="project" />
-    <orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.2" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.shiro:shiro-event:1.13.0" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.shiro:shiro-ehcache:1.13.0" level="project" />
-    <orderEntry type="library" name="Maven: net.sf.ehcache:ehcache-core:2.6.11" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.12.0" level="project" />
-    <orderEntry type="library" name="Maven: commons-io:commons-io:2.16.1" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml:4.1.2" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.poi:poi:4.1.2" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.commons:commons-collections4:4.4" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.6.1" level="project" />
-    <orderEntry type="library" name="Maven: com.zaxxer:SparseBitSet:1.2" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml-schemas:4.1.2" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.xmlbeans:xmlbeans:3.1.0" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.19" level="project" />
-    <orderEntry type="library" name="Maven: com.github.virtuald:curvesapi:1.06" level="project" />
-    <orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.28" level="project" />
-    <orderEntry type="library" name="Maven: com.aliyun.oss:aliyun-sdk-oss:3.10.2" level="project" />
-    <orderEntry type="library" name="Maven: org.jdom:jdom2:2.0.6.1" level="project" />
-    <orderEntry type="library" name="Maven: org.codehaus.jettison:jettison:1.1" level="project" />
-    <orderEntry type="library" name="Maven: stax:stax-api:1.0.1" level="project" />
-    <orderEntry type="library" name="Maven: com.aliyun:aliyun-java-sdk-core:3.4.0" level="project" />
-    <orderEntry type="library" name="Maven: com.aliyun:aliyun-java-sdk-ram:3.0.0" level="project" />
-    <orderEntry type="library" name="Maven: com.aliyun:aliyun-java-sdk-sts:3.0.0" level="project" />
-    <orderEntry type="library" name="Maven: com.aliyun:aliyun-java-sdk-ecs:4.2.0" level="project" />
-    <orderEntry type="library" name="Maven: com.aliyun:aliyun-java-sdk-kms:2.7.0" level="project" />
-    <orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:4.0.1" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-security:2.5.15" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.5.15" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.5.15" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:2.5.15" level="project" />
-    <orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.13" level="project" />
-    <orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.13" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-to-slf4j:2.17.2" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.17.2" level="project" />
-    <orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.36" level="project" />
-    <orderEntry type="library" name="Maven: jakarta.annotation:jakarta.annotation-api:1.3.5" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-aop:5.3.39" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-beans:5.3.39" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.security:spring-security-config:5.5.8" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:5.5.8" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.security:spring-security-crypto:5.5.8" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-context:5.3.39" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.security:spring-security-web:5.5.8" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-expression:5.3.39" level="project" />
-    <orderEntry type="library" name="Maven: io.jsonwebtoken:jjwt-api:0.11.2" level="project" />
-    <orderEntry type="library" scope="RUNTIME" name="Maven: io.jsonwebtoken:jjwt-impl:0.11.2" level="project" />
-    <orderEntry type="library" scope="RUNTIME" name="Maven: io.jsonwebtoken:jjwt-jackson:0.11.2" level="project" />
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.12.7.1" level="project" />
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.12.7" level="project" />
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.12.7" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-amqp:2.5.15" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-messaging:5.3.39" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.amqp:spring-rabbit:2.3.16" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.amqp:spring-amqp:2.3.16" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.retry:spring-retry:1.3.4" level="project" />
-    <orderEntry type="library" name="Maven: com.rabbitmq:amqp-client:5.12.0" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-tx:5.3.39" level="project" />
-    <orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.0" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:2.5.15" level="project" />
-    <orderEntry type="library" name="Maven: com.zaxxer:HikariCP:4.0.3" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-jdbc:5.3.39" level="project" />
-    <orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:2.2.0" level="project" />
-    <orderEntry type="library" name="Maven: org.mybatis:mybatis:3.5.7" level="project" />
-    <orderEntry type="library" name="Maven: org.mybatis:mybatis-spring:2.0.6" level="project" />
-    <orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper-spring-boot-starter:1.4.1" level="project" />
-    <orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper-spring-boot-autoconfigure:1.4.1" level="project" />
-    <orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper:5.3.0" level="project" />
-    <orderEntry type="library" name="Maven: com.github.jsqlparser:jsqlparser:4.2" level="project" />
-    <orderEntry type="library" name="Maven: com.alibaba:druid-spring-boot-starter:1.2.23" level="project" />
-    <orderEntry type="library" name="Maven: com.alibaba:druid:1.2.23" level="project" />
-    <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.36" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.5.15" level="project" />
-    <orderEntry type="library" name="Maven: org.glassfish.jaxb:jaxb-runtime:2.3.8" level="project" />
-    <orderEntry type="library" name="Maven: org.glassfish.jaxb:txw2:2.3.8" level="project" />
-    <orderEntry type="library" name="Maven: com.sun.istack:istack-commons-runtime:3.0.12" level="project" />
-    <orderEntry type="library" scope="RUNTIME" name="Maven: com.sun.activation:jakarta.activation:1.2.2" level="project" />
-    <orderEntry type="library" name="Maven: com.jhlabs:filters:2.0.235-1" level="project" />
-    <orderEntry type="library" name="Maven: net.coobird:thumbnailator:0.4.16" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:2.5.15" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-json:2.5.15" level="project" />
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.12.7" level="project" />
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.12.7" level="project" />
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.12.7" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:2.5.15" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:9.0.96" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:9.0.96" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-web:5.3.39" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-webmvc:5.3.39" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-validation:2.5.15" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-el:9.0.96" level="project" />
-    <orderEntry type="library" name="Maven: org.hibernate.validator:hibernate-validator:6.2.5.Final" level="project" />
-    <orderEntry type="library" name="Maven: jakarta.validation:jakarta.validation-api:2.0.2" level="project" />
-    <orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.4.3.Final" level="project" />
-    <orderEntry type="library" name="Maven: com.fasterxml:classmate:1.5.1" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-aop:2.5.15" level="project" />
-    <orderEntry type="library" name="Maven: org.aspectj:aspectjweaver:1.9.7" level="project" />
-    <orderEntry type="library" name="Maven: com.google.guava:guava:31.0.1-jre" level="project" />
-    <orderEntry type="library" name="Maven: com.google.guava:failureaccess:1.0.1" level="project" />
-    <orderEntry type="library" name="Maven: com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava" level="project" />
-    <orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:3.0.2" level="project" />
-    <orderEntry type="library" name="Maven: org.checkerframework:checker-qual:3.12.0" level="project" />
-    <orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.7.1" level="project" />
-    <orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
-    <orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.79" level="project" />
-    <orderEntry type="library" name="Maven: com.github.binarywang:wx-java-miniapp-spring-boot-starter:4.5.0" level="project" />
-    <orderEntry type="library" name="Maven: com.github.binarywang:weixin-java-miniapp:4.5.0" level="project" />
-    <orderEntry type="library" name="Maven: com.github.binarywang:weixin-java-common:4.5.0" level="project" />
-    <orderEntry type="library" name="Maven: com.thoughtworks.xstream:xstream:1.4.20" level="project" />
-    <orderEntry type="library" name="Maven: io.github.x-stream:mxparser:1.2.2" level="project" />
-    <orderEntry type="library" name="Maven: xmlpull:xmlpull:1.1.3.1" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.14" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.16" level="project" />
-    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.5.14" level="project" />
-    <orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.36" level="project" />
-    <orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.9" level="project" />
-    <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.15" level="project" />
-    <orderEntry type="library" name="Maven: org.dom4j:dom4j:2.1.3" level="project" />
-    <orderEntry type="library" name="Maven: org.bouncycastle:bcpkix-jdk15on:1.68" level="project" />
-    <orderEntry type="library" name="Maven: org.bouncycastle:bcprov-jdk15on:1.68" level="project" />
-    <orderEntry type="library" name="Maven: com.github.binarywang:weixin-java-mp:4.6.0" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-configuration-processor:2.5.15" level="project" />
-    <orderEntry type="library" scope="RUNTIME" name="Maven: com.mysql:mysql-connector-j:8.0.33" level="project" />
-    <orderEntry type="library" name="Maven: org.projectlombok:lombok:1.18.22" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-starter-test:2.5.15" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test:2.5.15" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test-autoconfigure:2.5.15" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: com.jayway.jsonpath:json-path:2.5.0" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: net.minidev:json-smart:2.4.10" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: net.minidev:accessors-smart:2.4.9" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.ow2.asm:asm:9.3" level="project" />
-    <orderEntry type="library" name="Maven: jakarta.xml.bind:jakarta.xml.bind-api:2.3.3" level="project" />
-    <orderEntry type="library" name="Maven: jakarta.activation:jakarta.activation-api:1.2.2" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.assertj:assertj-core:3.19.0" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest:2.2" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter:5.7.2" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.7.2" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.7.2" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-params:5.7.2" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.7.2" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.7.2" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:3.9.0" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy:1.10.22" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy-agent:1.10.22" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:3.2" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-junit-jupiter:3.9.0" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.skyscreamer:jsonassert:1.5.1" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: com.vaadin.external.google:android-json:0.0.20131108.vaadin1" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-core:5.3.39" level="project" />
-    <orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.3.39" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:5.3.39" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.xmlunit:xmlunit-core:2.8.4" level="project" />
-  </component>
 </module>

+ 8 - 0
08.src/Xingxi/xingxi-system/src/main/java/com/xingxi/system/mapper/SysUserMapper.java

@@ -45,6 +45,14 @@ public interface SysUserMapper {
     SysUser selectUserByLoginName(String userName);
 
     /**
+     * 通过用户名查询用户
+     *
+     * @param wxOpenId 用户名
+     * @return 用户对象信息
+     */
+    SysUser selectUserByOpenId(String wxOpenId);
+
+    /**
      * 通过手机号码查询用户
      *
      * @param phoneNumber 手机号码

+ 16 - 7
08.src/Xingxi/xingxi-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -14,6 +14,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<result property="phonenumber"   column="phonenumber"     />
 		<result property="sex"           column="sex"             />
 		<result property="avatar"        column="avatar"          />
+		<result property="wxOpenId"        column="wxOpenId"          />
+		<result property="wxUnionId"        column="wxUnionId"          />
+		<result property="wxSessionKey"        column="wxSessionKey"          />
 		<result property="password"      column="password"        />
 		<result property="salt"          column="salt"            />
 		<result property="status"        column="status"          />
@@ -52,7 +55,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	<sql id="selectUserVo">
         select  u.user_id, u.dept_id, u.login_name, u.user_name, u.user_type, u.email, u.avatar, u.phonenumber, u.sex, u.password, u.salt, u.status, u.del_flag, u.login_ip, u.login_date, u.pwd_update_date, u.create_by, u.create_time, u.update_by, u.update_time, u.remark,
        		    d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status,
-       		    r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
+       		    r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status,
+       		    u.wxOpenId, u.wxUnionId, u.wxSessionKey
 		from sys_user u
 			 left join sys_dept d on u.dept_id = d.dept_id
 			 left join sys_user_role ur on u.user_id = ur.user_id
@@ -60,7 +64,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </sql>
 	
 	<select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
-		select u.user_id, u.dept_id, u.login_name, u.user_name, u.user_type, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.salt, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u
+		select u.user_id, u.dept_id, u.login_name, u.user_name, u.user_type, u.email, u.wxOpenId, u.wxUnionId, u.wxSessionKey, u.avatar, u.phonenumber, u.password, u.sex, u.salt, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u
 		left join sys_dept d on u.dept_id = d.dept_id
 		where u.del_flag = '0'
 		<if test="userId != null and userId != 0">
@@ -89,7 +93,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</select>
 	
 	<select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult">
-	    select distinct u.user_id, u.dept_id, u.login_name, u.user_name, u.user_type, u.email, u.avatar, u.phonenumber, u.status, u.create_time
+	    select distinct u.user_id, u.dept_id, u.login_name, u.user_name, u.user_type, u.email, u.avatar, u.phonenumber, u.status, u.wxOpenId, u.wxUnionId, u.wxSessionKey, u.create_time
 	    from sys_user u
 			 left join sys_dept d on u.dept_id = d.dept_id
 			 left join sys_user_role ur on u.user_id = ur.user_id
@@ -106,7 +110,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</select>
 	
 	<select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult">
-	    select distinct u.user_id, u.dept_id, u.login_name, u.user_name, u.user_type, u.email, u.avatar, u.phonenumber, u.status, u.create_time
+	    select distinct u.user_id, u.dept_id, u.login_name, u.user_name, u.user_type, u.email, u.avatar, u.phonenumber, u.status, u.create_time, u.wxOpenId, u.wxUnionId, u.wxSessionKey
 	    from sys_user u
 			 left join sys_dept d on u.dept_id = d.dept_id
 			 left join sys_user_role ur on u.user_id = ur.user_id
@@ -122,12 +126,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<!-- 数据范围过滤 -->
 		${params.dataScope}
 	</select>
-	
+
 	<select id="selectUserByLoginName" parameterType="String" resultMap="SysUserResult">
-	    <include refid="selectUserVo"/>
+		<include refid="selectUserVo"/>
 		where u.login_name = #{userName} and u.del_flag = '0'
 	</select>
-	
+
+	<select id="selectUserByOpenId" parameterType="String" resultMap="SysUserResult">
+		<include refid="selectUserVo"/>
+		where u.wxOpenId = #{wxOpenId} and u.del_flag = '0'
+	</select>
+
 	<select id="selectUserByPhoneNumber" parameterType="String" resultMap="SysUserResult">
 		<include refid="selectUserVo"/>
 		where u.phonenumber = #{phonenumber} and u.del_flag = '0'