4 Star 0 Fork 4

hydrid/cnblogs-wxa

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
app.js 2.72 KB
一键复制 编辑 原始数据 按行查看 历史
dlj 提交于 2017-04-08 18:37 . 回答和评论删除,评论详情页
//app.js
App({
onLaunch: function () {
//调用API从本地缓存中获取数据
var logs = wx.getStorageSync('logs') || [];
logs.unshift(Date.now());
wx.setStorageSync('logs', logs);
},
getAccessToken: function (cb) {
var that = this;
if (that.accessToken) {
typeof cb == "function" && cb(this.accessToken);
} else {
wx.request({
url: 'https://api.cnblogs.com/token', //仅为示例,并非真实的接口地址
method: 'POST',
data: {
username: 'g9dDrMoMV4DzZrOAMcAnCegdisk20T6ddm6ySsUrbpdeID7bL9iV5QcjRISv/2/QfwK5SGClWe7YX8FAghw0jZYTtjUnB1kyPN5H712oKmxiVKMLzm35Yd6kYu5dql/FsCGujeEuzIxN9Mu92g1Xve92jZDz8nLIPe4vhk3nt1I=',
password: 'kTYhPUx6wxSTwWicd+7w5vhIgx6m0QzMYR5LCWmgICSmy+qWJbjpqi4U2/U0i0dSxFVnF9f1iyW9poPbW1xgHcQ46SGwQSRLv2SNnqwMEWph5DzGnMQzE1w7C5hVDMS2YwS8RgAO+U5euG778uCWAu/SejzeCf+37HqJrjN1IzQ=',
grant_type: 'password'
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic NTMxMmI0ZDMtODk3YS00ZWFjLTlkZmMtZWJiYzNkMTYwYmY1Ok5MdWtlRHRlMDktMkV5ZjBhbnFsZXpOeVZGTTVSb0N0SjF0d3dLTXZRalcwdFNWYmlzR3Y2MXRjblVnbjFfaHMyWTZrcU8yQ0xheDVlOTIw'
},
success: function (res) {
that.accessToken = res.data.accessToken;
typeof cb == "function" && cb(that.globalData.accessToken);
},
fail: function () {
console.log('获取token失败!');
}
});
}
},
getUserInfo: function (cb) {
var that = this;
var accessToken = that.accessToken;
if (this.user) {
typeof cb == "function" && cb(this.user);
} else {
wx.request({
url: 'https://api.cnblogs.com/api/Users', //仅为示例,并非真实的接口地址
method: 'GET',
data: {
},
header: {
'Authorization': 'Bearer ' + accessToken
},
success: function (res) {
that.user = res.data;
typeof cb == "function" && cb(that.user);
},
fail: function () {
console.log('获取用户信息失败!');
}
});
}
},
user: null,
accessToken: 'oIyW4j2T6YdaCs6ou-4iosGlp_2E4rs-IV7WRYj8kYJiU1np6jaL_HMZ9daHoVGaTFaF63mWgf80-7VqA3KGHPh7Nkp4gisDz26iTgc3i1IOQeZZMc15W2ytqi1SslFf9qlaIqY3QW7bHUEhY3ViaA052_15JX5yLNhJUuo1TW6TioDrZTp1w4378DBAh9zlyo9RColn6w3e3_3xXaoU3g'
});
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
微信
1
https://gitee.com/hydrid/cnblogs-wxa.git
git@gitee.com:hydrid/cnblogs-wxa.git
hydrid
cnblogs-wxa
cnblogs-wxa
master

搜索帮助