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