抖音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());
        }
    }
相关文章
|
5月前
|
缓存 监控 前端开发
顺企网 API 开发实战:搜索 / 详情接口从 0 到 1 落地(附 Elasticsearch 优化 + 错误速查)
企业API开发常陷参数、缓存、错误处理三大坑?本指南拆解顺企网双接口全流程,涵盖搜索优化、签名验证、限流应对,附可复用代码与错误速查表,助你2小时高效搞定开发,提升响应速度与稳定性。
|
5月前
|
JSON 算法 API
Python采集淘宝商品评论API接口及JSON数据返回全程指南
Python采集淘宝商品评论API接口及JSON数据返回全程指南
|
5月前
|
JSON API 数据安全/隐私保护
Python采集淘宝拍立淘按图搜索API接口及JSON数据返回全流程指南
通过以上流程,可实现淘宝拍立淘按图搜索的完整调用链路,并获取结构化的JSON商品数据,支撑电商比价、智能推荐等业务场景。
|
6月前
|
JSON 前端开发 API
如何调用体育数据足篮接口API
本文介绍如何调用体育数据API:首先选择可靠服务商并注册获取密钥,接着阅读文档了解基础URL、端点、参数及请求头,然后使用Python等语言发送请求、解析JSON数据,最后将数据应用于Web、App或分析场景,同时注意密钥安全、速率限制与错误处理。
640 152
|
5月前
|
API 开发者 数据采集
高效获取淘宝商品详情:API 开发实现链接解析的完整技术方案
2025反向海淘新机遇:依托代购系统,聚焦小众垂直品类,结合Pandabay数据选品,降本增效。系统实现智能翻译、支付风控、物流优化,助力中式养生茶等品类利润翻倍,新手也能快速入局全球市场。
高效获取淘宝商品详情:API 开发实现链接解析的完整技术方案
|
6月前
|
数据采集 缓存 API
小红书笔记详情 API 实战指南:从开发对接、场景落地到收益挖掘(附避坑技巧)
本文详解小红书笔记详情API的开发对接、实战场景与收益模式,涵盖注册避坑、签名生成、数据解析全流程,并分享品牌营销、内容创作、SAAS工具等落地应用,助力开发者高效掘金“种草经济”。
小红书笔记详情 API 实战指南:从开发对接、场景落地到收益挖掘(附避坑技巧)
|
5月前
|
人工智能 自然语言处理 测试技术
Apipost智能搜索:只需用业务语言描述需求,就能精准定位目标接口,API 搜索的下一代形态!
在大型项目中,API 数量庞大、命名不一,导致“找接口”耗时费力。传统工具依赖关键词搜索,难以应对语义模糊或命名不规范的场景。Apipost AI 智能搜索功能,支持自然语言查询,如“和用户登录有关的接口”,系统可理解语义并精准匹配目标接口。无论是新人上手、模糊查找还是批量定位,都能大幅提升检索效率,降低协作成本。从关键词到语义理解,智能搜索让开发者少花时间找接口,多专注核心开发,真正实现高效协作。
|
5月前
|
存储 缓存 算法
淘宝买家秀 API 深度开发:多模态内容解析与合规推荐技术拆解
本文详解淘宝买家秀接口(taobao.reviews.get)的合规调用、数据标准化与智能推荐全链路方案。涵盖权限申请、多模态数据清洗、情感分析、混合推荐模型及缓存优化,助力开发者提升审核效率60%、商品转化率增长28%,实现UGC数据高效变现。
|
5月前
|
存储 缓存 算法
亚马逊 SP-API 深度开发:关键字搜索接口的购物意图挖掘与合规竞品分析
本文深度解析亚马逊SP-API关键字搜索接口的合规调用与商业应用,涵盖意图识别、竞品分析、性能优化全链路。通过COSMO算法解析用户购物意图,结合合规技术方案提升关键词转化率,助力卖家实现数据驱动决策,安全高效优化运营。