sync messgae to web
This commit is contained in:
parent
eea2f92046
commit
a8895d5c99
@ -1,17 +1,17 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright 2018-2028 Akaxin Group
|
* Copyright 2018-2028 Akaxin Group
|
||||||
*
|
* <p>
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
* <p>
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
* <p>
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.windchat.im.message.executor;
|
package com.windchat.im.message.executor;
|
||||||
|
|
||||||
@ -36,79 +36,68 @@ import com.windchat.im.message.sync.handler.SyncFinishHandler;
|
|||||||
import com.windchat.im.message.sync.handler.SyncGroupMessageHandler;
|
import com.windchat.im.message.sync.handler.SyncGroupMessageHandler;
|
||||||
import com.windchat.im.message.sync.handler.SyncMsgStatusHandler;
|
import com.windchat.im.message.sync.handler.SyncMsgStatusHandler;
|
||||||
import com.windchat.im.message.sync.handler.SyncU2MessageHandler;
|
import com.windchat.im.message.sync.handler.SyncU2MessageHandler;
|
||||||
import com.windchat.im.message.user2.handler.U2MessageImageHandler;
|
import com.windchat.im.message.user2.handler.*;
|
||||||
import com.windchat.im.message.user2.handler.U2MessageImageSecretHandler;
|
|
||||||
import com.windchat.im.message.user2.handler.U2MessageNoticeHandler;
|
|
||||||
import com.windchat.im.message.user2.handler.U2MessageTextHandler;
|
|
||||||
import com.windchat.im.message.user2.handler.U2MessageTextSecretHandler;
|
|
||||||
import com.windchat.im.message.user2.handler.U2MessageVoiceHandler;
|
|
||||||
import com.windchat.im.message.user2.handler.U2MessageVoiceSecretHandler;
|
|
||||||
import com.windchat.im.message.user2.handler.U2MessageWebHandler;
|
|
||||||
import com.windchat.im.message.user2.handler.U2MessageWebNoticeHandler;
|
|
||||||
import com.windchat.im.message.user2.handler.UserDetectionHandler;
|
|
||||||
import com.windchat.im.message.user2.handler.UserPsnHandler;
|
|
||||||
import com.windchat.im.message.user2.handler.UserPushHandler;
|
|
||||||
import com.windchat.im.message.notice.handler.NoticeHandler;
|
import com.windchat.im.message.notice.handler.NoticeHandler;
|
||||||
import com.windchat.im.message.notice.handler.NoticePushHandler;
|
import com.windchat.im.message.notice.handler.NoticePushHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Sam{@link an.guoyue254@gmail.com}
|
* @author Sam{@link an.guoyue254@gmail.com}
|
||||||
* @since 2018-02-05 11:48:39
|
* @since 2018-02-05 11:48:39
|
||||||
*/
|
*/
|
||||||
public class MessageExecutor {
|
public class MessageExecutor {
|
||||||
private static AbstracteExecutor<Command, Boolean> executor = new SimpleExecutor<Command, Boolean>();
|
private static AbstracteExecutor<Command, Boolean> executor = new SimpleExecutor<Command, Boolean>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
AbstractHandlerChain<Command, Boolean> u2MessageChain = new SimpleHandlerChain<Command>();
|
AbstractHandlerChain<Command, Boolean> u2MessageChain = new SimpleHandlerChain<Command>();
|
||||||
u2MessageChain.addHandler(new UserDetectionHandler());
|
u2MessageChain.addHandler(new UserDetectionHandler());
|
||||||
u2MessageChain.addHandler(new U2MessageTextHandler());
|
u2MessageChain.addHandler(new U2MessageTextHandler());
|
||||||
u2MessageChain.addHandler(new U2MessageTextSecretHandler());
|
u2MessageChain.addHandler(new U2MessageTextSecretHandler());
|
||||||
u2MessageChain.addHandler(new U2MessageImageHandler());
|
u2MessageChain.addHandler(new U2MessageImageHandler());
|
||||||
u2MessageChain.addHandler(new U2MessageImageSecretHandler());
|
u2MessageChain.addHandler(new U2MessageImageSecretHandler());
|
||||||
u2MessageChain.addHandler(new U2MessageVoiceHandler());
|
u2MessageChain.addHandler(new U2MessageVoiceHandler());
|
||||||
u2MessageChain.addHandler(new U2MessageVoiceSecretHandler());
|
u2MessageChain.addHandler(new U2MessageVoiceSecretHandler());
|
||||||
u2MessageChain.addHandler(new U2MessageNoticeHandler());
|
u2MessageChain.addHandler(new U2MessageNoticeHandler());
|
||||||
u2MessageChain.addHandler(new U2MessageWebHandler());
|
u2MessageChain.addHandler(new U2MessageWebHandler());
|
||||||
u2MessageChain.addHandler(new U2MessageWebNoticeHandler());
|
u2MessageChain.addHandler(new U2MessageWebNoticeHandler());
|
||||||
u2MessageChain.addHandler(new UserPsnHandler());
|
u2MessageChain.addHandler(new U2MessageWebSyncHandler());
|
||||||
u2MessageChain.addHandler(new UserPushHandler());
|
u2MessageChain.addHandler(new UserPsnHandler());
|
||||||
|
u2MessageChain.addHandler(new UserPushHandler());
|
||||||
|
|
||||||
AbstractHandlerChain<Command, Boolean> groupMessageChain = new SimpleHandlerChain<Command>();
|
AbstractHandlerChain<Command, Boolean> groupMessageChain = new SimpleHandlerChain<Command>();
|
||||||
groupMessageChain.addHandler(new GroupDetectionHandler());
|
groupMessageChain.addHandler(new GroupDetectionHandler());
|
||||||
groupMessageChain.addHandler(new GroupMessageTextHandler());
|
groupMessageChain.addHandler(new GroupMessageTextHandler());
|
||||||
groupMessageChain.addHandler(new GroupMessageImageHandler());
|
groupMessageChain.addHandler(new GroupMessageImageHandler());
|
||||||
groupMessageChain.addHandler(new GroupMessageVoiceHandler());
|
groupMessageChain.addHandler(new GroupMessageVoiceHandler());
|
||||||
groupMessageChain.addHandler(new GroupMessageNoticeHandler());
|
groupMessageChain.addHandler(new GroupMessageNoticeHandler());
|
||||||
groupMessageChain.addHandler(new GroupMessageWebHandler());
|
groupMessageChain.addHandler(new GroupMessageWebHandler());
|
||||||
groupMessageChain.addHandler(new GroupMessageWebNoticeHandler());
|
groupMessageChain.addHandler(new GroupMessageWebNoticeHandler());
|
||||||
groupMessageChain.addHandler(new GroupPsnHandler());
|
groupMessageChain.addHandler(new GroupPsnHandler());
|
||||||
groupMessageChain.addHandler(new GroupPushHandler());
|
groupMessageChain.addHandler(new GroupPushHandler());
|
||||||
|
|
||||||
AbstractHandlerChain<Command, Boolean> syncMessageChain = new SimpleHandlerChain<Command>();
|
AbstractHandlerChain<Command, Boolean> syncMessageChain = new SimpleHandlerChain<Command>();
|
||||||
syncMessageChain.addHandler(new SyncU2MessageHandler());
|
syncMessageChain.addHandler(new SyncU2MessageHandler());
|
||||||
syncMessageChain.addHandler(new SyncGroupMessageHandler());
|
syncMessageChain.addHandler(new SyncGroupMessageHandler());
|
||||||
|
|
||||||
AbstractHandlerChain<Command, Boolean> noticeChain = new SimpleHandlerChain<Command>();
|
AbstractHandlerChain<Command, Boolean> noticeChain = new SimpleHandlerChain<Command>();
|
||||||
noticeChain.addHandler(new NoticeHandler());
|
noticeChain.addHandler(new NoticeHandler());
|
||||||
noticeChain.addHandler(new NoticePushHandler());
|
noticeChain.addHandler(new NoticePushHandler());
|
||||||
|
|
||||||
// "im.cts.message.u2"
|
// "im.cts.message.u2"
|
||||||
executor.addChain(RequestAction.IM_CTS_MESSAGE_U2.getName(), u2MessageChain);
|
executor.addChain(RequestAction.IM_CTS_MESSAGE_U2.getName(), u2MessageChain);
|
||||||
// "im.cts.message.group"
|
// "im.cts.message.group"
|
||||||
executor.addChain(RequestAction.IM_CTS_MESSAGE_GROUP.getName(), groupMessageChain);
|
executor.addChain(RequestAction.IM_CTS_MESSAGE_GROUP.getName(), groupMessageChain);
|
||||||
// "im.sync.message"
|
// "im.sync.message"
|
||||||
executor.addChain(RequestAction.IM_SYNC_MESSAGE.getName(), syncMessageChain);
|
executor.addChain(RequestAction.IM_SYNC_MESSAGE.getName(), syncMessageChain);
|
||||||
// "im.sync.finish"
|
// "im.sync.finish"
|
||||||
executor.addChain(RequestAction.IM_SYNC_FINISH.getName(), new SyncFinishHandler());
|
executor.addChain(RequestAction.IM_SYNC_FINISH.getName(), new SyncFinishHandler());
|
||||||
// "im.sync.msgStatus"
|
// "im.sync.msgStatus"
|
||||||
executor.addChain(RequestAction.IM_SYNC_MSGSTATUS.getName(), new SyncMsgStatusHandler());
|
executor.addChain(RequestAction.IM_SYNC_MSGSTATUS.getName(), new SyncMsgStatusHandler());
|
||||||
// "im.stc.notice"
|
// "im.stc.notice"
|
||||||
executor.addChain(RequestAction.IM_STC_NOTICE.getName(), noticeChain);
|
executor.addChain(RequestAction.IM_STC_NOTICE.getName(), noticeChain);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AbstracteExecutor<Command, Boolean> getExecutor() {
|
public static AbstracteExecutor<Command, Boolean> getExecutor() {
|
||||||
return executor;
|
return executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,103 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2018-2028 Akaxin Group
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.windchat.im.message.user2.handler;
|
||||||
|
|
||||||
|
import com.akaxin.proto.core.CoreProto;
|
||||||
|
import com.akaxin.proto.site.ImCtsMessageProto;
|
||||||
|
import com.windchat.common.command.Command;
|
||||||
|
import com.windchat.common.crypto.AESCrypto;
|
||||||
|
import com.windchat.common.http.ZalyHttpClient;
|
||||||
|
import com.windchat.common.logs.LogUtils;
|
||||||
|
import com.windchat.common.utils.GsonUtils;
|
||||||
|
import com.windchat.im.message.bean.WebBean;
|
||||||
|
import com.windchat.im.storage.api.IMessageDao;
|
||||||
|
import com.windchat.im.storage.bean.U2MessageBean;
|
||||||
|
import com.windchat.im.storage.service.MessageDaoService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sync message to web
|
||||||
|
*
|
||||||
|
* @author an.guoyue254@gmail.com
|
||||||
|
* @since 2020-10-12 22:45:20
|
||||||
|
*/
|
||||||
|
public class U2MessageWebSyncHandler extends AbstractU2Handler<Command> {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(U2MessageWebSyncHandler.class);
|
||||||
|
|
||||||
|
private static final int programId = 100;
|
||||||
|
private static final String programSecret = "gXDayjtSHtTk33Tfo4ILruYmYblO7nJe";
|
||||||
|
|
||||||
|
public Boolean handle(Command command) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
switch (command.getMsgType()) {
|
||||||
|
case CoreProto.MsgType.TEXT_VALUE: {
|
||||||
|
ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest
|
||||||
|
.parseFrom(command.getParams());
|
||||||
|
final String siteUserId = command.getSiteUserId();
|
||||||
|
final String proxySiteUserId = request.getText().getSiteUserId();
|
||||||
|
final String siteFriendId = request.getText().getSiteFriendId();
|
||||||
|
final String msgId = request.getText().getMsgId();
|
||||||
|
final String textBody = request.getText().getText().toString(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
// 构建Json格式消息体
|
||||||
|
String action = "duckchat.message.send";
|
||||||
|
Map<String, Object> data = new HashMap<String, Object>(3) {{
|
||||||
|
put("action", action);
|
||||||
|
put("body", new HashMap<String, Object>(2) {{
|
||||||
|
put("@type", "type.googleapis.com/plugin.DuckChatMessageSendRequest");
|
||||||
|
put("message", new HashMap<String, Object>(6) {{
|
||||||
|
put("msgId", msgId);
|
||||||
|
put("fromUserId", siteUserId);
|
||||||
|
put("toUserId", siteFriendId);
|
||||||
|
put("type", "MessageText");
|
||||||
|
put("roomType", "MessageRoomU2");
|
||||||
|
put("text", new HashMap<String, Object>(1) {{
|
||||||
|
put("body", textBody);
|
||||||
|
}});
|
||||||
|
}});
|
||||||
|
}});
|
||||||
|
put("timeServer", System.currentTimeMillis());
|
||||||
|
}};
|
||||||
|
// 构建HTTP URL
|
||||||
|
String requestUrl = "http://localhost:8000//?action=" + action + "&body_format=json&miniProgramId=" + programId;
|
||||||
|
// AES 加密
|
||||||
|
|
||||||
|
byte[] encrptData = AESCrypto.encrypt(programSecret.getBytes(), GsonUtils.toJson(data).getBytes());
|
||||||
|
|
||||||
|
// Http Post请求
|
||||||
|
ZalyHttpClient.getInstance().postBytes(requestUrl, encrptData);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.requestErrorLog(logger, command, this.getClass(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user