小程序获取code,openID与session_key


code:{{code}}
openID:{{openid}}
session_key:{{session_key}}
Page({
  data: {
    code:"",
    openid:"",
    session_key:""
  },
  login:function(){
    var that=this;
    wx.login({
      success:function(log){
        console.log(log.code);
        that.setData({
          code:log.code
        });
        wx.request({
          url: 'test.php',
          data:{code:log.code},
          success:function(data){
            console.log(data);
            that.setData({
              openid: data.data.openid,
              session_key: data.data.session_key
            });
          }
        })
      }
    })
  }
})

 

你可能感兴趣的:(小程序)