微信营销论坛

普通会员

29

帖子

1

回复

35

积分

楼主
发表于 2020-03-27 17:25:46 | 查看: 1722 | 回复: 1

微信机器人开发SDK使用教程--微信群发消息任务

case "WeChatGroupSendTask": {// 群发消息任务
log.debug("websocket:msgtype=WeChatGroupSendTask。。。。。");
weChatGroupSendTaskWesocketHandler.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.TransportMessageOuterClass.EnumErrorCode;
import Jubo.JuLiao.IM.Wx.Proto.TransportMessageOuterClass.EnumMsgType;
import Jubo.JuLiao.IM.Wx.Proto.TransportMessageOuterClass.TransportMessage;
import Jubo.JuLiao.IM.Wx.Proto.WeChatGroupSendTask.WeChatGroupSendTaskMessage;
import io.netty.channel.ChannelHandlerContext;

@Service
public class WeChatGroupSendTaskWesocketHandler{
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);
WeChatGroupSendTaskMessage.Builder bd = WeChatGroupSendTaskMessage.newBuilder();
JsonFormat.parser().merge(contentJsonStr, bd);
WeChatGroupSendTaskMessage req = bd.build();
//WeChatGroupSendTaskMessage req = vo.getContent().unpack(WeChatGroupSendTaskMessage.class);

        ChannelHandlerContext  chx = NettyConnectionUtil.getClientChannelHandlerContextByUserId(req.getWeChatId());
        if(null != chx){
            //转发给手机端
            MessageUtil.sendMsg(chx, EnumMsgType.WeChatGroupSendTask, 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);
    }
}

}

项目地址 http://www.wlkankan.cn/cate41/301.html
接口地址 http://www.yunlauncher.com/Blog/articles/119.html



超级管理员

216

帖子

77

回复

2200

积分
沙发
发表于 2020-08-26 17:00:50

微信第三方SDK解决方案咨询微信happybabby110

微信第三方SDK-微信开放平台-微信开发者平台-微信开发者工具 


您需要登录后才可以回帖 登录 | 立即注册

微信营销论坛,一个只关注手机微信营销的论坛! 浙ICP备13012843号-1