mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-17 08:13:42 +08:00
Merge pull request #125 from zchaser1024/feat-zjy
解决微信扫码回调和微信授权回调时,request和channel在不同服务器的问题:使用mq将消息利用广播模式让其他服务去处理
This commit is contained in:
@@ -16,4 +16,16 @@ public interface MQConstant {
|
||||
*/
|
||||
String PUSH_TOPIC = "websocket_push";
|
||||
String PUSH_GROUP = "websocket_push_group";
|
||||
|
||||
/**
|
||||
* (授权完成后)登录信息mq
|
||||
*/
|
||||
String LOGIN_MSG_TOPIC = "login_send_msg";
|
||||
String LOGIN_MSG_GROUP = "login_send_msg_group";
|
||||
|
||||
/**
|
||||
* 扫码成功 信息发送mq
|
||||
*/
|
||||
String SCAN_MSG_TOPIC = "scan_send_msg";
|
||||
String SCAN_MSG_GROUP = "scan_send_msg_group";
|
||||
}
|
||||
|
||||
@@ -58,6 +58,12 @@ public class RedisKey {
|
||||
|
||||
public static final String USER_CHAT_CONTEXT = "useChatGPTContext:uid_%d_roomId_%d";
|
||||
|
||||
/**
|
||||
* 保存Open id
|
||||
*/
|
||||
public static final String OPEN_ID_STRING = "openid:%s";
|
||||
|
||||
|
||||
/**
|
||||
* 用户上次使用GLM使用时间
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.abin.mallchat.common.common.domain.dto;
|
||||
|
||||
import com.abin.mallchat.common.user.domain.enums.WSBaseResp;
|
||||
import com.abin.mallchat.common.user.domain.enums.WSPushTypeEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Description: 将扫码登录返回信息推送给所有横向扩展的服务
|
||||
* Author: zjy
|
||||
* Date: 2023-08-12
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class LoginMessageDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 微信公众号获得扫码事件后,发送给我方的回调信息
|
||||
*/
|
||||
private WxMpXmlMessage wxMpXmlMessage ;
|
||||
|
||||
public LoginMessageDTO(WxMpXmlMessage wxMpXmlMessage) {
|
||||
this.wxMpXmlMessage = wxMpXmlMessage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.abin.mallchat.common.common.domain.dto;
|
||||
|
||||
import com.abin.mallchat.common.user.domain.enums.WSBaseResp;
|
||||
import com.abin.mallchat.common.user.domain.enums.WSPushTypeEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Description: 扫码成功对象,推送给用户的消息对象
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-08-12
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ScanSuccessMessageDTO implements Serializable {
|
||||
/**
|
||||
* 推送的ws消息
|
||||
*/
|
||||
private WSBaseResp<?> wsBaseMsg;
|
||||
/**
|
||||
* 推送的uid
|
||||
*/
|
||||
private Integer loginCode;
|
||||
|
||||
public ScanSuccessMessageDTO(Integer loginCode, WSBaseResp<?> wsBaseMsg) {
|
||||
this.loginCode = loginCode;
|
||||
this.wsBaseMsg = wsBaseMsg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.abin.mallchat.common.common.utils;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import io.netty.channel.Channel;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
/**
|
||||
* Description: Cache管理器
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-04-05
|
||||
*/
|
||||
public class CacheHolder {
|
||||
|
||||
private static final Long MAX_MUM_SIZE = 10000L;
|
||||
|
||||
private static final Duration EXPIRE_TIME = Duration.ofHours(1);
|
||||
/**
|
||||
* 所有请求登录的code与channel关系
|
||||
*/
|
||||
public static final Cache<Integer, Channel> WAIT_LOGIN_MAP = Caffeine.newBuilder()
|
||||
.expireAfterWrite(EXPIRE_TIME)
|
||||
.maximumSize(MAX_MUM_SIZE)
|
||||
.build();
|
||||
}
|
||||
@@ -39,6 +39,22 @@ public class RedisUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* 自增int
|
||||
*
|
||||
* @param key 键
|
||||
* @param time 时间(秒)
|
||||
*/
|
||||
public static Integer integerInc(String key, int time, TimeUnit unit) {
|
||||
RedisScript<Long> redisScript = new DefaultRedisScript<>(LUA_INCR_EXPIRE, Long.class);
|
||||
Long result = stringRedisTemplate.execute(redisScript, Collections.singletonList(key), String.valueOf(unit.toSeconds(time)));
|
||||
try{
|
||||
return Integer.parseInt(result.toString());
|
||||
}catch (Exception e) {
|
||||
RedisUtils.del(key);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 指定缓存失效时间
|
||||
*
|
||||
* @param key 键
|
||||
@@ -862,8 +878,8 @@ public class RedisUtils {
|
||||
* @param end
|
||||
* @return
|
||||
*/
|
||||
public static Set<ZSetOperations.TypedTuple<String>> zRangeWithScores(String key, long start,
|
||||
long end) {
|
||||
public static Set<TypedTuple<String>> zRangeWithScores(String key, long start,
|
||||
long end) {
|
||||
return stringRedisTemplate.opsForZSet().rangeWithScores(key, start, end);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user