Generation

code to explanationMon, 14 Nov 2022

function checkValidOrderId(orderid, account, platid, outputObject) { if (typeof orderid !== 'string') { throw new Error('参数错误,orderid非法'); } //格式:代理编号 +yyyyMMddHHmmssSSS+ account if (account != null) account = `${account}`; platid = `${platid}`; if (!orderid.startsWith(platid)) throw new Error('参数错误,orderid非法,没有以代理编号开头'); let s; if (account == null) { s = orderid.substring(platid.length); //account = s.substring(17); if (outputObject) outputObject.account = s.substring(17); s = s.substring(0, 17); if (s.length !== 17) throw new Error('参数错误,orderid非法'); } else { if (!orderid.endsWith(account)) throw new Error('参数错误,orderid非法,没有以account结尾'); s = orderid.substring(platid.length, orderid.length - account.length); } checkValidOrderIdOnly(s); }

function checkValidOrderIdOnly(s) { let len = s.length; if (len !== 17) throw new Error('参数错误,orderid非法'); let v = parseInt(s); if (!Number.isFinite(v)) throw new Error('参数错误,orderid非法'); let d = new Date(v); if (d.getTime() !== v) throw new Error('参数错误,orderid非法'); let now = Date.now(); if (v > now || v < now - 24 * 60 * 60 * 1000) throw new Error('参数错误,orderid非法'); }

Questions about programming?Chat with your personal AI assistant