个人微信api接口,java调用个人微信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);
        }
    }

java调用个人微信api接口实现收发消息发朋友圈相关推荐

  1. java调用个人微信API接口收发朋友圈,删除评论朋友圈

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

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

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

  3. java调用第三方天气预报API接口

    java调用第三方天气预报API接口 package com.sensordata.controller; import com.common.json.JSONObject; import java ...

  4. SERP调用企业微信API接口,发送文本信息实例

    SERP企业轻量级ERP(SSDCRM)起源于vtigercrm早期版本.随着我们不停的迭代研发与完善,今日已经形成了自己鲜明的应用风格.我们在完善平台内部功能的基础上,积极研发平台与企业微信,钉钉, ...

  5. 微信转发指定的图文消息到朋友圈(JAVA版)

    微信转发图文消息步骤 微信转发图文消息步骤 需求 获取凭证 获取aceess_token 获取jsapi_ticket 缓存获取的jsapi_ticket 代码 config接口注入权限 引入js文件 ...

  6. JAVA调用有道API接口对数据库中的中文语句进行翻译

    今天遇到一个小需求,就是将数据库中的某个中文字段翻译成英文,总共有六百多条,直接只用数据库update语句和手动翻译效率很慢.我想这如果可以调用有道翻译API接口将翻译的语句结合原中文字段拼接成upd ...

  7. html 调用weixinsharetimeline,微信小程序使用onShareTimeline分享到朋友圈的方法

    最近微信小程序终于公测了一个分享到朋友圈的功能,这对营销来说可是一个很重要的功能啊.如何使用这个功能呢?这里详细介绍一下. 使用到的函数onShareTimeline()与onShareAppMess ...

  8. 写一个微信pc端,还能发朋友圈!

    微信通信接口定义 1.基础消息类型 1.客户端发送的心跳包 HeartBeatReq = 1001; 2.消息接收确认回复(接收或拒绝接收) MsgReceivedAck = 1002; 3.错误单独 ...

  9. 小米9se(miui 10) 微信里保存的图片,发朋友圈时找不到的解决办法

    下面的解决办法在小米9se中,亲测有效. 这个问题应该是一键换机导致. 解决方案如下:1.确认自己照片已在云端备份.2.将tencent/micromsg重命名(可以随便取,只要和原来不同即可),然后 ...

最新文章

  1. linux创建启动连接数据库,DB2入门(1)--安装、启动、连接
  2. 堆栈 cookie 检测代码检测到基于堆栈的缓冲区溢出_WhatsApp缓冲区漏洞曝光 攻击者可通过MP4文件执行远程代码...
  3. SaaS服务在未来云计算中该如何发展
  4. 雅客EXCEL(7)-EXCEL居家常用必备函数(vlookup,IF,AND,OR)
  5. C# 调Win32 API SendMessage简单用法及wMsg常量
  6. 安装JDK以及配置Java运行环境
  7. 卡在linuxctrld进系统_Linux系统执行df -h命令卡死的解决方案
  8. css3 下拉缩放显示定位导航
  9. OEA ORM 框架中的冗余属性设计
  10. 15. (附加)链表中间节点(C++版本)
  11. 数据结构与算法 php pdf,数据结构与算法之美(完结)云盘分享_IT教程网
  12. spring揭秘_「死磕 Spring」—– IOC 之深入理解 Spring IoC
  13. 清理FLASH_RECOVERY_AREA
  14. TDA4 制作 SD卡驱动
  15. 关于无法在驱动器0分区上安装Windows
  16. three.js自定义材质各向异性
  17. 像CFO一样思考(1)- 给私域运营算个帐
  18. 五子棋游戏-1(绘制棋盘)
  19. IOS APP画面防截屏
  20. eos游戏开发德州扑克

热门文章

  1. 好看有个性的轻量级可配置网站导航源码 可做各种网站导航
  2. 【时间管理】对工作的进度得把控
  3. 什么是语音识别的语音助手?
  4. 无法定位程序输入点dxgiget_星球大战战机中队打不开怎么办 游戏报错修复方法...
  5. 冰蓝云支付系统 可对接官方接口易支付码支付
  6. Hive SQL 中ARRAY或MAP类型数据处理:lateral view explode()/posexplode()——行转列函数
  7. [教学小东西][游戏][js] 修改js游戏的属性
  8. 详解交换两个数的五种思路
  9. centos部署nextcloud
  10. 大庆 让胡路 长青 车检中心 检车流程