app.js 881 B

123456789101112131415161718192021222324252627282930313233343536
  1. // app.js
  2. App({
  3. onLaunch() {
  4. // 展示本地存储能力
  5. const logs = wx.getStorageSync('logs') || []
  6. logs.unshift(Date.now())
  7. wx.setStorageSync('logs', logs)
  8. // 登录
  9. wx.login({
  10. success: res => {
  11. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  12. console.log(res)
  13. wx.request( {
  14. url: this.globalData.url + "/v1/user/open.id/set",
  15. header: {
  16. "Content-Type": "application/json"
  17. },
  18. method: "POST",
  19. data: { code: res.code },
  20. complete: function( res ) {
  21. if (res.data.code == 200){
  22. wx.setStorageSync('openId', res.data.data.openid)
  23. }
  24. }
  25. })
  26. }
  27. })
  28. },
  29. globalData: {
  30. userInfo: null,
  31. //url:"http://127.0.0.1:8081"
  32. url:"http://www.tao1024.com:8081"
  33. }
  34. })