From 7975676cbb2783280752ca2649d259da219742ae Mon Sep 17 00:00:00 2001 From: neilyhe <228429803@qq.com> Date: Fri, 13 Sep 2024 14:45:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9B=A0=E8=BF=87=E6=9C=9F?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=A4=AA=E7=9F=AD=EF=BC=8C=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=88=B3=E8=BF=87=E6=9C=9F=E5=8F=91=E7=94=9F?= =?UTF-8?q?=E6=96=AD=E5=BC=80=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device/android/mqtt/TXMqttConnection.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/explorer/explorer-device-android/src/main/java/com/tencent/iot/explorer/device/android/mqtt/TXMqttConnection.java b/explorer/explorer-device-android/src/main/java/com/tencent/iot/explorer/device/android/mqtt/TXMqttConnection.java index 93c9ae6c4..3efbf227a 100644 --- a/explorer/explorer-device-android/src/main/java/com/tencent/iot/explorer/device/android/mqtt/TXMqttConnection.java +++ b/explorer/explorer-device-android/src/main/java/com/tencent/iot/explorer/device/android/mqtt/TXMqttConnection.java @@ -50,6 +50,7 @@ public class TXMqttConnection extends com.tencent.iot.hub.device.java.core.mqtt. protected TXAlarmPingSender mPingSender = null; + private long mExpiredTime = Integer.MAX_VALUE; /** * @param context 用户上下文(这个参数在回调函数时透传给用户) @@ -206,6 +207,10 @@ private String sign(String src, String psk) { return null; } + public void setExpiredTime(long expiredTime) { + this.mExpiredTime = Math.max(expiredTime, System.currentTimeMillis() / 1000 + 600); + } + /** * 连接 MQTT 服务器,结果通过回调函数通知,无需设置 username 和 password,内部会自动填充 * @@ -230,13 +235,7 @@ public synchronized Status connect(MqttConnectOptions options, Object userContex return Status.PARAMETER_INVALID; } - Long timestamp; - if (options.isAutomaticReconnect()) { - timestamp = (long) Integer.MAX_VALUE; - } else { - timestamp = System.currentTimeMillis()/1000 + 600; - } - String userNameStr = mUserName + ";" + getConnectId() + ";" + timestamp; + String userNameStr = mUserName + ";" + getConnectId() + ";" + mExpiredTime; mConnOptions.setUserName(userNameStr);