微信开发SDK|微信sdk使用教程--手机客户端微信下线通知服务端

微信开发SDK|微信sdk使用教程--手机客户端微信下线通知服务端

case WeChatOfflineNotice: {// 手机客户端微信下线通知
log.debug("socket:msgtype=WeChatOfflineNotice");
weChatOfflineNoticeHandler.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.AccountInfo;
import com.jubotech.business.web.domain.WeChatAccountInfo;
import com.jubotech.business.web.service.AccountService;
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.WeChatOfflineNotice.WeChatOfflineNoticeMessage;
import io.netty.channel.ChannelHandlerContext;

@Service
public class WeChatOfflineNoticeHandler{
private final Logger log = LoggerFactory.getLogger(getClass());
@Autowired
private WeChatAccountService weChatAccountService;
@Autowired
private AccountService accountService;
/
手机客户端微信下线通知
* @author wechatno:tangjinjinwx
* @param ctx
* @param vo
*/
public void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
try {
WeChatOfflineNoticeMessage req = vo.getContent().unpack(WeChatOfflineNoticeMessage.class);
log.info(JsonFormat.printer().print(req));
WeChatAccountInfo accountInfo = weChatAccountService.findWeChatAccountInfoByDeviceid(req.getIMEI());
if(null != req && null != accountInfo){
// 把消息转发给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) {
MessageUtil.sendJsonMsg(chx, EnumMsgType.WeChatOfflineNotice, NettyConnectionUtil.getNettyId(chx),null, req);
}
}

            }
            
            accountInfo.setIsonline(1);//下线
            weChatAccountService.updateOnline(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);
    }
}

}

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,关于微信php开发包和TP5专用微信sdk使用教程,我可以给您提供一些基本的信息和建议。 首先,微信php开发包是一个开源的PHP类库,主要用于实现微信公众号开发中的各种功能,包括公众号的认证、消息的接收和回复、素材管理、用户管理等等。该类库基于微信官方API进行封装,使用起来比较方便,适合PHP开发者快速开发微信公众号应用。 而TP5专用微信sdk则是一个基于微信php开发包封装的TP5扩展包,可以直接在TP5框架中使用,提供了更加简便的接口和操作方法。使用该扩展包可以大大简化微信公众号开发的流程,快速实现各种功能。 下面是使用教程的一些基本步骤: 1. 首先,您需要在微信公众平台上申请并获得公众号的appid和appsecret,以及token等基本信息。 2. 然后,您可以下载微信php开发包和TP5专用微信sdk,将其放置在您的项目目录下。 3. 在TP5框架中,您需要在config目录下创建一个wechat.php的配置文件,用于存储微信公众号的基本信息和配置。 4. 在控制器中,您可以使用如下代码初始化微信sdk: ``` use think\facade\Config; use think\facade\Request; use wechat\Wechat; class WechatController extends Controller { protected $wechat; public function __construct() { parent::__construct(); $config = Config::get('wechat'); $this->wechat = new Wechat($config); } } ``` 其中,$config变量是您在config/wechat.php中定义的微信公众号配置信息。 5. 接下来,您可以根据需要使用微信sdk提供的各种功能。例如,接收用户发送的消息并回复: ``` public function index() { $request = Request::instance(); if ($request->isGet()) { // 验证消息的确来自微信服务器 $this->wechat->valid(); } else { // 处理用户发送的消息 $message = $this->wechat->getMessage(); if ($message) { $this->wechat->reply($message->Content); } } } ``` 在以上代码中,我们使用了valid()方法用于验证消息是否来自微信服务器,getMessage()方法用于获取用户发送的消息,reply()方法用于回复消息。 当然,以上只是一个简单的示例,您可以根据自己的需求选择合适的方法和接口进行开发。同时,建议您仔细阅读微信php开发包和TP5专用微信sdk的官方文档,了解更多详细信息和使用方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值