记得上下班打卡 | git大法好,push需谨慎

Commit e6496182 authored by sunyuntian's avatar sunyuntian

猫登天空新建分支

parent ec362e6a
...@@ -63,4 +63,10 @@ public class SweetConstant { ...@@ -63,4 +63,10 @@ public class SweetConstant {
//2022草莓音乐节活动海报相关 //2022草莓音乐节活动海报相关
public final static String REDIS_KEY_SWEET_STRAWBERRY_POSTER = "sweet:strawberry:poster"; public final static String REDIS_KEY_SWEET_STRAWBERRY_POSTER = "sweet:strawberry:poster";
//猫登活动-触发活动
public final static String REDIS_KEY_SWEET_WECHAT_MAODENG_OPEN_POSTER = "sweet:maoDeng:open:userId";
//猫登活动-文本
public final static String REDIS_KEY_SWEET_WECHAT_MAODENG_TEXT_POSTER = "sweet:maoDeng:text:userId";
//猫登活动-图片
public final static String REDIS_KEY_SWEET_WECHAT_MAODENG_IMAGE_POSTER = "sweet:maoDeng:image:userId";
} }
package com.liquidnet.service.sweet.vo;
import lombok.Data;
import java.io.Serializable;
@Data
public class SweetMaoDengVo implements Serializable, Cloneable {
private static final long serialVersionUID = 1L;
/**
* 用户id
*/
private String userId;
/**
* 用户id
*/
private String maoId;
/**
* 消息
*/
private String textMsg;
/**
* 图片url
*/
private String picUrl;
private static final SweetMaoDengVo obj = new SweetMaoDengVo();
public static SweetMaoDengVo getNew() {
try {
return (SweetMaoDengVo) obj.clone();
} catch (CloneNotSupportedException e) {
return new SweetMaoDengVo();
}
}
}
package com.liquidnet.service.sweet.config; package com.liquidnet.service.sweet.config;
import com.liquidnet.service.sweet.handler.StrawberryPosterHandler; import com.liquidnet.service.sweet.handler.*;
import com.liquidnet.service.sweet.handler.SubscribeHandler;
import com.liquidnet.service.sweet.handler.TextMsgHandler;
import com.liquidnet.service.sweet.handler.UnsubscribeHandler;
import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker; import me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker;
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps; import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
...@@ -70,6 +67,8 @@ public class WechatMpConfigure { ...@@ -70,6 +67,8 @@ public class WechatMpConfigure {
private StrawberryPosterHandler posterHandler; private StrawberryPosterHandler posterHandler;
@Autowired @Autowired
private TextMsgHandler textMsgHandler; private TextMsgHandler textMsgHandler;
@Autowired
private MaodengImageHandler maodengImageHandler;
@PostConstruct @PostConstruct
public void init() { public void init() {
...@@ -153,6 +152,11 @@ public class WechatMpConfigure { ...@@ -153,6 +152,11 @@ public class WechatMpConfigure {
.handler(textMsgHandler) .handler(textMsgHandler)
.end(); .end();
// 猫登活动 图片
router.rule().async(false).msgType(WxConsts.XmlMsgType.IMAGE)
.handler(maodengImageHandler)
.end();
return router; return router;
} }
} }
package com.liquidnet.service.sweet.controller;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.sweet.utils.WechatUsersRedisUtils;
import com.liquidnet.service.sweet.vo.SweetMaoDengVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = "猫登活动")
@RestController
@RequestMapping("/wechatMaoDeng")
@Slf4j
public class SweetWechatMaoDengController {
@Autowired
private WechatUsersRedisUtils redisUtils;
@GetMapping("/backData")
@ApiOperation("返回文字图片")
public ResponseDto<SweetMaoDengVo> backDatas(String userId){
userId="1234";
SweetMaoDengVo sweetMaoDengVo = SweetMaoDengVo.getNew();
String textMsg = redisUtils.getSweetMaoDengText(userId);
String image = redisUtils.getSweetMaoDengImage(userId);
sweetMaoDengVo.setPicUrl(image);
sweetMaoDengVo.setTextMsg(textMsg);
sweetMaoDengVo.setUserId(userId);
// redisUtils.setSweetMaoDengText(sweetMaoDengVo,-1);
// redisUtils.setSweetMaoDengImage(sweetMaoDengVo,-1);
if (StringUtil.isEmpty(textMsg) && StringUtil.isEmpty(image)) {
return ResponseDto.failure("90081", "获取信息失败");
}
return ResponseDto.success(sweetMaoDengVo);
}
}
package com.liquidnet.service.sweet.handler;
import com.liquidnet.service.sweet.utils.WechatUsersRedisUtils;
import com.liquidnet.service.sweet.vo.SweetMaoDengVo;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Map;
@Component
@Slf4j
public class MaodengImageHandler implements WxMpMessageHandler {
@Autowired
private WechatUsersRedisUtils redisUtils;
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> map, WxMpService wxMpService, WxSessionManager wxSessionManager) throws WxErrorException {
String fromUser = wxMessage.getFromUser();//用户id
String picUrl = wxMessage.getPicUrl();//图片url
String maoContent = wxMessage.getContent();//获取文字消息
SweetMaoDengVo sweetMaoDengVo = SweetMaoDengVo.getNew();
sweetMaoDengVo.setUserId(fromUser);
sweetMaoDengVo.setPicUrl(picUrl);
Integer i = redisUtils.getSweetMaoDengOpen(fromUser);
if (i == 1){
//活动已开启 持久化
redisUtils.setSweetMaoDengImage(sweetMaoDengVo);
}else {
//活动过期 不响应
return null;
}
return null;
}
}
...@@ -2,6 +2,7 @@ package com.liquidnet.service.sweet.handler; ...@@ -2,6 +2,7 @@ package com.liquidnet.service.sweet.handler;
import com.liquidnet.service.sweet.config.WechatMaConfigure; import com.liquidnet.service.sweet.config.WechatMaConfigure;
import com.liquidnet.service.sweet.utils.WechatUsersRedisUtils; import com.liquidnet.service.sweet.utils.WechatUsersRedisUtils;
import com.liquidnet.service.sweet.vo.SweetMaoDengVo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.common.session.WxSessionManager;
...@@ -37,6 +38,28 @@ public class TextMsgHandler implements WxMpMessageHandler { ...@@ -37,6 +38,28 @@ public class TextMsgHandler implements WxMpMessageHandler {
@Override @Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService,
WxSessionManager sessionManager) throws WxErrorException { WxSessionManager sessionManager) throws WxErrorException {
String maoContent = wxMessage.getContent();//获取文字消息
String fromUser = wxMessage.getFromUser();//用户id
SweetMaoDengVo sweetMaoDengVo = SweetMaoDengVo.getNew();
sweetMaoDengVo.setUserId(fromUser);
sweetMaoDengVo.setTextMsg(maoContent);
if(maoContent == "猫登天空"){
redisUtils.setSweetMaoDengOpen(fromUser,10*60);
}
Integer i = redisUtils.getSweetMaoDengOpen(fromUser);
if (i == 1){
//活动已开启 持久化
redisUtils.setSweetMaoDengText(sweetMaoDengVo);
}else {
//活动过期 不响应
return null;
}
//--------------------------------------------------------------------------------------------------------------------------
boolean IsPosterClick = redisUtils.getStrawberryPosterClick(wxMessage.getFromUser()); boolean IsPosterClick = redisUtils.getStrawberryPosterClick(wxMessage.getFromUser());
if (IsPosterClick) { if (IsPosterClick) {
String content = wxMessage.getContent(); String content = wxMessage.getContent();
...@@ -58,5 +81,8 @@ public class TextMsgHandler implements WxMpMessageHandler { ...@@ -58,5 +81,8 @@ public class TextMsgHandler implements WxMpMessageHandler {
// 正常消息不处理 // 正常消息不处理
return null; return null;
} }
} }
} }
...@@ -3,6 +3,7 @@ package com.liquidnet.service.sweet.utils; ...@@ -3,6 +3,7 @@ package com.liquidnet.service.sweet.utils;
import com.liquidnet.common.cache.redis.util.RedisUtil; import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.service.sweet.constant.SweetConstant; import com.liquidnet.service.sweet.constant.SweetConstant;
import com.liquidnet.service.sweet.vo.SweetAppletUsersVo; import com.liquidnet.service.sweet.vo.SweetAppletUsersVo;
import com.liquidnet.service.sweet.vo.SweetMaoDengVo;
import com.liquidnet.service.sweet.vo.SweetWechatUsersVo; import com.liquidnet.service.sweet.vo.SweetWechatUsersVo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -97,4 +98,52 @@ public class WechatUsersRedisUtils { ...@@ -97,4 +98,52 @@ public class WechatUsersRedisUtils {
return true; return true;
} }
} }
public String getSweetMaoDengText(String userId) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_WECHAT_MAODENG_TEXT_POSTER.concat(userId);
Object obj = redisUtil.get(redisKey);
if (null == obj) {
return null;
} else {
SweetMaoDengVo sweetMaoDengVo = (SweetMaoDengVo) obj;
String textMsg = sweetMaoDengVo.getTextMsg();
return textMsg;
}
}
public String getSweetMaoDengImage(String userId) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_WECHAT_MAODENG_IMAGE_POSTER.concat(userId);
Object obj = redisUtil.get(redisKey);
if (null == obj) {
return null;
} else {
SweetMaoDengVo sweetMaoDengVo = (SweetMaoDengVo) obj;
String picUrl = sweetMaoDengVo.getPicUrl();
return picUrl;
}
}
public Integer getSweetMaoDengOpen(String fromUser) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_WECHAT_MAODENG_OPEN_POSTER.concat(fromUser);
Integer obj = (Integer) redisUtil.get(redisKey);
if (null == obj) {
return null;
} else {
return obj;
}
}
public void setSweetMaoDengText(SweetMaoDengVo sweetMaoDengVo) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_WECHAT_MAODENG_TEXT_POSTER.concat(sweetMaoDengVo.getUserId());
redisUtil.set(redisKey,sweetMaoDengVo);
}
public void setSweetMaoDengImage(SweetMaoDengVo sweetMaoDengVo) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_WECHAT_MAODENG_IMAGE_POSTER.concat(sweetMaoDengVo.getUserId());
redisUtil.set(redisKey,sweetMaoDengVo);
}
public void setSweetMaoDengOpen(String fromUser, long time) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_WECHAT_MAODENG_OPEN_POSTER.concat(fromUser);
redisUtil.set(redisKey,1,time);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment