Просмотр исходного кода

feat: 更新weapp控制器,调整refresh接口为POST请求,新增weapp子项目控制器及相关接口

lanjianrong 1 месяц назад
Родитель
Сommit
d8dec5f3c9

+ 4 - 3
app/controller/weapp_controller.js

@@ -76,7 +76,7 @@ module.exports = app => {
         }
 
         async refresh(ctx) {
-            const { refresh_token } = ctx.request.query;
+            const { refresh_token } = ctx.request.body;
             if (!refresh_token) {
                 ctx.body = { code: -1, msg: '缺少 refresh_token', data: null };
                 return;
@@ -86,7 +86,7 @@ module.exports = app => {
                 ctx.body = { code: 0, msg: '', data: { access_token: token } };
             } catch (error) {
                 this.log(error);
-                ctx.body = { code: -1, msg: '登已过期,请重新登录', data: null };
+                ctx.body = { code: -1, msg: '登已过期,请重新登录', data: null };
             }
         }
 
@@ -103,13 +103,14 @@ module.exports = app => {
                 ctx.body = {
                     code: 0, msg: '', data: {
                         userInfo: projectAccount,
-                    }
+                    },
                 };
             } catch (error) {
                 this.log(error);
                 ctx.body = { code: -1, msg: '', data: null };
             }
         }
+
     }
 
     return WeappController;

+ 32 - 0
app/controller/weapp_subp_controller.js

@@ -0,0 +1,32 @@
+'use strict';
+
+/**
+ * weapp控制器
+ *
+ * @author Lan
+ * @date 2025/12/22
+ * @version
+ */
+
+
+module.exports = app => {
+    class WeappSubpController extends app.BaseController {
+
+        async subProjectList(ctx) {
+            try {
+                const list = await ctx.service.subProject.getSubProject(ctx.project.id, ctx.projectAccount.id, ctx.projectAccount.is_admin);
+                ctx.body = {
+                    code: 0, msg: '', data: {
+                        list,
+                    },
+                };
+            } catch (error) {
+                this.log(error);
+                ctx.body = { code: -1, msg: '', data: null };
+            }
+
+        }
+    }
+
+    return WeappSubpController;
+};

+ 4 - 2
app/middleware/weapp_auth.js

@@ -5,9 +5,11 @@ module.exports = (options, app) => {
 
     return async function wechatAuth(ctx, next) {
         const token = ctx.headers.authorization && ctx.headers.authorization.replace('Bearer ', '');
-        console.log('1111');
         const code = ctx.headers['platform-code'];
-        if (!token || !code) return ctx.fail(401, '请登录');
+        if (!token || !code) {
+            ctx.body = { code: 2, msg: '请登录', data: null };
+            return;
+        }
         try {
             const decoded = jwt.verify(token, weappConfig.jwtSecret);
             const projectData = await ctx.service.project.getProjectByCode(

+ 2 - 1
app/router.js

@@ -1238,7 +1238,8 @@ module.exports = app => {
     app.post('/wx/weapp/accountLogin', 'weappController.accountLogin'); // 测试用,正式环境要删除
     app.post('/wx/weapp/wxLogin', 'weappController.wxLogin');
     app.get('/wx/weapp/getCaptcha', 'weappController.getCaptcha');
-    app.get('/wx/weapp/refresh', 'weappController.refresh');
+    app.post('/wx/weapp/auth/refresh', 'weappController.refresh');
     app.get('/wx/weapp/userInfo', weappAuth, 'weappController.getUserInfo');
     app.get('/wx/weapp/dashboard', weappAuth, 'weappDashboardController.workspace');
+    app.get('/wx/weapp/subp/list', weappAuth, 'weappSubpController.subProjectList');
 };