{"record":{"id":"e61e729349939b91","repo":"jeecgboot/JeecgBoot","slug":"item","errorCode":null,"errorMessage":"模板缺少参数：${item}","messagePattern":"模板缺少参数：(.+?)","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/DySmsHelper.java","lineNumber":143,"sourceCode":"\n        //hint 此处可能会抛出异常，注意catch\n        SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);\n        logger.info(\"短信接口返回的数据----------------\");\n        logger.info(\"{Code:\" + sendSmsResponse.getCode()+\",Message:\" + sendSmsResponse.getMessage()+\",RequestId:\"+ sendSmsResponse.getRequestId()+\",BizId:\"+sendSmsResponse.getBizId()+\"}\");\n        String ok = \"OK\";\n        if (ok.equals(sendSmsResponse.getCode())) {\n            result = true;\n        }\n        return result;\n        \n    }\n    \n    private static void validateParam(JSONObject templateParamJson,DySmsEnum dySmsEnum) {\n    \tString keys = dySmsEnum.getKeys();\n    \tString [] keyArr = keys.split(\",\");\n    \tfor(String item :keyArr) {\n    \t\tif(!templateParamJson.containsKey(item)) {\n    \t\t\tthrow new RuntimeException(\"模板缺少参数：\"+item);\n    \t\t}\n    \t}\n    }\n    \n\n//    public static void main(String[] args) throws ClientException, InterruptedException {\n//    \tJSONObject obj = new JSONObject();\n//    \tobj.put(\"code\", \"1234\");\n//    \tsendSms(\"13800138000\", obj, DySmsEnum.FORGET_PASSWORD_TEMPLATE_CODE);\n//    }\n}\n","sourceCodeStart":125,"sourceCodeEnd":155,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/DySmsHelper.java#L125-L155","documentation":"DySmsHelper sends Alibaba Cloud (Dysms) SMS messages using template codes defined in DySmsEnum. Each enum entry declares required parameter keys (comma-separated). validateParam checks that every required key is present in the templateParamJson before calling the SMS API; if any key is missing it throws RuntimeException, preventing a guaranteed-to-fail API call. This is a pre-flight validation guard for SMS template parameters.","triggerScenarios":"Calling DySmsHelper.sendSms with a JSONObject missing one of the template's declared keys — e.g. a verification-code template requiring 'code' and 'minutes' but the caller only supplies 'code'. The keys come from DySmsEnum.getKeys() for the chosen template.","commonSituations":"Adding a new SMS template and forgetting to supply all its parameters; changing a template's parameters in Alibaba console without updating the enum or the caller; a code path that builds the param JSON conditionally and omits a key.","solutions":["Supply every key declared in the DySmsEnum entry's getKeys() for the template you are using.","If a template parameter is genuinely optional, split into separate enum entries or adjust getKeys.","Log the full required-keys list alongside the error to make debugging faster.","Add a unit test asserting sendSms is always called with all required keys."],"exampleFix":"// before — missing required 'minutes' key\nJSONObject params = new JSONObject();\nparams.put(\"code\", \"1234\");\nDySmsHelper.sendSms(phone, params, DySmsEnum.REGISTER_TEMPLATE);\n\n// after — include all required keys\nparams.put(\"code\", \"1234\");\nparams.put(\"minutes\", \"5\");","handlingStrategy":"validation","validationCode":"// Pre-validate required SMS keys before sending\npublic static void validateBeforeSend(JSONObject params, DySmsEnum tpl) {\n  for (String key : tpl.getKeys().split(\",\")) {\n    if (!params.containsKey(key.trim()))\n      throw new IllegalArgumentException(\"Missing SMS param: \" + key);\n  }\n}","typeGuard":"public static boolean hasAllTemplateKeys(JSONObject params, DySmsEnum tpl) {\n  for (String key : tpl.getKeys().split(\",\")) {\n    if (!params.containsKey(key.trim())) return false;\n  }\n  return true;\n}","tryCatchPattern":"try {\n  DySmsHelper.sendSms(phone, params, tpl);\n} catch (RuntimeException e) {\n  if (e.getMessage().contains(\"模板缺少参数\")) {\n    // fill missing keys and retry, or log\n  }\n}","preventionTips":["Keep DySmsEnum key lists in sync with the Alibaba SMS template parameters.","Build the param JSON with all keys unconditionally for a given template.","Unit-test sendSms calls with the full required key set."],"tags":["backend","sms","validation","aliyun","jeecg"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}