Skip to content

Commit 4317fc0

Browse files
authored
Merge pull request #48 from sanshengshui/main
upgrade mobile from NB-IoT API to OpenAPI Platform
2 parents e16827c + 2716873 commit 4317fc0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2249
-78
lines changed

toolkit-app/src/main/resources/i18n/messages.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ nb.cmd.hex.desc=messages will be hex decoded.
192192
nb.cmd.limit.desc=the limit of data list
193193
nb.cmd.startTime.desc=start time of search data list
194194
nb.cmd.endTime.desc=end time of search data list
195+
nb.cmd.offset.desc=the pageNo of data list
196+
nb.cmd.auth_code.desc=the device auth code
197+
nb.cmd.lat.desc=the device lat
198+
nb.cmd.lon.desc=the device lon
195199

196200
##NB prompt
197201
nbType.prompt=Please select the Nb-IoT type

toolkit-app/src/main/resources/i18n/messages_de.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ nb.cmd.hex.desc=messages will be hex decoded.
189189
nb.cmd.limit.desc=the limit of data list
190190
nb.cmd.startTime.desc=start time of search data list
191191
nb.cmd.endTime.desc=end time of search data list
192+
nb.cmd.offset.desc=the pageNo of data list
193+
nb.cmd.auth_code.desc=the device auth code
194+
nb.cmd.lat.desc=the device lat
195+
nb.cmd.lon.desc=the device lon
192196

193197
##NB prompt
194198
nbType.prompt=Please select the Nb-IoT type

toolkit-app/src/main/resources/i18n/messages_fr.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ nb.cmd.hex.desc=messages will be hex decoded.
188188
nb.cmd.limit.desc=the limit of data list
189189
nb.cmd.startTime.desc=start time of search data list
190190
nb.cmd.endTime.desc=end time of search data list
191+
nb.cmd.offset.desc=the pageNo of data list
192+
nb.cmd.auth_code.desc=the device auth code
193+
nb.cmd.lat.desc=the device lat
194+
nb.cmd.lon.desc=the device lon
191195

192196
##NB prompt
193197
nbType.prompt=Please select the Nb-IoT type

toolkit-app/src/main/resources/i18n/messages_zh.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ nb.cmd.hex.desc=\u6d88\u606f\u5c06\u88ab\u5341\u516d\u8fdb\u5236\u89e3\u7801(\u6
188188
nb.cmd.limit.desc=\u6570\u636e\u5217\u8868\u6761\u6570(\u9009\u586b)
189189
nb.cmd.startTime.desc=\u641c\u7d22\u6570\u636e\u5217\u8868\u7684\u8d77\u59cb\u65f6\u95f4(\u683c\u5f0f\u4e3a:2015-01-10T08:00:35, \u9ed8\u8ba4\u662f\u5f53\u592900:00:00,\u9009\u586b)
190190
nb.cmd.endTime.desc=\u641c\u7d22\u6570\u636e\u5217\u8868\u7684\u7ed3\u675f\u65f6\u95f4(\u683c\u5f0f\u4e3a:2015-01-10T08:00:35, \u9ed8\u8ba4\u662f\u5f53\u592923:59:59,\u9009\u586b)
191+
nb.cmd.offset.desc=\u6570\u636e\u5217\u8868\u7684\u9875\u7801(\u9009\u586b)
192+
nb.cmd.auth_code.desc=\u8bbe\u5907\u8ba4\u8bc1\u7801
193+
nb.cmd.lat.desc=\u8bbe\u5907\u7eac\u5ea6
194+
nb.cmd.lon.desc=\u8bbe\u5907\u7ecf\u5ea6
191195

192196
##NB prompt
193197
nbType.prompt=\u8bf7\u9009\u62e9 Nb-IoT \u5e73\u53f0
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package iot.technology.client.toolkit.common.constants;
2+
3+
4+
public interface OneNetSettings {
5+
6+
String AUTH_VERSION = "2022-05-01";
7+
String AUTH_RES_PREFIX = "products/";
8+
String AUTH_METHOD = "sha256";
9+
String AUTH_HEADER = "Authorization";
10+
11+
String ROOT_URL = "https://iot-api.heclouds.com";
12+
String DEVICE_URL = ROOT_URL + "/device";
13+
String PRODUCT_URL = ROOT_URL + "/product";
14+
String COMMAND_URL = ROOT_URL + "/nb-iot";
15+
16+
String ADD_DEVICE_URL = DEVICE_URL + "/create";
17+
String DETAIL_DEVICE_URL = DEVICE_URL + "/detail";
18+
String DELETE_DEVICE_URL = DEVICE_URL + "/delete";
19+
String UPDATE_DEVICE_URL = DEVICE_URL + "/update";
20+
String LIST_DEVICE_URL = DEVICE_URL + "/list";
21+
22+
String PRODUCT_DETAIL_URL = PRODUCT_URL + "/detail";
23+
24+
String OFFLINE_COMMAND_URL = COMMAND_URL + "/offline";
25+
String HISTORY_OFFLINE_COMMAND_URL = OFFLINE_COMMAND_URL + "/history";
26+
}

toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/NbBizService.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import iot.technology.client.toolkit.common.utils.JsonUtils;
2525
import iot.technology.client.toolkit.nb.service.lwm2m.domain.Lwm2mConfigSetting;
2626
import iot.technology.client.toolkit.nb.service.lwm2m.domain.Lwm2mConfigSettingsDomain;
27+
import iot.technology.client.toolkit.nb.service.mobile.OneNetService;
2728
import iot.technology.client.toolkit.nb.service.mobile.domain.MobileConfigDomain;
29+
import iot.technology.client.toolkit.nb.service.mobile.domain.action.device.OneNetProductResponse;
2830
import iot.technology.client.toolkit.nb.service.mobile.domain.settings.MobProjectSettings;
2931
import iot.technology.client.toolkit.nb.service.processor.Lwm2mBizService;
3032
import iot.technology.client.toolkit.nb.service.processor.MobileBizService;
@@ -52,6 +54,7 @@ public class NbBizService {
5254
private final MobileBizService mobileBizService = new MobileBizService();
5355
private final TelecomProductService productService = new TelecomProductService();
5456
private final Lwm2mBizService lwm2mBizService = new Lwm2mBizService();
57+
private final OneNetService oneNetService = new OneNetService();
5558
ResourceBundle bundle = ResourceBundle.getBundle(StorageConstants.LANG_MESSAGES);
5659

5760
public List<String> getNbSettingsFromFile(String fileName) {
@@ -110,10 +113,14 @@ public boolean nbProcessorAfterLogic(String code, NbConfigSettingsDomain domain,
110113
*/
111114
if (code.equals(NbSettingsCodeEnum.NB_MOB_ACCESS_KEY.getCode())) {
112115
MobileConfigDomain mobileConfigDomain = domain.convertMobileConfig();
116+
OneNetProductResponse response = oneNetService.getProductDetail(mobileConfigDomain);
113117
MobProjectSettings mobProjectSettings = new MobProjectSettings();
114-
mobProjectSettings.setProductName(mobileConfigDomain.getProductName());
115118
mobProjectSettings.setProductId(mobileConfigDomain.getProductId());
116119
mobProjectSettings.setAccessKey(mobileConfigDomain.getAccessKey());
120+
if (Objects.nonNull(response.getData())) {
121+
mobProjectSettings.setProductName(response.getData().getName());
122+
mobileConfigDomain.setProductName(response.getData().getName());
123+
}
117124
String settingsJson = JsonUtils.object2Json(mobProjectSettings);
118125
FileUtils.writeDataToFile(SYS_NB_MOBILE_PRODUCT_FILE_NAME, settingsJson);
119126
return mobileBizService.call(mobileConfigDomain, terminal);

toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/mobile/AbstractMobileService.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package iot.technology.client.toolkit.nb.service.mobile;
1717

1818
import iot.technology.client.toolkit.common.constants.MobileSettings;
19+
import iot.technology.client.toolkit.common.constants.OneNetSettings;
1920
import iot.technology.client.toolkit.common.utils.SignUtils;
2021
import iot.technology.client.toolkit.nb.service.mobile.domain.MobileConfigDomain;
2122

@@ -34,6 +35,12 @@ public static Map<String, String> getHeaderMap(MobileConfigDomain config) {
3435
return authInfoMap;
3536
}
3637

38+
public static Map<String, String> getOneNetHeaderMap(MobileConfigDomain config) {
39+
Map<String, String> authInfoMap = new HashMap<>();
40+
authInfoMap.put(OneNetSettings.AUTH_HEADER, getOneNetAuthInfo(config));
41+
return authInfoMap;
42+
}
43+
3744

3845
public static String getAuthInfo(MobileConfigDomain config) {
3946
String version = MobileSettings.MOBILE_AUTH_VERSION;
@@ -43,4 +50,12 @@ public static String getAuthInfo(MobileConfigDomain config) {
4350
return SignUtils.getMobileAssembleToken(version, res, Long.toString(et), method, config.getAccessKey());
4451
}
4552

53+
public static String getOneNetAuthInfo(MobileConfigDomain config) {
54+
String version = OneNetSettings.AUTH_VERSION;
55+
String res = OneNetSettings.AUTH_RES_PREFIX + config.getProductId();
56+
long et = System.currentTimeMillis() / 1000 + TimeUnit.SECONDS.toSeconds(10);
57+
String method = OneNetSettings.AUTH_METHOD;
58+
return SignUtils.getMobileAssembleToken(version, res, Long.toString(et), method, config.getAccessKey());
59+
}
60+
4661
}

toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/mobile/MobileDeviceDataService.java

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import iot.technology.client.toolkit.common.utils.JsonUtils;
2525
import iot.technology.client.toolkit.common.utils.StringUtils;
2626
import iot.technology.client.toolkit.nb.service.mobile.domain.MobileConfigDomain;
27-
import iot.technology.client.toolkit.nb.service.mobile.domain.action.data.MobCachedCommandResponse;
27+
import iot.technology.client.toolkit.nb.service.mobile.domain.action.data.OneNetCachedCommandResponse;
2828
import iot.technology.client.toolkit.nb.service.mobile.domain.action.data.MobDeviceHisDataResponse;
2929
import iot.technology.client.toolkit.nb.service.mobile.domain.action.data.MobDeviceLatestDataResponse;
3030

@@ -110,43 +110,4 @@ public MobDeviceHisDataResponse getHisDataPoints(MobileConfigDomain config, Stri
110110
}
111111
}
112112

113-
114-
public MobCachedCommandResponse getCachedCommandList(MobileConfigDomain config, String imei,
115-
String startTime, String endTime,
116-
Integer pageNo, Integer pageSize) {
117-
MobCachedCommandResponse mobCachedCommandResponse = new MobCachedCommandResponse();
118-
try {
119-
HttpRequestEntity entity = new HttpRequestEntity();
120-
entity.setType(NBTypeEnum.MOBILE.getValue());
121-
entity.setUrl(MobileSettings.MOBILE_CACHED_COMMAND_LIST);
122-
Map<String, String> headerMap = getHeaderMap(config);
123-
entity.setHeaders(headerMap);
124-
125-
Map<String, String> params = new HashMap<>();
126-
params.put("imei", imei);
127-
params.put("start", startTime);
128-
params.put("end", endTime);
129-
params.put("page", pageNo + "");
130-
params.put("per_page", pageSize + "");
131-
entity.setParams(params);
132-
HttpResponseEntity response = HttpRequestExecutor.executeGet(entity);
133-
if (StringUtils.isNotBlank(response.getBody())) {
134-
mobCachedCommandResponse = JsonUtils.jsonToObject(response.getBody(), MobCachedCommandResponse.class);
135-
if (mobCachedCommandResponse.getErrno() == 0) {
136-
mobCachedCommandResponse.setSuccess(Boolean.TRUE);
137-
} else {
138-
System.out.format(ColorUtils.redError(mobCachedCommandResponse.getError()));
139-
mobCachedCommandResponse.setSuccess(Boolean.FALSE);
140-
}
141-
} else {
142-
mobCachedCommandResponse.setSuccess(Boolean.FALSE);
143-
System.out.format(config.getProductId() + ColorUtils.redError(" getCachedCommandList failed!"));
144-
}
145-
return mobCachedCommandResponse;
146-
} catch (Exception e) {
147-
mobCachedCommandResponse.setSuccess(Boolean.FALSE);
148-
System.out.format(config.getProductId() + ColorUtils.redError(" getCachedCommandList failed!"));
149-
return mobCachedCommandResponse;
150-
}
151-
}
152113
}

0 commit comments

Comments
 (0)