From c1d20b425b10e8ba59f102dd1ab413055883eed0 Mon Sep 17 00:00:00 2001 From: 彭雪彬 <1724387007@qq.com> Date: Mon, 14 Jul 2025 16:57:11 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/xin' into pxb --- oying-system/src/main/java/com/oying/modules/security/service/WeiXinService.java | 37 ++++++++++++++++++++++++++++--------- 1 files changed, 28 insertions(+), 9 deletions(-) diff --git a/oying-system/src/main/java/com/oying/modules/security/service/WeiXinService.java b/oying-system/src/main/java/com/oying/modules/security/service/WeiXinService.java index 2fe0146..0c3efe8 100644 --- a/oying-system/src/main/java/com/oying/modules/security/service/WeiXinService.java +++ b/oying-system/src/main/java/com/oying/modules/security/service/WeiXinService.java @@ -2,6 +2,10 @@ import com.alibaba.fastjson2.JSONObject; import com.oying.modules.security.config.WeiXinProperties; +import com.oying.modules.system.domain.User; +import com.oying.modules.system.domain.UserSubscribe; +import com.oying.modules.system.service.UserService; +import com.oying.modules.system.service.UserSubscribeService; import com.oying.utils.HttpRequest; import com.oying.utils.RedisUtils; import lombok.extern.slf4j.Slf4j; @@ -24,6 +28,10 @@ private RedisUtils redisUtils; @Value("${wx.enabled}") private Boolean wxEnabled; + @Resource + private UserSubscribeService subscribeService; + @Resource + private UserService userService; /** * POST 获取稳定版接口调用凭据 获取小程序全局唯一后台接口调用凭据,token有效期为7200s,开发者需要进行妥善保存。 @@ -61,7 +69,7 @@ url = url.replace("{appid}", weiXinProperties.getAppId()) .replace("{secret}", weiXinProperties.getAppSecret()) .replace("{js_code}", js_code); - return HttpRequest.exchangeJsonObject(HttpMethod.GET, url, null); + return JSONObject.parseObject(HttpRequest.exchangeString(HttpMethod.GET, url, null)); } /** @@ -81,19 +89,30 @@ /** * POST 该接口用于发送订阅消息。 * - * @param data 请求参数 - * @return JSONObject + * @param data 请求参数 + * @param openid 用户openId + * @param templateId 订阅模板id + * @param page 小程序跳转链接 */ - public JSONObject sendMessage(Map<String, Object> data, String openId, String templateId, String page) { + public void sendMessage(Map<String, Object> data, String openid, String templateId, String page) { + JSONObject jsonObject = new JSONObject(); if (wxEnabled) { String url = weiXinProperties.getSendMessage(); url = url.replace("{accessToken}", getStableAccessToken()); - Map<String, Object> map = getSendMessageDto(data, openId, templateId, page); - return HttpRequest.exchangeJsonObject(HttpMethod.POST, url, map); + Map<String, Object> map = getSendMessageDto(data, openid, templateId, page); + jsonObject = HttpRequest.exchangeJsonObject(HttpMethod.POST, url, map); + } else { + jsonObject.put("message", "测试环境"); } - JSONObject jsonObject = new JSONObject(); - jsonObject.put("message", "测试环境"); - return jsonObject; + User user = userService.findByOpenid(openid); + UserSubscribe sub = new UserSubscribe(); + sub.setSubType(templateId); + sub.setUserId(user.getId()); + sub.setOpenid(openid); + sub.setUsername(user.getUsername()); + sub.setSendMessage(JSONObject.toJSONString(data)); + sub.setSubMessage(jsonObject.toJSONString()); + subscribeService.save(sub); } private Map<String, Object> getSendMessageDto(Map<String, Object> data, String openId, String templateId, String page) { -- Gitblit v1.9.3