博客列表 >模仿拼多多小程序自动登录思想

模仿拼多多小程序自动登录思想

搁浅
搁浅原创
2021年12月11日 03:41:261412浏览

登录页面的js

  1. onShow: function (onshow) {
  2. let that = this
  3. this.setData({
  4. head:wx.getStorageSync('head'),
  5. username:wx.getStorageSync('username')
  6. })
  7. }

APP.JS

  1. onLaunch() {
  2. if(wx.getStorageSync('openid')==false||wx.getStorageSync('username')==false||wx.getStorageSync('head')==false){
  3. wx.login({
  4. success: res => {
  5. wx.request({
  6. url: "https://api.weixin.qq.com/sns/jscode2session",
  7. data: {
  8. 'appid': "自己的appid",
  9. 'secret': "自己的secret",
  10. 'js_code': res.code,
  11. 'grant_type': "authorization_code"
  12. },
  13. method: 'POST',
  14. header: {
  15. "Content-Type": "application/x-www-form-urlencoded"
  16. },
  17. success: function (data) {
  18. wx.request({
  19. url: "http://192.168.199.99/api/autologin.php",
  20. data:{
  21. 'openid':data.data.openid,
  22. },
  23. method: 'POST',
  24. header: { "Content-Type": "application/x-www-form-urlencoded" },
  25. success:res2=>{
  26. res2.data.forEach(element => {
  27. wx.setStorageSync('head', element.head)
  28. wx.setStorageSync('username', element.name)
  29. wx.setStorageSync('openid', element.openid)
  30. });
  31. }
  32. })
  33. },
  34. fail: function (err) {
  35. console.log(err);
  36. }
  37. })
  38. }
  39. })
  40. }
  41. },
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议