zoukankan      html  css  js  c++  java
  • 微信二次开发sdk使用教程--手机微信上回复好友的聊天消息通知服务端

    微信二次开发sdk使用教程--手机微信上回复好友的聊天消息通知服务端

    case WeChatTalkToFriendNotice: {// 手机上回复好友的聊天消息
    log.debug("socket:msgtype=WeChatTalkToFriendNotice");
    weChatTalkToFriendNoticeHandler.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.stereotype.Service;

    import com.google.protobuf.util.JsonFormat;
    import com.jubotech.business.web.domain.AccountInfo;
    import com.jubotech.business.web.domain.BusinessWechatFriends;
    import com.jubotech.business.web.domain.WeChatAccountInfo;
    import com.jubotech.business.web.service.AccountService;
    import com.jubotech.business.web.service.BusinessWechatFriendsService;
    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.TransportMessageOuterClass.EnumErrorCode;
    import Jubo.JuLiao.IM.Wx.Proto.TransportMessageOuterClass.EnumMsgType;
    import Jubo.JuLiao.IM.Wx.Proto.TransportMessageOuterClass.TransportMessage;
    import Jubo.JuLiao.IM.Wx.Proto.WeChatTalkToFriendNotice.WeChatTalkToFriendNoticeMessage;
    import io.netty.channel.ChannelHandlerContext;
    @Service
    public class WeChatTalkToFriendNoticeHandler{
    private final Logger log = LoggerFactory.getLogger(getClass());
    @Autowired
    private WeChatAccountService weChatAccountService;
    @Autowired
    private AccountService accountService;
    @Autowired
    private BusinessWechatFriendsService businessWechatFriendsService;

    /**
     * 手机上回复好友的聊天消息 
     * @author wechatno:tangjinjinwx
     * @param ctx
     * @param vo
     */
    public  void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
        try {
        	WeChatTalkToFriendNoticeMessage req = vo.getContent().unpack(WeChatTalkToFriendNoticeMessage.class);
        	log.info(JsonFormat.printer().print(req));
    		// 把消息转发给pc端
    		// a、根据wechatId找到accountid
    		// b、通过accountid找到account
    		// c、通过account账号找到通道
    		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) {
    					MessageUtil.sendJsonMsg(chx, EnumMsgType.WeChatTalkToFriendNotice, NettyConnectionUtil.getNettyId(chx),null, req);
    				}
    			}
    		} 
    		//转发给商务app端
    		BusinessWechatFriends  buiness = businessWechatFriendsService.getBusinessWechatFriendsByFriendWechatid(req.getFriendId());
    		if(null != buiness){
    			String nettyName = buiness.getCid()+"_"+buiness.getB_number();
            	ChannelHandlerContext cx_netty = NettyConnectionUtil.getClientChannelHandlerContextByUserId(nettyName);
            	if(null != cx_netty){
            		MessageUtil.sendJsonMsg(cx_netty, EnumMsgType.WeChatTalkToFriendNotice, NettyConnectionUtil.getNettyId(ctx), null, req);
            	}
    		}
    		
        	// 告诉客户端消息已收到
    		MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
        }
    }
    

    }

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

  • 相关阅读:
    [转]从程序员到项目经理(一)
    [转]WCF技术的不同应用场景及其实现分析(续)
    [转]从程序员到项目经理(12):如何管理自己的时间(上)
    [转]使用XML文件来动态配置ASP.NET MVC的Route规则
    [转]WF是什么系列之 [ WF控制机械手臂 (3D模型) ]
    [引]深圳 2013年软考 报名处理
    亮剑 项目开发管理 你的电脑都用有哪些工具软件?
    [转]关于vs2005、vs2008和vs2010项目互转的总结
    TinyMCE(富文本编辑器)
    html编辑器kindeditor
  • 原文地址:https://www.cnblogs.com/wuliaokankan/p/10606637.html
Copyright © 2011-2022 走看看