mac
2023-11-03 9e875b253959eff8f6af567308ad804fe69d0a62
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
package com.hdl.linkpm.sdk.user.controller;
 
import com.google.gson.JsonObject;
import com.hdl.hdlhttp.HxHttp;
import com.hdl.linkpm.sdk.HDLLinkPMSdk;
import com.hdl.linkpm.sdk.core.api.HDLCloudUserApi;
import com.hdl.linkpm.sdk.core.callback.IDefaultCallBack;
import com.hdl.linkpm.sdk.core.callback.IDefaultStrCallBack;
import com.hdl.linkpm.sdk.core.callback.IResponseCallBack;
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.linkpm.sdk.core.response.HDLResponse;
import com.hdl.linkpm.sdk.user.bean.HDLLoginBean;
import com.hdl.linkpm.sdk.user.bean.HDLMemberInfoBean;
import com.hdl.linkpm.sdk.user.bean.HDLUserRegionBean;
import com.hdl.linkpm.sdk.user.bean.ImageSubmitInfo;
import com.hdl.linkpm.sdk.user.bean.MqttInfo;
import com.hdl.linkpm.sdk.user.bean.NewVersionBean;
import com.hdl.linkpm.sdk.user.bean.UploadImageRequest;
import com.hdl.linkpm.sdk.user.callback.ILoginCallBack;
import com.hdl.linkpm.sdk.user.callback.IMemberInfoBack;
import com.hdl.linkpm.sdk.user.callback.IRegionByAccountCallBack;
import com.hdl.linkpm.sdk.utils.HDLExceptionSubmitUtils;
import com.hdl.linkpm.sdk.utils.HDLGsonUtils;
 
import java.io.File;
 
import io.reactivex.rxjava3.disposables.Disposable;
 
/**
 * Created by jlchen on 12/3/21.
 * B端用户相关的网络请求
 */
public class HDLPMUserController {
 
    /**
     * instance
     */
    private volatile static HDLPMUserController instance;
 
    /**
     * getInstance
     *
     * @return HDLUserController
     */
    public static synchronized HDLPMUserController getInstance() {
        if (instance == null) {
            synchronized (HDLPMUserController.class) {
                if (instance == null) {
                    instance = new HDLPMUserController();
                }
            }
        }
        return instance;
    }
 
    /**
     * 获取账号所在区域
     *
     * @param account
     * @param callBack
     * @return https://nearest.hdlcontrol.com/smart-footstone/region/regionByUserAccount
     */
    public Disposable regionByAccount(String account, IRegionByAccountCallBack callBack) {
        String requestUrl = HDLLinkPMSdk.getInitUrl() + HDLCloudUserApi.POST_RegionByAccount;
        return HxHttp.builder()
                .url(requestUrl)
                .params("account", account)
                .build()
                .post()
                .subscribeWith(new HDLResponse<HDLUserRegionBean>() {
                    @Override
                    public void onResponse(HDLUserRegionBean response) {
                        if (callBack != null) {
                            callBack.onSuccess(response);
                        }
                    }
 
                    @Override
                    public void onFailure(HDLException e) {
                        HDLExceptionSubmitUtils.submit(requestUrl, account, e);
                        if (callBack != null) {
                            callBack.onFailure(e);
                        }
                    }
                });
 
    }
 
    /**
     * 登录
     * 通过账号和密码
     *
     * @param isBooleanB true=B,false=C
     * @param account    手机或者邮箱
     * @param loginPwd   密码
     * @param callBack   回调
     * @return -
     */
    public Disposable loginByPassword(boolean isBooleanB, String account, String loginPwd, ILoginCallBack callBack) {
        String requestUrl = HDLCloudUserApi.getRequestUrl(HDLCloudUserApi.POST_LOGIN);
        if (!isBooleanB) {
            requestUrl = HDLCloudUserApi.getRequestUrl(HDLCloudUserApi.C_POST_LOGIN);
        }
        JsonObject json = new JsonObject();
        json.addProperty("account", account);
        json.addProperty("loginPwd", loginPwd);
//        json.addProperty("platform", "APP");
        json.addProperty("grantType", "password");
 
        String finalRequestUrl = requestUrl;
        return HxHttp.builder()
                .url(requestUrl)
                .raw(json.toString())
                .build()
                .post()
                .subscribeWith(new HDLResponse<HDLLoginBean>() {
                    @Override
                    public void onResponse(HDLLoginBean response) {
                        if (callBack != null) {
                            callBack.onSuccess(response);
                        }
                    }
 
                    @Override
                    public void onFailure(HDLException e) {
                        HDLExceptionSubmitUtils.submit(finalRequestUrl, json, e);
                        if (callBack != null) {
                            callBack.onFailure(e);
                        }
                    }
                });
 
    }
 
    /**
     * 登录
     * 通过验证码
     *
     * @param account  手机或者邮箱
     * @param vCode    验证码
     * @param callBack 回调
     * @return
     */
    public Disposable loginByCode(String account, String vCode, ILoginCallBack callBack) {
        String requestUrl = HDLCloudUserApi.getRequestUrl(HDLCloudUserApi.POST_LOGIN);
        JsonObject json = new JsonObject();
        json.addProperty("account", account);
        json.addProperty("verifyCode", vCode);
//        json.addProperty("platform", "APP");
        json.addProperty("grantType", "verify");
        return HxHttp.builder()
                .url(requestUrl)
                .raw(json.toString())
                .build()
                .post()
                .subscribeWith(new HDLResponse<HDLLoginBean>() {
                    @Override
                    public void onResponse(HDLLoginBean response) {
                        if (callBack != null) {
                            callBack.onSuccess(response);
                        }
                    }
 
                    @Override
                    public void onFailure(HDLException e) {
                        HDLExceptionSubmitUtils.submit(requestUrl, json, e);
                        if (callBack != null) {
                            callBack.onFailure(e);
                        }
                    }
                });
 
    }
 
    /**
     * 通用 发送验证码方法
     * LanguageTypeEnum CHINESE,ENGLISH
     *
     * @param verifyType    1:注册 2:找回密码 3:绑定 4:验证码登陆 5:敏感数据
     * @param account       邮箱或者手机号
     * @param isPhone       是否手机
     * @param phoneZoneCode 手机国家区号
     * @param languageType  语言
     * @param callBack
     * @return
     */
    public Disposable verificationCodeSend(int verifyType, String account, Boolean isPhone, String phoneZoneCode, String languageType, IDefaultCallBack callBack) {
        String requestUrl = HDLCloudUserApi.getRequestUrl(HDLCloudUserApi.POST_VERIFICATION_CODE_SEND);
        JsonObject json = new JsonObject();
        json.addProperty("verifyType", verifyType);
        json.addProperty("languageType", languageType);
        json.addProperty("expireSecond", 300);////验证码过期时间(秒),默认5分钟
        //是否手机
        if (isPhone) {
            json.addProperty("phone", account);
            json.addProperty("phonePrefix", phoneZoneCode);
        } else {
            json.addProperty("mail", account);
        }
        return HxHttp.builder()
                .url(requestUrl)
                .raw(json.toString())
                .build()
                .post()
                .subscribeWith(new HDLResponse<String>() {
                    @Override
                    public void onResponse(String response) {
                        if (callBack != null) {
                            callBack.onSuccess();
                        }
                    }
 
                    @Override
                    public void onFailure(HDLException e) {
                        HDLExceptionSubmitUtils.submit(requestUrl, json, e);
                        if (callBack != null) {
                            callBack.onFailure(e);
                        }
                    }
                });
 
    }
 
    /**
     * 忘记密码,重置密码
     *
     * @param account  邮箱或者手机号
     * @param password 新密码
     * @param vCode    验证码
     * @param isPhone  是否手机
     * @param callBack 回调
     */
    public Disposable forgetPassword(String account, String password, String vCode, Boolean isPhone, IDefaultCallBack callBack) {
        String requestUrl = HDLCloudUserApi.getRequestUrl(HDLCloudUserApi.POST_FORGET_PROGRAM_PWD);
        JsonObject json = new JsonObject();
        json.addProperty("loginPwd", password);
        json.addProperty("verifyCode", vCode);
        //是否手机
        if (isPhone) {
            json.addProperty("userPhone", account);
        } else {
            json.addProperty("userEmail", account);
        }
        return HxHttp.builder()
                .url(requestUrl)
                .raw(json.toString())
                .build()
                .post()
                .subscribeWith(new HDLResponse<String>() {
                    @Override
                    public void onResponse(String response) {
                        if (callBack != null) {
                            callBack.onSuccess();
                        }
                    }
 
                    @Override
                    public void onFailure(HDLException e) {
                        HDLExceptionSubmitUtils.submit(requestUrl, json, e);
                        if (callBack != null) {
                            callBack.onFailure(e);
                        }
                    }
                });
    }
 
    /**
     * 更改个人密码
     *
     * @param userId      当前用户ID
     * @param loginOldPwd 老密码
     * @param loginPwd    新密码
     * @param callBack    回调
     */
    public Disposable updateProgramPassword(String userId, String loginOldPwd, String loginPwd, IDefaultCallBack callBack) {
        String requestUrl = HDLCloudUserApi.getRequestUrl(HDLCloudUserApi.POST_UPDATE_PROGRAM_PASSWORD);
        JsonObject json = new JsonObject();
        json.addProperty("userId", userId);
        json.addProperty("loginOldPwd", loginOldPwd);
        json.addProperty("loginPwd", loginPwd);
        json.addProperty("confirmLoginPwd", loginPwd);
        return HxHttp.builder()
                .url(requestUrl)
                .raw(json.toString())
                .build()
                .post()
                .subscribeWith(new HDLResponse<String>() {
                    @Override
                    public void onResponse(String response) {
                        if (callBack != null) {
                            callBack.onSuccess();
                        }
                    }
 
                    @Override
                    public void onFailure(HDLException e) {
                        HDLExceptionSubmitUtils.submit(requestUrl, json, e);
                        if (callBack != null) {
                            callBack.onFailure(e);
                        }
                    }
                });
    }
 
    /**
     * 获取用户个人信息
     *
     * @param callBack
     */
    public Disposable getMemberInfo(IMemberInfoBack callBack) {
        String requestUrl = HDLCloudUserApi.getRequestUrl(HDLCloudUserApi.POST_GET_MEMBER_INFO);
        return HxHttp.builder()
                .url(requestUrl)
                .build()
                .post()
                .subscribeWith(new HDLResponse<HDLMemberInfoBean>() {
                    @Override
                    public void onResponse(HDLMemberInfoBean response) {
                        if (callBack != null) {
                            callBack.onSuccess(response);
                        }
                    }
 
                    @Override
                    public void onFailure(HDLException e) {
                        HDLExceptionSubmitUtils.submit(requestUrl, null, e);
                        if (callBack != null) {
                            callBack.onFailure(e);
                        }
                    }
                });
    }
 
    /**
     * 更新个人信息
     * memberHeadIcon、memberName、memberBirthday、languageType、memberSex
     *
     * @param callBack
     */
    public Disposable updateMemberInfo(JsonObject updateInfo, IDefaultCallBack callBack) {
        String requestUrl = HDLCloudUserApi.getRequestUrl(HDLCloudUserApi.POST_UPDATE_MEMBER_INFO);
        return HxHttp.builder()
                .url(requestUrl)
                .raw(updateInfo.toString())
                .build()
                .post()
                .subscribeWith(new HDLResponse<String>() {
                    @Override
                    public void onResponse(String response) {
                        if (callBack != null) {
                            callBack.onSuccess();
                        }
                    }
 
                    @Override
                    public void onFailure(HDLException e) {
                        HDLExceptionSubmitUtils.submit(requestUrl, updateInfo, e);
                        if (callBack != null) {
                            callBack.onFailure(e);
                        }
                    }
                });
    }
 
    /**
     * 获取用户头像路径
     *
     * @param memberHeadIconKey 用户头像imageKey
     * @param callBack
     */
    public Disposable getHeadImageUrl(String memberHeadIconKey, IDefaultStrCallBack callBack) {
        String requestUrl = HDLCloudUserApi.getRequestUrl(HDLCloudUserApi.POST_GET_IMAGE_URL);
        return HxHttp.builder()
                .url(requestUrl)
                .params("imageKey", memberHeadIconKey)
                .build()
                .post()
                .subscribeWith(new HDLResponse<String>() {
                    @Override
                    public void onResponse(String response) {
                        if (callBack != null) {
                            callBack.onSuccess(response);
                        }
                    }
 
                    @Override
                    public void onFailure(HDLException e) {
                        HDLExceptionSubmitUtils.submit(requestUrl, memberHeadIconKey, e);
                        if (callBack != null) {
                            callBack.onFailure(e);
                        }
                    }
                });
    }
 
    /**
     * 上传用户头像
     *
     * @param userId     用户id
     * @param imageBytes 头像图片
     * @param callBack
     * @return
     */
    public Disposable uploadUserHeadImage(String userId, byte[] imageBytes, IDefaultStrCallBack callBack) {
        UploadImageRequest uploadImageRequest = new UploadImageRequest();
        uploadImageRequest.setPrefix("Icon" + System.currentTimeMillis());
        uploadImageRequest.setUid(userId);
        uploadImageRequest.setFileName("HeadImage.png");
        uploadImageRequest.setContent(imageBytes);
 
        String requestUrl = HDLCloudUserApi.getRequestUrl(HDLCloudUserApi.POST_UPLOAD_IMAGE);
        return HxHttp.builder()
                .url(requestUrl)
                .raw(HDLGsonUtils.toJson(uploadImageRequest))
                .build()
                .post()
                .subscribeWith(new HDLResponse<String>() {
                    @Override
                    public void onResponse(String response) {
                        if (callBack != null) {
                            callBack.onSuccess(response);
                        }
                    }
 
                    @Override
                    public void onFailure(HDLException e) {
                        HDLExceptionSubmitUtils.submit(requestUrl, uploadImageRequest, e);
                        if (callBack != null) {
                            callBack.onFailure(e);
                        }
                    }
                });
    }
 
    /**
     * 上传用户头像(新)
     *
     * @param file     图片
     * @param callBack
     * @return
     */
    public Disposable uplfadUserHeadImage(File file, IResponseCallBack<ImageSubmitInfo> callBack) {
        String requestUrl = HDLCloudUserApi.getRequestUrl(HDLCloudUserApi.POST_UPLOAD_IMAGE_NEW);
        return HxHttp.builder()
                .url(requestUrl)
                .file(file)
                .build()
                .upload()
                .subscribeWith(new HDLResponse<ImageSubmitInfo>() {
                    @Override
                    public void onResponse(ImageSubmitInfo response) {
                        if (callBack != null) {
                            callBack.onSuccess(response);
                        }
                    }
 
                    @Override
                    public void onFailure(HDLException e) {
                        HDLExceptionSubmitUtils.submit(requestUrl, null, e);
                        if (callBack != null) {
                            callBack.onFailure(e);
                        }
                    }
                });
    }
 
//    /**
//     * 版本检测更新
//     *
//     * @param appName  app名称
//     * @param version  版本号
//     * @param callBack 如果onSuccess 回调的bean为空,代表当前版本已经是最新版本,没有新版本
//     * @return
//     */
//    public Disposable checkAppVersion(String appName, String version, IResponseCallBack<NewVersionBean> callBack) {
//        JsonObject json = new JsonObject();
//        json.addProperty("appName", appName);
//        json.addProperty("version", version);
//        json.addProperty("version", version);
//        String requestUrl = HDLLinkPMSdk.getRegionUrl() + HDLCloudUserApi.POST_APP_APPVERSION_CHECK;
//        return HxHttp.builder()
//                .url(requestUrl)
//                .raw(json.toString())
//                .build()
//                .post()
//                .subscribeWith(new HDLResponse<NewVersionBean>() {
//                    @Override
//                    public void onResponse(NewVersionBean response) {
//                        if (callBack != null) {
//                            callBack.onSuccess(response);
//                        }
//                    }
//
//                    @Override
//                    public void onFailure(HDLException e) {
//                        if (callBack != null) {
//                            callBack.onFailure(e);
//                        }
//                    }
//                });
//    }
 
    /**
     * 版本检测更新
     * 支持Android、iOS、wgt检测
     *
     * @param appCode       app编码
     * @param version       版本号
     * @param releaseSystem 发布系统,IOS、Android, wgt
     * @param callBack      如果onSuccess 回调的bean为空,代表当前版本已经是最新版本,没有新版本
     * @return
     */
    public Disposable checkAppVersion(String appCode, String version, String releaseSystem, IResponseCallBack<NewVersionBean> callBack) {
        JsonObject json = new JsonObject();
        json.addProperty("appCode", appCode);
        json.addProperty("version", version);
        json.addProperty("releaseSystem", releaseSystem);
        String requestUrl = HDLCloudUserApi.getRequestUrl(HDLCloudUserApi.POST_APP_APPVERSION_CHECK);
        return HxHttp.builder()
                .url(requestUrl)
                .raw(json.toString())
                .build()
                .post()
                .subscribeWith(new HDLResponse<NewVersionBean>() {
                    @Override
                    public void onResponse(NewVersionBean response) {
                        if (callBack != null) {
                            callBack.onSuccess(response);
                        }
                    }
 
                    @Override
                    public void onFailure(HDLException e) {
                        HDLExceptionSubmitUtils.submit(requestUrl, json, e);
                        if (callBack != null) {
                            callBack.onFailure(e);
                        }
                    }
                });
    }
 
    /**
     * 获取mqtt信息
     *
     * @return
     */
    public static Disposable getMqttInfo(String attachClientId, String homeType, String deviceUuid, IResponseCallBack<MqttInfo> listener) {
        return HxHttp.builder()
                .url(HDLCloudUserApi.getRequestUrl(HDLCloudUserApi.MQTT_INFO_URL))
                .params("attachClientId", attachClientId)
                .params("homeType", homeType)
                .params("deviceUuid", deviceUuid)
                .build()
                .post()
                .subscribeWith(new HDLResponse<MqttInfo>() {
                    @Override
                    public void onResponse(MqttInfo response) {
                        if (listener != null) {
                            listener.onSuccess(response);
                        }
                    }
 
                    @Override
                    public void onFailure(HDLException e) {
                        JsonObject json = new JsonObject();
                        json.addProperty("attachClientId", attachClientId);
                        json.addProperty("homeType", homeType);
                        json.addProperty("deviceUuid", deviceUuid);
                        HDLExceptionSubmitUtils.submit(HDLCloudUserApi.getRequestUrl(HDLCloudUserApi.MQTT_INFO_URL), json, e);
                        if (listener != null) {
                            listener.onFailure(e);
                        }
                    }
                });
    }
 
}