Browse Source

feat(app): 微信小程序接入

- 填写微信小程序 appid 和 secret
- 小程序相关接口免 token 认证
- 新增微信用户快速注册逻辑
- 优化登录逻辑,支持微信用户登录
SheepHy 3 weeks ago
parent
commit
3b1eb446c0

+ 3 - 1
national-motion-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java

@@ -101,6 +101,8 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/sys/common/static/**", "anon");//图片预览 &下载文件不限制token
         filterChainDefinitionMap.put("/sys/common/pdf/**", "anon");//pdf预览
 
+        filterChainDefinitionMap.put("/app/user/**", "anon");//小程序相关
+
         //filterChainDefinitionMap.put("/sys/common/view/**", "anon");//图片预览不限制token
         //filterChainDefinitionMap.put("/sys/common/download/**", "anon");//文件下载不限制token
         filterChainDefinitionMap.put("/generic/**", "anon");//pdf预览需要文件
@@ -231,7 +233,7 @@ public class ShiroConfig {
     @Bean("securityManager")
     public DefaultWebSecurityManager securityManager(ShiroRealm myRealm) {
         DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
-        securityManager.setRememberMeManager(rememberMeManager());
+        securityManager.setRememberMeManager(null);
         securityManager.setRealm(myRealm);
 
         /*

+ 9 - 11
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/impl/UserServiceImpl.java

@@ -11,6 +11,7 @@ import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.system.util.JwtUtil;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.RedisUtil;
+import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.app.service.IUserService;
 import org.jeecg.modules.app.vo.LoginUserVO;
 import org.jeecg.modules.app.vo.MsgInfoVO;
@@ -58,8 +59,13 @@ public class UserServiceImpl implements IUserService {
                 // 用户不存在则创建
                     user = new SysUser()
                             .setOpenid(openid)
+                            .setPassword(openid)
+                            .setStatus(1)
+                            .setDelFlag(0)
+                            .setSalt(oConvertUtils.randomGen(8))
+                            .setCreateBy("admin")
                             .setRealname("微信用户")
-                            .setUsername("微信用户")
+                            .setUsername("微信用户_" + System.currentTimeMillis())
                             .setOrgCode("A03");
                     boolean result = sysUserMapper.insert(user) > 0;
                     if (!result) {
@@ -102,16 +108,8 @@ public class UserServiceImpl implements IUserService {
 
 
     private LoginUserVO generateLoginUserVO(SysUser user) {
-        String orgCode = user.getOrgCode().substring(0, 3);
-        String userAccount = "";
-        String userPassword = "";
-        if(orgCode.equals("A03") || user.getOpenid() != null){
-            userAccount = user.getUsername();
-            userPassword = user.getOpenid();
-        }else if (orgCode.equals("A04")){
-            userAccount = user.getUsername();
-            userPassword = user.getPassword();
-        }
+        String userAccount = user.getUsername();
+        String userPassword = user.getPassword();
         // 1.生成token
         String token = JwtUtil.sign(userAccount, userPassword);
         // 设置token缓存有效时间

+ 2 - 2
national-motion-module-system/national-motion-system-start/src/main/resources/application-dev.yml

@@ -329,8 +329,8 @@ wx:
   # 微信小程序
   miniapp:
     configs:
-      - appid:
-        secret:
+      - appid: wx62ba790ae7983d34
+        secret: 8df754e6d36a7f0ac26f108f1607beff
         token: #微信小程序消息服务器配置的token
         aesKey: #微信小程序消息服务器配置的EncodingAESKey
         msgDataFormat: JSON