151 lines
3.3 KiB
JavaScript
151 lines
3.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': {
|
|
if(content.indexOf('qr.alipay.com') != -1) {
|
|
return content
|
|
} else if (content.indexOf('QR.ALIPAY.COM') != -1) {
|
|
return content
|
|
} else {
|
|
wx.showToast({
|
|
title: '请扫描合格的支付宝收款码',
|
|
icon: 'none'
|
|
})
|
|
return ''
|
|
}
|
|
}
|
|
case 'qqcode': {
|
|
if(content.indexOf('qianbao.qq.com') != -1) {
|
|
return content
|
|
} else {
|
|
wx.showToast({
|
|
title:'请扫描合格的QQ收款码',
|
|
icon: 'none'
|
|
})
|
|
return ''
|
|
}
|
|
}
|
|
case 'wxcode': {
|
|
if(content.indexOf('wxp') != -1) {
|
|
return content
|
|
} else if(content.indexOf('payapp.weixin.qq.com') != -1) {
|
|
return content
|
|
} else {
|
|
wx.showToast({
|
|
title: '请扫描合格的微信收款码',
|
|
icon: 'none'
|
|
})
|
|
return ''
|
|
}
|
|
}
|
|
case 'username': {
|
|
content = content.replace(/"/gi,'')
|
|
content = content.replace(/ /gi,'')
|
|
content = content.replace(/'/gi,'')
|
|
content = content.replace(/\$/gi,'')
|
|
return content
|
|
}
|
|
case 'node': {
|
|
content = content.replace(/"/gi,'')
|
|
content = content.replace(/'/gi,'')
|
|
content = content.replace(/\$/gi,'')
|
|
content = content.replace(/ /gi,'')
|
|
return content
|
|
}
|
|
case 'month': {
|
|
content = parseInt(content)
|
|
if(content) {
|
|
if(0 < content && content < 13) {
|
|
return content
|
|
}
|
|
}
|
|
return ''
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
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
|
|
}
|
|
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
|
|
return data
|
|
}
|
|
|
|
module.exports = {
|
|
formatTime: formatTime,
|
|
getMD5: getMD5,
|
|
checkFlag: checkFlag,
|
|
checkSubmit: checkSubmit,
|
|
checkInput: checkInput
|
|
}
|