1 Star 5 Fork 0

柯基与佩奇 / 柯基阅读

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.js 3.04 KB
一键复制 编辑 原始数据 按行查看 历史
柯基与佩奇 提交于 2021-08-23 11:42 . koki 阅读
//app.js
let https = require('utils/https.js')
function Login(code, userInfo) {
let that = this
let nickName = userInfo.nickName;
let avatarUrl = userInfo.avatarUrl;
let gender = userInfo.gender;
let language = userInfo.language;
let url = `https://api.stiles.cc/wechat/onLogin?code=${code}&nickName=${nickName}&avatarUrl=${avatarUrl}&gender=${gender}&language=${language}`;
https.get(url, function (res) {
let token = res.token;
wx.setStorageSync('token', token);
},function(){
//wx.setStorageSync('token', "defalutToken")
// 在这里你要考虑到用户登录失败的情况
},false)
}
App({
globalData: {
domain: "https://api.stiles.cc",
detailUrl:"https://api.stiles.cc/novels/get",
novelsUrl: "https://api.stiles.cc/novels",
recommendUrl: "https://api.stiles.cc/novels/recommend",
chaptersUrl: "https://api.stiles.cc/novels/getChapters",
chaptersContentUrl: "https://api.stiles.cc/novels/getChaptersContent",
categoryUrl: "https://api.stiles.cc/novels/getCategory",
searchUrl: "https://api.stiles.cc/novels/search",
feedbackUrl: "https://api.stiles.cc/feedback/send",
novelSerialNumbersUrl: "https://api.stiles.cc/novels/getNovelSerialNumbers",
searchKeywords: "https://api.stiles.cc/novels/getSearchKeywords",
token:null,
userInfo: null
},
onLaunch: function () {
// wx.clearStorage();
this.getUserInfo();
this.removeCache();
},
removeCache:function(){
let value = wx.getStorageSync('cateListTime')
let nowTime = new Date().getTime();
if(value){
if (value < nowTime) {
wx.removeStorage("cateList");
}
}
value = wx.getStorageSync('searchKeysTime')
if (value) {
if (value < nowTime) {
wx.removeStorage("searchKeysTime");
}
}
},
WechatLogin:function(){
let that = this
wx.login({
success: function (res) {
//登录成功
if (res.code) {
// 这里是用户的授权信息每次都不一样
let code = res.code;
wx.getUserInfo({
success: function (info) {
wx.setStorageSync('userInfo', info.userInfo);
that.globalData.userInfo = info.userInfo;
typeof cb == "function" && cb(that.globalData.userInfo)
// 请求自己的服务器
Login(code, info.userInfo);
},fail:function(e){
console.log(e);
}
})
}
}, fail: function (e) {
console.log(e);
}
})
},
getUserInfo: function (cb) {
let that = this
if (this.globalData.userInfo) {
console.log(cb);
typeof cb == "function" && cb(this.globalData.userInfo)
} else {
wx.checkSession({
success: function () {
let userInfo=wx.getStorageSync('userInfo');
if(userInfo){
that.globalData.userInfo = userInfo;
}else{
that.WechatLogin();
}
console.log("success login");
},fail(){
that.WechatLogin();
}});
}
}
})
微信
1
https://gitee.com/wp950820/koki-reading.git
git@gitee.com:wp950820/koki-reading.git
wp950820
koki-reading
柯基阅读
master

搜索帮助