package com.ruoyi.message.sms.provider.hzszlyy; import com.ruoyi.message.MessageChannel; import com.ruoyi.message.SendResult; import com.ruoyi.message.sms.AbstractSmsSender; import com.ruoyi.message.sms.SmsSendRequest; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; /** * 杭州市一短信发送方({@code hzszlyy} 通道)。 *
* ⚠️ 该通道有两个院区、两套短信签名,必须区分开: *
* 成功判定:HTTP 200({@link ShiyiSmsApi} 返回 {@code "true"}),或响应字符串包含「处理成功」。 * 代码来源:{@code RyTask.hzszlyy 分支}(行为保持不变)。 */ @Slf4j @Component public class ShiyiSmsSender extends AbstractSmsSender { /** * 渠道 key,与 {@code spring.profiles.active=hzszlyy} 对应 */ public static final String KEY = "hzszlyy"; /** * 院区编码:湖滨 */ public static final String CAMPUS_HIBIN = "1"; private final ShiyiSmsApi shiyiSmsApi; public ShiyiSmsSender(ShiyiSmsApi shiyiSmsApi) { this.shiyiSmsApi = shiyiSmsApi; } @Override public String key() { return KEY; } @Override public String description() { return "杭州市一短信(吴山/湖滨两套签名)"; } @Override protected SendResult doSend(SmsSendRequest request) { boolean hibin = CAMPUS_HIBIN.equals(request.getCampus()); String result = hibin ? shiyiSmsApi.sendHibin(request.getPhone(), request.getContent()) : shiyiSmsApi.sendWushan(request.getPhone(), request.getContent()); log.info("【{}】市一短信发送结果({}):{}", KEY, hibin ? "湖滨" : "吴山", result); // ⚠️ 这里必须与 /sms/sendTest 的成功判定保持一致: // ShiyiSmsApi 底层用的是 HttpUtil.postJsonRequest,HTTP 200 时固定返回 "true" // (非 200 会直接抛异常),并不会返回网关报文里的「处理成功」。 // 原判断只认「处理成功」,导致 sendTest 能发、定时任务却一律判失败。 boolean accepted = StringUtils.isNotEmpty(result) && ("true".equalsIgnoreCase(result) || result.contains("处理成功")); if (accepted) { return SendResult.success(KEY, MessageChannel.SMS, result).withCode(result); } return SendResult.fail(KEY, MessageChannel.SMS, "短信发送失败", result).withCode(result); } }