小程序模板網(wǎng)

微信小程序用戶數(shù)據(jù)解密

發(fā)布時間:2018-02-10 12:02 所屬欄目:小程序開發(fā)教程

 

參考鏈接:

官方文檔

官方指引圖

按照官方引導(dǎo)圖一步一步操作

1、獲取code


  1. onLoad: function (options) {
    // 頁面初始化 options為頁面跳轉(zhuǎn)所帶來的參數(shù)
    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()
    }
    })
    }
    })
    }

2、發(fā)送code到第三方服務(wù)器,獲取3rd_session


  1. 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: {}, // 設(shè)置請求的 header
    success: function (res) {
    // success
    var sessionId = res.data.session;
    that.setData({ sessionId: sessionId })
    wx.setStorageSync('sessionId', sessionId)
    that.decodeUserInfo()
    }
    })
    }

3、在第三方服務(wù)器上發(fā)送appid、appsecret、code到微信服務(wù)器換取session_key和openid

這里使用JFinal搭建的服務(wù)器

Redis配置


  1. public void configPlugin(Plugins me) {
    //用于緩存userinfo模塊的redis服務(wù)
    RedisPlugin userInfoRedis = new RedisPlugin("userInfo","localhost");
    me.add(userInfoRedis);
    }

獲取第三方session


  1. public void get3rdSession() {
    //獲取名為userInfo的Redis Cache對象
    Cache userInfoCache = Redis.use("userInfo");
    


本文地址:http://www.u-renovate.com/wxmini/doc/course/21975.html 復(fù)制鏈接 如需定制請聯(lián)系易優(yōu)客服咨詢:800182392 點(diǎn)擊咨詢
QQ在線咨詢
AI智能客服 ×