Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

用eggjs的看过来,setToken getToken 的用法 #53

Open
looping84 opened this issue May 8, 2019 · 0 comments
Open

用eggjs的看过来,setToken getToken 的用法 #53

looping84 opened this issue May 8, 2019 · 0 comments

Comments

@looping84
Copy link

looping84 commented May 8, 2019

要bind this,要不然,里边的this 指向的是oAuth

new OAuth(app.appid, app.secret, ctx.service.wechat.getToken.bind(this), ctx.service.wechat.setToken.bind(this), true);

// service/wechatToken.js

async getToken(openid) {
    const res = await this.ctx.model.WechatToken.findOne({ openid });
    return res;
  }

  async setToken(openid, token) {
    // 有则更新,无则添加
    var query = { openid: openid };
    var options = { upsert: true };

    await this.ctx.model.WechatToken.update(query, token, options);
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant