代码拉取完成,页面将自动刷新
//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'
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。