博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
微信云控开发SDK使用教程--手机端回传朋友圈数据通知服务端
阅读量:5236 次
发布时间:2019-06-14

本文共 3890 字,大约阅读时间需要 12 分钟。

微信云控开发SDK使用教程-手机端回传朋友圈数据通知服务端

case CirclePushNotice: {//手机回传朋友圈数据

log.debug("socket:msgtype=CirclePushNotice");
circlePushNoticeHandler.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.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import com.google.protobuf.util.JsonFormat;

import com.jubotech.business.web.domain.AccountInfo;
import com.jubotech.business.web.domain.BusinessWechatFriends;
import com.jubotech.business.web.domain.WeChatAccountInfo;
import com.jubotech.business.web.service.AccountService;
import com.jubotech.business.web.service.BusinessWechatFriendsService;
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.CirclePushNotice.CirclePushNoticeMessage;

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 CirclePushNoticeHandler{
private final Logger log = LoggerFactory.getLogger(getClass());
@Autowired
private WeChatAccountService weChatAccountService;
@Autowired
private AccountService accountService;

@Autowiredprivate BusinessWechatFriendsService businessWechatFriendsService;/** * 手机回传朋友圈数据 * @author wechatno:tangjinjinwx * @param ctx * @param vo */public  void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {    try {        CirclePushNoticeMessage req = vo.getContent().unpack(CirclePushNoticeMessage.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){                    asyncSendMsg(chx, req);//异步调用                }            }                    }                //转发给商务app端        BusinessWechatFriends  buiness = businessWechatFriendsService.getBusinessWechatFriendsByFriendWechatid(req.getWeChatId());        if(null != buiness){            String nettyName = buiness.getCid()+"_"+buiness.getB_number();            ChannelHandlerContext cx_netty = NettyConnectionUtil.getClientChannelHandlerContextByUserId(nettyName);            if(null != cx_netty){                MessageUtil.sendJsonMsg(cx_netty, EnumMsgType.CirclePushNotice, NettyConnectionUtil.getNettyId(ctx), null, req);            }        }                //告诉客户端消息已收到        MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);    } catch (Exception e) {        e.printStackTrace();        MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);    }}@Asyncprivate void asyncSendMsg(ChannelHandlerContext  chx ,CirclePushNoticeMessage req){    MessageUtil.sendJsonMsg(chx, EnumMsgType.CirclePushNotice, NettyConnectionUtil.getNettyId(chx), null, req);    }

}

项目地址:https://www.wuliaokankan.cn/url301/138.html

接口参考:http://www.yunlauncher.com/Blog/articles/119.html

转载于:https://www.cnblogs.com/wuliaokankan/p/10608145.html

你可能感兴趣的文章
java Facade模式
查看>>
NYOJ 120校园网络(有向图的强连通分量)(Kosaraju算法)
查看>>
SpringAop与AspectJ
查看>>
Leetcode 226: Invert Binary Tree
查看>>
http站点转https站点教程
查看>>
解决miner.start() 返回null
查看>>
bzoj 2007: [Noi2010]海拔【最小割+dijskstra】
查看>>
BZOJ 1001--[BeiJing2006]狼抓兔子(最短路&对偶图)
查看>>
C# Dynamic通用反序列化Json类型并遍历属性比较
查看>>
128 Longest Consecutive Sequence 一个无序整数数组中找到最长连续序列
查看>>
定制jackson的自定义序列化(null值的处理)
查看>>
auth模块
查看>>
javascript keycode大全
查看>>
前台freemark获取后台的值
查看>>
log4j.properties的作用
查看>>
游戏偶感
查看>>
Leetcode: Unique Binary Search Trees II
查看>>
C++ FFLIB 之FFDB: 使用 Mysql&Sqlite 实现CRUD
查看>>
Spring-hibernate整合
查看>>
c++ map
查看>>