|
@@ -1,12 +1,18 @@
|
|
|
const getReq = require('../config.js').getReq
|
|
|
const api = require('../config.js').host
|
|
|
+
|
|
|
export default class WxAuthor {
|
|
|
- constructor(app) {
|
|
|
+ fGetSetting = true
|
|
|
+
|
|
|
+ constructor(app, getsetting) {
|
|
|
this.target = app
|
|
|
- this.init()
|
|
|
+ this.init(getsetting)
|
|
|
}
|
|
|
// 首先wx.login
|
|
|
- init() {
|
|
|
+ init(getsetting) {
|
|
|
+ this.target.globalData.fMinistart = false
|
|
|
+
|
|
|
+ this.fGetSetting = getsetting
|
|
|
wx.login({
|
|
|
success: res => {
|
|
|
this.ministart(res.code)
|
|
@@ -26,14 +32,15 @@ export default class WxAuthor {
|
|
|
let { openid, unionid } = res.datas
|
|
|
if (openid && unionid) {
|
|
|
this.setId(openid, unionid)
|
|
|
- this.getSetting(false)
|
|
|
+ if(this.fGetSetting) {
|
|
|
+ this.getSetting(false)
|
|
|
+ }
|
|
|
} else {
|
|
|
- this.getSetting(true)
|
|
|
+ if(this.fGetSetting) {
|
|
|
+ this.getSetting(true)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- else {
|
|
|
- return
|
|
|
- }
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -41,11 +48,9 @@ export default class WxAuthor {
|
|
|
wx.getSetting({
|
|
|
success: res => {
|
|
|
if (res.authSetting['scope.userInfo']) {
|
|
|
+ console.log('wx getSetting:',res)
|
|
|
this.getUserInfo(flag)
|
|
|
}
|
|
|
- else {
|
|
|
- return
|
|
|
- }
|
|
|
}
|
|
|
})
|
|
|
}
|
|
@@ -56,6 +61,7 @@ export default class WxAuthor {
|
|
|
withCredentials,
|
|
|
success: res => {
|
|
|
this.setUserInfo(res.userInfo, res.userInfo.nickName)
|
|
|
+
|
|
|
let userInfo = this.target.globalData.userInfo
|
|
|
if (flag) {
|
|
|
let { encryptedData, signature, iv } = res
|
|
@@ -76,7 +82,6 @@ export default class WxAuthor {
|
|
|
op: "wxauthen",
|
|
|
relay_id: relay_id
|
|
|
}
|
|
|
-
|
|
|
getReq(this.target,params, res => {
|
|
|
if (res.code == 200) {
|
|
|
this.target.globalData.member_id = res.datas.member_id
|
|
@@ -124,5 +129,8 @@ export default class WxAuthor {
|
|
|
setId(openid, unionid) {
|
|
|
this.target.globalData.userId.openid = openid
|
|
|
this.target.globalData.userId.unionid = unionid
|
|
|
+ var timeStamp = new Date().getTime();
|
|
|
+ timeStamp = Math.floor(timeStamp);
|
|
|
+ this.target.globalData.userId.timeStamp = timeStamp
|
|
|
}
|
|
|
}
|