Rumah > pembangunan bahagian belakang > tutorial php > javascript - 微信网页扫码登录不能获取用户信息

javascript - 微信网页扫码登录不能获取用户信息

WBOY
Lepaskan: 2016-06-06 20:12:04
asal
1157 orang telah melayarinya

<code>getToken: function(code) {
        var url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=id&secret=sec&code=" + code +"&grant_type=authorization_code";
        //synchronous GET
        // console.log("url:" + url);
        var result = HTTP.get(url, {timeout:30000});
        // console.log("result:" + result);
        if(result.statusCode==200) {
            var respJson = JSON.parse(result.content);
            console.log("response received.");
            return respJson;
        } else {
            console.log("Response issue: ", result.statusCode);
            var errorJson = JSON.parse(result.content);
            throw new Meteor.Error(result.statusCode, errorJson.error);
        }
    },</code>
Salin selepas log masuk
Salin selepas log masuk

已经获取到access_token和openid,调用https://api.weixin.qq.com/sns/authaccess...验证access_token也没问题。但是用access_token和openid获取用户信息总是返回errcode: 40001, errmsg: "invalid credential, access_token is invalid or not latest, hints: [ req_id: vkq6LA0879ns44 ]"。正确的返回是:

<code>{ 
"openid":"OPENID",
"nickname":"NICKNAME",
"sex":1,
"province":"PROVINCE",
"city":"CITY",
"country":"COUNTRY",
"headimgurl": "http://wx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/0",
"privilege":[
"PRIVILEGE1", 
"PRIVILEGE2"
],
"unionid": " o6_bmasdasdsad6_2sgVt7hMZOPfL"

}
</code>
Salin selepas log masuk
Salin selepas log masuk

网页扫码登录的scope只能是snsapi_login,难道是因为scope不是snsapi_userinfo而获取数据失败?
那这样网页扫码登录微信就只能拿到一个openid?

回复内容:

<code>getToken: function(code) {
        var url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=id&secret=sec&code=" + code +"&grant_type=authorization_code";
        //synchronous GET
        // console.log("url:" + url);
        var result = HTTP.get(url, {timeout:30000});
        // console.log("result:" + result);
        if(result.statusCode==200) {
            var respJson = JSON.parse(result.content);
            console.log("response received.");
            return respJson;
        } else {
            console.log("Response issue: ", result.statusCode);
            var errorJson = JSON.parse(result.content);
            throw new Meteor.Error(result.statusCode, errorJson.error);
        }
    },</code>
Salin selepas log masuk
Salin selepas log masuk

已经获取到access_token和openid,调用https://api.weixin.qq.com/sns/authaccess...验证access_token也没问题。但是用access_token和openid获取用户信息总是返回errcode: 40001, errmsg: "invalid credential, access_token is invalid or not latest, hints: [ req_id: vkq6LA0879ns44 ]"。正确的返回是:

<code>{ 
"openid":"OPENID",
"nickname":"NICKNAME",
"sex":1,
"province":"PROVINCE",
"city":"CITY",
"country":"COUNTRY",
"headimgurl": "http://wx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/0",
"privilege":[
"PRIVILEGE1", 
"PRIVILEGE2"
],
"unionid": " o6_bmasdasdsad6_2sgVt7hMZOPfL"

}
</code>
Salin selepas log masuk
Salin selepas log masuk

网页扫码登录的scope只能是snsapi_login,难道是因为scope不是snsapi_userinfo而获取数据失败?
那这样网页扫码登录微信就只能拿到一个openid?

access_token is invalid or not latest
明明有问题。

检查下是否正确,是否已过期。

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan