个人微信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. 微信api接口调用-发朋友圈

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

  2. java给朋友发微信_微信api接口,给微信好友收发消息

    微信api接口,给微信好友收发消息 /** * 给微信好友发消息 * @author wechatno:tangjinjinwx * @blog http://www.wlkankan.cn */ @ ...

  3. php获取蓝奏云直连,最新php蓝奏云直链api接口源代码

    最新php蓝奏云直链API接口源代码<?php $url=base64_decode('aHR0cHM6Ly9hcGkucGluZ3Bpbmc2LmNvbS90b29scy9sYW56b3Uv' ...

  4. 最新php蓝奏云直链api接口源代码

    最新php蓝奏云直链API接口源代码 <?php$url=base64_decode('aHR0cHM6Ly9hcGkucGluZ3Bpbmc2LmNvbS90b29scy9sYW56b3Uv' ...

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

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

  6. 微信API接口目录大全

    微信API接口目录大全 1.基础消息类型 1.客户端发送的心跳包HeartBeatReq = 1001;  2.消息接收确认回复(接收或拒绝接收)MsgReceivedAck = 1002;  3.错 ...

  7. 微信API接口、微信二次开发API调用

    微信API接口.微信二次开发API调用 微信协议接口调用-加微信好友及通过好友请求 加微信好友 /**       * 微信自动添加好友      * @author wechatno:tangjin ...

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

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

  9. java版微信朋友圈_java调用个人微信API接口发朋友圈,评论和删除朋友圈

    java调用个人微信API接口发朋友圈,评论和删除朋友圈 /** * 发送朋友圈任务 * @author wechatno:tangjinjinwx * @param ctx * @param vo ...

最新文章

  1. 借助深度卷积神经网络对图片 GIF 视频进行超分辨率放大(即放大与降噪) 以及 对视频进行 插帧(即补帧).
  2. php mysql备份成sql_单php文件实现备份MySQL导出为.sql数据库代码
  3. linux编写复制脚本程,常用的Shell脚本
  4. android 例子源码_AOSP系列文章(一)-Android系统源码下载和编译
  5. 决策树缺失值python_【机器学习笔记之二】决策树的python实现
  6. 混淆矩阵与精确度、召回率、F1 Score
  7. Vue CLI 3.0 正式发布,Vue.js 开发标准化工具
  8. 从caffe2 开源的代码中抽取 用于加载已训练神经网络参数,使用CPU进行预测的 部分代码,并运行成功一个预测模型...
  9. [原译]实现IEnumerable接口理解yield关键字
  10. 拥塞控制,图文并茂(挺丰富,借鉴较多大佬的思想)
  11. 不足300的游戏蓝牙耳机靠谱吗?五款高人气蓝牙耳机测评
  12. Android中app的请求抓包工具 Fiddler 详解
  13. 按键精灵手机助手错误:at tempt to compare nu11 with number
  14. python程序设计实用教程答案_Python程序设计实用教程
  15. bzoj5145 [Ynoi2018]未来日记 (多校第4场1013 Yuno and Claris)
  16. java id 锁_java 多线程synchronized同步锁锁住相同用户Id
  17. 实现蓝色理想的运行代码
  18. 【Scratch画图100例】图39-scratch实心圆 少儿编程 scratch编程画图案例教程 考级比赛画图集训案例
  19. 金蝶专业版过账提示运行时错误5_金蝶专业版过账提示运行时错误5_金蝶KIS专业版常见故障及解决办法...
  20. 2022-11-01 网工进阶(三十四) IP组播协议(PIM)-模式概述、组播分发树的分类、PIM路由表项、PIM-DM工作原理(组播分发树的形成、配置举例)

热门文章

  1. 在ARCGIS SERVER 9.2中动态增加图层(附代码)
  2. 博弈论——混合博弈和监督博弈
  3. VUE jsplumb流程图设计
  4. 搜狗微信APP分析(二)so层
  5. 电脑复制手机粘贴神器-快贴使用方法
  6. 2018CCPC吉林总结
  7. cmd自定义批量修改文件名
  8. 手机网速越来越慢?路由器别放在这3个地方
  9. 云从发布从容AI大模型;莫言用ChatGPT帮余华写颁奖词;罗普特遭立案调查丨每日大事件...
  10. D05——C语言基础学PYTHON