获取openid,报errcode: 48001
发布于 7 年前 作者 zcao 11008 次浏览 来自 问答

上周刚申请的一个新的小程序,在获取openId的时候,延用了以前的api,发现返回报错了,

网上评论说新申请的小程序不能用网页版的api。

请问现在用什么接口去调用,需要什么授权?

error 信息

normal - { errcode: 48001,

  errmsg: 'api unauthorized, hints: [ req_id: SQG1fa0162th20 ]' 


调用的接口为:

https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code
10 回复

        wx.login({
            success: function (res) {
                if (res.code) {
                    //发起网络请求
                    wx.request({
                        url: ‘https://api.weixin.qq.com/sns/jscode2session’,
                        method: ‘GET’,
                        data: { appid: appid, secret: SECRET, js_code: res.code, grant_type: ‘authorization_code’ },
                        header: {
                            ‘content-type’: ‘application/json’
                        },
                        success: function (res) {
                            //res.data就是微信返回值
                        }
                    })
                } else {
                    console.log(‘获取用户登录态失败!’ + res.errMsg)
                }
            }
        });

?现在是有放到前端做了?

我试试

我只是写个列子,前后端没区别

你把那个请求的第三方微信url改为这个就好了

"https://api.weixin.qq.com/sns/jscode2session?appid=$appid&secret=$appsecret&js_code=$code&grant_type=authorization_code"

请求的url问题,困扰了我好长时间,如果还报错那你在检查一下自己的参数




这个url有三种

1、$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$appsecret&code=$code&grant_type=authorization_code";


2、$url = "https://api.weixin.qq.com/sns/oauth2/component/access_token?appid=$appid&secret=$appsecret&code=$code&grant_type=authorization_code";


3、$url = "https://api.weixin.qq.com/sns/jscode2session?appid=$appid&secret=$appsecret&js_code=$code&grant_type=authorization_code";



-----------------------------华丽分割线------------以上是我自己总结的---------以下是自己又查找的资料---------------------------

详细参考https://www.cnblogs.com/sxmny/articles/4969119.html

wx.login({
            success: function (res) {
                if (res.code) {
                    //发起网络请求,这个res.code就是js_code的值
                } else {
                    console.log(‘获取用户登录态失败!’ + res.errMsg)
                }
            }
        });

官方大哥们,你们在哪儿??

为了安全https://api.weixin.qq.com,不能放在域名配置中,所以还是不能在前端调用。

只能通过后台获取。

谢谢你的回答。

反正错误码是48001的就是url问题线面三种url你换一换,总有一个好使



你把那个请求的第三方微信url改为这个就好了

"https://api.weixin.qq.com/sns/jscode2session?appid=$appid&secret=$appsecret&js_code=$code&grant_type=authorization_code"

请求的url问题,困扰了我好长时间,如果还报错那你在检查一下自己的参数




这个url有三种

1、$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$appsecret&code=$code&grant_type=authorization_code";


2、$url = "https://api.weixin.qq.com/sns/oauth2/component/access_token?appid=$appid&secret=$appsecret&code=$code&grant_type=authorization_code";


3、$url = "https://api.weixin.qq.com/sns/jscode2session?appid=$appid&secret=$appsecret&js_code=$code&grant_type=authorization_code";



-----------------------------华丽分割线------------以上是我自己总结的---------以下是自己又查找的资料---------------------------

详细参考https://www.cnblogs.com/sxmny/articles/4969119.html

解决了没,同问

openId:wx4f7b65b8cf112f9a

在线等

回到顶部