模仿拼多多小程序自动登录思想
16lz
2022-01-21
登录页面的js
onShow: function (onshow) {
let that = this
this.setData({
head:wx.getStorageSync('head'),
username:wx.getStorageSync('username')
})
}
APP.JS
onLaunch() {
if(wx.getStorageSync('openid')==false||wx.getStorageSync('username')==false||wx.getStorageSync('head')==false){
wx.login({
success: res => {
wx.request({
url: "https://api.weixin.qq.com/sns/jscode2session",
data: {
'appid': "自己的appid",
'secret': "自己的secret",
'js_code': res.code,
'grant_type': "authorization_code"
},
method: 'POST',
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
success: function (data) {
wx.request({
url: "http://192.168.199.99/api/autologin.php",
data:{
'openid':data.data.openid,
},
method: 'POST',
header: { "Content-Type": "application/x-www-form-urlencoded" },
success:res2=>{
res2.data.forEach(element => {
wx.setStorageSync('head', element.head)
wx.setStorageSync('username', element.name)
wx.setStorageSync('openid', element.openid)
});
}
})
},
fail: function (err) {
console.log(err);
}
})
}
})
}
},
更多相关文章
- Android(安卓)WebView的使用(一)
- Android与H5互调
- Android修改Gallery页面布局
- 获取手机安装的全部应用的示例教程
- Android基于基于布局嵌套的页面导航实现
- 对话框的练习(android)
- mysql配置SSL证书登录的实现
- MySQL 1130异常,无法远程登录解决方案详解
- 【Android】Web开发之使用WebView控件展示Web页面