抖⾳上的程序代码java_抖⾳sdk,抖⾳api接⼝java调⽤源代码抖⾳sdk,抖⾳api接⼝
1、抖⾳上线下线
/**
* 抖⾳上线通知
* @author wechat:happybabby110
*/
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 与通道
DeviceInfo device = Imei());
if(null != device){
//做个保护,如果当前号在其他设备上登陆过,就把之前那条记录删除
if(!StringUtils.ImUid()) && !StringUtils.Imei())){
if(!StringUtils.Imuid()) && !ImUid().Imuid())){
device.setAvatar("");
device.setImuid("");
device.setNickname("");
device.setIsonline(1);
deviceService.update(device);
}
}
//设置新的参数
device.ImUid());
device.NickName());
device.Avatar());
device.GenderValue());
device.Phone());
device.UniqueId());
device.Province());
device.City());
device.District());
device.Signature());
device.AwemeCount());
device.FollowingCount());
device.FollowerCount());
device.FriendCount());
//改为上线状态
device.setIsonline(0);//上线
deviceService.update(device);
/
/3、告诉客户端消息已收到
MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null); asyncTaskService.ImUid(), EnumMsgType.ImOnlineNotice, req);
}
}
} catch (Exception e) {
e.printStackTrace();
MessageUtil.sendErrMsg(ctx, EnumErrorCode.Id(), e.getMessage());
}
}
/**
* 抖⾳下线通知
* @author wechat:happybabby110
*/
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 = ImUid());
if (null != account) {
account.setIsonline(1);// 下线
deviceService.update(account);
asyncTaskService.ImUid(), 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
*/
@Async
public void handleMsg(ChannelHandlerContext ctx,TransportMessage vo, String contentJsonStr) {
try {
log.debug(contentJsonStr);
TalkToFriendTaskMessage.Builder bd = wBuilder();
JsonFormat.parser().merge(contentJsonStr, bd);
TalkToFriendTaskMessage req = bd.build();
//将消息转发送给⼿机客户端
asyncTaskService.msgSend2Phone(ctx, ImUid(), EnumMsgType.TalkToFriendTask, vo, req);
} catch (Exception e) {
e.printStackTrace();
MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
}
}
/**
* 抖⾳聊天消息实时推送
* @author wechat:happybabby110
*/
@Async
public void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
try {
ChatMsgNoticeMessage req = vo.getContent().unpack(ChatMsgNoticeMessage.class);
log.debug(JsonFormat.printer().print(req));
log.w()+" ChatMsgNoticeMessage 对应的线程名: "+Thread.currentThread().getName()); //消息转发到pc端
asyncTaskService.ImUid(), EnumMsgType.ChatMsgNotice, req);
// 告诉客户端消息已收到
MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);
} catch (Exception e) {
e.printStackTrace();
MessageUtil.sendErrMsg(ctx, EnumErrorCode.Id(), e.getMessage());
}
}
3、关注与取消关注抖⾳号
/**
* @author wechat:happybabby110
* 关注抖⾳号
*/
@Async
public void handleMsg(ChannelHandlerContext ctx,TransportMessage vo, String contentJsonStr) {
try {
log.debug(contentJsonStr);
FollowTaskMessage.Builder bd = wBuilder();
JsonFormat.parser().merge(contentJsonStr, bd);
FollowTaskMessage req = bd.build();
//将消息转发送给⼿机客户端
asyncTaskService.msgSend2Phone(ctx, ImUid(), EnumMsgType.FollowTask, vo, req);
} catch (Exception e) {
e.printStackTrace();
MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
}
}
/**
* 取消关注抖⾳号
* @author wechat:happybabby110
*/
@Async
public void handleMsg(ChannelHandlerContext ctx,TransportMessage vo, String contentJsonStr) {
try {
log.debug(contentJsonStr);
UnFollowTaskMessage.Builder bd = wBuilder();
JsonFormat.parser().merge(contentJsonStr, bd);
UnFollowTaskMessage req = bd.build();
//将消息转发送给⼿机客户端
asyncTaskService.msgSend2Phone(ctx, ImUid(), EnumMsgType.UnFollowTask, vo, req);
} catch (Exception e) {
e.printStackTrace();
MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL); }
}
4、同步抖⾳推荐的好友
/**
* 同步抖⾳推荐的好友
* @author wechat:happybabby110
*/
@Async
public void handleMsg(ChannelHandlerContext ctx,TransportMessage vo, String contentJsonStr) {
try {
log.debug(contentJsonStr);
SyncRecFriendsTaskMessage.Builder bd = wBuilder();
JsonFormat.parser().merge(contentJsonStr, bd);
SyncRecFriendsTaskMessage req = bd.build();
//将消息转发送给⼿机客户端java影视app源码
asyncTaskService.msgSend2Phone(ctx, ImUid(), EnumMsgType.SyncRecFriendsTask, vo, req);

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。