From 30127d773510a3c9c52432ae3dc1e844d08a64a0 Mon Sep 17 00:00:00 2001 From: luotaiqian <1147642922@qq.com> Date: Mon, 6 Jul 2026 18:06:15 +0800 Subject: [PATCH] sms --- .../infrastructure/remote/SmsRemote.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/safety-eval-infrastructure/src/main/java/org/qinan/safetyeval/infrastructure/remote/SmsRemote.java b/safety-eval-infrastructure/src/main/java/org/qinan/safetyeval/infrastructure/remote/SmsRemote.java index 3392165..44a1ba6 100644 --- a/safety-eval-infrastructure/src/main/java/org/qinan/safetyeval/infrastructure/remote/SmsRemote.java +++ b/safety-eval-infrastructure/src/main/java/org/qinan/safetyeval/infrastructure/remote/SmsRemote.java @@ -162,13 +162,23 @@ public class SmsRemote { String body = resp.getBody(); log.info("助通短信发送响应: status={}, body={}", resp.getStatusCodeValue(), body); - // 融合云成功返回 HTTP 200,且响应 JSON 中 code=200 - if (resp.getStatusCodeValue() == 200) { - response = SingleResponse.of(body); - } else { - log.warn("助通短信发送失败 - mobile={}, body={}", mobile, body); + // 融合云 HTTP 状态码恒为 200,真正结果在 body 的 code 字段(200 才算成功) + if (resp.getStatusCodeValue() != 200) { + log.warn("助通短信发送失败(HTTP) - mobile={}, body={}", mobile, body); throw new BizException("SMS_SEND_FAIL", "短信发送失败: " + body); } + + // 解析 body 中的 code 字段判断业务结果 + Map bodyMap = parseJson(body); + int code = bodyMap.get("code") instanceof Number + ? ((Number) bodyMap.get("code")).intValue() : -1; + if (code != 200) { + String msg = bodyMap.getOrDefault("msg", "未知错误").toString(); + log.error("助通短信发送失败(业务) - mobile={}, code={}, msg={}", mobile, code, msg); + throw new BizException("SMS_SEND_FAIL", + "短信发送失败[" + code + "]: " + msg); + } + response = SingleResponse.of(body); } catch (BizException e) { throw e; } catch (Exception e) { @@ -255,6 +265,17 @@ public class SmsRemote { return sb.toString(); } + /** + * 解析 JSON 字符串为 Map(基于 hutool JSONUtil) + */ + @SuppressWarnings("unchecked") + private Map parseJson(String json) { + if (StringUtils.isBlank(json)) { + return Collections.emptyMap(); + } + return JSONUtil.parseObj(json); + } + @ApiOperation("发送短信") @PostMapping("/sendMessage")