lrf402788946 4 년 전
부모
커밋
e66b4c8cb4
3개의 변경된 파일38개의 추가작업 그리고 0개의 파일을 삭제
  1. 5 0
      app/controller/weixin.js
  2. 3 0
      app/router.js
  3. 30 0
      app/service/weixin.js

+ 5 - 0
app/controller/weixin.js

@@ -180,6 +180,11 @@ class WeixinController extends Controller {
     }
     return user;
   }
+  // 用户绑定
+  async bind() {
+    const res = await this.service.weixin.bindUser(this.ctx.request.body);
+    return this.ctx.ok(res);
+  }
 }
 
 module.exports = WeixinController;

+ 3 - 0
app/router.js

@@ -36,4 +36,7 @@ module.exports = app => {
   router.get('/api/auth/wxchat', controller.weixin.auth); // 微信登录
   // 微信端访问地址
   router.get('/api/auth/wxchattest', controller.weixin.authTest); // 微信登录测试
+
+  // 微信端访问地址
+  router.post('/api/auth/wxbind', controller.weixin.bind); // 微信登录测试
 };

+ 30 - 0
app/service/weixin.js

@@ -221,6 +221,36 @@ class WeixinAuthService extends AxiosService {
       data: JSON.stringify(requestData),
     });
   }
+  // openid绑定用户
+  async bindUser({ dock_id, role, openid }) {
+    if (role === '3') {
+      const url = 'http://127.0.0.1:9008/api/live/dock/' + dock_id;
+      const res = await this.ctx.curl(url, {
+        method: 'get',
+        headers: {
+          'content-type': 'application/json',
+        },
+        dataType: 'json',
+      });
+      if (res.status === 200) {
+        if (res.data.errcode === 0) {
+          const data = res.data.data;
+          data.openid = openid;
+          console.log(data);
+          const ur = await this.ctx.curl(url, {
+            method: 'post',
+            headers: {
+              'content-type': 'application/json',
+            },
+            dataType: 'json',
+            data: JSON.stringify(data),
+          });
+          if (ur.status === 200) return res.data;
+        }
+      }
+    }
+  }
+
 }
 
 module.exports = WeixinAuthService;