loemkie 1 mês atrás
pai
commit
e2015deec3

+ 10 - 2
src/main/java/com/qmrb/system/controller/UserController.java

@@ -22,7 +22,9 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 /**
  * <p>
@@ -105,7 +107,7 @@ public class UserController extends CommonController {
     public CommonResult<UserInfo> wxMpLogin(LoginParam loginParam){
         UserInfo userInfo = userService.wxMpLogin(loginParam);
         if(loginParam.getOpenId() != null){
-            UserAuthInfo userAuthInfo = sysUserService.getUserAuthInfo(loginParam.getOpenId());
+            UserAuthInfo userAuthInfo = sysUserService.getUserAuthInfo(userInfo.getOpenId());
             if(userAuthInfo == null){
                 //如果没有注册,需要注册该微信用户
                 UserForm userForm = new UserForm();
@@ -120,13 +122,19 @@ public class UserController extends CommonController {
                 //生成token
                 userAuthInfo = new UserAuthInfo();
                 userAuthInfo.setUsername(userInfo.getOpenId());
+                Set<String> roles = new HashSet<>();
+                roles.add("PARK_USER");
                 userInfo.setAccessToken(getToken(userAuthInfo));
             }else{
                 userInfo.setId(userAuthInfo.getUserId().toString());
                 userInfo.setNickName(userAuthInfo.getNickname());
                 userInfo.setAvatarUrl(userInfo.getAvatarUrl());
+                Set<String> roles = new HashSet<>();
+                roles.add("PARK_USER");
+                userAuthInfo.setRoles(roles);
                 //生成token
-                userInfo.setAccessToken(getToken(userAuthInfo));
+                String token = getToken(userAuthInfo);
+                userInfo.setAccessToken(token);
             }
 
         }

+ 1 - 0
src/main/java/com/qmrb/system/service/impl/UserServiceImpl.java

@@ -46,6 +46,7 @@ public class UserServiceImpl extends ServiceImpl<OrderMapper, Order> implements
         hashMap.put("grant_type", "authorization_code");
         String json = HttpUtil.get(WxApiType.WX_LOGIN_URL.getValue(), hashMap);
         JSONObject jsonObject = JSONUtil.parseObj(json);
+        log.info("json:{}",jsonObject);
         String openid = jsonObject.getStr("openid");
         String sessionKey = jsonObject.getStr("session_key");
         WxLoginVO result = new WxLoginVO();