|
|
@@ -5,15 +5,19 @@ import cn.dev33.satoken.annotation.SaIgnore;
|
|
|
import com.kym.common.annotation.ApiLog;
|
|
|
import com.kym.common.annotation.SysLog;
|
|
|
import com.kym.common.utils.wx.WxPbUtil;
|
|
|
+import com.kym.common.R;
|
|
|
+import com.kym.service.MpRelationService;
|
|
|
import com.kym.service.wechat.WeixinMPService;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
|
|
@@ -24,28 +28,21 @@ import java.io.PrintWriter;
|
|
|
public class WeixinMPController {
|
|
|
|
|
|
private final WeixinMPService weixinMPService;
|
|
|
+ private final MpRelationService mpRelationService;
|
|
|
|
|
|
- public WeixinMPController(WeixinMPService weixinMPService) {
|
|
|
+ public WeixinMPController(WeixinMPService weixinMPService, MpRelationService mpRelationService) {
|
|
|
this.weixinMPService = weixinMPService;
|
|
|
+ this.mpRelationService = mpRelationService;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 消息通知(订阅、用户消息)
|
|
|
- *
|
|
|
- * @param request
|
|
|
- */
|
|
|
-
|
|
|
-// @PostMapping(value = "notify", produces = MediaType.TEXT_XML_VALUE)
|
|
|
-// @ApiLog(value = "微信公众号服务器推送消息", ignoreParams = true)
|
|
|
-// public void handleMessage(HttpServletRequest request, HttpServletResponse response) {
|
|
|
-// weixinMPService.handleWxMPNotify(request, response);
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
- /*
|
|
|
-
|
|
|
-
|
|
|
*/
|
|
|
+ @PostMapping(value = "notify", produces = MediaType.TEXT_XML_VALUE)
|
|
|
+ @ApiLog(value = "微信公众号服务器推送消息", ignoreParams = true)
|
|
|
+ public void handleMessage(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ weixinMPService.handleWxMPNotify(request, response);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 微信服务器token验证
|
|
|
@@ -76,19 +73,20 @@ public class WeixinMPController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// @GetMapping(value = "/test")
|
|
|
-// public void test() throws WxErrorException {
|
|
|
-// WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
|
|
|
-// .toUser("oK-oR5gAn9hrYNim4x64l4kzmMXs")
|
|
|
-// .templateId("SjszYYiHcN-GaEeZTKJsCcB6ACxYJWfTddkSywf1q1g")
|
|
|
-// .url("")
|
|
|
-// .build();
|
|
|
-// templateMessage.addData(new WxMpTemplateData("character_string2.DATA", "000001"));
|
|
|
-// templateMessage.addData(new WxMpTemplateData("thing9.DATA}", "测试站点"));
|
|
|
-// templateMessage.addData(new WxMpTemplateData("character_string3.DATA", "编号001"));
|
|
|
-// templateMessage.addData(new WxMpTemplateData("time4.DATA", "2022-12-01 19:30:00"));
|
|
|
-// wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
|
|
|
-//
|
|
|
-// }
|
|
|
+ /**
|
|
|
+ * 手动同步公众号关注用户(一次性触发)
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/syncMpUsers")
|
|
|
+ @SaIgnore
|
|
|
+ @ResponseBody
|
|
|
+ public R<?> syncMpUsers() {
|
|
|
+ try {
|
|
|
+ mpRelationService.batchBindMpUser();
|
|
|
+ return R.success("同步完成");
|
|
|
+ } catch (WxErrorException e) {
|
|
|
+ log.error("手动同步公众号用户失败", e);
|
|
|
+ return R.failed("同步失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|