zoukankan      html  css  js  c++  java
  • 微信群控开发SDK使用教程--手机端推送群聊列表通知服务端

    微信群控开发SDK使用教程--手机端推送群聊列表通知服务端

    case ChatroomPushNotice: {// 手机端推送群聊列表
    log.debug("socket:msgtype=ChatroomPushNotice");
    chatroomPushNoticeHandler.handleMsg(ctx, msgVo);
    break;
    }

    package com.jubotech.framework.netty.handler.socket;

    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.scheduling.annotation.Async;
    import org.springframework.stereotype.Service;

    import com.google.protobuf.util.JsonFormat;
    import com.jubotech.business.web.domain.AccountInfo;
    import com.jubotech.business.web.domain.WeChatAccountInfo;
    import com.jubotech.business.web.service.AccountService;
    import com.jubotech.business.web.service.WeChatAccountService;
    import com.jubotech.framework.netty.common.Constant;
    import com.jubotech.framework.netty.utils.MessageUtil;
    import com.jubotech.framework.netty.utils.NettyConnectionUtil;

    import Jubo.JuLiao.IM.Wx.Proto.ChatRoomPushNotice.ChatRoomPushNoticeMessage;
    import Jubo.JuLiao.IM.Wx.Proto.TransportMessageOuterClass.EnumErrorCode;
    import Jubo.JuLiao.IM.Wx.Proto.TransportMessageOuterClass.EnumMsgType;
    import Jubo.JuLiao.IM.Wx.Proto.TransportMessageOuterClass.TransportMessage;
    import io.netty.channel.ChannelHandlerContext;

    @Service
    public class ChatroomPushNoticeHandler{
    private final Logger log = LoggerFactory.getLogger(getClass());
    @Autowired
    private WeChatAccountService weChatAccountService;
    @Autowired
    private AccountService accountService;

    /**
     * 手机端推送群聊列表
     * @author wechatno:tangjinjinwx
     * @param ctx
     * @param vo
     */
    
    public  void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
        try {
        	ChatRoomPushNoticeMessage req = vo.getContent().unpack(ChatRoomPushNoticeMessage.class);
        	log.info(JsonFormat.printer().print(req));
    		WeChatAccountInfo account = weChatAccountService.findWeChatAccountInfoByWeChatId(req.getWeChatId());
    		if (null != account && null != account.getAccountid() && 1 != account.getIslogined()) {
    			AccountInfo accInfo = accountService.findAccountInfoByid(account.getAccountid());
    			if (null != accInfo) {
    				// 转发给pc端
    				ChannelHandlerContext chx = NettyConnectionUtil.getClientChannelHandlerContextByUserId(accInfo.getAccount());
    				if (null != chx) {
    					asyncSendMsg(chx, req);
    				}
    			}
    			// 告诉客户端消息已收到
    			MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);
    		} else {
    			// 对方不在线
    			MessageUtil.sendErrMsg(ctx, EnumErrorCode.TargetNotOnline, Constant.ERROR_MSG_NOTONLINE);
    		}
    		
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
        }
    }
    
    @Async
    private  void  asyncSendMsg(ChannelHandlerContext chx,ChatRoomPushNoticeMessage req){
    	MessageUtil.sendJsonMsg(chx, EnumMsgType.ChatroomPushNotice,NettyConnectionUtil.getNettyId(chx), null, req);
    }
    

    }

    项目地址:https://www.wuliaokankan.cn/url301/138.html
    接口参考:http://www.yunlauncher.com/Blog/articles/119.html

  • 相关阅读:
    jar包打包成exe示例(基于maven项目)
    助教小工具
    HUST软件测试1504班: 第0周作业成绩
    软件质量与测试2018春第0周作业1:开设博客
    RobotFramework学习-问题
    Java读取本地文件乱码的解决方案
    滑动窗口模板题(对读写性能要求贼高)
    Invalid index name [xxx], must be lowercase
    Java自动装箱和自动拆箱的理解
    TKMabatis坑
  • 原文地址:https://www.cnblogs.com/wuliaokankan/p/10608166.html
Copyright © 2011-2022 走看看