• 微信开发SDK使用教程--手机微信有好友请求添加好友的通知服务端


    微信开发SDK使用教程--手机微信有好友请求添加好友的通知服务端

    case FriendAddReqeustNotice: {//有好友请求添加好友的通知
    log.debug("socket:msgtype=FriendAddReqeustNotice");
    friendAddReqeustNoticeHandler.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.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.FriendAddReqeustNotice.FriendAddReqeustNoticeMessage;
    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 FriendAddReqeustNoticeHandler{
    private final Logger log = LoggerFactory.getLogger(getClass());
    @Autowired
    private WeChatAccountService weChatAccountService;
    @Autowired
    private AccountService accountService;
    /**
    * 个人号好友请求通知---手机端经过服务端转发给pc端
    * @author wechatno:tangjinjinwx
    * @param ctx
    * @param vo
    */
    public void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
    try {
    FriendAddReqeustNoticeMessage req = vo.getContent().unpack(FriendAddReqeustNoticeMessage.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.FriendAddReqeustNotice, 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);
    }

        } catch (Exception e) {
        	MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
            e.printStackTrace();
        }
    }
    

    }

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

  • 相关阅读:
    mssql索引视图无法对视图创建 索引,因为该视图未绑定到架构
    说说回车键触发表单提交的问题
    在C#中使用SqlDbType.Xml类型参数
    使用nginx实施负载均衡
    SQL Server 索引中include的魅力(具有包含性列的索引)
    群发“站内信”的实现
    ORM映射框架总结终极JSON
    51 地图基本接口(二)
    通用短信平台接口
    ORM映射框架总结Flash 处理
  • 原文地址:https://www.cnblogs.com/wuliaokankan/p/10606642.html
Copyright © 2020-2023  润新知