抖音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),具备多硬件支持、丰富的功能服务(如人脸检测、年龄性别识别等)和便捷的部署方式。适用于安防监控、商业领域和医疗美容等多个场景。
速卖通商品详情接口(速卖通API系列)
速卖通(AliExpress)是阿里巴巴旗下的跨境电商平台,提供丰富的商品数据。通过速卖通开放平台(AliExpress Open API),开发者可获取商品详情、订单管理等数据。主要功能包括商品搜索、商品详情、订单管理和数据报告。商品详情接口aliexpress.affiliate.productdetail.get用于获取商品标题、价格、图片等详细信息。开发者需注册账号并创建应用以获取App Key和App Secret,使用PHP等语言调用API。该接口支持多种请求参数和返回字段,方便集成到各类电商应用中。
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请求接口-优雅草卓伊凡
亚马逊商品详情接口(亚马逊 API 系列)
亚马逊作为全球最大的电商平台之一,提供了丰富的商品资源。开发者和电商从业者可通过亚马逊商品详情接口获取商品的描述、价格、评论、排名等数据,对市场分析、竞品研究、价格监控及业务优化具有重要价值。接口基于MWS服务,支持HTTP/HTTPS协议,需注册并获得API权限。Python示例展示了如何使用mws库调用接口获取商品详情。应用场景包括价格监控、市场调研、智能选品、用户推荐和库存管理等,助力电商运营和决策。
80 23
lazada商品详情接口 (lazada API系列)
Lazada 是东南亚知名电商平台,提供海量商品资源。通过其商品详情接口,开发者和商家可获取商品标题、价格、库存、描述、图片、用户评价等详细信息,助力市场竞争分析、商品优化及库存管理。接口采用 HTTP GET 请求,返回 JSON 格式的响应数据,支持 Python 等语言调用。应用场景包括竞品分析、价格趋势研究、用户评价分析及电商应用开发,为企业决策和用户体验提升提供有力支持。
71 21
云原生应用实战:基于阿里云Serverless的API服务开发与部署
随着云计算的发展,Serverless架构日益流行。阿里云函数计算(Function Compute)作为Serverless服务,让开发者无需管理服务器即可运行代码,按需付费,简化开发运维流程。本文从零开始,介绍如何使用阿里云函数计算开发简单的API服务,并探讨其核心优势与最佳实践。通过Python示例,演示创建、部署及优化API的过程,涵盖环境准备、代码实现、性能优化和安全管理等内容,帮助读者快速上手Serverless开发。
eBay商品详情接口(ebay API系列)
eBay 商品详情接口是电商从业者、开发者和数据分析师获取商品详细信息的重要工具,涵盖标题、价格、库存、卖家信息等。使用前需在 eBay 开发者平台注册并获取 API 凭证,通过 HTTP GET 请求调用接口,返回 JSON 格式数据。Python 示例代码展示了如何发送请求并解析响应,确保合法合规使用数据。
49 12
阿里巴巴商品详情接口(阿里巴巴 API 系列)
在电商开发中,获取阿里巴巴商品详情信息对数据分析、竞品研究等至关重要。通过调用其商品详情接口,开发者可获取标题、价格、图片、描述等数据,满足多种业务需求。接口采用HTTPS协议,支持GET/POST请求,返回JSON格式数据。示例代码展示了如何使用Python的requests库进行接口请求,需传递商品ID和访问令牌。实际应用时,请依据官方文档调整参数并确保安全性。
46 10
速卖通商品列表接口(以 AliExpress Affiliate 商品查询 API 为例)
以下是使用 Python 调用速卖通商品列表接口(以 AliExpress Affiliate 商品查询 API 为例)的代码示例。该示例包含准备基础参数、生成签名、发送请求和处理响应等关键步骤,并附有详细注释说明。代码展示了如何通过公共参数和业务参数构建请求,使用 HMAC-SHA256 加密生成签名,确保请求的安全性。最后,解析 JSON 响应并输出商品信息。此接口适用于商品监控、数据采集与分析及商品推荐等场景。注意需通过 OAuth2.0 获取 `access_token`,并根据官方文档调整参数和频率限制。

热门文章

最新文章

AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等