|
@@ -1,7 +1,12 @@
|
|
|
package com.flyer.foster.controller.app;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
|
|
import com.flyer.foster.consts.WechatConst;
|
|
|
+import com.flyer.foster.dto.app.AppSubscribeRespDTO;
|
|
|
import com.flyer.foster.dto.app.AppUserQueryDTO;
|
|
|
+import com.flyer.foster.entity.AppSubscribe;
|
|
|
+import com.flyer.foster.entity.AppUser;
|
|
|
+import com.flyer.foster.service.IAppSubscribeService;
|
|
|
import com.flyer.foster.service.IAppUserService;
|
|
|
import com.flyer.foster.util.WeChatApiUtil;
|
|
|
import com.flyer.foster.util.WxAccessToken;
|
|
@@ -11,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -31,6 +37,8 @@ public class AppUserController {
|
|
|
@Autowired
|
|
|
private WeChatApiUtil weChatApiUtil;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IAppSubscribeService iAppSubscribeService;
|
|
|
|
|
|
@RequestMapping("/login")
|
|
|
public R login(@RequestBody AppUserQueryDTO dto) {
|
|
@@ -54,12 +62,26 @@ public class AppUserController {
|
|
|
|
|
|
/**
|
|
|
* 给订阅用户发送消息
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("/send-sub-msg")
|
|
|
public R sendSubscribeMessage() {
|
|
|
String accessToken = weChatApiUtil.getAccessToken(WechatConst.APP_ID, WechatConst.APP_SECRET);
|
|
|
- weChatApiUtil.subscribeMessage(accessToken, "oiUkI7dJILmw43YavQ6SD9BuiDsU", WechatConst.SUBSCRIBE_TEMPLATE1);
|
|
|
+
|
|
|
+ // 获取已经订阅用户信息
|
|
|
+ List<AppSubscribeRespDTO> subscribeUserInfoList = iAppSubscribeService.getSubscribeUserInfo();
|
|
|
+ for (AppSubscribeRespDTO respDTO : subscribeUserInfoList) {
|
|
|
+ int count = respDTO.getCount();
|
|
|
+ // 订阅次数-1
|
|
|
+ iAppSubscribeService
|
|
|
+ .lambdaUpdate()
|
|
|
+ .set(AppSubscribe::getCount, --count)
|
|
|
+ .eq(AppSubscribe::getAppUserId, respDTO.getAppUserId())
|
|
|
+ .update();
|
|
|
+ // 给订阅用户发消息
|
|
|
+ weChatApiUtil.subscribeMessage(accessToken, respDTO.getOpenId(), WechatConst.SUBSCRIBE_TEMPLATE1);
|
|
|
+ }
|
|
|
return R.ok();
|
|
|
}
|
|
|
}
|