loemkie 1 mês atrás
pai
commit
cbf4afacfe

+ 34 - 24
src/main/java/com/qmrb/system/controller/UserController.java

@@ -71,32 +71,15 @@ public class UserController extends CommonController {
     public CommonResult<UserInfo> getMyInfo(UserParam userParam){
         UserInfo userInfo = new UserInfo();
         if(StringUtils.isNotBlank(userParam.getOpenId())){
-            UserAuthInfo userAuthInfo = sysUserService.getUserAuthInfo(userParam.getOpenId());
-            if(userAuthInfo == null){
-                //如果没有注册,需要注册该微信用户
-                UserForm userForm = new UserForm();
-                userForm.setUsername(userParam.getOpenId());
-                userForm.setNickname(userParam.getNickName());
-                userForm.setAvatar(userParam.getAvatarUrl());
-                userForm.setGender(userParam.getGender());
-                sysUserService.saveUser(userForm);
-                userInfo.setId(userForm.getId().toString());
-                userInfo.setNickName(userParam.getNickName());
-                userInfo.setAvatarUrl(userParam.getAvatarUrl());
-                //生成token
-                userAuthInfo = new UserAuthInfo();
-                userAuthInfo.setUsername(userParam.getOpenId());
-                userInfo.setAccessToken(getToken(userAuthInfo));
-            }else{
-                userInfo.setId(userAuthInfo.getUserId().toString());
-                userInfo.setNickName(userAuthInfo.getNickname());
-                userInfo.setAvatarUrl(userParam.getAvatarUrl());
-                //生成token
-                userInfo.setAccessToken(getToken(userAuthInfo));
-            }
+            userInfo.setAccessToken("");
+            userInfo.setNickName("test");
+            userInfo.setId("1");
         }else{
             //登录失败
             log.info("获取用户信息失败");
+            userInfo.setAccessToken("");
+            userInfo.setNickName("test");
+            userInfo.setId("1");
         }
         return process(() -> userInfo);
     }
@@ -120,7 +103,34 @@ public class UserController extends CommonController {
      */
     @GetMapping("/wxMpLogin")
     public CommonResult<UserInfo> wxMpLogin(LoginParam loginParam){
-        return process(() -> userService.wxMpLogin(loginParam));
+        UserInfo userInfo = userService.wxMpLogin(loginParam);
+        if(loginParam.getOpenId() != null){
+            UserAuthInfo userAuthInfo = sysUserService.getUserAuthInfo(loginParam.getOpenId());
+            if(userAuthInfo == null){
+                //如果没有注册,需要注册该微信用户
+                UserForm userForm = new UserForm();
+                userForm.setUsername(userInfo.getOpenId());
+                userForm.setNickname(userInfo.getNickName());
+                userForm.setAvatar(userInfo.getAvatarUrl());
+                userForm.setGender(userInfo.getGender());
+                sysUserService.saveUser(userForm);
+                //组装
+                userInfo.setNickName(userInfo.getNickName());
+                userInfo.setAvatarUrl(userInfo.getAvatarUrl());
+                //生成token
+                userAuthInfo = new UserAuthInfo();
+                userAuthInfo.setUsername(userInfo.getOpenId());
+                userInfo.setAccessToken(getToken(userAuthInfo));
+            }else{
+                userInfo.setId(userAuthInfo.getUserId().toString());
+                userInfo.setNickName(userAuthInfo.getNickname());
+                userInfo.setAvatarUrl(userInfo.getAvatarUrl());
+                //生成token
+                userInfo.setAccessToken(getToken(userAuthInfo));
+            }
+
+        }
+        return process(() -> userInfo);
     }
 
 

+ 5 - 12
src/main/java/com/qmrb/system/framework/security/config/SecurityConfig.java

@@ -1,23 +1,15 @@
 package com.qmrb.system.framework.security.config;
 
-import com.qmrb.system.framework.security.filter.JwtAuthenticationFilter;
-import com.qmrb.system.framework.security.exception.MyAccessDeniedHandler;
-import com.qmrb.system.framework.security.exception.MyAuthenticationEntryPoint;
 import com.qmrb.system.common.constant.SecurityConstants;
 import com.qmrb.system.framework.security.JwtTokenManager;
+import com.qmrb.system.framework.security.exception.MyAccessDeniedHandler;
+import com.qmrb.system.framework.security.exception.MyAuthenticationEntryPoint;
+import com.qmrb.system.framework.security.filter.JwtAuthenticationFilter;
 import com.qmrb.system.framework.security.filter.VerifyCodeFilter;
-import com.qmrb.system.framework.security.userdetails.SysUserDetailsService;
-import com.qmrb.system.framework.security.userdetails.UserPasswordProvider;
 import lombok.RequiredArgsConstructor;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Lazy;
 import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.security.authentication.AuthenticationProvider;
-import org.springframework.security.authentication.ProviderManager;
-import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
-import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
 import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
 import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@@ -104,7 +96,8 @@ public class SecurityConfig {
                         "/api/v1/patientSign/saveDataToRedis",
                         "/api/v1/patientSign/uploadJcReport",
                         "/api/v1/patientSign/getCaUnSignQrcode",
-                        "/api/v1/patientSign/getFwzxScanQrcode"
+                        "/api/v1/patientSign/getFwzxScanQrcode",
+                        "/api/ucenter/**"
 
                 );
     }

+ 2 - 0
src/main/java/com/qmrb/system/pojo/dto/LoginParam.java

@@ -14,4 +14,6 @@ public class LoginParam {
     String encryptedData;
     String session_key;
     String code;
+
+    String openId;
 }

+ 2 - 0
src/main/java/com/qmrb/system/pojo/vo/UserInfo.java

@@ -15,4 +15,6 @@ public class UserInfo {
     String avatarUrl;
 
     String accessToken;
+    Integer gender;
+    String openId;
 }

+ 12 - 2
src/main/java/com/qmrb/system/service/impl/UserServiceImpl.java

@@ -12,10 +12,12 @@ import com.qmrb.system.pojo.entity.Order;
 import com.qmrb.system.pojo.entity.ToolWxConfig;
 import com.qmrb.system.pojo.vo.UserInfo;
 import com.qmrb.system.pojo.vo.WxLoginVO;
+import com.qmrb.system.service.ToolWxConfigService;
 import com.qmrb.system.service.UserService;
 import com.qmrb.system.utils.WxPayUtil;
 import com.qmrb.system.wxpayback.Enum.WxApiType;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.HashMap;
@@ -32,6 +34,9 @@ import java.util.Map;
 @Service
 @Slf4j
 public class UserServiceImpl extends ServiceImpl<OrderMapper, Order> implements UserService {
+    @Autowired
+    private ToolWxConfigService toolWxConfigService;
+
     public WxLoginVO getOpenId(ToolWxConfig wxConfig, WxLoginVO loginVO){
         //获取当前的openid
         Map hashMap = new HashMap();
@@ -66,8 +71,13 @@ public class UserServiceImpl extends ServiceImpl<OrderMapper, Order> implements
      */
     @Override
     public UserInfo wxMpLogin(LoginParam loginParam) {
-        String jsonStr = WxPayUtil.decryptS5(loginParam.getEncryptedData(), loginParam.getSession_key(), loginParam.getIv());
-        return JSONUtil.toBean(jsonStr, UserInfo.class, true);
+        WxLoginVO loginVO = new WxLoginVO();
+        loginVO.setCode(loginParam.getCode());
+        WxLoginVO wxLoginVO = getOpenId(toolWxConfigService.findConf(), loginVO);
+        String jsonStr = WxPayUtil.decryptS5(loginParam.getEncryptedData(), wxLoginVO.getSession_key(), loginParam.getIv());
+        UserInfo userInfo = JSONUtil.toBean(jsonStr, UserInfo.class, true);
+        userInfo.setOpenId(wxLoginVO.getOpenId());
+        return userInfo;
     }
 
 }