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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.ruoyi.message.sms.provider.hzszlyy;
 
import com.ruoyi.common.utils.HttpUtil;
import com.ruoyi.common.utils.sign.Md5Utils;
import com.ruoyi.message.config.MessageProperties;
import com.ruoyi.message.config.XhsmsConfig;
import com.ruoyi.message.config.RootMessageProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
 
import java.util.Date;
 
/**
 * 杭州市一短信网关 API(新华网关地址 + 市一自有签名算法)。
 * <p>
 * 对接特征:JSON 报文 {@code userName/content/phoneList/timestamp/sign},
 * 签名为 {@code MD5(userName + timestamp + MD5(passWord))}。
 * <p>
 * ⚠️ 站点差异(必须区分,不能合并):
 * <ul>
 *   <li>吴山院区:签名前缀 {@code 【杭州市肿瘤医院】};</li>
 *   <li>湖滨院区:签名前缀 {@code 【杭州市第一人民医院】}。</li>
 * </ul>
 * 原实现分两个方法 {@code smsUtils.sendSms} / {@code smsUtils.sendSms1} 承载这一差异。
 * <p>
 * 迁移说明:原类为 {@code com.ruoyi.common.utils.sms.smsUtils},签名前缀保持不变。
 */
@Slf4j
@Component
public class ShiyiSmsApi {
 
    /**
     * 吴山院区短信签名前缀
     */
    public static final String PREFIX_WUSHAN = "【杭州市肿瘤医院】";
 
    /**
     * 湖滨院区短信签名前缀
     */
    public static final String PREFIX_HIBIN = "【杭州市第一人民医院】";
 
    private final MessageProperties properties;
 
    public ShiyiSmsApi(MessageProperties properties) {
        this.properties = properties;
    }
 
    /**
     * 吴山院区发送(等价 {@code smsUtils.sendSms})
     *
     * @return 网关返回的字符串,含「处理成功」表示成功
     */
    public String sendWushan(String phone, String content) {
        return send(phone, content, PREFIX_WUSHAN);
    }
 
    /**
     * 湖滨院区发送(等价 {@code smsUtils.sendSms1})
     *
     * @return 网关返回的字符串,含「处理成功」表示成功
     */
    public String sendHibin(String phone, String content) {
        return send(phone, content, PREFIX_HIBIN);
    }
 
    private String send(String phone, String content, String prefix) {
        XhsmsConfig cfg = properties.getSms().getXhsms();
        long timestamp = new Date().getTime();
        String sign = Md5Utils.hash(cfg.getAccount() + timestamp + Md5Utils.hash(cfg.getPwd()));
        String fullContent = prefix + content;
        String jsonMsg = "{"
                + "\"userName\": \"" + cfg.getAccount() + "\","
                + "\"content\": \"" + fullContent + "\","
                + "\"phoneList\": [" + phone + "],"
                + "\"timestamp\": " + timestamp + ","
                + "\"sign\": \"" + sign + "\""
                + "}";
        log.info("【ShiyiSmsApi】市一短信发送,地址:{},签名前缀:{},手机号:{}", cfg.getPath(), prefix, phone);
        Boolean sendMsg = HttpUtil.postJsonRequest(cfg.getPath(), jsonMsg);
        return String.valueOf(sendMsg);
    }
}