登录和绑定微信的完善,我的页面需要登录验证

This commit is contained in:
姚亚男
2021-10-18 17:39:06 +08:00
parent 78715f6712
commit 78f894957a
9 changed files with 150 additions and 127 deletions
+23 -6
View File
@@ -1,25 +1,42 @@
export function wxBind(callback){
// 获取openid进行手机号和微信的绑定
let count = 1
wx.login({
success (res) {
if (res.code) {
//发起网络请求
if (res.code && count === 1) {
wx.request({
url: 'https://api.weixin.qq.com/sns/jscode2session',
data: {
appid: 'wx24914e866df035fb',
secret: '0d2830f26f57722716249f2b2236f409',
appid: 'wx322b63d1e6ff4765',
secret: '7d3dd94092bb50981d0a8ded849601a0',
js_code: res.code,
grant_type: 'authorization_code'
},
success (res) { // 成功拿到openId
// 微信和该账号绑定
callback(res)
if(count === 1){ // 回调会莫名回调两次,未知原因
callback(res)
}
count++
}
})
} else {
console.log('授权失败!' + res.errMsg)
console.log('授权失败!' + res.message)
}
}
})
}
// 检验是否登录
export function isLogin(callback){
wx.getStorage({
key: 'X-Access-Token',
success(res){
callback()
},
fail(){
wx.navigateTo({
url: '../login/login',
})
}
})
}
+6 -8
View File
@@ -22,7 +22,6 @@ const http = (method, url, data, header= headerDefault) => {
header: header,
data: data,
success: res => {
console.log(res)
wx.hideLoading();
if (res.statusCode === 200) {
// 接口请求错误的时候提示
@@ -37,15 +36,14 @@ const http = (method, url, data, header= headerDefault) => {
// 200: 服务端业务处理正常结束
resolve(res.data)
} else {
console.error(res.data);
reject(res.data);
wx.hideLoading();
wx.showToast({
title: "登录失效,请重新登录",
icon: "none",
duration: 1500,
mask: true
});
// wx.showToast({
// title: "登录失效,请重新登录",
// icon: "none",
// duration: 1500,
// mask: true
// });
// wx.navigateTo({
// url: '/pages/login/login',
// })