Browse Source

微信qa测试

laiguoran 5 years ago
parent
commit
2c76fd9758

+ 30 - 4
app/controller/wechat_controller.js

@@ -134,10 +134,36 @@ module.exports = app => {
             }
         }
 
-        async urlchange(ctx) {
-            // 设置用户微信登录项目,跳转到对应wap页面
-            co
-            ctx.redirect(ctx.query.url);
+        // 设置用户微信登录项目,跳转到对应wap页面
+        async url2wap(ctx) {
+            try {
+                if (!ctx.query.project || !ctx.query.url) {
+                    throw '参数有误';
+                }
+                const code = ctx.query.project;
+                // 查找项目数据
+                const projectData = await ctx.service.project.getProjectByCode(code.toString().trim());
+                if (projectData === null) {
+                    throw '不存在项目数据';
+                }
+                const pa = await ctx.service.projectAccount.getDataByCondition({ code, wx_openid: ctx.session.wechatToken.openid });
+                if (!pa) {
+                    throw '该微信号未绑定此项目';
+                }
+                if (pa.enable !== 1) {
+                    throw '该账号已被停用,请联系销售人员';
+                }
+                // 设置项目和用户session记录
+                const result = await ctx.service.projectAccount.accountLogin({ project: projectData, accountData: pa }, 3);
+                if (!result) {
+                    throw '登录出错';
+                }
+                ctx.redirect(ctx.query.url);
+            } catch (error) {
+                console.log(error);
+                ctx.body = error;
+            }
+
         }
 
         async oauthTxt(ctx) {

+ 7 - 1
app/middleware/wechat_auth.js

@@ -16,7 +16,13 @@ module.exports = (options, app) => {
             }
             const wechatToken = ctx.session.wechatToken;
             if (!wechatToken) {
-                ctx.redirect('/wx/oauth?redirect_uri=' + encodeURIComponent(ctx.request.headers.referer));
+                // ctx.body = encodeURIComponent(ctx.request.url);
+                ctx.body = {
+                    ctx,
+                    host: ctx.request.header.host,
+                };
+                return;
+                // ctx.redirect('/wx/oauth?redirect_uri=' + encodeURIComponent(ctx.request.headers.referer));
             }
             // 同步系统维护信息
             await ctx.service.maintain.syncMaintainData();

+ 1 - 0
app/router.js

@@ -382,5 +382,6 @@ module.exports = app => {
     app.get('/wx/bind', wechatAuth, 'wechatController.bind');
     app.post('/wx/bindwx', wechatAuth, 'wechatController.bindwx');
     app.get('/wx/test', wechatAuth, 'wechatController.testwx');
+    app.get('/wx/url2wap', wechatAuth, 'wechatController.url2wap');
     app.get('/MP_verify_t3MkWAMqplVxPjmr.txt', 'wechatController.oauthTxt');
 };

+ 1 - 1
app/service/project_account.js

@@ -100,7 +100,7 @@ module.exports = app => {
          * 账号登录
          *
          * @param {Object} data - 表单post数据
-         * @param {Number} loginType - 登录类型 1 | 2
+         * @param {Number} loginType - 登录类型 1(sso登录) | 2(正常或副密码登录) | 3(接口登录或微信登录)
          * @return {Boolean} - 返回登录结果
          */
         async accountLogin(data, loginType) {