• 微信开发SDK|微信二次开发sdk使用教程--手机微信上线通知服务端


    微信开发SDK|微信二次开发sdk使用教程--手机微信上线通知服务端

    case WeChatOnlineNotice: {// 手机客户端微信上线通知
    log.debug("socket:msgtype=WeChatOnlineNotice");
    weChatOnlineNoticeHandler.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.PhoneInfo;
    import com.jubotech.business.web.domain.WeChatAccountInfo;
    import com.jubotech.business.web.service.PhoneService;
    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.TransportMessageOuterClass.EnumErrorCode;
    import Jubo.JuLiao.IM.Wx.Proto.TransportMessageOuterClass.EnumMsgType;
    import Jubo.JuLiao.IM.Wx.Proto.TransportMessageOuterClass.TransportMessage;
    import Jubo.JuLiao.IM.Wx.Proto.WeChatOnlineNotice.WeChatOnlineNoticeMessage;
    import io.netty.channel.ChannelHandlerContext;

    @Service
    public class WeChatOnlineNoticeHandler{
    private final Logger log = LoggerFactory.getLogger(getClass());
    @Autowired
    private WeChatAccountService weChatAccountService;

    @Autowired
    private PhoneService phoneService;
     
        /** 
     * 微信上线通知 
     * @author wechatno:tangjinjinwx
     * @param ctx
     * @param vo
     */
    public  void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
        try {
        	WeChatOnlineNoticeMessage req = vo.getContent().unpack(WeChatOnlineNoticeMessage.class);
        	log.info(JsonFormat.printer().print(req));
        	//1、校验用户信息
        	if(null != req){
            	//2、存储微信全局id 与通道
            	NettyConnectionUtil.registerUserid(req.getWeChatId(),ctx);
            	 
        		WeChatAccountInfo  accountInfo =  weChatAccountService.findWeChatAccountInfoByDeviceid(req.getIMEI());
        		PhoneInfo  pi = phoneService.getPhoneInfoByDeviceid(req.getIMEI());
        		if(null != accountInfo && null != accountInfo.getWechatid()){
        			//是否还是之前的那个微信号
        			if(!accountInfo.getWechatid().equals(req.getWeChatId())){
        				updateAccountInfo(req, accountInfo);
        			}
        			if(null != pi && null != pi.getAccountid()){
        				accountInfo.setAccountid(pi.getAccountid());
        			}
        			//改为上线状态
        			accountInfo.setIsonline(0);//上线
    				weChatAccountService.updateOnline(accountInfo);
        			
        			//3、告诉客户端消息已收到
    	    		MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);
        		}else{
        			if(null != pi){
        				accountInfo = new WeChatAccountInfo(req.getWeChatId(), req.getWeChatNo(), req.getWeChatNick(), req.getGenderValue(),
            					req.getAvatar(), req.getCountry(), req.getProvince(), req.getCity(), 0, req.getIMEI(), pi.getCid(), pi.getAccountid());
        				weChatAccountService.insert(accountInfo);
        				//3、告诉客户端消息已收到
        	    		MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);
        			}else{
        			    MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_ILLEGALDEVICE);
        			}
        		}
        		 
        	} 
         
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
        }
    }
    private void updateAccountInfo(WeChatOnlineNoticeMessage req, WeChatAccountInfo accountInfo) {
    	accountInfo.setWechatid(req.getWeChatId());
    	accountInfo.setWechatno(req.getWeChatNo());
    	accountInfo.setWechatnick(req.getWeChatNick());
    	accountInfo.setGender(req.getGenderValue());
    	accountInfo.setCountry(req.getCountry());
    	accountInfo.setCity(req.getCity());
    	accountInfo.setAvatar(req.getAvatar());
    	accountInfo.setProvince(req.getProvince());
    	weChatAccountService.update(accountInfo);
    }
    

    }

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

  • 相关阅读:
    .Net解析html文档类库HtmlAgilityPack完整使用说明
    C# 中使用JSON
    Property 'submit' of object #<HTMLFormElement> is not a function
    bin/...的访问被拒绝被拒绝的问题
    vs2012 ultimate 密钥
    ASP.NET-自定义HttpModule与HttpHandler
    jQuery同步Ajax带来的UI线程阻塞问题及解决办法
    Windows API
    服务器不安装Excel,实现导出Excel功能
    内存或磁盘空间不足,Microsoft Office Excel 无法再次打开或保存任何文档。 [问题点数:20分,结帖人wenyang2004]
  • 原文地址:https://www.cnblogs.com/wuliaokankan/p/10606366.html
Copyright © 2020-2023  润新知