|
|
@@ -0,0 +1,72 @@
|
|
|
+package com.cyksj.service.mange.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.cyksj.common.EnvCommonService;
|
|
|
+import com.cyksj.common.constant.TemplateEnum;
|
|
|
+import com.cyksj.common.util.Jsons;
|
|
|
+import com.cyksj.mapper.SpotifyUnLimitRecordMapper;
|
|
|
+import com.cyksj.mapper.UserMapper;
|
|
|
+import com.cyksj.model.dto.WxMpTemplateData;
|
|
|
+import com.cyksj.model.dto.WxMpTemplateMessage;
|
|
|
+import com.cyksj.model.entity.SpotifyUnLimitRecord;
|
|
|
+import com.cyksj.model.entity.User;
|
|
|
+import com.cyksj.service.mange.SpotifySendMsgService;
|
|
|
+import com.cyksj.service.wechat.WeChatService;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
+
|
|
|
+/*
|
|
|
+ *项目名: netflix
|
|
|
+ *文件名: SpotifySendMsgServiceImpl
|
|
|
+ *创建者: JavaZou
|
|
|
+ *创建时间:2022/12/21 16:01
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class SpotifySendMsgServiceImpl implements SpotifySendMsgService {
|
|
|
+ private final EnvCommonService envCommonService;
|
|
|
+
|
|
|
+ private final WeChatService weChatService;
|
|
|
+
|
|
|
+ private final UserMapper userMapper;
|
|
|
+
|
|
|
+ private final SpotifyUnLimitRecordMapper spotifyUnLimitRecordMapper;
|
|
|
+
|
|
|
+ private static String spotifyUnLimitSuccessUrl;
|
|
|
+
|
|
|
+ @PostConstruct
|
|
|
+ public void init() {
|
|
|
+ String host = envCommonService.getHost();
|
|
|
+ String domain = envCommonService.getDomain();
|
|
|
+ String redirectUrl = String.format("%s%s", domain, "yinhe/web/?temp=couponId?1?goodsId?4?skuId?14");
|
|
|
+ spotifyUnLimitSuccessUrl = String.format("%sauth/weChat?url=%s", host, redirectUrl);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void sendSpotifyUnLimitSuccessMsg(SpotifyUnLimitRecord record) throws Exception {
|
|
|
+ if (!EnvCommonService.active.equals(envCommonService.getEnv())) {
|
|
|
+ SpotifyUnLimitRecord unLimitRecord = spotifyUnLimitRecordMapper.selectById(record.getId());
|
|
|
+ if (unLimitRecord != null && !unLimitRecord.getIsSend()) {
|
|
|
+ User user = userMapper.selectById(unLimitRecord.getUserId());
|
|
|
+ if (user != null) {
|
|
|
+ WxMpTemplateMessage templateMessage = new WxMpTemplateMessage()
|
|
|
+ .setToUser(user.getOpenId())
|
|
|
+ .setTemplateId(TemplateEnum.SPOTIFY_ACCOUNT_UN_LIMIT_SUCCESS_PRD_TEMPLATE.getTemplateId())
|
|
|
+ .setUrl(spotifyUnLimitSuccessUrl);
|
|
|
+ WxMpTemplateMessage.TemplateData data = templateMessage.getData();
|
|
|
+ data.setFirst(new WxMpTemplateData("您的Spotify账号登录限制解除成功"));
|
|
|
+ data.setKeyword1(new WxMpTemplateData(user.getNickname()));
|
|
|
+ data.setKeyword2(new WxMpTemplateData(DateUtil.format(unLimitRecord.getUpdateTime(), "yyyy-MM-dd HH:mm:ss")));
|
|
|
+ data.setRemark(new WxMpTemplateData("建议您购买Spotify年付会员,无需每过14天解除限制,点击了解"));
|
|
|
+ weChatService.sendTemplateMessage(weChatService.getAccessToken(), Jsons.toJson(templateMessage));
|
|
|
+ unLimitRecord.setIsSend(true);
|
|
|
+ spotifyUnLimitRecordMapper.updateById(unLimitRecord);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|