微信机器人开发SDK使用教程--请求图片或视频消息的详细内容
case "RequestTalkDetailTask": {// 请求图片或视频消息的详细内容
log.debug("websocket:msgtype=RequestTalkDetailTask。。。。。");
requestTalkDetailTaskWebsocketHandler.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.RequestTalkDetailTask.RequestTalkDetailTaskMessage;
import Jubo.JuLiao.IM.Wx.Proto.TaskResultNotice.TaskResultNoticeMessage;
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 RequestTalkDetailTaskWebsocketHandler{
private final Logger log = LoggerFactory.getLogger(getClass());
/**
* 请求图片或视频消息的详细内容
* @author wechatno:tangjinjinwx
* @param ctx
* @param vo
*/
public void handleMsg(ChannelHandlerContext ctx,TransportMessage vo, String contentJsonStr) {
try {
log.info(contentJsonStr);
RequestTalkDetailTaskMessage.Builder bd = RequestTalkDetailTaskMessage.newBuilder();
JsonFormat.parser().merge(contentJsonStr, bd);
RequestTalkDetailTaskMessage req = bd.build();
//将消息转发送给手机客户端
ChannelHandlerContext cx= NettyConnectionUtil.getClientChannelHandlerContextByUserId(req.getWeChatId());
if(null != cx){
MessageUtil.sendMsg(cx, EnumMsgType.RequestTalkDetailTask, NettyConnectionUtil.getNettyId(ctx), null, req);
//告诉客户端消息已收到
TaskResultNoticeMessage resp = TaskResultNoticeMessage.newBuilder()
.setSuccess(true)
.setTaskId(vo.getId())
.build();
MessageUtil.sendJsonMsg(ctx, EnumMsgType.TaskResultNotice, vo.getAccessToken(), vo.getId(), resp);
}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://github.com/wechatbot/wechat.robot.sdk
接口参考:http://www.yunlauncher.com/Blog/articles/119.html
原文地址:https://www.cnblogs.com/wuliaokankan/p/10655854.html