修改拍卖房结构,目前修改到拍卖者上麦下麦
This commit is contained in:
@@ -49,7 +49,7 @@ public class MyMqttService extends Service implements MyEmqttConnectListener, My
|
||||
private static int qos = 2;
|
||||
// private static String HOST ="tcp://81.70.45.221";//正式
|
||||
private static String HOST = "tcp://1.13.181.248";//测试
|
||||
// private static String HOST = "tcp://47.120.21.132";//测试
|
||||
// private static String HOST = "tcp://47.120.21.132";//测试
|
||||
private static MqttAndroidClient mqttAndroidClient;
|
||||
private MqttConnectOptions mMqttConnectOptions;
|
||||
private static boolean b = true;
|
||||
@@ -60,6 +60,8 @@ public class MyMqttService extends Service implements MyEmqttConnectListener, My
|
||||
private static MyEmqttSubscribeListener mMyEmqttSubscribeListener;
|
||||
|
||||
private static final String TOPIC_BOSS = "qx_room_topic";
|
||||
|
||||
private static final String TOPIC_XLH = "qx_xunlehui";
|
||||
private static final int NOTIFICATION_ID = 1;
|
||||
|
||||
|
||||
@@ -228,7 +230,8 @@ public class MyMqttService extends Service implements MyEmqttConnectListener, My
|
||||
@Override
|
||||
public void onFailure(IMqttToken asyncActionToken,
|
||||
Throwable exception) {
|
||||
if (!TOPIC_BOSS.equals(topic) && mMyEmqttSubscribeListener != null) {
|
||||
if ((!TOPIC_BOSS.equals(topic) && mMyEmqttSubscribeListener != null)
|
||||
|| (!TOPIC_XLH.equals(topic) && mMyEmqttSubscribeListener != null)) {
|
||||
mMyEmqttSubscribeListener.onSubscribeFailure();
|
||||
}
|
||||
Logger.e(TAG, "订阅失败:" + topic + ", error: " + exception.getMessage());
|
||||
@@ -381,6 +384,7 @@ public class MyMqttService extends Service implements MyEmqttConnectListener, My
|
||||
}
|
||||
Logger.e(TAG, "链接状态:", "链接成功");
|
||||
subscribe(TOPIC_BOSS);
|
||||
subscribe(TOPIC_XLH);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -411,16 +415,19 @@ public class MyMqttService extends Service implements MyEmqttConnectListener, My
|
||||
try {
|
||||
String messageStr = message.toString();
|
||||
Logger.e(TAG, "收到的消息", "主题:" + topic + " 收到的消息:" + messageStr);
|
||||
if (topic.equals(TOPIC_BOSS)) {
|
||||
// 处理消息
|
||||
receiveMessage(topic, messageStr);
|
||||
|
||||
// 处理消息
|
||||
receiveMessage(topic, messageStr);
|
||||
|
||||
// 通知监听器
|
||||
if (mMyEmqttMesgListener != null) {
|
||||
// 切换到主线程通知
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
mMyEmqttMesgListener.messageArrived(topic, messageStr);
|
||||
});
|
||||
// 通知监听器
|
||||
if (mMyEmqttMesgListener != null) {
|
||||
// 切换到主线程通知
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
mMyEmqttMesgListener.messageArrived(topic, messageStr);
|
||||
});
|
||||
}
|
||||
} else if (topic.equals(TOPIC_XLH)) {
|
||||
receiveXlhMessage(messageStr);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "处理MQTT消息异常", e);
|
||||
@@ -454,6 +461,25 @@ public class MyMqttService extends Service implements MyEmqttConnectListener, My
|
||||
}
|
||||
};
|
||||
|
||||
private void receiveXlhMessage(String messageStr) {
|
||||
try {
|
||||
String newdata = messageStr;//TextLengthUtil.decode(data);
|
||||
JSONObject jsonObject = JSON.parseObject(newdata);
|
||||
|
||||
int type = jsonObject.getIntValue("type");
|
||||
String message = jsonObject.getString("msg");
|
||||
|
||||
|
||||
|
||||
// 将事件处理放到主线程执行
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
processMessageType(type, message);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "解析MQTT消息异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void receiveMessage(String topic, String data) {
|
||||
try {
|
||||
String newdata = data;//TextLengthUtil.decode(data);
|
||||
@@ -640,6 +666,7 @@ public class MyMqttService extends Service implements MyEmqttConnectListener, My
|
||||
}
|
||||
|
||||
cleanSubscribe(TOPIC_BOSS);
|
||||
cleanSubscribe(TOPIC_XLH);
|
||||
if (mqttAndroidClient != null) {
|
||||
mqttAndroidClient.disconnect(); //断开连接
|
||||
mqttAndroidClient.unregisterResources();
|
||||
@@ -680,16 +707,16 @@ public class MyMqttService extends Service implements MyEmqttConnectListener, My
|
||||
|
||||
@Override
|
||||
public void messageArrived(String topic, String mesg) {
|
||||
|
||||
LogUtils.e("lxj", "messageArrived:"+mesg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubscribeSuccess(String topic) {
|
||||
|
||||
LogUtils.e("lxj", "onSubscribeSuccess:"+topic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubscribeFailure() {
|
||||
|
||||
LogUtils.e("lxj", "onSubscribeFailure");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user