From 2c7615cd73dfa6a7ca4df975430d2217524513d2 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期四, 28 九月 2023 11:38:28 +0800
Subject: [PATCH] 2023年09月28日11:38:24
---
app/src/main/java/com/hdl/photovoltaic/other/HdlAccountLogic.java | 360 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 316 insertions(+), 44 deletions(-)
diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlAccountLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlAccountLogic.java
index 63c9ae5..bbd321a 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlAccountLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlAccountLogic.java
@@ -1,13 +1,34 @@
package com.hdl.photovoltaic.other;
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.hdl.linkpm.sdk.core.exception.HDLException;
+import com.hdl.linkpm.sdk.user.HDLLinkPMUser;
+import com.hdl.linkpm.sdk.user.bean.HDLLoginBean;
+import com.hdl.linkpm.sdk.user.bean.HDLUserRegionBean;
+import com.hdl.linkpm.sdk.user.callback.ILoginCallBack;
+import com.hdl.linkpm.sdk.user.callback.IRegionByAccountCallBack;
+import com.hdl.photovoltaic.config.UserConfigManage;
+import com.hdl.photovoltaic.internet.HttpClient;
+import com.hdl.photovoltaic.internet.api.HttpApi;
+import com.hdl.photovoltaic.listener.CloudCallBeak;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
/**
- * 鐧婚檰鐣岄潰鐨勯�昏緫
+ * 璐﹀彿閫昏緫
*/
public class HdlAccountLogic {
private static volatile HdlAccountLogic sHdlAccountLogic;
+ /**
+ * 鑾峰彇褰撳墠瀵硅薄
+ *
+ * @return HdlAccountLogic
+ */
public static synchronized HdlAccountLogic getInstance() {
if (sHdlAccountLogic == null) {
synchronized (HdlAccountLogic.class) {
@@ -20,57 +41,308 @@
return sHdlAccountLogic;
}
+ // region --------銆怋绔处鍙枫��---------
/**
- * 鍒濆鍖栬处鍙风殑Url鍖哄煙鍦板潃(鍙兘鐘舵�佺爜:Sucess NotAccount NotNetWork)
+ * 鍒濆鍖栬处鍙风殑Url鍖哄煙鍦板潃
*
- * @param i_account
- * @return
+ * @param i_account 璐﹀彿
*/
- private void InitAccoutRegionInfo(String i_account) {
-// String regionUrl = this.GetAccoutRegionInfo(i_account);
-//
-//
-// if (regionUrl == null) {
-// return AccountStatu.NotNetWork;
-// }
-// if (regionUrl == string.Empty) {
-// return AccountStatu.NotAccount;
-// }
-//
-// return AccountStatu.Sucess;
+ public void regionByAccount(String i_account, CloudCallBeak<HDLUserRegionBean> cloudCallBeak) {
+ HDLLinkPMUser.getInstance().regionByAccount(i_account, new IRegionByAccountCallBack() {
+ @Override
+ public void onSuccess(HDLUserRegionBean regionBean) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(regionBean);
+ }
+ }
+
+ @Override
+ public void onFailure(HDLException error) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onFailure(error);
+ }
+ }
+ });
}
/**
- * 鑾峰彇璐﹀彿鎵�鍦ㄥ尯鍩�
+ * 鐧诲綍(B绔处鍙�)
+ * 閫氳繃璐﹀彿鍜屽瘑鐮�
*
- * @param account
- * @param callBack
- * @return https://nearest.hdlcontrol.com/smart-footstone/region/regionByUserAccount
+ * @param account 鎵嬫満鎴栬�呴偖绠�
+ * @param loginPwd 瀵嗙爜
+ * @param callBack -
*/
-// public Disposable regionByAccount(String account, IRegionByAccountCallBack callBack) {
-// String requestUrl = HDLLinkPMSdk.getInitUrl() + HttpApi.POST_RegionByUserAccount;
-// 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);
-// }
-// }
-// });
+ public void loginByPassword(String account, String loginPwd, ILoginCallBack callBack) {
+ String requestUrl = HttpApi.POST_Login;
+ JsonObject json = new JsonObject();
+ json.addProperty("account", account);
+ json.addProperty("loginPwd", loginPwd);
+// json.addProperty("platform", "APP");
+ json.addProperty("grantType", "password");
+ HDLLinkPMUser.getInstance().loginByPassword(account, loginPwd, new ILoginCallBack() {
+ @Override
+ public void onSuccess(HDLLoginBean loginBean) {
-// }
+ if (callBack != null) {
+ saveUserData(loginBean);
+ callBack.onSuccess(loginBean);
+ }
+ }
+
+ @Override
+ public void onFailure(HDLException error) {
+ if (callBack != null) {
+ callBack.onFailure(error);
+ }
+ }
+ });
+
+ }
+
+ /**
+ * 淇敼瀵嗙爜(B绔处鍙�)
+ *
+ * @param isPhone true琛ㄧず鎵嬫満鍙�,鍚﹀垯鏄偖绠�
+ * @param account 璐﹀彿 (鎵嬫満鎴栬�呴偖绠�)
+ * @param loginPwd 鏂板瘑鐮�
+ * @param verifyCode 楠岃瘉鐮�
+ * @param cloudCallBeak -
+ */
+ public void changeBPassword(boolean isPhone, String account, String loginPwd, String verifyCode, CloudCallBeak<Boolean> cloudCallBeak) {
+ String requestUrl = HttpApi.B_POST_FORGET_PROGRAM_PWD;
+ JsonObject json = new JsonObject();
+ if (isPhone) {
+ json.addProperty("userPhone", account);//鐢ㄦ埛鎵嬫満鍙� 鎵嬫満鍙峰拰閭蹇呭~鍏朵竴
+ } else {
+ json.addProperty("userEmail", account);
+ }
+ json.addProperty("loginPwd", loginPwd);//鏂板瘑鐮�
+ json.addProperty("verifyCode", verifyCode);//楠岃瘉鐮�
+// json.addProperty("platform", "APP");
+
+ HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
+ @Override
+ public void onSuccess(String str) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(true);
+ }
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onFailure(e);
+ }
+ }
+ });
+
+
+ }
+
+
+ /**
+ * 鍒锋柊Token(B绔处鍙�)
+ *
+ * @param account 鎵嬫満鎴栬�呴偖绠�
+ * @param loginPwd 瀵嗙爜
+ * @param cloudCallBeak -
+ */
+ public void refreshToken(String account, String loginPwd, CloudCallBeak<HDLLoginBean> cloudCallBeak) {
+ String requestUrl = HttpApi.POST_Login;
+ JsonObject json = new JsonObject();
+ json.addProperty("grantType", "refresh_token");
+// json.addProperty("refreshToken", UserConfigManage.getInstance().getRefreshToken());
+ HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
+ @Override
+ public void onSuccess(String jsonStr) {
+ Gson gson = new Gson();
+ HDLLoginBean loginBean = gson.fromJson(jsonStr, HDLLoginBean.class);
+// saveUserData(loginBean);
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(loginBean);
+ }
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onFailure(e);
+ }
+ }
+ });
+ }
+
+
+ // endregion
+
+ // region --------銆怌绔处鍙枫��---------
+
+ /**
+ * 娉ㄥ唽璐﹀彿(C绔处鍙�)
+ * 娉ㄦ剰:B
+ *
+ * @param isPhone true琛ㄧず鎵嬫満鍙�,鍚﹀垯鏄偖绠�
+ * @param account 璐﹀彿 (鎵嬫満鎴栬�呴偖绠�)
+ * @param loginPwd 瀵嗙爜
+ * @param verifyCode 楠岃瘉鐮�
+ * @param cloudCallBeak -
+ */
+ public void registerAccount(boolean isPhone, String account, String loginPwd, String verifyCode, CloudCallBeak<Boolean> cloudCallBeak) {
+ String requestUrl = HttpApi.C_POST_GET_OAUTH_REGISTER;
+ JsonObject json = new JsonObject();
+ if (isPhone) {
+ json.addProperty("memberPhone", account);//鐢ㄦ埛鎵嬫満鍙� 鎵嬫満鍙峰拰閭蹇呭~鍏朵竴
+ } else {
+ json.addProperty("memberEmail", account);
+ }
+ json.addProperty("loginPwd", loginPwd);//鐧婚檰瀵嗙爜锛岄渶瑕丮D5澶勭悊
+ json.addProperty("verifyCode", verifyCode);//楠岃瘉鐮�
+// json.addProperty("platform", "APP");
+// json.addProperty("memberName", "memberName");//浼氬憳鏄电О
+
+ HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
+ @Override
+ public void onSuccess(String str) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(true);
+ }
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onFailure(e);
+ }
+ }
+ });
+
+
+ }
+
+
+ /**
+ * 淇敼瀵嗙爜(C绔处鍙�)
+ *
+ * @param isPhone true琛ㄧず鎵嬫満鍙�,鍚﹀垯鏄偖绠�
+ * @param account 璐﹀彿 (鎵嬫満鎴栬�呴偖绠�)
+ * @param loginPwd 鏂板瘑鐮�
+ * @param verifyCode 楠岃瘉鐮�
+ * @param cloudCallBeak -
+ */
+ public void changeCPassword(boolean isPhone, String account, String loginPwd, String verifyCode, CloudCallBeak<Boolean> cloudCallBeak) {
+ String requestUrl = HttpApi.C_POST_FORGET_PROGRAM_PWD;
+ JsonObject json = new JsonObject();
+ if (isPhone) {
+ json.addProperty("memberPhone", account);//鐢ㄦ埛鎵嬫満鍙� 鎵嬫満鍙峰拰閭蹇呭~鍏朵竴
+ } else {
+ json.addProperty("memberEmail", account);
+ }
+ json.addProperty("loginPwd", loginPwd);//鏂板瘑鐮�
+ json.addProperty("verifyCode", verifyCode);//楠岃瘉鐮�
+// json.addProperty("platform", "APP");
+
+ HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
+ @Override
+ public void onSuccess(String str) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(true);
+ }
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onFailure(e);
+ }
+ }
+ });
+
+
+ }
+ // endregion
+
+
+ /**
+ * 鍙戦�侀獙璇佺爜
+ *
+ * @param isPhone true琛ㄧず鎵嬫満鍙�,鍚﹀垯鏄偖绠�
+ * @param account 璐﹀彿 (鎵嬫満鎴栬�呴偖绠�)
+ * @param phonePrefix 鎵嬫満鍙峰墠缂�
+ * @param verifyType 1:娉ㄥ唽 2锛氭壘鍥炲瘑鐮� 3锛氱粦瀹�4:楠岃瘉鐮佺櫥闄� 5:鏁忔劅鏁版嵁
+ * @param cloudCallBeak -
+ */
+ public void sendVerifyCode(boolean isPhone, String account, String phonePrefix, int verifyType, CloudCallBeak<Boolean> cloudCallBeak) {
+ String requestUrl = HttpApi.POST_SEND_VERIFICATION;
+ JsonObject json = new JsonObject();
+ if (isPhone) {
+ json.addProperty("phone", account);//鐢ㄦ埛鎵嬫満鍙�
+ json.addProperty("phonePrefix", phonePrefix);//鎵嬫満鍙峰墠缂�
+ } else {
+ json.addProperty("mail", account);//閭
+ }
+ json.addProperty("verifyType", verifyType);//1:娉ㄥ唽 2锛氭壘鍥炲瘑鐮� 3锛氱粦瀹�4:楠岃瘉鐮佺櫥闄� 5:鏁忔劅鏁版嵁
+// json.addProperty("languageType", loginPwd);//璇█
+// json.addProperty("expireSecond", expireSecond);//楠岃瘉鐮佽繃鏈熸椂闂达紙绉掞級,榛樿5鍒嗛挓
+// json.addProperty("platform", "APP");
+
+ HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
+ @Override
+ public void onSuccess(String str) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(true);
+ }
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onFailure(e);
+ }
+ }
+ });
+
+
+ }
+
+ /**
+ * 閫�鍑虹櫥褰曟椂璋冪敤锛屾竻闄ゆ帹閫佹暟鎹�
+ */
+ public void SignOutClearData() {
+ String requestUrl = HttpApi.POST_GET_IMAGE_LOGOUT;
+ //閫氱煡浜戠锛屽凡缁忛��鍑虹櫥闄�
+ }
+
+ public boolean isPhone(String phone) {
+ Pattern p = Pattern.compile("^((13[0-9])|(14[0|5|6|7|9])|(15[0-3])|(15[5-9])|(16[6|7])|(17[2|3|5|6|7|8])|(18[0-9])|(19[1|8|9]))\\d{8}$");
+ Matcher m = p.matcher(phone);
+ return m.matches();
+ }
+
+ public boolean isMailbox(String mailbox) {
+ String regex = "^(\\w+([-.][A-Za-z0-9]+)*){3,18}@\\w+([-.][A-Za-z0-9]+)*\\.\\w+([-.][A-Za-z0-9]+)*$";
+ return mailbox.matches(regex);
+ }
+
+ /**
+ * 鐧诲綍鎴愬姛淇濆瓨鐧诲綍淇℃伅
+ */
+ private void saveUserData(HDLLoginBean obj) {
+ if (obj != null) {
+ UserConfigManage.getInstance().setLogin(true);//鏄惁鐧诲綍
+ UserConfigManage.getInstance().setAcceiptPolicy(true);//鏄惁閫夋嫨闅愮鏀跨瓥
+ UserConfigManage.getInstance().setLoginDateTime(System.currentTimeMillis());//鐧诲綍鏃堕棿
+ UserConfigManage.getInstance().setUserId(obj.getUserId());//鐢ㄦ埛id
+ UserConfigManage.getInstance().setAccount(obj.getAccount());//璐﹀彿
+ UserConfigManage.getInstance().setToken(obj.getAccessToken());//Token
+ UserConfigManage.getInstance().setHeaderPrefix(obj.getHeaderPrefix());//璁よ瘉璇锋眰澶村墠缂�(搴曞眰璇锋眰缁熶竴鍔�)
+ UserConfigManage.getInstance().setRefreshToken(obj.getRefreshToken());//鍒锋柊Token鐢ㄧ殑鍒锋柊Token鐢ㄧ殑
+ boolean isUserId = UserConfigManage.getInstance().getUserId().equals(obj.getUserId());
+ UserConfigManage.getInstance().setTheSameLoginAccount(isUserId);//涓庝笂涓�涓处鍙锋槸鍚﹀悓涓�涓�
+ }
+
+ }
+
+
}
--
Gitblit v1.8.0