1 Star 1 Fork 0

Jesse_Yang_/jinsanjiaopinche

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.js 1.81 KB
一键复制 编辑 原始数据 按行查看 历史
Jesse_Yang_ 提交于 2018-06-24 21:55 +08:00 . 0624
//app.js
var mydomain = 'https://api.hgtengfei.cn/wechat/user/'
App({
onLaunch: function () {
var that = this
wx.checkSession({
success: function () {
console.log('登录了')
wx.getStorage({
key: 'userId',
success: function (res) {
console.log('get storage success')
console.log('userid:'+res.data)
that.globalData.userId = res.data
},
fail: function () {
console.log('没有缓存')
that.doLogin()
return
}
})
}, fail: function () {
console.log('没登录')
that.doLogin()
return
}
})
// 查看是否授权
wx.getSetting({
success: function (res) {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称
wx.getUserInfo({
success: function (res) {
// console(res.userInfo)
console.log(res.userInfo)
that.globalData.userInfo=res.userInfo
}
})
}
}
})
},
doLogin: function () {
console.log('doLogin')
var that = this;
wx.login({
success: function (res) {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
console.log('login success')
wx.request({
url: mydomain+'login',
data:{code:res.code},
success:function(res){
console.log(res)
var userId = res.data.openid
wx.setStorage({
key: 'userId',
data: userId,
})
}
})
},
fail: function () {
console.log('login fail')
}
})
},
globalData: {
userInfo: null,
userId:null
}
})
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/jesseyang/jinsanjiaopinche.git
[email protected]:jesseyang/jinsanjiaopinche.git
jesseyang
jinsanjiaopinche
jinsanjiaopinche
master

搜索帮助