Skip to content

Commit

Permalink
修复json 反序列化bug
Browse files Browse the repository at this point in the history
  • Loading branch information
admimistrator committed Sep 17, 2022
1 parent 2110bc3 commit 48ea2dc
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 20 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# xiaomi2meidi


使用方法参考 https://www.cnblogs.com/mysgk/p/16687363.html

如果登录出现 1020 状态码,并且在手机重新登录无效 ,可以尝试把 config.json 中的 appVersion/deviceId/deviceName/osVersion 设置为空字符串

配置修改后需重启程序
45 changes: 37 additions & 8 deletions src/main/java/com/yxd/xiaomi2meidi/controller/AcController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.TypeReference;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yxd.xiaomi2meidi.anotation.TokenCheck;
import com.yxd.xiaomi2meidi.cache.Gcache;
import com.yxd.xiaomi2meidi.corn.RefreshToken;
Expand All @@ -26,6 +28,7 @@

import static com.yxd.xiaomi2meidi.tracker.Common.HTTP_SERVER_IOT_SECRET;
import static com.yxd.xiaomi2meidi.util.Utils.*;

/**
* @author Administrator
*/
Expand Down Expand Up @@ -94,6 +97,24 @@ public MasRsp login() {
MasRsp<LoginRspData> loginResp = JSON.parseObject(resp1, new TypeReference<MasRsp<LoginRspData>>() {
});

// ObjectMapper mapper = new ObjectMapper();
// MasRsp<LoginRspData> loginResp = null;
// try {
// loginResp = mapper.readValue(resp1, new com.fasterxml.jackson.core.type.TypeReference<MasRsp<LoginRspData>>() {
// });
// } catch (Exception e) {
// e.printStackTrace();
//
// try {
// JavaType javaType = mapper.getTypeFactory().constructType(MasRsp.class, LoginRspData.class);
// mapper.readValue(resp1, javaType);
// } catch (Exception e1) {
// e1.printStackTrace();
// throw new RuntimeException("json 转换异常");
// }
//
// }


LoginRspData data = loginResp.getData();
String tokenPwd = data.getMdata().getTokenPwdInfo().getTokenPwd();
Expand Down Expand Up @@ -122,6 +143,12 @@ public MasRsp getDeviceList() throws IOException {
String resp2 = doExecute(httpClient, request2);
log.info("getDeviceListResp: " + resp2);
checkResp(resp2);

// ObjectMapper mapper = new ObjectMapper();
//
// MasRsp<ApplianceList> homegroupRespObj = mapper.readValue(resp2, new com.fasterxml.jackson.core.type.TypeReference<MasRsp<ApplianceList>>() {
// });

MasRsp<ApplianceList> homegroupRespObj = JSON.parseObject(resp2, new TypeReference<MasRsp<ApplianceList>>() {
});
List<Appliance> appliance = homegroupRespObj.getData().getAppliance();
Expand All @@ -140,23 +167,28 @@ public MasRsp getDeviceList() throws IOException {

@GetMapping("/togglePower")
@TokenCheck
public void togglePower(String name,boolean state) throws IOException {
public void togglePower(String name, boolean state) throws IOException {

log.info("togglePower: name: " + name + " , state: " + state);
List<Device> deviceList = Gcache.config.getDeviceList();
if (deviceList.isEmpty()) {
log.error("当前无设备列表");
return;
log.error("当前无设备列表,尝试重新获取");
getDeviceList();
}
deviceList = Gcache.config.getDeviceList();
log.info("deviceList: " + JSON.toJSONString(deviceList));
String sn = "";
if (StringUtils.hasText(name)) {
for (Device device : deviceList) {
log.info("togglePower: device.getName(): " + device.getName() + " , name: " + name + " ,equals: " + name.equals(device.getName()));
if (name.equals(device.getName())) {
sn = device.getApplianceCode();
}
}
} else {
sn = deviceList.get(0).getApplianceCode();
state =true;
state = true;
log.info("未指定空调名称,当前操作为打开第一个");
}

PowerControl powerControl = new PowerControl();
Expand All @@ -172,7 +204,7 @@ public void togglePower(String name,boolean state) throws IOException {
.build();
String resp2 = doExecute(httpClient, request2);

log.info("未指定空调名称,当前操作为打开第一个. togglePowerResp: " + resp2);
log.info(" togglePowerResp: " + resp2);
}

@TokenCheck
Expand Down Expand Up @@ -202,7 +234,4 @@ public MasRsp getHomeList() {
}





}
20 changes: 10 additions & 10 deletions src/main/java/com/yxd/xiaomi2meidi/entity/LoginRspData.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ public class LoginRspData {
private UserInfo userInfo;


public LoginRspData(Long clusterId, String iotUserId, String isOldUse, String jwtToken, String key, LoginRspMData mdata, String uid, UserInfo userInfo) {
this.clusterId = clusterId;
this.iotUserId = iotUserId;
this.isOldUse = isOldUse;
this.jwtToken = jwtToken;
this.key = key;
this.mdata = mdata;
this.uid = uid;
this.userInfo = userInfo;
}
// public LoginRspData(Long clusterId, String iotUserId, String isOldUse, String jwtToken, String key, LoginRspMData mdata, String uid, UserInfo userInfo) {
// this.clusterId = clusterId;
// this.iotUserId = iotUserId;
// this.isOldUse = isOldUse;
// this.jwtToken = jwtToken;
// this.key = key;
// this.mdata = mdata;
// this.uid = uid;
// this.userInfo = userInfo;
// }

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,158 @@

[
{
"name": "com.yxd.xiaomi2meidi.entity.Appliance",
"allPublicFields": true,
"allDeclaredFields": true,
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "com.yxd.xiaomi2meidi.entity.ApplianceList",
"allPublicFields": true,
"allDeclaredFields": true,
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "com.yxd.xiaomi2meidi.entity.CommonReqData",
"allPublicFields": true,
"allDeclaredFields": true,
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "com.yxd.xiaomi2meidi.entity.Device",
"allPublicFields": true,
"allDeclaredFields": true,
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "com.yxd.xiaomi2meidi.entity.Home",
"allPublicFields": true,
"allDeclaredFields": true,
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "com.yxd.xiaomi2meidi.entity.HomeList",
"allPublicFields": true,
"allDeclaredFields": true,
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "com.yxd.xiaomi2meidi.entity.IotData",
"allPublicFields": true,
"allDeclaredFields": true,
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "com.yxd.xiaomi2meidi.entity.LoginIdRspData",
"allPublicFields": true,
"allDeclaredFields": true,
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "com.yxd.xiaomi2meidi.entity.LoginRspData",
"allPublicFields": true,
"allDeclaredFields": true,
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "com.yxd.xiaomi2meidi.entity.LoginRspMData",
"allPublicFields": true,
"allDeclaredFields": true,
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "com.yxd.xiaomi2meidi.entity.MasRsp",
"allPublicFields": true,
"allDeclaredFields": true,
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "com.yxd.xiaomi2meidi.entity.MucData",
"allPublicFields": true,
"allDeclaredFields": true,
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "com.yxd.xiaomi2meidi.entity.NewToken",
"allPublicFields": true,
"allDeclaredFields": true,
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "com.yxd.xiaomi2meidi.entity.PowerControl",
"allPublicFields": true,
"allDeclaredFields": true,
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "com.yxd.xiaomi2meidi.entity.Room",
"allPublicFields": true,
"allDeclaredFields": true,
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "com.yxd.xiaomi2meidi.entity.TokenPwdInfo",
"allPublicFields": true,
"allDeclaredFields": true,
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "com.yxd.xiaomi2meidi.entity.UserInfo",
"allPublicFields": true,
"allDeclaredFields": true,
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "com.yxd.xiaomi2meidi.entity.Config",
"allPublicFields": true,
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<appender name="RollingFile"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS}/hello-world.log</file>
<file>${LOGS}/logs.log</file>
<encoder
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
Expand All @@ -30,7 +30,7 @@
</encoder>

<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOGS}/archived/hello-world-%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
<fileNamePattern>${LOGS}/archived/logs-%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
<!-- each archived file, size max 10MB -->
<maxFileSize>10MB</maxFileSize>
<!-- total size of all archive files, if total size > 10GB, it will delete old archived file -->
Expand Down

0 comments on commit 48ea2dc

Please sign in to comment.