Home  >  Article  >  WeChat Applet  >  How to deal with security issues in WeChat mini programs

How to deal with security issues in WeChat mini programs

php中世界最好的语言
php中世界最好的语言Original
2018-06-05 14:05:375481browse

This time I will show you how to deal with security issues in WeChat Mini Programs, and what are the precautions for security issues in WeChat Mini Programs. The following is a practical case, let’s take a look.

The following is the code about configuration information, for reference only!

//app.js
var host = ""
App({
  onLaunch: function () {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    // var url = app.globalData.index
    // 登录
    wx.login({
      success: res => {
        // console.log(res);
        // 发送 res.code 到后台换取 openId, sessionKey, unionId

        wx.request({
          url: this.globalData.session,
          data:{
            code:res.code,
          },
          success:res=>{
            // console.log(res.header['Set-Cookie']);
            wx.setStorage({
              key: 'session_id',
              data: res.header['Set-Cookie'],
            })
          }
        })
      }
    })
    // 获取用户信息
    // wx.getSetting({
    //   success: res => {
    //     if (res.authSetting['scope.userInfo']) {
    //       // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
    //       wx.getUserInfo({
    //         success: res  => {
    //           // 可以将 res 发送给后台解码出 unionId
    //           this.globalData.userInfo = res.userInfo

    //           // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
    //           // 所以此处加入 callback 以防止这种情况
    //           if (this.userInfoReadyCallback) {
    //             this.userInfoReadyCallback(res)
    //           }
    //         }
    //       })
    //     }
    //   }
    // })
  },
  globalData: {
    userInfo: null,
    index:`${host}/home/index/index`,
    add: `${host}/home/index/add`,
    session: `${host}/home/index/session`,
    upload: `${host}/home/index/upload`,
    getstu: `${host}/home/index/getstu`,
    login: `${host}/home/index/login`
  }
})

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to implement WeChat payment in the development of WeChat applet

How to implement pictures in the development of WeChat applet Upload

The above is the detailed content of How to deal with security issues in WeChat mini programs. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn