Backend login after WeChat development (login without WeChat account)

零下一度
Release: 2017-05-19 15:54:19
Original
2792 people have browsed it

Recently I wrote a small tool program. According to the requirements, you do not need to log in with the WeChat account provided by WeChat. You need to call the background login interface to log in. Since most of the mini programs use WeChat information to log in, and rarely use their own backend to log in, there are various pitfalls when writing them. Now I will share the code with everyone! (PS: If there is anything wrong, please share it.)

Backend login after WeChat development (login without WeChat account)


Backend login after WeChat development (login without WeChat account)

Don’t talk nonsense, go directly to the code

Find app.js and write the following code in it

App({ onLaunch: function () { //调用API从本地缓存中获取数据 var logs = wx.getStorageSync('logs') || [] logs.unshift(Date.now()) wx.setStorageSync('logs', logs) }, globalData: { adminUserViewId: "", token: "", userInfo: null, BaseURL:"http://airb.cakeboss.com.cn" // BaseURL:"http://192.168.0.107:8080" },
Copy after login

Knock on the blackboard to highlight: The important part of the code snippet in the picture above is: "globalData adminUserViewId: "",token: "" ”
These two parameters are background parameters that need to be stored by the front end and are used to mark the user's login status.

Then create a login folder and write the following code in login.wxml