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


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

    微信协议接口调用-加微信好友及通过好友请求

    加微信好友

        /** 
         * 微信自动添加好友
         * @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){
                    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);
            }
        }

    微信协议接口调用-群发微信好友,群发群消息

    群发微信好友、群发群
    private static void talkMsgToFriend(TaskTimeInfo info, TimeTaskDetailsDao timeTaskDetailsDao,

    List friends) {
    String executeTime = info.getExecute_time();
    Date newDate = DateUtil.convertString2Date(executeTime, DateUtil.DATE_FORMAT_4);
    Integer betweenTime = info.getBetween_time();

    if (betweenTime ==null || betweenTime==0) {
    betweenTime = (int)(Math.random()*3+3);
    }

    for (String friend : friends) {

    String newExecuteTime = DateUtil.convertDate2String(newDate, DateUtil.DATE_FORMAT_4);
    String msgStr = "";
    String jsonStr = info.getContent();
    List list = JsonUtils.json2Bean(jsonStr);

    for (int i = 0; i < list.size(); i++) {
    MessageVo msg = list.get(i);

    ByteString byteString = ByteString.copyFromUtf8(msg.getContent());

    TalkToFriendTaskMessage.Builder build = TalkToFriendTaskMessage.newBuilder();
    build.setWeChatId(info.getWechatId());
    build.setFriendId(friend);
    build.setContent(byteString);
    build.setMsgId(MsgIdBuilder.getId());

    if (msg.getContentType().equalsIgnoreCase("Text")) {// 文本类型
    build.setContentType(EnumContentType.Text);
    } else if (msg.getContentType().equalsIgnoreCase("Picture")) {// 图片类型
    build.setContentType(EnumContentType.Picture);
    } else if (msg.getContentType().equalsIgnoreCase("Voice")) {// 语音类型
    build.setContentType(EnumContentType.Voice);
    } else if (msg.getContentType().equalsIgnoreCase("Video")) {// 视频类型
    build.setContentType(EnumContentType.Video);
    } else if (msg.getContentType().equalsIgnoreCase("Link")) {// 链接类型
    build.setContentType(EnumContentType.Link);
    } else if (msg.getContentType().equalsIgnoreCase("WeApp")) {// 小程序
    build.setContentType(EnumContentType.WeApp);
    }

    TalkToFriendTaskMessage msg1 = build.build();
    if (null != msg1) {
    try {
    String json = JsonFormat.printer().print(msg1);

    if (!StringUtils.isEmpty(json)) {
    msgStr = msgStr + json;
    if (i != (list.size() - 1)) {
    msgStr = msgStr + "&&";
    }
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    }

    if (null != msgStr) {
    try {
    if (!StringUtils.isEmpty(msgStr)) {
    TimeTaskDetails detail = new TimeTaskDetails();
    detail.setTid(info.getId());
    detail.setExecute_time(newExecuteTime);
    detail.setJson_content(msgStr);
    detail.setMsgid(String.valueOf(MsgIdBuilder.getId()));
    timeTaskDetailsDao.insert(detail);
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    newDate = DateUtil.offsetSecode(newDate, betweenTime);

    }
    }

    个人微信api接口调用-发微信朋友圈、拉取朋友圈数据功能

    推送微信朋友圈列表
         /**
         * 触发推送朋友圈列表
         * @author wechatno:tangjinjinwx 
         * @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);
            }
        }

  • 相关阅读:
    ReentrantLock锁与AQS的联系
    Java高级教程
    C#企业办公自动化系统asp.net+sqlserver
    信号(软中断)
    NFT 的潜力:扩展的艺术品鉴定证书
    Kasisto AI:金融对话人工智能
    WorkManager 一篇文章就够了
    软考 系统架构设计师系列知识点之设计模式(9)
    状压dp。
    Shader的属性和语义
  • 原文地址:https://blog.csdn.net/u010405836/article/details/128199313