摘要:
小程序获得openid实例App({ onLaunch: function () { ...
小程序获得openid实例
App({ onLaunch: function () { var _this = this; wx.login({ //获取code success: function (res) { //得到openid 开始 wx.request({ url: 'https://api.weixin.qq.com/sns/jscode2session', data: { appid: _this.globalData.appid, secret:_this.globalData.appsecret, js_code:res.code, grant_type:'authorization_code' }, method:'GET', header: { 'content-type': 'application/json' }, success: function (res) { console.log(res.data); var openid = res.data.openid; //返回openid } }) //得到openid结束 } }) //用户登陆结束 }, globalData: { appid:'wx99777c04115e0238', appsecret:'4c0f48c8003550b399aab023424sdf', }})