liusheng
2026-10-10 0afac42fb2e9d6e5291304dd0044ce3042b45d2b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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} 通道)。
 * <p>
 * ⚠️ 该通道有两个院区、两套短信签名,必须区分开:
 * <ul>
 *   <li>{@link SmsSendRequest#getCampus()} 为 {@code "1"} → 湖滨院区({@code smsUtils.sendSms1});</li>
 *   <li>其他(含为空)→ 吴山院区({@code smsUtils.sendSms})。</li>
 * </ul>
 * 判定依据来自 {@code RyTask} 中通过 {@code SysDept.campusid} 查到的院区编码,
 * 调用方负责把 {@code campus} 传进来;不传则保持与线上「非湖滨即吴山」一致的默认行为。
 * <p>
 * 成功判定:网关返回字符串包含「处理成功」。
 * 代码来源:{@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);
        if (StringUtils.isNotEmpty(result) && result.contains("处理成功")) {
            return SendResult.success(KEY, MessageChannel.SMS, result).withCode(result);
        }
        return SendResult.fail(KEY, MessageChannel.SMS, "短信发送失败", result).withCode(result);
    }
}