lrf402788946 4 anni fa
parent
commit
a1694d853b
3 ha cambiato i file con 12 aggiunte e 5 eliminazioni
  1. 4 4
      app/controller/weixin.js
  2. 1 1
      app/service/user.js
  3. 7 0
      config/config.default.js

+ 4 - 4
app/controller/weixin.js

@@ -179,13 +179,13 @@ class WeixinController extends Controller {
   async appAuth() {
     console.warn('in appAuth');
     const { js_code, login = true } = this.ctx.query;
+    console.log(js_code);
     const appopenid = await this.ctx.service.weixin.appAuth(js_code);
     if (!login) this.ctx.ok(appopenid);
-    console.warn('-------');
     console.warn(`openid=>${appopenid}`);
-    const state = uuid();
-    const key = `appinfo:${state}`;
-    await this.app.redis.set(key, appopenid, 'EX', 600);
+    // const state = uuid();
+    // const key = `appinfo:${state}`;
+    // await this.app.redis.set(key, appopenid, 'EX', 600);
     const res = await this.ctx.service.user.findByAppOpenid(appopenid);
     const obj = { user: res, openid: appopenid };
     this.ctx.ok(obj);

+ 1 - 1
app/service/user.js

@@ -184,7 +184,7 @@ class UserService extends CrudService {
       throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '用户信息不存在');
     }
     user.appopenid = appopenid;
-    const res = user.save();
+    const res = await user.save();
     // const res = await this.model.update(
     //   { name, mobile },
     //   { $set: { appopenid } }

+ 7 - 0
config/config.default.js

@@ -50,6 +50,13 @@ module.exports = appInfo => {
     sendDirMq: 'http://wx.cc-lotus.info/api.weixin.qq.com/cgi-bin/message/template/send?appid=',
   };
 
+  // 签到小程序
+  config.wxapp = {
+    appid: 'wx3b5ac763ada73e0e',
+    secret: '0f30fcbb9ad45697800611ad4af585bb',
+    grant_type: 'authorization_code',
+  };
+
   config.proxy = true;
   config.hostHeaders = 'x-forwarded-host';
   // 服务器发布路径