|
@@ -1,6 +1,5 @@
|
|
const getReq = require('../config.js').getReq
|
|
const getReq = require('../config.js').getReq
|
|
const api = require('../config.js').host
|
|
const api = require('../config.js').host
|
|
-
|
|
|
|
export default class WxAuthor {
|
|
export default class WxAuthor {
|
|
constructor(app) {
|
|
constructor(app) {
|
|
this.target = app
|
|
this.target = app
|
|
@@ -22,31 +21,50 @@ export default class WxAuthor {
|
|
code
|
|
code
|
|
}
|
|
}
|
|
getReq(params, res => {
|
|
getReq(params, res => {
|
|
- let { openid, unionid } = res.datas
|
|
|
|
- this.setId(openid, unionid)
|
|
|
|
- // 获取用户授权设置信息
|
|
|
|
- this.getSetting()
|
|
|
|
|
|
+ if (res.code == 200) {
|
|
|
|
+ let { openid, unionid, HPHPSESSID } = res.datas
|
|
|
|
+ wx.setStorageSync('session_id', HPHPSESSID);
|
|
|
|
+ if (openid && unionid) {
|
|
|
|
+ this.setId(openid, unionid)
|
|
|
|
+ this.getSetting(false)
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ this.getSetting(true)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
- getSetting() {
|
|
|
|
|
|
+ getSetting(flag) {
|
|
wx.getSetting({
|
|
wx.getSetting({
|
|
success: res => {
|
|
success: res => {
|
|
if (res.authSetting['scope.userInfo']) {
|
|
if (res.authSetting['scope.userInfo']) {
|
|
- this.getUserInfo()
|
|
|
|
|
|
+ this.getUserInfo(flag)
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- return
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
- getUserInfo() {
|
|
|
|
|
|
+ getUserInfo(flag) {
|
|
|
|
+ let withCredentials = flag
|
|
wx.getUserInfo({
|
|
wx.getUserInfo({
|
|
|
|
+ withCredentials,
|
|
success: res => {
|
|
success: res => {
|
|
this.setUserInfo(res.userInfo, res.userInfo.nickName)
|
|
this.setUserInfo(res.userInfo, res.userInfo.nickName)
|
|
- let userInfo = Object.assign({}, this.target.globalData.userId, this.target.globalData.userInfo)
|
|
|
|
|
|
+ let userInfo = this.target.globalData.userInfo
|
|
|
|
+ if (flag) {
|
|
|
|
+ let { encryptedData, signature, iv } = res
|
|
|
|
+ userInfo = Object.assign({}, { encryptedData }, { signature }, { iv }, userInfo)
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ userInfo = Object.assign({}, this.target.globalData.userId, userInfo)
|
|
|
|
+ }
|
|
this.wxauthen(userInfo)
|
|
this.wxauthen(userInfo)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
@@ -58,7 +76,6 @@ export default class WxAuthor {
|
|
op: "wxauthen"
|
|
op: "wxauthen"
|
|
}
|
|
}
|
|
getReq(params, res => {
|
|
getReq(params, res => {
|
|
- wx.setStorageSync('session_id', res.datas.HPHPSESSID)
|
|
|
|
if (res.code == 200) {
|
|
if (res.code == 200) {
|
|
let url = this.getUrl()
|
|
let url = this.getUrl()
|
|
wx.reLaunch({
|
|
wx.reLaunch({
|
|
@@ -67,10 +84,10 @@ export default class WxAuthor {
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
wx.showToast({
|
|
wx.showToast({
|
|
- icon: 'none',
|
|
|
|
- title: '登陆失败',
|
|
|
|
- duration: 2000
|
|
|
|
- })
|
|
|
|
|
|
+ icon: 'none',
|
|
|
|
+ title: '登陆失败',
|
|
|
|
+ duration: 2000
|
|
|
|
+ })
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|