56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
// app.js
|
|
import {
|
|
make_new_session_id,
|
|
} from './utils.js';
|
|
|
|
App({
|
|
onLaunch() {
|
|
// 展示本地存储能力
|
|
const logs = wx.getStorageSync('logs') || []
|
|
logs.unshift(Date.now())
|
|
wx.setStorageSync('logs', logs)
|
|
this.globalData.verify_failures = 0;
|
|
// 登录
|
|
wx.login({
|
|
success: res => {
|
|
// 发送 res.code 到后台换取 openId, sessionKey, unionId
|
|
}
|
|
})
|
|
this.get_real_ip();
|
|
// On iOS, the js runtime is reported to be too slow for wasm, use experimental JIT worker.
|
|
// https://developers.weixin.qq.com/community/develop/doc/000cac2319cbd8ecdc7f062eb53400
|
|
this.globalData.get_worker = () => {
|
|
if (!this.globalData.worker) {
|
|
this.globalData.worker = wx.createWorker('worker/index.js', {
|
|
useExperimentalWorker: true,
|
|
});
|
|
}
|
|
return this.globalData.worker;
|
|
}
|
|
},
|
|
onShow(options) {
|
|
if (options.referrerInfo && options.referrerInfo.extraData && options.referrerInfo.extraData.caller_info) {
|
|
var ci = options.referrerInfo.extraData.caller_info;
|
|
this.globalData.caller_info = ci;
|
|
}
|
|
},
|
|
globalData: {
|
|
userInfo: null,
|
|
server_url: 'https://themblem.com',
|
|
session_id: make_new_session_id(),
|
|
},
|
|
|
|
get_real_ip() {
|
|
this.globalData.real_ip = "0.0.0.0";
|
|
wx.request({
|
|
url: "https://whatsmyip.themblem.com",
|
|
success: (res) => {
|
|
var rip = res.data;
|
|
console.log("my real ip:", rip);
|
|
this.globalData.real_ip = rip;
|
|
}
|
|
}
|
|
);
|
|
}
|
|
})
|