Commit 8e1653f6 by 汪睦雄

'提交修改手机号'

parent fd519add
......@@ -27,7 +27,8 @@ Page({
remark: '',
// 订单
order: {},
nums: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
nums: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
sessionId: ''
},
/**
* 生命周期函数--监听页面加载
......@@ -38,6 +39,31 @@ Page({
id: options.id
})
}
// 获取session id
Wx.login().then(res => {
if (res.errMsg == 'login:ok') {
api.getSessionKey({
code: res.code
}).then(res => {
if (res.code == 0) {
this.setData({
sessionid: res.data
})
} else {
$Toast({
content: res.msg,
type: 'error'
});
}
})
} else {
$Toast({
content: 'wx.login失败',
type: 'error'
});
}
})
},
/**
......@@ -88,60 +114,104 @@ Page({
// 获取session key
let encryptedData = event.detail.encryptedData
let iv = event.detail.iv
let that = this
Wx.login().then(res => {
console.log('wx.login', res, ' event:', event)
if (res.errMsg == 'login:ok') {
api.getSessionKey({
code: res.code
}).then(res => {
if (!res.code) {
let sessionId = res.data
let that = this
api.getPhoneNumber({
sessionId: sessionId,
encryptedData: encryptedData,
iv: encodeURIComponent(iv)
}).then(res => {
console.log('iv: ', iv, ' res.code: ', res.code)
if (!res.code) {
$Toast({
content: '手机号授权成功',
type: 'success'
});
this.setData({
phone: res.data.phone
})
// 将刚拿到的手机号码放到全局数据中,否则phone数据只会是当前页面数据
if (app.globalData.userInfo) {
app.globalData.userInfo.phone = res.data.phone
}
} else {
$Toast({
content: res.msg,
type: 'error'
});
wx.checkSession({
success: function(res) {
if (res.errMsg == 'checkSession:ok'){
let sessionId = that.data.sessionid
console.log( 'sessionId', sessionId )
api.getPhoneNumber({
sessionId: sessionId,
encryptedData: encryptedData,
iv: encodeURIComponent(iv)
}).then(res => {
console.log('iv: ', iv, ' res.code: ', res.code)
if (!res.code) {
$Toast({
content: '手机号授权成功',
type: 'success'
});
that.setData({
phone: res.data.phone
})
// 将刚拿到的手机号码放到全局数据中,否则phone数据只会是当前页面数据
if (app.globalData.userInfo) {
app.globalData.userInfo.phone = res.data.phone
}
})
} else {
$Toast({
content: res.msg,
type: 'error'
});
}
})
} else {
$Toast({
content: 'wx.login失败',
type: 'error'
});
} else {
$Toast({
content: res.msg,
type: 'error'
});
}
})
}else{
$Toast({
content: res.errMsg,
type: 'success'
});
console.log('checkSession', res.errMsg)
}
},
fail: function() {
console.log('checkSession', 'fail')
}
// let encryptedData = event.detail.encryptedData
// let iv = event.detail.iv
// this.decodePhoneData(res.code, encryptedData, iv)
})
// Wx.login().then(res => {
// console.log('wx.login', res, ' event:', event)
// if (res.errMsg == 'login:ok') {
// api.getSessionKey({
// code: res.code
// }).then(res => {
// if (!res.code) {
// let sessionId = res.data
// let that = this
// api.getPhoneNumber({
// sessionId: sessionId,
// encryptedData: encryptedData,
// iv: encodeURIComponent(iv)
// }).then(res => {
// console.log('iv: ', iv, ' res.code: ', res.code)
// if (!res.code) {
// $Toast({
// content: '手机号授权成功',
// type: 'success'
// });
// this.setData({
// phone: res.data.phone
// })
// // 将刚拿到的手机号码放到全局数据中,否则phone数据只会是当前页面数据
// if (app.globalData.userInfo) {
// app.globalData.userInfo.phone = res.data.phone
// }
// } else {
// $Toast({
// content: res.msg,
// type: 'error'
// });
// }
// })
// } else {
// $Toast({
// content: res.msg,
// type: 'error'
// });
// }
// })
// } else {
// $Toast({
// content: 'wx.login失败',
// type: 'error'
// });
// }
// // let encryptedData = event.detail.encryptedData
// // let iv = event.detail.iv
// // this.decodePhoneData(res.code, encryptedData, iv)
// })
},
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment