请问为什么开发版本的小程序用手机测的时候只能能开调试才能获取openid?
发布于 7 年前 作者 ping51 3219 次浏览 来自 问答

代码如下

wx.login({

//获取code

success: function (res) {

let code = res.code //返回code

let APPID = “wx07de8bea337407f2”;

let SECRET = “f88ba62fbfa5b647487a3ddc91c3f151”;

wx.request({

url: https://api.weixin.qq.com/sns/jscode2session?appid= + APPID + ‘&secret=’ + SECRET + ‘&js_code=’ + res.code+ ‘&grant_type=authorization_code’,

data: {},

header: {

‘content-type’: ‘application/json’

},

success: function (res) {

let openid = res.data.openid //返回openid

console.log(openid)

getApp().globalData.openid = openid;

wx.setStorage({

key: ‘openid’,

data: openid,

success: function(res) {},

fail: function(res) {},

complete: function(res) {},

})

wx.getUserInfo({

success: function(res) {

getApp().globalData.userInfo = res.rawData;

},

fail: function(res) {},

complete: function(res) {},

})

},

fail(res) {

// console.log(“q”)

}

})

}

});

回到顶部