微信机器人开发SDK使用教程--接受好友请求通知
case "AcceptFriendAddRequestTask": {// 客户端或者服务端接受好友请求通知
log.debug("websocket:msgtype=AcceptFriendAddRequestTask。。。。。");
acceptFriendAddRequestTaskWebsocketHandler.handleMsg(ctx, vo,contentJsonStr);
break;
}
package com.jubotech.framework.netty.handler.websocket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import com.google.protobuf.util.JsonFormat;
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.AcceptFriendAddRequestTask.AcceptFriendAddRequestTaskMessage;
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 AcceptFriendAddRequestTaskWebsocketHandler{
private final Logger log = LoggerFactory.getLogger(getClass());
/**
* PC客户端或者服务端接受好友请求通知
* @author wechatno:tangjinjinwx
* @param ctx
* @param vo
*/
public void handleMsg(ChannelHandlerContext ctx,TransportMessage vo, String contentJsonStr) {
try {
log.info(contentJsonStr);
AcceptFriendAddRequestTaskMessage.Builder bd = AcceptFriendAddRequestTaskMessage.newBuilder();
JsonFormat.parser().merge(contentJsonStr, bd);
AcceptFriendAddRequestTaskMessage req = bd.build();
//AcceptFriendAddRequestTaskMessage req = vo.getContent().unpack(AcceptFriendAddRequestTaskMessage.class);
ChannelHandlerContext chx = NettyConnectionUtil.getClientChannelHandlerContextByUserId(req.getWeChatId());
if(null != chx){
//转发给手机端
MessageUtil.sendMsg(chx, EnumMsgType.AcceptFriendAddRequestTask, vo.getAccessToken(), null, req);
//告诉发送方 消息已经收到
MessageUtil.sendJsonMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);
}else{
//对方不在线
MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.TargetNotOnline, Constant.ERROR_MSG_NOTONLINE);
}
} catch (Exception e) {
e.printStackTrace();
MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
}
}
}
项目地址:https://www.wuliaokankan.cn/url301/138.html
接口参考:http://www.yunlauncher.com/Blog/articles/119.html