2019-11-13 12:02:33 +08:00

121 lines
2.3 KiB
JavaScript

const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : '0' + n
}
const getMD5 = obj => {
let secret = 'wx0df150c438e4c8f0'
let keys = Object.keys(obj)
keys.sort()
let params = []
keys.forEach(e => {
if (obj[e] != null) {
params.push(e + '=' + obj[e])
}
})
params.push('key=' + secret)
let paramStr = params.join('&')
const md5Util = require('./md5.js')
let signResult = md5Util.md5(paramStr).toUpperCase()
return signResult
}
const checkFlag = (arg,flag, callBack) => {
flag--
console.log(arg)
console.log(flag)
if(flag == 0) {
callBack && callBack()
}
return flag
}
const checkInput = (type,content) => {
switch(type) {
case 'alcode': {
return 'alcode'
}
case 'qqcode': {
return 'qqcode'
}
case 'wxcode': {
return 'wxcode'
}
case 'username': {
return 'username'
}
case 'node': {
return 'node'
}
case 'month': {
return 'month'
}
}
}
const checkSubmit = (c) => {
var codeStatus = 0
if (c.wxcode) codeStatus++
if (c.qqcode) codeStatus++
if (c.alcode) codeStatus++
if (codeStatus < 2) {
wx.showToast({
title:'请至少录入两张二维码呦',
icon: 'none'
})
return false
}
if (!c.username) {
wx.showToast({
title:'请输入您的标题',
icon: 'none'
})
return false
}
if(!c.month) {
wx.showToast({
title: '请输入您的使用时长',
icon: 'none'
})
return false
}
var data = {}
data['wxcode'] = c.wxcode
data['alcode'] = c.alcode
data['qqcode'] = c.qqcode
data['username'] = c.username
data['openId'] = c.openId
data['node'] = c.node
data['timeout'] = ((new Date()).getTime() + 1000*60*60*24*30*c.month).toString()
var totalFee = c.month * 0.5
return {
data: data,
totalFee: totalFee
}
}
module.exports = {
formatTime: formatTime,
getMD5: getMD5,
checkFlag: checkFlag,
checkSubmit: checkSubmit,
checkInput: checkInput
}