抖音sdk,抖音开发api接口

简介: 抖音sdk,抖音开发api接口

抖音sdk,抖音开发api接口

1、抖音上线下线

/** 
     * 抖音上线通知 
     * @author wechat:happybabby110
     * @blog http://www.wlkankan.cn
     */
    public  void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
        try {
            ImOnlineNoticeMessage req = vo.getContent().unpack(ImOnlineNoticeMessage.class);
            log.debug(JsonFormat.printer().print(req));
            //1、校验用户信息
            if(null != req){
                //2、存储全局id 与通道
                NettyConnectionUtil.registerUserid(req.getImUid(),ctx);
                   
                DeviceInfo  device = deviceService.getByDeviceid(req.getImei());
                if(null != device){
                    //做个保护,如果当前微信号在其他设备上登陆过,就把之前那条记录删除
                    if(!StringUtils.isBlank(req.getImUid()) && !StringUtils.isBlank(req.getImei())){
                         if(!StringUtils.isEmpty(device.getImuid()) && !req.getImUid().equals(device.getImuid())){
                             device.setAvatar("");
                             device.setImuid("");
                             device.setNickname("");
                             device.setIsonline(1);
                             deviceService.update(device);
                         }
                    }
                    //设置新的参数
                    device.setImuid(req.getImUid());
                    device.setNickname(req.getNickName());
                    device.setAvatar(req.getAvatar());
                    device.setGender(req.getGenderValue());
                    device.setPhone(req.getPhone());
                    device.setUniqueid(req.getUniqueId());
                    device.setProvince(req.getProvince());
                    device.setCity(req.getCity());
                    device.setDistrict(req.getDistrict());
                    device.setSignature(req.getSignature());
                    device.setAwemecount(req.getAwemeCount());
                    device.setFollowingcount(req.getFollowingCount());
                    device.setFollowercount(req.getFollowerCount());
                    device.setFriendcount(req.getFriendCount());
                         
                    //改为上线状态
                    device.setIsonline(0);//上线
                    deviceService.update(device);
                    //3、告诉客户端消息已收到
                    MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);
                    
                    asyncTaskService.msgSend2pc(req.getImUid(), EnumMsgType.ImOnlineNotice, req);
                }
                 
            } 
         
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam,vo.getId(), e.getMessage());
        }
    }
   /**
     * 抖音下线通知
     * @author wechat:happybabby110
     * @blog http://www.wlkankan.cn
     */
    public void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
        try {
            ImOfflineNoticeMessage req = vo.getContent().unpack(ImOfflineNoticeMessage.class);
            log.debug(JsonFormat.printer().print(req));
            if (null != req) {
                // 把消息转发给pc端
                DeviceInfo account = deviceService.getByImUid(req.getImUid());
                if (null != account) {
                    account.setIsonline(1);// 下线
                    deviceService.update(account);
                     
                    asyncTaskService.msgSend2pc(req.getImUid(), EnumMsgType.ImOfflineNotice, req);
                }
                // 3、告诉客户端消息已收到
                MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);
            } else {
                MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam, vo.getId(), Constant.ERROR_MSG_ILLEGALDEVICE);
            }
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam, vo.getId(), Constant.ERROR_MSG_DECODFAIL);
        }
    }

2、抖音粉丝或好友收发消息

/**
     * 给抖音粉丝或好友发消息
     * @author wechat:happybabby110
     * @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.msgSend2Phone(ctx, req.getImUid(), EnumMsgType.TalkToFriendTask, vo, req);
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
        }
    }
   /**
     * 抖音聊天消息实时推送
     * @author wechat:happybabby110
     * @blog http://www.wlkankan.cn
     */
    @Async
    public void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
        try {
            ChatMsgNoticeMessage req = vo.getContent().unpack(ChatMsgNoticeMessage.class);
            log.debug(JsonFormat.printer().print(req));
            
            log.debug(LocalDateTime.now()+" ChatMsgNoticeMessage  对应的线程名: "+Thread.currentThread().getName());
               
            //消息转发到pc端
            asyncTaskService.msgSend2pc(req.getImUid(), EnumMsgType.ChatMsgNotice, req);
             
            // 告诉客户端消息已收到
            MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);
              
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam,vo.getId(), e.getMessage());
        }
    }

3、关注与取消关注抖音号

/**
     * @author wechat:happybabby110
     * @blog http://www.wlkankan.cn
     * 关注抖音号
     */
    @Async
    public  void handleMsg(ChannelHandlerContext ctx,TransportMessage vo, String contentJsonStr) {
        try {
            log.debug(contentJsonStr);
            FollowTaskMessage.Builder bd = FollowTaskMessage.newBuilder();
            JsonFormat.parser().merge(contentJsonStr, bd);
            FollowTaskMessage req = bd.build();
            //将消息转发送给手机客户端
            asyncTaskService.msgSend2Phone(ctx, req.getImUid(), EnumMsgType.FollowTask, vo, req);
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
        }
    }
   /**
     * 取消关注抖音号
     * @author wechat:happybabby110
     * @blog http://www.wlkankan.cn
     */
    @Async
    public  void handleMsg(ChannelHandlerContext ctx,TransportMessage vo, String contentJsonStr) {
        try {
            log.debug(contentJsonStr);
            UnFollowTaskMessage.Builder bd = UnFollowTaskMessage.newBuilder();
            JsonFormat.parser().merge(contentJsonStr, bd);
            UnFollowTaskMessage req = bd.build();
            //将消息转发送给手机客户端
            asyncTaskService.msgSend2Phone(ctx, req.getImUid(), EnumMsgType.UnFollowTask, vo, req);
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
        }
    }

4、同步抖音推荐的好友

/**
     * 同步抖音推荐的好友
     * @author wechat:happybabby110
     * @blog http://www.wlkankan.cn
     */
    @Async
    public  void handleMsg(ChannelHandlerContext ctx,TransportMessage vo, String contentJsonStr) {
        try {
            log.debug(contentJsonStr);
            SyncRecFriendsTaskMessage.Builder bd = SyncRecFriendsTaskMessage.newBuilder();
            JsonFormat.parser().merge(contentJsonStr, bd);
            SyncRecFriendsTaskMessage req = bd.build();
            //将消息转发送给手机客户端
            asyncTaskService.msgSend2Phone(ctx, req.getImUid(), EnumMsgType.SyncRecFriendsTask, vo, req);
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
        }
    }
   /**
     * 推送抖音推荐的好友
     * @author wechat:happybabby110
     * @blog http://www.wlkankan.cn
     */
    @Async
    public void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
        try {
            RecFriendsPushNoticeMessage req = vo.getContent().unpack(RecFriendsPushNoticeMessage.class);
            log.debug(JsonFormat.printer().print(req));
            
            log.debug(LocalDateTime.now()+" RecFriendsPushNoticeMessage  对应的线程名: "+Thread.currentThread().getName());
               
            //消息转发到pc端
            asyncTaskService.msgSend2pc(req.getImUid(), EnumMsgType.RecFriendsPushNotice, req);
             
            // 告诉客户端消息已收到
            MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);
             
             
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam,vo.getId(), e.getMessage());
        }
    }

5、同步抖音聊天会话列表

/**
     * 同步抖音会话列表
     * @author wechat:happybabby110
     * @blog http://www.wlkankan.cn
     */
    @Async
    public  void handleMsg(ChannelHandlerContext ctx,TransportMessage vo, String contentJsonStr) {
        try {
            log.debug(contentJsonStr);
            SyncConversationTaskMessage.Builder bd = SyncConversationTaskMessage.newBuilder();
            JsonFormat.parser().merge(contentJsonStr, bd);
            SyncConversationTaskMessage req = bd.build();
            //将消息转发送给手机客户端
            asyncTaskService.msgSend2Phone(ctx, req.getImUid(), EnumMsgType.SyncConversationTask, vo, req);
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
        }
    }
   /**
     * 推送抖音会话列表
     * @author wechat:happybabby110
     * @blog http://www.wlkankan.cn
     */
    @Async
    public void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
        try {
            ConversationPushNoticeMessage req = vo.getContent().unpack(ConversationPushNoticeMessage.class);
            log.debug(JsonFormat.printer().print(req));
            
            log.debug(LocalDateTime.now()+" ConversationPushNoticeMessage  对应的线程名: "+Thread.currentThread().getName());
               
            //消息转发到pc端
            asyncTaskService.msgSend2pc(req.getImUid(), EnumMsgType.ConversationPushNotice, req);
             
            // 告诉客户端消息已收到
            MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);
             
             
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam,vo.getId(), e.getMessage());
        }
    }

6、同步抖音粉丝列表

/**
     * 同步抖音粉丝
     * @author wechat:happybabby110
     * @blog http://www.wlkankan.cn
     */
    @Async
    public  void handleMsg(ChannelHandlerContext ctx,TransportMessage vo, String contentJsonStr) {
        try {
            log.debug(contentJsonStr);
            SyncFollowersTaskMessage.Builder bd = SyncFollowersTaskMessage.newBuilder();
            JsonFormat.parser().merge(contentJsonStr, bd);
            SyncFollowersTaskMessage req = bd.build();
            //将消息转发送给手机客户端
            asyncTaskService.msgSend2Phone(ctx, req.getImUid(), EnumMsgType.SyncFollowersTask, vo, req);
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
        }
    }
   /**
     * 推送抖音粉丝
     * @author wechat:happybabby110
     * @blog http://www.wlkankan.cn
     */
    @Async
    public void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
        try {
            FollowersPushNoticeMessage req = vo.getContent().unpack(FollowersPushNoticeMessage.class);
            log.debug(JsonFormat.printer().print(req));
            
            log.debug(LocalDateTime.now()+this.getClass().getName()+"对应的线程名: "+Thread.currentThread().getName());
               
            //消息转发到pc端
            asyncTaskService.msgSend2pc(req.getImUid(), EnumMsgType.FollowersPushNotice, req);
             
            // 告诉客户端消息已收到
            MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);
             
        } catch (Exception e) {
            e.printStackTrace();
            MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam,vo.getId(), e.getMessage());
        }
    }
目录
打赏
0
0
0
0
120
分享
相关文章
CompreFace:Star6.1k,Github上火爆的轻量化且强大的人脸识别库,api,sdk都支持
CompreFace 是一个在 GitHub 上拥有 6.1k Star 的轻量级人脸识别库,支持 API 和 SDK。它由 Exadel 公司开发,基于深度学习技术,提供高效、灵活的人脸识别解决方案。CompreFace 支持多种模型(如 VGG-Face、OpenFace 和 Facenet),具备多硬件支持、丰富的功能服务(如人脸检测、年龄性别识别等)和便捷的部署方式。适用于安防监控、商业领域和医疗美容等多个场景。
【11】flutter进行了聊天页面的开发-增加了即时通讯聊天的整体页面和组件-切换-朋友-陌生人-vip开通详细页面-即时通讯sdk准备-直播sdk准备-即时通讯有无UI集成的区别介绍-开发完整的社交APP-前端客户端开发+数据联调|以优雅草商业项目为例做开发-flutter开发-全流程-商业应用级实战开发-优雅草Alex
【11】flutter进行了聊天页面的开发-增加了即时通讯聊天的整体页面和组件-切换-朋友-陌生人-vip开通详细页面-即时通讯sdk准备-直播sdk准备-即时通讯有无UI集成的区别介绍-开发完整的社交APP-前端客户端开发+数据联调|以优雅草商业项目为例做开发-flutter开发-全流程-商业应用级实战开发-优雅草Alex
162 90
【11】flutter进行了聊天页面的开发-增加了即时通讯聊天的整体页面和组件-切换-朋友-陌生人-vip开通详细页面-即时通讯sdk准备-直播sdk准备-即时通讯有无UI集成的区别介绍-开发完整的社交APP-前端客户端开发+数据联调|以优雅草商业项目为例做开发-flutter开发-全流程-商业应用级实战开发-优雅草Alex
小红书笔记详情 API 接口的开发、应用与收益
小红书(RED)作为国内领先的生活方式分享平台,汇聚了大量用户生成内容(UGC),尤其是“种草”笔记。小红书笔记详情API接口为开发者提供了获取笔记详细信息的强大工具,包括标题、内容、图片、点赞数等。通过注册开放平台账号、申请API权限并调用接口,开发者可以构建内容分析工具、笔记推荐系统、数据爬虫等应用,提升用户体验和运营效率,创造新的商业模式。本文详细介绍API的开发流程、应用场景及潜在收益,并附上Python代码示例。
192 61
【04】鸿蒙实战应用开发-华为鸿蒙纯血操作系统Harmony OS NEXT-正确安装鸿蒙SDK-结构目录介绍-路由介绍-帧动画(ohos.animator)书写介绍-能够正常使用依赖库等-ArkUI基础组件介绍-全过程实战项目分享-从零开发到上线-优雅草卓伊凡
【04】鸿蒙实战应用开发-华为鸿蒙纯血操作系统Harmony OS NEXT-正确安装鸿蒙SDK-结构目录介绍-路由介绍-帧动画(ohos.animator)书写介绍-能够正常使用依赖库等-ArkUI基础组件介绍-全过程实战项目分享-从零开发到上线-优雅草卓伊凡
38 5
【04】鸿蒙实战应用开发-华为鸿蒙纯血操作系统Harmony OS NEXT-正确安装鸿蒙SDK-结构目录介绍-路由介绍-帧动画(ohos.animator)书写介绍-能够正常使用依赖库等-ArkUI基础组件介绍-全过程实战项目分享-从零开发到上线-优雅草卓伊凡
【02】鸿蒙实战应用开发-华为鸿蒙纯血操作系统Harmony OS NEXT-项目开发实战-准备工具安装-编译器DevEco Studio安装-arkts编程语言认识-编译器devco-鸿蒙SDK安装-模拟器环境调试-hyper虚拟化开启-全过程实战项目分享-从零开发到上线-优雅草卓伊凡
【02】鸿蒙实战应用开发-华为鸿蒙纯血操作系统Harmony OS NEXT-项目开发实战-准备工具安装-编译器DevEco Studio安装-arkts编程语言认识-编译器devco-鸿蒙SDK安装-模拟器环境调试-hyper虚拟化开启-全过程实战项目分享-从零开发到上线-优雅草卓伊凡
28 2
【02】鸿蒙实战应用开发-华为鸿蒙纯血操作系统Harmony OS NEXT-项目开发实战-准备工具安装-编译器DevEco Studio安装-arkts编程语言认识-编译器devco-鸿蒙SDK安装-模拟器环境调试-hyper虚拟化开启-全过程实战项目分享-从零开发到上线-优雅草卓伊凡
DeepClaude:结合 DeepSeek R1 和 Claude AI 各自优势开发的 AI 应用平台,支持 API 调用和零延迟的即时响应
DeepClaude 是一个开源的 AI 应用开发平台,结合了 DeepSeek R1 和 Claude 模型的优势,提供即时响应、端到端加密和高度可配置的功能。
244 4
DeepClaude:结合 DeepSeek R1 和 Claude AI 各自优势开发的 AI 应用平台,支持 API 调用和零延迟的即时响应
以项目登录接口为例-大前端之开发postman请求接口带token的请求测试-前端开发必学之一-如果要学会联调接口而不是纯写静态前端页面-这个是必学-本文以优雅草蜻蜓Q系统API为实践来演示我们如何带token请求接口-优雅草卓伊凡
以项目登录接口为例-大前端之开发postman请求接口带token的请求测试-前端开发必学之一-如果要学会联调接口而不是纯写静态前端页面-这个是必学-本文以优雅草蜻蜓Q系统API为实践来演示我们如何带token请求接口-优雅草卓伊凡
48 5
以项目登录接口为例-大前端之开发postman请求接口带token的请求测试-前端开发必学之一-如果要学会联调接口而不是纯写静态前端页面-这个是必学-本文以优雅草蜻蜓Q系统API为实践来演示我们如何带token请求接口-优雅草卓伊凡
云原生应用实战:基于阿里云Serverless的API服务开发与部署
随着云计算的发展,Serverless架构日益流行。阿里云函数计算(Function Compute)作为Serverless服务,让开发者无需管理服务器即可运行代码,按需付费,简化开发运维流程。本文从零开始,介绍如何使用阿里云函数计算开发简单的API服务,并探讨其核心优势与最佳实践。通过Python示例,演示创建、部署及优化API的过程,涵盖环境准备、代码实现、性能优化和安全管理等内容,帮助读者快速上手Serverless开发。
阿里巴巴热卖商品推荐 API 接口的开发、应用与收益
阿里巴巴热卖商品推荐API为开发者提供了获取平台热卖商品信息的强大工具,涵盖商品标题、价格、销量等数据。通过注册开放平台账号、申请API权限并调用接口,开发者可构建热卖商品推荐系统、数据分析工具及供应链管理系统等应用,提升用户体验与运营效率,创造新的商业模式。该API采用RESTful风格,支持多种应用场景,助力电商从业者实现创新与增值。
106 7
1688APP 原数据 API 接口的开发、应用与收益
1688作为阿里巴巴旗下的B2B平台,汇聚海量供应商和商品资源。其APP原数据API接口为开发者提供获取商品详细信息的强大工具,涵盖商品标题、价格、图片等。通过注册开放平台账号、申请API权限并调用接口,开发者可构建比价工具、供应链管理及自动化上架工具等应用,提升用户体验与运营效率,创造新的商业模式。示例代码展示了如何使用Python调用API并解析返回结果。
88 8

热门文章

最新文章