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

Commit 607b80b7 authored by jiangxiulong's avatar jiangxiulong

取消关注的时候获取不到unid 多存一份openid以便使用

parent cdf81784
...@@ -55,5 +55,6 @@ public class SweetConstant { ...@@ -55,5 +55,6 @@ public class SweetConstant {
// 微信用户相关 新 // 微信用户相关 新
public final static String REDIS_KEY_SWEET_WECHAT_USERS = "sweet:user:service:unionId:"; public final static String REDIS_KEY_SWEET_WECHAT_USERS = "sweet:user:service:unionId:";
public final static String REDIS_KEY_SWEET_WECHAT_USERS_TYPE = ":type:"; public final static String REDIS_KEY_SWEET_WECHAT_USERS_TYPE = ":type:";
public final static String REDIS_KEY_SWEET_WECHAT_USERS_UNIONID = "sweet:user:service:openId:";
public final static String REDIS_KEY_SWEET_APPLET_USERS_PHONE = "sweet:user:applet:mobile:"; public final static String REDIS_KEY_SWEET_APPLET_USERS_PHONE = "sweet:user:applet:mobile:";
} }
...@@ -6,6 +6,7 @@ import com.liquidnet.service.base.constant.MQConst; ...@@ -6,6 +6,7 @@ import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.sweet.config.WechatMpConfigure; import com.liquidnet.service.sweet.config.WechatMpConfigure;
import com.liquidnet.service.sweet.utils.QueueUtils; import com.liquidnet.service.sweet.utils.QueueUtils;
import com.liquidnet.service.sweet.utils.WechatUsersRedisUtils; import com.liquidnet.service.sweet.utils.WechatUsersRedisUtils;
import com.liquidnet.service.sweet.vo.SweetWechatUsersVo;
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;
...@@ -47,30 +48,34 @@ public class UnsubscribeHandler implements WxMpMessageHandler { ...@@ -47,30 +48,34 @@ public class UnsubscribeHandler implements WxMpMessageHandler {
log.info("接收到一个取消订阅事件:[{}]", wxMessage.toString()); log.info("接收到一个取消订阅事件:[{}]", wxMessage.toString());
// 1、获取微信用户信息 // 1、获取微信用户信息
WxMpUser wxMpUser = wxMpService.getUserService().userInfo(wxMessage.getFromUser()); /*WxMpUser wxMpUser = wxMpService.getUserService().userInfo(wxMessage.getFromUser());
if (null == wxMpUser) { if (null == wxMpUser) {
log.warn("从微信公众号获取用户(FromUser)信息:[{}]失败.", wxMessage.getFromUser()); log.warn("从微信公众号获取用户(FromUser)信息:[{}]失败.", wxMessage.getFromUser());
return null; return null;
} }
log.info("根据 openId:[{}]获取到的微信用户信息:[{}]", wxMessage.getFromUser(), wxMpUser.toString()); log.info("根据 openId:[{}]获取到的微信用户信息:[{}]", wxMessage.getFromUser(), wxMpUser.toString());*/
String openId = wxMessage.getFromUser();
Integer type = 0; Integer type = 0;
if (zhengzaiAppId.equals(otherAppId)) {// 正在服务号 if (zhengzaiAppId.equals(otherAppId)) {// 正在服务号
type = 1; type = 1;
} else {// 摩登服务号 } else {// 摩登服务号
type = 2; type = 2;
} }
SweetWechatUsersVo sweetWechatUsers = redisUtils.getSweetWechatUsersOfOpenId(openId, type);
if (null != sweetWechatUsers) {
// 删除用户信息 // 删除用户信息
if (!wxMpUser.getUnionId().isEmpty()) { if (!sweetWechatUsers.getUnionId().isEmpty()) {
redisUtils.delSweetWechatUsers(wxMpUser.getUnionId(), type); redisUtils.delSweetWechatUsers(sweetWechatUsers.getUnionId(), openId, type);
LinkedList<String> sqls = CollectionUtil.linkedListString(); LinkedList<String> sqls = CollectionUtil.linkedListString();
LinkedList<Object[]> sqlsDataA = CollectionUtil.linkedListObjectArr(); LinkedList<Object[]> sqlsDataA = CollectionUtil.linkedListObjectArr();
sqls.add(SqlMapping.get("sweet_wechat_users.delete")); sqls.add(SqlMapping.get("sweet_wechat_users.delete"));
sqlsDataA.add(new Object[]{ sqlsDataA.add(new Object[]{
wxMpUser.getUnionId(), type sweetWechatUsers.getUnionId(), type
}); });
queueUtils.sendMsgByRedis(MQConst.SweetQueue.SWEET_WECHAT_USER_INSERT.getKey(), queueUtils.sendMsgByRedis(MQConst.SweetQueue.SWEET_WECHAT_USER_INSERT.getKey(),
SqlMapping.gets(sqls, sqlsDataA)); SqlMapping.gets(sqls, sqlsDataA));
} }
}
return null; return null;
} }
} }
...@@ -26,15 +26,34 @@ public class WechatUsersRedisUtils { ...@@ -26,15 +26,34 @@ public class WechatUsersRedisUtils {
return sweetWechatUsersVo; return sweetWechatUsersVo;
} }
} }
public SweetWechatUsersVo getSweetWechatUsersOfOpenId(String openId, Integer type) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_WECHAT_USERS_UNIONID.concat(openId)
.concat(SweetConstant.REDIS_KEY_SWEET_WECHAT_USERS_TYPE).concat(String.valueOf(type));
Object obj = redisUtil.get(redisKey);
if (null == obj) {
return null;
} else {
SweetWechatUsersVo sweetWechatUsersVo = (SweetWechatUsersVo) obj;
return sweetWechatUsersVo;
}
}
public void setSweetWechatUsers(SweetWechatUsersVo sweetWechatUsersVo) { public void setSweetWechatUsers(SweetWechatUsersVo sweetWechatUsersVo) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_WECHAT_USERS.concat(sweetWechatUsersVo.getUnionId()) String redisKey = SweetConstant.REDIS_KEY_SWEET_WECHAT_USERS.concat(sweetWechatUsersVo.getUnionId())
.concat(SweetConstant.REDIS_KEY_SWEET_WECHAT_USERS_TYPE).concat(String.valueOf(sweetWechatUsersVo.getType())); .concat(SweetConstant.REDIS_KEY_SWEET_WECHAT_USERS_TYPE).concat(String.valueOf(sweetWechatUsersVo.getType()));
redisUtil.set(redisKey, sweetWechatUsersVo); redisUtil.set(redisKey, sweetWechatUsersVo);
String redisKeyOpenId = SweetConstant.REDIS_KEY_SWEET_WECHAT_USERS_UNIONID.concat(sweetWechatUsersVo.getOpenId())
.concat(SweetConstant.REDIS_KEY_SWEET_WECHAT_USERS_TYPE).concat(String.valueOf(sweetWechatUsersVo.getType()));
redisUtil.set(redisKeyOpenId, sweetWechatUsersVo);
} }
public void delSweetWechatUsers(String unionId, Integer type) { public void delSweetWechatUsers(String unionId, String openId, Integer type) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_WECHAT_USERS.concat(unionId) String redisKey = SweetConstant.REDIS_KEY_SWEET_WECHAT_USERS.concat(unionId)
.concat(SweetConstant.REDIS_KEY_SWEET_WECHAT_USERS_TYPE).concat(String.valueOf(type)); .concat(SweetConstant.REDIS_KEY_SWEET_WECHAT_USERS_TYPE).concat(String.valueOf(type));
redisUtil.del(redisKey); redisUtil.del(redisKey);
String redisKeyOpenId = SweetConstant.REDIS_KEY_SWEET_WECHAT_USERS_UNIONID.concat(openId)
.concat(SweetConstant.REDIS_KEY_SWEET_WECHAT_USERS_TYPE).concat(String.valueOf(type));
redisUtil.del(redisKeyOpenId);
} }
public SweetAppletUsersVo getSweetAppletUsers(String mobile) { public SweetAppletUsersVo getSweetAppletUsers(String mobile) {
......
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