wechat-oauth icon indicating copy to clipboard operation
wechat-oauth copied to clipboard

getAccessToken进不去

Open callmesoul opened this issue 8 years ago • 2 comments

` get_redrict:function (req,res) {

    console.log(req.query.code);

    client.getAccessToken(req.query.code, function (err, result) {

        console.log(req.query.code);

        var accessToken = result.data.access_token;

        var openid = result.data.openid;

        client.getUser(openid, function (err, user) {

            console.log(user)

        });

    });

},

` 第一个console.log(req.query.code);能打印,之后旧没反应了

callmesoul avatar Feb 22 '17 10:02 callmesoul

这是实例化代码

`var client = new OAuth(wechat.appID, wechat.appSecret, function (openid, callback) { // 传入一个根据openid获取对应的全局token的方法 // 在getUser时会通过该方法来获取token db.token.findOne({where:{openid:openid}}).then(function (token) { return callback(null,token); }) }, function (openid, token, callback) { // 请将token存储到全局,跨进程、跨机器级别的全局,比如写到数据库、redis等 // 这样才能在cluster模式及多机情况下使用,以下为写入到文件的示例 // 持久化时请注意,每个openid都对应一个唯一的token! db.token.upsert({access_token:token.access_token,expires_in:token.expires_in,refresh_token:token.refresh_token,openid:token.openid,scope:token.scope,create_at:token.create_at},{where:{openid:token.openid}}).then(function (result) {

})

});`

callmesoul avatar Feb 22 '17 10:02 callmesoul

我也遇到这个问题 你那怎么解决的啊

qinghechaoge avatar Jan 15 '18 14:01 qinghechaoge