package com.ruoyi.message.wechat.provider.hzszlyy;
|
|
import com.ruoyi.common.utils.http.HttpUtils;
|
import com.ruoyi.message.config.MessageProperties;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Component;
|
|
/**
|
* 杭州市一微信公众号 API。
|
* <p>
|
* 对接特征:GET 请求 {@code /sfjk/SendMessage},参数 {@code sfzh/title/content/phone/url/key},
|
* 返回 JSON(判定字段 {@code success == 1})。
|
* <p>
|
* 迁移说明:原实现为 {@code com.ruoyi.common.utils.sms.smsUtils.sendChat},其中地址、密钥、
|
* 标题文案、内容文案都是硬编码;这里全部提为可配置(默认值与原硬编码一致),
|
* 便于后续按机构/任务类型区分文案,见 {@link MessageProperties.ShiyiWechat}。
|
*/
|
@Slf4j
|
@Component
|
public class ShiyiMpApi {
|
|
private final MessageProperties properties;
|
|
public ShiyiMpApi(MessageProperties properties) {
|
this.properties = properties;
|
}
|
|
/**
|
* 发送公众号消息
|
*
|
* @param url 外链地址
|
* @param phone 手机号
|
* @param idCard 身份证号
|
* @return 第三方原始响应
|
*/
|
public String sendMessage(String url, String phone, String idCard) {
|
MessageProperties.ShiyiWechat cfg = properties.getWechat().getShiyi();
|
String urlTemp = cfg.getUrl()
|
+ "?sfzh=" + idCard
|
+ "&title=" + cfg.getTitle()
|
+ "&content=" + cfg.getContent()
|
+ "&phone=" + phone
|
+ "&url=" + url
|
+ "&key=" + cfg.getKey();
|
String sendMsg = "";
|
try {
|
log.info("【ShiyiMpApi】市一微信公众号请求参数:{}", urlTemp);
|
sendMsg = HttpUtils.sendPost(urlTemp);
|
log.info("【ShiyiMpApi】市一微信公众号返回值:{}", sendMsg);
|
} catch (Exception ex) {
|
sendMsg = ex.getMessage();
|
log.error("【ShiyiMpApi】市一微信公众号发送异常:{}", ex.getMessage(), ex);
|
}
|
return sendMsg;
|
}
|
}
|