审批同意后,推送订阅消息

This commit is contained in:
chenglijuan
2026-04-24 09:31:22 +08:00
parent ec461fd1f4
commit c88b047d01
6 changed files with 132 additions and 89 deletions
@@ -14,13 +14,13 @@ import java.util.Map;
/**
* 微信小程序订阅消息服务
* 调用微信 /cgi-bin/message/subscribe/send 接口推送订阅消息
*
* <p>
* 模板字段映射:
* name1 (姓名) → 访客姓名
* thing3 (事物) → 来访事由
* date8 (日期) → 预约时间
* thing10 (事物) → 到访区域
* phrase18 (短语) → 审批状态
* name1 (姓名) → 访客姓名
* thing3 (事物) → 来访事由
* date8 (日期) → 预约时间
* thing10 (事物) → 到访区域
* phrase18 (短语) → 审批状态
*/
@Slf4j
@Service
@@ -38,7 +38,9 @@ public class WxSubscribeMessageService {
@Value("${wx.miniapp.subscribe-template-id:}")
private String templateId;
/** 获取小程序 access_token */
/**
* 获取小程序 access_token
*/
public String getAccessToken() {
String url = String.format(GET_TOKEN_URL, wxMiniAppConfig.getAppid(), wxMiniAppConfig.getSecret());
try {
@@ -57,12 +59,11 @@ public class WxSubscribeMessageService {
* 所有字段不允许为空字符串(微信返回47003),name类型不接受纯数字
*/
public void sendSubscribeMessage(String openid, String visitorName, String reason,
String visitTime, String area, String status) {
String visitTime, String area, String status) {
if (templateId == null || templateId.isEmpty()) {
log.warn("未配置 subscribe-template-id,跳过订阅消息推送");
return;
}
String accessToken = getAccessToken();
String url = String.format(SEND_MSG_URL, accessToken);
@@ -82,8 +83,10 @@ public class WxSubscribeMessageService {
Map<String, Object> body = new HashMap<>();
body.put("touser", openid);
body.put("template_id", templateId);
//点击模板卡片后的跳转页面,仅限本小程序内的页面。
body.put("page", "pages/records/records");
body.put("data", data);
//跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
body.put("miniprogram_state", "formal");
body.put("lang", "zh_CN");