收藏
回答

请问为什么开发版本的小程序用手机测的时候只能能开调试才能获取openid?

问题模块
API和组件

代码如下

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")

}

})

}

});


最后一次编辑于  2017-11-19  (未经腾讯允许,不得转载)
回答关注问题邀请回答
收藏