个人微信api接口

1、微信好友收发消息
        /**
     * 给微信好友发消息
     * @author wechatno:tangjinjinwx
     * @blog http://www.wlkankan.cn
     */
    @Async
    public void handleMsg(ChannelHandlerContext ctx, TransportMessage vo, String contentJsonStr) {
        try {
            log.debug(contentJsonStr);
            TalkToFriendTaskMessage.Builder bd = TalkToFriendTaskMessage.newBuilder();
            JsonFormat.parser().merge(contentJsonStr, bd);
            TalkToFriendTaskMessage req = bd.build();
            // 消息记录数据库
            asyncTaskService.savePcMessage(req);
            // 将消息转发送给手机客户端
            asyncTaskService.msgSend2Phone(ctx, req.getWeChatId(), EnumMsgType.TalkToFriendTask, vo, req);

} catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
        }
    }

/**
     * 微信好友发来聊天消息通知
     * @author wechatno:tangjinjinwx
         * @blog http://www.wlkankan.cn
     */
    @Async
    public void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
        try {
            FriendTalkNoticeMessage req = vo.getContent().unpack(FriendTalkNoticeMessage.class);
            log.debug(JsonFormat.printer().print(req));
            
            log.debug(LocalDateTime.now()+" 微信好友发来聊天消息  对应的线程名: "+Thread.currentThread().getName());
              
            //拦截消息
            asyncTaskService.msgAopTask(ctx,req,vo.getAccessToken(), vo.getId());
            //消息转发到pc端
            asyncTaskService.msgSend2pc(req.getWeChatId(), EnumMsgType.FriendTalkNotice, req);
             
            // 告诉客户端消息已收到
            MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);
            
            WxAccountInfo account = weChatAccountService.findWeChatAccountInfoByWeChatId(req.getWeChatId());
            //消息记录数据库
            if (null != account){
                asyncTaskService.saveMessage(account, req);
            }
             
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam,vo.getId(), e.getMessage());
        }
    }

2、触发手机推送微信好友列表及返回
        /**
     * 触发手机推送微信好友列表
     * @author wechatno:tangjinjinwx
     * @blog http://www.wlkankan.cn
     */
    @Async
    public  void handleMsg(ChannelHandlerContext ctx,TransportMessage vo, String contentJsonStr) {
        try {
            log.debug(contentJsonStr);
            TriggerFriendPushTaskMessage.Builder bd = TriggerFriendPushTaskMessage.newBuilder();
            JsonFormat.parser().merge(contentJsonStr, bd);
            TriggerFriendPushTaskMessage req = bd.build();
            //TriggerFriendPushTaskMessage req = vo.getContent().unpack(TriggerFriendPushTaskMessage.class);
            
            //将消息转发送给手机客户端
            asyncTaskService.msgSend2Phone(ctx, req.getWeChatId(), EnumMsgType.TriggerFriendPushTask, vo, req);
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
        }
    }

/**
     * 微信好友列表消息推送
     * @author wechatno:tangjinjinwx
         * @blog http://www.wlkankan.cn
     */
    @Async
    public void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
        try {
            FriendPushNoticeMessage req = vo.getContent().unpack(FriendPushNoticeMessage.class);
            log.debug(JsonFormat.printer().print(req));
            // 把消息转发给pc端
            asyncTaskService.msgSend2pc(req.getWeChatId(), EnumMsgType.FriendPushNotice, req);
             
            // 异步保存到数据库
            asyncTaskService.friendListSave(req);
             
            // 告诉客户端消息已收到
            MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);

} catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam, vo.getId(), Constant.ERROR_MSG_DECODFAIL);
        }
    }

3、触发推送微信群聊列表及返回
    /**
     * 触发推送微信群聊列表
     * @author wechatno:tangjinjinwx
     * @blog http://www.wlkankan.cn
     */
    @Async
    public void handleMsg(ChannelHandlerContext ctx, TransportMessage vo, String contentJsonStr) {
        try {
            log.debug(contentJsonStr);
            TriggerChatRoomPushTaskMessage.Builder bd = TriggerChatRoomPushTaskMessage.newBuilder();
            JsonFormat.parser().merge(contentJsonStr, bd);
            TriggerChatRoomPushTaskMessage req = bd.build();
            // 将消息转发送给手机客户端
            asyncTaskService.msgSend2Phone(ctx, req.getWeChatId(), EnumMsgType.TriggerChatroomPushTask, vo, req);
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
        }
    }

/**
     * 推送微信群聊列表
     * @author wechatno:tangjinjinwx
         * @blog http://www.wlkankan.cn
     */
    @Async
    public  void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
        try {
            ChatRoomPushNoticeMessage req = vo.getContent().unpack(ChatRoomPushNoticeMessage.class);
            log.debug(JsonFormat.printer().print(req));
            
            asyncTaskService.msgSend2pc(req.getWeChatId(), EnumMsgType.ChatroomPushNotice, req);
             
            asyncTaskService.qunListSave(req);
              
            // 告诉客户端消息已收到
            MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam,vo.getId(), Constant.ERROR_MSG_DECODFAIL);
        }
    }

4、推送微信朋友圈、发朋友圈
        /**
     * 触发推送朋友圈列表
     * @author wechatno:tangjinjinwx 
     * startTime传秒
     * @blog http://www.wlkankan.cn
     */
    @Async
    public void handleMsg(ChannelHandlerContext ctx, TransportMessage vo, String contentJsonStr) {
        try {
            log.debug(contentJsonStr);
            TriggerCirclePushTaskMessage.Builder bd = TriggerCirclePushTaskMessage.newBuilder();
            JsonFormat.parser().merge(contentJsonStr, bd);
            TriggerCirclePushTaskMessage req = bd.build();
            // TriggerCirclePushTaskMessage req =
            // vo.getContent().unpack(TriggerCirclePushTaskMessage.class);
            // 将消息转发送给手机客户端
            asyncTaskService.msgSend2Phone(ctx, req.getWeChatId(), EnumMsgType.TriggerCirclePushTask, vo, req);
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
        }
    }

/**
     * 回传手机微信朋友圈数据
     * @author wechatno:tangjinjinwx
         * @blog http://www.wlkankan.cn
     */
    @Async
    public  void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
        try {
            CirclePushNoticeMessage req = vo.getContent().unpack(CirclePushNoticeMessage.class);
            log.debug(JsonFormat.printer().print(req));
            //把消息转发给pc端
            asyncTaskService.msgSend2pc(req.getWeChatId(), EnumMsgType.CirclePushNotice, req);
            
            //保存朋友圈信息
            asyncTaskService.asyncSaveCircleMsg(req, circleService, weChatContactService);
            
            //告诉客户端消息已收到
            MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam,vo.getId(), Constant.ERROR_MSG_DECODFAIL);
        }
    }

/**
     * 发微信朋友圈
     * @author wechatno:tangjinjinwx
     * @blog http://www.wlkankan.cn
     */

@Async
    public  void handleMsg(ChannelHandlerContext ctx,TransportMessage vo, String contentJsonStr) {
        try {
            log.debug(contentJsonStr);
            PostSNSNewsTaskMessage.Builder bd = PostSNSNewsTaskMessage.newBuilder();
            JsonFormat.parser().merge(contentJsonStr, bd);
            PostSNSNewsTaskMessage req = bd.build();
            //PostSNSNewsTaskMessage req = vo.getContent().unpack(PostSNSNewsTaskMessage.class);
              
            asyncTaskService.msgSend2Phone(ctx, req.getWeChatId(), EnumMsgType.PostSNSNewsTask, vo, req);
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
        }
    }

5、加好友及通过好友请求

/** 
     * 微信自动添加好友
     * @author wechatno:tangjinjinwx
         * @blog http://www.wlkankan.cn
     */
    @Async
    public  void handleMsg(ChannelHandlerContext ctx ,TransportMessage vo, String contentJsonStr) {
        try {
            log.debug(contentJsonStr);
            FriendAddTaskSetting  req =  JSON.parseObject(contentJsonStr,FriendAddTaskSetting.class);
            if(null != req){
                String resp ="fail";
                 
                resp = friendAddTaskService.savePcTask(req);
                 
                //3、告诉PC客户端消息已收到
                MessageUtil.sendCustomJsonMsg(ctx, "AutoFriendAddTaskResp", resp);
                
            } 
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
        }
    }

/**
     * 微信新增好友通知
     * @author wechatno:tangjinjinwx
         * @blog http://www.wlkankan.cn
     */
    @Async
    public  void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
        try {
            FriendAddNoticeMessage req = vo.getContent().unpack(FriendAddNoticeMessage.class);
             
            //把消息转发给pc端
            asyncTaskService.msgSend2pc(req.getWeChatId(), EnumMsgType.FriendAddNotice, req);
            
            //保存新增好友
            asyncTaskService.saveFriendAddContactinfo(req);
            
            //告诉客户端消息已收到
            MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);
              
             
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam,vo.getId(), Constant.ERROR_MSG_DECODFAIL);
        }
    }

个人微信api接口调用代码相关推荐

  1. java 朋友圈分享接口_微信发朋友圈api接口调用代码

    微信发朋友圈api接口调用代码,推送微信朋友圈.发朋友圈 /** * 触发推送朋友圈列表 * @author wechatno:tangjinjinwx * startTime传秒 * @blog h ...

  2. 微信api接口调用-发朋友圈

    微信api接口调用-发朋友圈 /*** 发微信朋友圈* @author wechatno:tangjinjinwx* @blog http://www.wlkankan.cn*/@Asyncpubli ...

  3. 个人微信api接口调用-微信群管理

    个人微信api接口调用-微信群管理 /*** 微信群聊管理* @author wechatno:tangjinjinwx* @blog http://www.wlkankan.cn*/@Asyncpu ...

  4. 个人微信api接口调用-给微信好友或群聊发消息

    个人微信api接口调用-给微信好友或群聊发消息 /*** 给微信好友发消息* @author wechatno:tangjinjinwx* @blog http://www.wlkankan.cn*/ ...

  5. 定制电竞比分网LOL英雄联盟数据API接口调用代码

    定制电竞比分网LOL英雄联盟数据API接口调用代码 GET /api/result/lol 说明 该接口为LOL英雄联盟API接口,主要用来拉取比赛结果数据 当每一局比赛结束时,破晓字节电竞数据API ...

  6. 微信api接口调用-触发推送微信好友列表

    微信api接口调用-触发推送微信好友列表 /*** 触发推送微信好友列表任务* @author wechatno:tangjinjinwx* @blog http://www.wlkankan.cn* ...

  7. 个人微信api接口调用,推送微信好友群聊列表及返回

    个人微信api接口调用,推送微信好友群聊列表及返回 触发手机推送微信好友列表及返回/*** 触发手机推送微信好友列表* @author wechatno:tangjinjinwx* @blog htt ...

  8. 企业微信api接口调用-企业微信好友收发消息

    企业微信api消息接口调用-企业微信好友收发消息 /** * 给企业微信好友发消息 * @author wechat:happybabby110 * @blog http://www.wlkankan ...

  9. 企业微信api接口调用-触发推送企业微信微信好友

    企业微信SDK接口API调用-触发推送企业微信微信好友 /*** 触发企业微信推送微信好友列表* @author wechat:happybabby110* @blog http://www.wlka ...

  10. 企业微信api接口调用-触发推送企业微信联系人列表

    企业微信SDK接口API调用-触发推送企业微信联系人列表 /** * 触发推送企业微信联系人列表任务 * @author wechat:happybabby110 * @blog http://www ...

最新文章

  1. 高斯消元法对矩阵LU分解的影响
  2. 广域网优化产品的5大应用场景—Vecloud
  3. 【Protocol Buffer】Protocol Buffer入门教程(五):repeated限定修饰符
  4. java wsdl xfire_java调用wsdl xfire和cxf两种方式
  5. react+ant练习
  6. [转载] python numpy矩阵运算加速器 NumExpr
  7. Vuex actions 异步操作基础
  8. C实现NV12转I420
  9. 485通讯的校验和_三菱FX3U与变频器通讯程序如何编写
  10. ubuntu 16.04 配置网络代理
  11. 【收藏】QCIF、 CIF、2CIF、DCIF、D1(4CIF)格式介绍
  12. VS1005 功放板
  13. 【单片机】2.9 看门狗定时器(WDT)功能简介
  14. win10计算机系统慢,解决Win10电脑变慢的一些方法
  15. 滚珠螺杆螺母的安装教程来了
  16. numeric比较大小 数据库_数据库基础知识个人整理版-强烈推荐
  17. Unity入门03——Unity脚本
  18. 晨跑、午后跑和夜跑对身体的影响及优缺点
  19. SAP中采购收退货与发票校验对应关系解读
  20. 网络工程基础- -mac地址以及端口安全

热门文章

  1. Cisco NX-OS 基础配置指南(持续更新)
  2. 几款脑力训练软件分析与推荐
  3. ubuntu20.04安装谷歌拼音输入法
  4. 我的世界java手机_我的世界Java安卓版下载_我的世界Java手机版官方下载_牛游戏网...
  5. 一些内网穿透的软件一览表
  6. 服务器mdf ldf文件,数据库mdf和ldf文件上传到服务器
  7. JavaWeb学习DAY2—Java web的创建
  8. 如何刷新DNS缓存(Windows,Mac,Chrome)
  9. 曾宪武《物联网通信技术》课后答案(三)
  10. linux桌面监控软件,Ubuntu安装Conky系统监控桌面插件