码迷,mamicode.com
首页 > 微信 > 详细

微信开发SDK使用教程--手机微信个人号移除好友通知服务端

时间:2019-03-27 12:48:27      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:通过   accounts   nms   pre   dac   catch   user   handle   getc   

微信开发SDK使用教程--手机微信个人号移除好友通知服务端

case FriendDelNotice: {// 微信个人号移除好友通知
log.debug("socket:msgtype=FriendDelNotice");
friendDelNoticeHandler.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.jubotech.business.web.domain.AccountInfo;
import com.jubotech.business.web.domain.WeChatAccountInfo;
import com.jubotech.business.web.domain.WeChatContactInfo;
import com.jubotech.business.web.service.AccountService;
import com.jubotech.business.web.service.WeChatAccountService;
import com.jubotech.business.web.service.WeChatContactService;
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.FriendDelNotice.FriendDelNoticeMessage;
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 FriendDelNoticeHandler{
Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private WeChatAccountService weChatAccountService;
@Autowired
private AccountService accountService;
@Autowired
private WeChatContactService weChatContactService;

/**
 * 个人号删除好友通知消息---手机端经过服务端转发给pc端
 * @author wechatno:tangjinjinwx
 * @param ctx
 * @param vo
 */
public  void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
    try {
        FriendDelNoticeMessage req = vo.getContent().unpack(FriendDelNoticeMessage.class);
         
        //把消息转发给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.FriendDelNotice, NettyConnectionUtil.getNettyId(chx), null, req);
                }
            }
            //告诉客户端消息已收到
            MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);
        }else{
            //对方不在线
            MessageUtil.sendErrMsg(ctx, EnumErrorCode.TargetNotOnline, Constant.ERROR_MSG_NOTONLINE);
        }
        
        if(null != account ){
            WeChatContactInfo   contactinfo = weChatContactService.findContactinfoByfriendid(account.getCid(),req.getWeChatId(),req.getFriendId());
            if(null != contactinfo){
                contactinfo.setState(1);//1代表已删除
                weChatContactService.update(contactinfo);
            }
        }
        
    } catch (Exception e) {
        e.printStackTrace();
        MessageUtil.sendErrMsg(ctx, EnumErrorCode.NoRight, Constant.ERROR_MSG_DECODFAIL);
    }
}

}

项目地址:https://github.com/tangjinjinwx/Public.WeChat.CRM.SDK
接口参考:http://www.yunlauncher.com/Blog/articles/119.html

微信开发SDK使用教程--手机微信个人号移除好友通知服务端

标签:通过   accounts   nms   pre   dac   catch   user   handle   getc   

原文地址:https://www.cnblogs.com/wuliaokankan/p/10606655.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!