bug
This commit is contained in:
@ -5,6 +5,8 @@ import cn.hutool.captcha.AbstractCaptcha;
|
||||
import cn.hutool.captcha.generator.CodeGenerator;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -76,7 +78,7 @@ public class CaptchaController {
|
||||
SmsResponse smsResponse = smsBlend.sendMessage(phonenumber, map);
|
||||
if (!smsResponse.isSuccess()) {
|
||||
log.error("验证码短信发送异常 => {}", smsResponse);
|
||||
return R.fail(smsResponse.getData().toString());
|
||||
return R.fail(parseData(smsResponse));
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
@ -140,4 +142,35 @@ public class CaptchaController {
|
||||
return R.ok(captchaVo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static String parseData(SmsResponse smsResponse ) {
|
||||
try {
|
||||
JSONObject json = JSONUtil.parseObj(smsResponse.getData());
|
||||
// 核心:用 JsonUtil 解析 data,通过键路径 "Response.SendStatusSet[0].Code" 提取字段
|
||||
// 键路径规则:层级用 "." 分隔,列表索引用 "[0]" 表示(第 1 个元素)
|
||||
String code = json.getByPath("Response.SendStatusSet[0].Code", String.class);
|
||||
System.out.println("错误码:" + code); // 输出:FailedOperation.InsufficientBalanceInSmsPackage
|
||||
return convert(code);
|
||||
} catch (Exception e) {
|
||||
return "短信发送未知错误";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String convert(String code) {
|
||||
return switch (code) {
|
||||
case "FailedOperation.InsufficientBalanceInSmsPackage" -> "套餐包余量不足,请购买套餐包";
|
||||
case "InternalError.SendAndRecvFail" -> "短信收发超时,请检查您的网络是否有波动";
|
||||
case "InvalidParameterValue.IncorrectPhoneNumber" -> "手机号格式错误";
|
||||
case "LimitExceeded.AppCountryOrRegionDailyLimit" -> "业务短信国家/地区日下发条数超过设定的上限";
|
||||
case "LimitExceeded.AppDailyLimit" -> "业务短信日下发条数超过设定的上限";
|
||||
case "LimitExceeded.PhoneNumberDailyLimit" -> "单个手机号日下发短信条数超过设定的上限";
|
||||
case "UnauthorizedOperation.ServiceSuspendDueToArrears" -> "欠费被停止服务";
|
||||
case "UnsupportedOperation.UnsupportedRegion" -> "不支持该地区短信下发";
|
||||
default -> "短信发送未知错误";
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user