blob: 7e7902febebe4fbc142ea4b79189abe4a93c2478 [file] [log] [blame]
//app.js
var server = 'https://yy.dlsmk.cn/payapi/mobileapi';
wx.$doCountdown=function(that){
var inter = setInterval(function () {
that.setData({
smsFlag: false,
sendColor: '#cccccc',
sendTime: that.data.snsMsgWait + 's后重发',
snsMsgWait: that.data.snsMsgWait - 1
});
if (that.data.snsMsgWait < 0) {
clearInterval(inter)
that.setData({
smsFlag: true,
sendColor: 'rgb(124, 255, 112)',
sendTime: '获取验证码',
snsMsgWait: 30
});
}
}.bind(that), 1000);
}
wx.$checkBankcard=function() {
var userid = wx.getStorageSync("userid");
if (wx.$isEmpty(userid)) {
wx.showModal({
title: '提示',
content: '使用该功能前请先绑卡',
})
return false;
}
return true;
}
wx.$doPost = function(url, param, callback) {
var token = wx.getStorageSync("token") || '';
var tenantid = wx.getStorageSync("tenantid") || '';
var auth = 'Bearer ' + token;
var tenantid = tenantid;
wx.request({
url: server + url,
timeout: 10000,
method: 'POST',
header: {
'content-type': 'application/x-www-form-urlencoded',
'Authorization': auth,
'X-TENANT-ID': tenantid
},
data: param,
success: function(result) {
console.log(result);
if (callback) {
callback(true, result)
}
},
fail: function(result) {
console.log(result);
var status=result.status;
if (status && status == 401) {
wx.redirectTo({
url: '../wxlogin/wxlogin'
})
} else {
if (callback) {
callback(false, result)
}
}
}
})
}
wx.$isEmpty = function(str) {
if (!str || str == 'undefined' || str == null || str == '') {
return true;
}
return false;
}
wx.$getUUID = function(str) {
var d = new Date().getTime();
if (window.performance && typeof window.performance.now === "function") {
d += performance.now(); //use high-precision timer if available
}
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});
return uuid;
}
App({
onLaunch: function() {
// 展示本地存储能力
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
}
})
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
}
})
}
}
})
},
globalData: {
userInfo: null
}
})