名字
同样以该图为例,如何解析出“群聊通知消息体”内容呢?
19:56:54 发送一条群聊请求
19:56:54 收到一条群聊通知
public enum MyCommand {
/**
* 群聊通知
*/
GROUP_CHAT_NTY((short) 11);
public static MyCommand from(Short value) {
MyCommand[] values = MyCommand.values();
for (MyCommand v : values) {
if (v.value.equals(value)) {
return v;
}
}
return null;
}
Short value;
private MyCommand(Short value) {
this.value = value;
}
public Short getValue() {
return value;
}
public void setValue(Short value) {
this.value = value;
}
}
mTioClient.registerTioCallback(new TioSimpleClientCallback() {
@Override
public void onReceiveEnd(TioClient client, TioPacket packet, Object body) {
short command = packet.getCommand();
if (command == MyCommand.GROUP_CHAT_NTY.getValue()) {
// 群聊通知的json格式字符串
String groupChatNtfJsonString = packet.toString();
}
}
});
将群聊通知内容格式化如下:
{
"command":11,
"gzip":1,
"bodyLength":468,
"body":[
{
"c":"hi~ tio-android",
"cid":"1161969981764804608",
"ct":1,
"d":2,
"f":{
"a":"/avatar/fengjing2/2018/08/19/8.jpeg",
"cid":"1161969981764804608",
"groupid":"/product/index.html",
"i":23436,
"ipInfo":{
"area":"",
"city":"杭州市",
"country":"中国",
"id":651384,
"ip":"124.160.42.146",
"operator":"联通",
"province":"浙江省",
"time":"2019-05-13 09:42:59"
},
"l":1,
"ln":"watayouxiang@qq.com",
"mobileInfo":{
"appversion":"1.0.0",
"cid":"tio-android",
"deviceinfo":"HUAWEI MHA-AL00",
"devicetype":2,
"imei":"866716035107410",
"resolution":"1080,1808",
"size":"5.9"
},
"n":"wata",
"r":[
2,
6,
7
],
"timeCreated":1565870206665,
"timeJoinGroup":1565870210915,
"x":2
},
"g":"/product/index.html",
"mid":"346571",
"t":"1565870210915"
}
]
}
public class GroupChatNtf extends ArrayList {
/**
* c : hi~ tio-android
* cid : 1161969981764804608
* ct : 1
* d : 2
* f : {"a":"/avatar/fengjing2/2018/08/19/8.jpeg","cid":"1161969981764804608","groupid":"/product/index.html","i":23436,"ipInfo":{"area":"","city":"杭州市","country":"中国","id":651384,"ip":"124.160.42.146","operator":"联通","province":"浙江省","time":"2019-05-13 09:42:59"},"l":1,"ln":"watayouxiang@qq.com","mobileInfo":{"appversion":"1.0.0","cid":"tio-android","deviceinfo":"HUAWEI MHA-AL00","devicetype":2,"imei":"866716035107410","resolution":"1080,1808","size":"5.9"},"n":"wata","r":[2,6,7],"timeCreated":1565870206665,"timeJoinGroup":1565870210915,"x":2}
* g : /product/index.html
* mid : 346571
* t : 1565870210915
*/
private String c;
private String cid;
private int ct;
private int d;
private FBean f;
private String g;
private String mid;
private String t;
public String getC() {
return c;
}
public void setC(String c) {
this.c = c;
}
public String getCid() {
return cid;
}
public void setCid(String cid) {
this.cid = cid;
}
public int getCt() {
return ct;
}
public void setCt(int ct) {
this.ct = ct;
}
public int getD() {
return d;
}
public void setD(int d) {
this.d = d;
}
public FBean getF() {
return f;
}
public void setF(FBean f) {
this.f = f;
}
public String getG() {
return g;
}
public void setG(String g) {
this.g = g;
}
public String getMid() {
return mid;
}
public void setMid(String mid) {
this.mid = mid;
}
public String getT() {
return t;
}
public void setT(String t) {
this.t = t;
}
public static class FBean {
/**
* a : /avatar/fengjing2/2018/08/19/8.jpeg
* cid : 1161969981764804608
* groupid : /product/index.html
* i : 23436
* ipInfo : {"area":"","city":"杭州市","country":"中国","id":651384,"ip":"124.160.42.146","operator":"联通","province":"浙江省","time":"2019-05-13 09:42:59"}
* l : 1
* ln : watayouxiang@qq.com
* mobileInfo : {"appversion":"1.0.0","cid":"tio-android","deviceinfo":"HUAWEI MHA-AL00","devicetype":2,"imei":"866716035107410","resolution":"1080,1808","size":"5.9"}
* n : wata
* r : [2,6,7]
* timeCreated : 1565870206665
* timeJoinGroup : 1565870210915
* x : 2
*/
private String a;
private String cid;
private String groupid;
private int i;
private IpInfoBean ipInfo;
private int l;
private String ln;
private MobileInfoBean mobileInfo;
private String n;
private long timeCreated;
private long timeJoinGroup;
private int x;
private List<Integer> r;
public String getA() {
return a;
}
public void setA(String a) {
this.a = a;
}
public String getCid() {
return cid;
}
public void setCid(String cid) {
this.cid = cid;
}
public String getGroupid() {
return groupid;
}
public void setGroupid(String groupid) {
this.groupid = groupid;
}
public int getI() {
return i;
}
public void setI(int i) {
this.i = i;
}
public IpInfoBean getIpInfo() {
return ipInfo;
}
public void setIpInfo(IpInfoBean ipInfo) {
this.ipInfo = ipInfo;
}
public int getL() {
return l;
}
public void setL(int l) {
this.l = l;
}
public String getLn() {
return ln;
}
public void setLn(String ln) {
this.ln = ln;
}
public MobileInfoBean getMobileInfo() {
return mobileInfo;
}
public void setMobileInfo(MobileInfoBean mobileInfo) {
this.mobileInfo = mobileInfo;
}
public String getN() {
return n;
}
public void setN(String n) {
this.n = n;
}
public long getTimeCreated() {
return timeCreated;
}
public void setTimeCreated(long timeCreated) {
this.timeCreated = timeCreated;
}
public long getTimeJoinGroup() {
return timeJoinGroup;
}
public void setTimeJoinGroup(long timeJoinGroup) {
this.timeJoinGroup = timeJoinGroup;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public List<Integer> getR() {
return r;
}
public void setR(List<Integer> r) {
this.r = r;
}
public static class IpInfoBean {
/**
* area :
* city : 杭州市
* country : 中国
* id : 651384
* ip : 124.160.42.146
* operator : 联通
* province : 浙江省
* time : 2019-05-13 09:42:59
*/
private String area;
private String city;
private String country;
private int id;
private String ip;
private String operator;
private String province;
private String time;
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getOperator() {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}
public static class MobileInfoBean {
/**
* appversion : 1.0.0
* cid : tio-android
* deviceinfo : HUAWEI MHA-AL00
* devicetype : 2
* imei : 866716035107410
* resolution : 1080,1808
* size : 5.9
*/
private String appversion;
private String cid;
private String deviceinfo;
private int devicetype;
private String imei;
private String resolution;
private String size;
public String getAppversion() {
return appversion;
}
public void setAppversion(String appversion) {
this.appversion = appversion;
}
public String getCid() {
return cid;
}
public void setCid(String cid) {
this.cid = cid;
}
public String getDeviceinfo() {
return deviceinfo;
}
public void setDeviceinfo(String deviceinfo) {
this.deviceinfo = deviceinfo;
}
public int getDevicetype() {
return devicetype;
}
public void setDevicetype(int devicetype) {
this.devicetype = devicetype;
}
public String getImei() {
return imei;
}
public void setImei(String imei) {
this.imei = imei;
}
public String getResolution() {
return resolution;
}
public void setResolution(String resolution) {
this.resolution = resolution;
}
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
}
}
}
Map<Short, Class> commandBodyMap = new HashMap<>();
commandBodyMap.put(MyCommand.GROUP_CHAT_NTY.getValue(), GroupChatNtf.class);
//设置“命令码所对应的消息体Map"
mTioClient.setCommandBodyMap(commandBodyMap);
mClient.registerTioCallback(new TioSimpleClientCallback() {
@Override
public void onReceiveEnd(TioClient client, TioPacket packet, Object body) {
short command = packet.getCommand();
if (command == MyCommand.GROUP_CHAT_NTY.getValue()) {
//群聊通知消息体
GroupChatNtf groupChatNtf = (GroupChatNtf) body;
}
}
});
最新评论 我的评论
t-io为本站提供HTTP、WebSocket、Socket、页面渲染与压缩等服务,nginx为本站提供反向代理服务
© 2017-2023 钛特云 版权所有 | 浙ICP备17032976号 | 浙公网安备 33011802002129号