參考鏈接:
官方指引圖
按照官方引導圖一步一步操作
onLoad: function (options) { // 頁面初始化 options為頁面跳轉所帶來的參數 let that = this wx.login({ success: function (res) { // success let code = res.code that.setData({ code: code }) wx.getUserInfo({ success: function (res) { // success that.setData({ userInfo: res.userInfo }) that.setData({ iv: res.iv }) that.setData({ encryptedData: res.encryptedData }) that.get3rdSession() } }) } }) } |
get3rdSession:function(){ let that = this wx.request({ url: 'https://localhost:8443/get3rdSession', data: { code: this.data.code }, method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT // header: {}, // 設置請求的 header success: function (res) { // success var sessionId = res.data.session; that.setData({ sessionId: sessionId }) wx.setStorageSync('sessionId', sessionId) that.decodeUserInfo() } }) } |
這里使用JFinal搭建的服務器
Redis配置
public void configPlugin(Plugins me) { //用于緩存userinfo模塊的redis服務 RedisPlugin userInfoRedis = new RedisPlugin("userInfo","localhost"); me.add(userInfoRedis); } |
獲取第三方session
public void get3rdSession() { //獲取名為userInfo的Redis Cache對象 Cache userInfoCache = Redis.use("userInfo"); |