Page({
/**
* 页面的初始数据
*/
data: {
openid: "",
loginstate: "0",
openid: "",
userEntity: null,
terminal: "",
osVersion: "",
phoneNumber: "",
showModal: false,//定义登录弹窗
},
//在页面加载的时候,判断缓存中是否有内容,如果有,存入到对应的字段里
onLoad: function () {
var that = this;
wx.getStorage({
key: 'openid',
success: function (res) {
that.setData({ openid: res.data });
},
fail: function (res) {
that.getcode();
}
});
wx.getStorage({
key: 'userEntity',
success: function (res) {
that.setData({ userEntity: res.data });
},
fail: function (res) {
console.log("fail1");
}
});
wx.getStorage({
key: 'loginstate',
success: function (res) {
that.setData({ loginstate: res.data });
}, fail: function (res) {
console.log("fail2");
}
});
},
onGotUserInfo: function (e) {
var that = this;
if (e.detail.errMsg == "getUserInfo:ok") {
wx.setStorage({
key: "userinfo",
data: e.detail.userInfo
})
this.setData({ userInfo: e.detail.userInfo });
that.showDialogBtn();//调用一键获取手机号弹窗(自己写的)
}
},
// 显示一键获取手机号弹窗
showDialogBtn: function () {
this.setData({
showModal: true//修改弹窗状态为true,即显示
})
},
// 隐藏一键获取手机号弹窗
hideModal: function () {
this.setData({
showModal: false//修改弹窗状态为false,即隐藏
});
},
onshow: function (openid, userInfo, phoneNumber) {
var that = this;
wx.getSystemInfo({
success: function (res) {
that.setData({ terminal: res.model });
that.setData({ osVersion: res.system });
}
})
wx.request({
url: '登录接口',
method: 'POST',
header: {
'content-type': 'application/json' // 默认值
},
data: {
username: phoneNumber,
parentuser: 'xudeihai',
wximg: userInfo.avatarUrl,
nickname: userInfo.nickName,
identity: "",
terminal: that.data.terminal,
osVersion: that.data.system,
logintype: "10",//微信登录
openid: that.data.openid,
},
success(res) {
if (res.data.r == "T") {
that.setData({ userEntity: res.data.d });
wx.setStorage({
key: "userEntity",
data: res.data.d
})
that.setData({ loginstate: "1" });
wx.setStorage({
key: "loginstate",
data: "1"
})
wx.setStorage({
key: 'userinfo',
data: "1"
})
}
else {
return;
}
},
fail(res) {
console.log(res);
}
})
},
//绑定手机
getPhoneNumber: function (e) {
var that = this;
that.hideModal();
wx.checkSession({
success: function () {
wx.login({
success: res => {
wx.request({
url: '自己的登录接口', //仅为示例,并非真实的接口地址
data: {
account: '1514382701',
jscode: res.code
},
method: "POST",
header: {
'content-type': 'application/json' // 默认值
},
success(res) {
if (res.data.r == "T") {
wx.setStorage({
key: "openid",
data: res.data.openid
})
wx.setStorage({
key: "sessionkey",
data: res.data.sessionkey
})
wx.setStorageSync("sessionkey", res.data.sessionkey);
wx.request({
url: '自己的解密接口',//自己的解密地址
data: {
encryptedData: e.detail.encryptedData,
iv: e.detail.iv,
code: wx.getStorageSync("sessionkey")
},
method: "post",
header: {
'content-type': 'application/json'
},
success: function (res) {
if (res.data.r == "T") {
that.onshow(that.data.openid, that.data.userInfo, res.data.d.phoneNumber);//调用onshow方法,并传递三个参数
console.log("登录成功")
console.log(res.data.d.phoneNumber)//成功后打印微信手机号
}
else {
console.log(res);
}
}
})
}
}
})
}
})
},
fail: function () {
wx.login({
success: res => {
wx.request({
url: '自己的登录接口', //仅为示例,并非真实的接口地址
data: {
account: '1514382701',
jscode: res.code
},
method: "POST",
header: {
'content-type': 'application/json' // 默认值
},
success(res) {
if (res.data.r == "T") {
wx.setStorage({
key: "openid",
data: res.data.openid
})
wx.setStorage({
key: "sessionkey",
data: res.data.sessionkey
})
wx.request({
url: '自己的解密接口',//自己的解密地址
data: {
encryptedData: e.detail.encryptedData,
iv: e.detail.iv,
code: res.data.sessionkey
},
method: "post",
header: {
'content-type': 'application/json'
},
success: function (res) {
that.onshow(that.data.openid, that.data.userInfo, res.data.d.phoneNumber);//调用onshow方法,并传递三个参数
}
})
}
}
})
}
})
}
})
},
})
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
LoginDemoTest.zip (14个子文件)
LoginTest
project.config.json 945B
pages
logs
logs.wxml 173B
logs.json 77B
logs.wxss 106B
logs.js 261B
login
index.wxss 1KB
index.json 27B
index.wxml 699B
index.js 6KB
utils
util.js 472B
app.js 1KB
sitemap.json 191B
app.json 285B
app.wxss 194B
共 14 条
- 1
资源评论
- xiaoyu_10022021-01-29解密接口呢
- weixin_387470872020-04-30可以,很完美很不错的,谢谢分享了
- 我是个假程序员2021-01-22图片呢???
- 抢街饭2021-12-29先下载看看,符合要求不
小潴
- 粉丝: 33
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功