|
|
@@ -10,11 +10,34 @@ App({ |
|
|
|
wx.login({ |
|
|
|
success: res => { |
|
|
|
// 发送 res.code 到后台换取 openId, sessionKey, unionId |
|
|
|
console.log(res.code) |
|
|
|
console.log(res, 'wx.login') |
|
|
|
doLogin(res.code) |
|
|
|
getWxToken() |
|
|
|
}, |
|
|
|
}) |
|
|
|
|
|
|
|
// 获取小程序AccessToken |
|
|
|
const getWxToken = () => { |
|
|
|
const data = { |
|
|
|
grant_type: 'client_credential', |
|
|
|
appid: 'wxf288a9b8167ff2ca', |
|
|
|
secret: 'cf012a9015594f0a95f718a801497fbd' |
|
|
|
} |
|
|
|
wx.request({ |
|
|
|
url: 'https://api.weixin.qq.com/cgi-bin/stable_token', |
|
|
|
header: { |
|
|
|
"Content-Type": "application/json;charset=UTF-8", |
|
|
|
}, |
|
|
|
data: data, |
|
|
|
method: "POST", |
|
|
|
success: res => { |
|
|
|
console.log(res, 'getWxToken'); |
|
|
|
wx.setStorageSync('AccessToken', res.data.access_token) |
|
|
|
}, |
|
|
|
fail: err => { } |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @description 登录 |
|
|
|
* @param {*} loginData {code , appid} |
|
|
@@ -36,8 +59,8 @@ App({ |
|
|
|
that.globalData.sessionKey = res.data.sessionKey |
|
|
|
wx.setStorageSync('openId', res.data.openId) |
|
|
|
that.globalData.openId = res.data.openId |
|
|
|
wx.setStorageSync('AccessToken', res.data.token) |
|
|
|
that.globalData.AccessToken = res.data.token |
|
|
|
wx.setStorageSync('token', res.data.token) |
|
|
|
that.globalData.token = res.data.token |
|
|
|
|
|
|
|
// 检查用户信息 |
|
|
|
checkUserInfo() |
|
|
|