You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

57 lines
1.5 KiB

// app.js
const http = require('./api/http.js')
App({
onLaunch() {
},
login(){
return new Promise((resolve,reject)=>{
wx.getUserProfile({
lang: 'zh_CN',
desc: '需要获取您的信息用来展示',
success: res => {
wx.showLoading({ title: '登录中' })
wx.login({
success: result => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
let data = {
code: result.code,
iv: res.iv,
encryptedData: res.encryptedData
}
console.log(data)
http.$http('post','wxapp/auth',data).then((result)=>{
if(result.data.success){
wx.setStorageSync('token', result.data.data.token)
wx.setStorageSync('userInfo', result.data.data.user)
wx.showToast({
title: '授权成功!',
icon: 'none'
})
} else{
wx.showToast({
title: result.data.msg,
icon: 'none'
})
}
resolve(result)
})
}
})
},
fail: res=>{
console.log('取消授权')
}
})
})
},
alertMessage(msg){
wx.showToast({
title: msg,
icon: 'none'
})
},
globalData: {
http: http.$http,
products: []
}
})