Javascript-WeChat web page scan login cannot obtain user information

Source: Internet
Author: User
Tags openid
{Code...} has obtained access_token and openid. It is okay to call api. weixin. qq. comsnsauthaccess... to verify access_token. However, if you use access_token and openid to obtain user information, the system always returns errcode: 40001, errmsg: & quot; invalidcred...
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);        }    },

You have obtained the access_token and openid. You have no question when calling https://api.weixin.qq.com/sns/authaccess...verify access_token. However, if you use access_token and openid to obtain user information, the system always returns errcode: 40001, errmsg: "invalid credential, access_token is invalid or not latest, hints: [req_id: vkq6LA0879ns44] The correct response is:

{ "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"}

The scope for logon by scanning the webpage can only be snsapi_login. Is it because scope is not snsapi_userinfo and data acquisition fails?
In this way, only one openid can be obtained for web page scan login?

Reply content:
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);        }    },

You have obtained the access_token and openid. You have no question when calling https://api.weixin.qq.com/sns/authaccess...verify access_token. However, if you use access_token and openid to obtain user information, the system always returns errcode: 40001, errmsg: "invalid credential, access_token is invalid or not latest, hints: [req_id: vkq6LA0879ns44] The correct response is:

{ "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"}

The scope for logon by scanning the webpage can only be snsapi_login. Is it because scope is not snsapi_userinfo and data acquisition fails?
In this way, only one openid can be obtained for web page scan login?

access_token is invalid or not latest
Obviously there is a problem.

Check whether it is correct and whether it has expired.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.