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);
|
}
|
}
|