{"record":{"id":"becbbe58689f2c73","repo":"elunez/eladmin","slug":"error-becbbe","errorCode":null,"errorMessage":"测试金额过大","messagePattern":"测试金额过大","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"warning","filePath":"eladmin-tools/src/main/java/me/zhengjie/service/impl/AliPayServiceImpl.java","lineNumber":101,"sourceCode":"                \"    \\\"sys_service_provider_id\\\":\\\"\"+alipay.getSysServiceProviderId()+\"\\\"\" +\n                \"    }\"+\n                \"  }\");//填充业务参数\n        // 调用SDK生成表单, 通过GET方式，口可以获取url\n        return alipayClient.pageExecute(request, \"GET\").getBody();\n\n    }\n\n    @Override\n    public String toPayAsWeb(AlipayConfig alipay, TradeVo trade) throws Exception {\n        if(alipay.getId() == null){\n            throw new BadRequestException(\"请先添加相应配置，再操作\");\n        }\n        AlipayClient alipayClient = new DefaultAlipayClient(alipay.getGatewayUrl(), alipay.getAppId(), alipay.getPrivateKey(), alipay.getFormat(), alipay.getCharset(), alipay.getPublicKey(), alipay.getSignType());\n\n        double money = Double.parseDouble(trade.getTotalAmount());\n        double maxMoney = 5000;\n        if(money <= 0 || money >= maxMoney){\n            throw new BadRequestException(\"测试金额过大\");\n        }\n        // 创建API对应的request(手机网页版)\n        AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();\n        request.setReturnUrl(alipay.getReturnUrl());\n        request.setNotifyUrl(alipay.getNotifyUrl());\n        request.setBizContent(\"{\" +\n                \"    \\\"out_trade_no\\\":\\\"\"+trade.getOutTradeNo()+\"\\\",\" +\n                \"    \\\"product_code\\\":\\\"FAST_INSTANT_TRADE_PAY\\\",\" +\n                \"    \\\"total_amount\\\":\"+trade.getTotalAmount()+\",\" +\n                \"    \\\"subject\\\":\\\"\"+trade.getSubject()+\"\\\",\" +\n                \"    \\\"body\\\":\\\"\"+trade.getBody()+\"\\\",\" +\n                \"    \\\"extend_params\\\":{\" +\n                \"    \\\"sys_service_provider_id\\\":\\\"\"+alipay.getSysServiceProviderId()+\"\\\"\" +\n                \"    }\"+\n                \"  }\");\n        return alipayClient.pageExecute(request, \"GET\").getBody();\n    }\n}","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-tools/src/main/java/me/zhengjie/service/impl/AliPayServiceImpl.java#L83-L119","documentation":"Thrown by AliPayServiceImpl.toPayAsWeb when Double.parseDouble(trade.getTotalAmount()) is <= 0 or >= 5000 (hard-coded maxMoney = 5000). It is a demo-safety guard for the sandbox payment feature: amounts must be strictly between 0 and 5000. A NumberFormatException would instead escape parseDouble if totalAmount is not numeric.","triggerScenarios":"POST to the WAP pay endpoint with totalAmount \"0\", a negative value, exactly \"5000\" or above, or an empty string (parsed as 0.0 after trim? no — empty throws NumberFormatException). The boundary is exclusive: exactly 5000 also fails.","commonSituations":"Test orders with large amounts in demos; frontend sending amount in cents (e.g. \"500000\") instead of yuan; locale formatting (\"1.299,00\" or \"1,299.00\") that either throws NumberFormatException or inflates the value; copying production-like amounts into the demo pay feature.","solutions":["Send totalAmount as a plain numeric string in yuan between 0 and 5000, e.g. \"9.90\".","Fix the frontend unit (yuan, not cents) and strip thousands separators before submitting.","If this is a real integration (not the demo), raise or make maxMoney configurable instead of editing the hard-coded 5000 inline.","Validate the amount format client-side before calling the API to avoid NumberFormatException on non-numeric input."],"exampleFix":"// before\ndouble money = Double.parseDouble(trade.getTotalAmount());\ndouble maxMoney = 5000;\nif(money <= 0 || money >= maxMoney){\n    throw new BadRequestException(\"测试金额过大\");\n}\n\n// after: explicit message per branch\nBigDecimal money = new BigDecimal(trade.getTotalAmount());\nif(money.compareTo(BigDecimal.ZERO) <= 0){\n    throw new BadRequestException(\"金额必须大于 0\");\n}\nif(money.compareTo(new BigDecimal(\"5000\")) >= 0){\n    throw new BadRequestException(\"测试金额过大，请控制在 5000 以内\");\n}","handlingStrategy":"validation","validationCode":"// mirror the server rule before submitting\nconst amount = Number(totalAmount);\nif (!(amount > 0 && amount < 5000)) { showToast('金额必须在 0 到 5000 之间'); return; }","typeGuard":null,"tryCatchPattern":"try { aliPayService.toPayAsWeb(alipay, trade); } catch (BadRequestException e) { if (\"测试金额过大\".equals(e.getMessage())) { /* clamp or ask for smaller amount; note boundary 5000 itself is rejected */ } }","preventionTips":["Always send totalAmount as a plain numeric string in yuan without separators.","Keep client and server bounds in sync (5000 exclusive) to avoid the exact-boundary surprise.","Prefer BigDecimal parsing server-side to avoid float artifacts on amounts."],"tags":["alipay","payment","amount-validation","business-rule"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}