From 16d47cc936d66c272621ef1d91e984db13f957c8 Mon Sep 17 00:00:00 2001 From: wenfei Date: Tue, 20 Jan 2026 17:50:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E9=A2=84=E8=AD=A6=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=20=E7=99=BB=E5=BD=95=E6=8E=A5=E5=8F=A3=E5=8A=A0?= =?UTF-8?q?=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/rehome/zhdcoa/Contans.java | 2 +- .../utils/AuthenticationLoginAIUtils.java | 161 +++++++++--------- 2 files changed, 80 insertions(+), 83 deletions(-) diff --git a/app/src/main/java/com/rehome/zhdcoa/Contans.java b/app/src/main/java/com/rehome/zhdcoa/Contans.java index 0f552a3..96a7d6b 100644 --- a/app/src/main/java/com/rehome/zhdcoa/Contans.java +++ b/app/src/main/java/com/rehome/zhdcoa/Contans.java @@ -529,7 +529,7 @@ public class Contans { //设备状态智能监测及分析平台 登录 public final static String DeviceAlermInfoLoginUrl = "dserver/user/login"; - public final static String DeviceAlermInfoLoginRsaUrl = "dserver/user/loginRsaUpAndDown"; + public final static String DeviceAlermInfoLoginRsaUrl = "dserver/user/loginRsaUpAndDownRsa"; //设备预警信息列表 //http://192.168.2.28:1700/dserver/warning/page?v=1765422183414&keyword=&pageNo=1&pageSize=10 public final static String DeviceAlermInfoListUrl = "dserver/warning/page"; diff --git a/app/src/main/java/com/rehome/zhdcoa/utils/AuthenticationLoginAIUtils.java b/app/src/main/java/com/rehome/zhdcoa/utils/AuthenticationLoginAIUtils.java index 760671f..08839c6 100644 --- a/app/src/main/java/com/rehome/zhdcoa/utils/AuthenticationLoginAIUtils.java +++ b/app/src/main/java/com/rehome/zhdcoa/utils/AuthenticationLoginAIUtils.java @@ -6,6 +6,7 @@ import android.content.Context; import android.content.pm.ApplicationInfo; import android.text.TextUtils; import android.util.Log; + import com.rehome.zhdcoa.Contans; import com.rehome.zhdcoa.bean.DeviceAlarmLoginResultBean; import com.rehome.zhdcoa.bean.DeviceAlarmLoginResultDataBean; @@ -14,19 +15,22 @@ import com.yolanda.nohttp.NoHttp; import com.yolanda.nohttp.RequestMethod; import com.yolanda.nohttp.rest.Request; import com.yolanda.nohttp.rest.Response; + import static com.rehome.zhdcoa.utils.GsonUtils.GsonToBean; + import java.util.HashMap; import java.util.Map; + import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSocketFactory; public class AuthenticationLoginAIUtils { /** - * @param mActivity Activity - * @param account 工号 - * @param password 密码 - * @param listener 监听回调 + * @param mActivity Activity + * @param account 工号 + * @param password 密码 + * @param listener 监听回调 */ public static void authenticationAILogin(Activity mActivity, String account, String password, OnAuthenticationLoginListener listener) { @@ -40,7 +44,7 @@ public class AuthenticationLoginAIUtils { params.put("password", password); String json = GsonUtils.GsonString(params); - showLog(json,mActivity); + showLog(json, mActivity); String jsonEncrypt = RSAUtils.encryptBASE64Str(json); //showLog(jsonEncrypt); request.setDefineRequestBodyForJson(jsonEncrypt); @@ -63,17 +67,17 @@ public class AuthenticationLoginAIUtils { @Override public void onSucceed(int what, Response response) { - showLog("----------------",mActivity); + showLog("----------------", mActivity); String result = response.get(); - showLog(result,mActivity); + showLog(result, mActivity); String jsonDecode = RSAUtils.decryptBASE64StrClient(result); if (TextUtils.isEmpty(jsonDecode)) { //解密失败 - showLog("APP解密失败",mActivity); + showLog("APP解密失败", mActivity); listener.onAuthenticationSuccess(false, ""); } else { - showLog(jsonDecode,mActivity); + showLog(jsonDecode, mActivity); UserAuthenticationAIBean bean = GsonToBean(jsonDecode, UserAuthenticationAIBean.class); if (bean != null) { if (bean.isSuccess()) {//登录成功 @@ -88,19 +92,19 @@ public class AuthenticationLoginAIUtils { } else { listener.onAuthenticationSuccess(false, ""); if (bean.getFlag() == -2) { - showLog("没有传参",mActivity); + showLog("没有传参", mActivity); } if (bean.getFlag() == -3) { - showLog("服务器解密失败",mActivity); + showLog("服务器解密失败", mActivity); } if (bean.getFlag() == -4) { - showLog("Json 格式不正确",mActivity); + showLog("Json 格式不正确", mActivity); } if (bean.getFlag() == -5) { - showLog("账号密码不能为空",mActivity); + showLog("账号密码不能为空", mActivity); } if (bean.getFlag() == -6) { - showLog("账号或密码错误",mActivity); + showLog("账号或密码错误", mActivity); } } } @@ -136,7 +140,7 @@ public class AuthenticationLoginAIUtils { @Override public void onFailed(int what, Response response) { - showLog("onFailed",mActivity); + showLog("onFailed", mActivity); listener.onAuthenticationSuccess(false, ""); } }); @@ -177,17 +181,17 @@ public class AuthenticationLoginAIUtils { @Override public void onSucceed(int what, Response response) { - showLog("----------------",mActivity); + showLog("----------------", mActivity); String result = response.get(); - showLog(result,mActivity); + showLog(result, mActivity); String jsonDecode = RSAUtils.decryptBASE64StrClient(result); if (TextUtils.isEmpty(jsonDecode)) { //解密失败 - showLog("APP解密失败",mActivity); + showLog("APP解密失败", mActivity); listener.onAuthenticationSuccess(false, ""); } else { - showLog(jsonDecode,mActivity); + showLog(jsonDecode, mActivity); UserAuthenticationAIBean bean = GsonToBean(jsonDecode, UserAuthenticationAIBean.class); if (bean != null) { if (bean.isSuccess()) {//登录成功 @@ -202,19 +206,19 @@ public class AuthenticationLoginAIUtils { } else { listener.onAuthenticationSuccess(false, ""); if (bean.getFlag() == -2) { - showLog("没有传参",mActivity); + showLog("没有传参", mActivity); } if (bean.getFlag() == -3) { - showLog("服务器解密失败",mActivity); + showLog("服务器解密失败", mActivity); } if (bean.getFlag() == -4) { - showLog("Json 格式不正确",mActivity); + showLog("Json 格式不正确", mActivity); } if (bean.getFlag() == -5) { - showLog("账号密码不能为空",mActivity); + showLog("账号密码不能为空", mActivity); } if (bean.getFlag() == -6) { - showLog("账号或密码错误",mActivity); + showLog("账号或密码错误", mActivity); } } } @@ -250,7 +254,7 @@ public class AuthenticationLoginAIUtils { @Override public void onFailed(int what, Response response) { - showLog("onFailed",mActivity); + showLog("onFailed", mActivity); listener.onAuthenticationSuccess(false, ""); } }); @@ -291,14 +295,14 @@ public class AuthenticationLoginAIUtils { @Override public void onSucceed(int what, Response response) { - showLog("----------------",mActivity); + showLog("----------------", mActivity); String result = response.get(); - showLog(result,mActivity); + showLog(result, mActivity); - if(!TextUtils.isEmpty(result)){ + if (!TextUtils.isEmpty(result)) { UserAuthenticationAIBean bean = GsonToBean(result, UserAuthenticationAIBean.class); if (bean != null) { - if (bean.isSuccess()&&bean.getCode()==20000) {//登录成功 + if (bean.isSuccess() && bean.getCode() == 20000) {//登录成功 SPUtils.put(mActivity, Contans.AUTHENTICATIONLOGINTOKENAI, bean.getData().getToken()); listener.onAuthenticationSuccess(true, bean.getData().getToken()); } else { @@ -310,19 +314,19 @@ public class AuthenticationLoginAIUtils { } else { listener.onAuthenticationSuccess(false, ""); if (bean.getFlag() == -2) { - showLog("没有传参",mActivity); + showLog("没有传参", mActivity); } if (bean.getFlag() == -3) { - showLog("服务器解密失败",mActivity); + showLog("服务器解密失败", mActivity); } if (bean.getFlag() == -4) { - showLog("Json 格式不正确",mActivity); + showLog("Json 格式不正确", mActivity); } if (bean.getFlag() == -5) { - showLog("账号密码不能为空",mActivity); + showLog("账号密码不能为空", mActivity); } if (bean.getFlag() == -6) { - showLog("账号或密码错误",mActivity); + showLog("账号或密码错误", mActivity); } } } @@ -332,7 +336,7 @@ public class AuthenticationLoginAIUtils { @Override public void onFailed(int what, Response response) { - showLog("onFailed",mActivity); + showLog("onFailed", mActivity); listener.onAuthenticationSuccess(false, ""); } }); @@ -349,7 +353,7 @@ public class AuthenticationLoginAIUtils { String json = GsonUtils.GsonString(params); //showLog(json,mActivity); String jsonEncrypt = RSAUtils.encryptBASE64Str(json); - showLog(jsonEncrypt,mActivity); + showLog(jsonEncrypt, mActivity); request.setDefineRequestBodyForJson(jsonEncrypt); if (Contans.IP.equals(Contans.IP_EXTRANET)) { @@ -370,53 +374,46 @@ public class AuthenticationLoginAIUtils { @Override public void onSucceed(int what, Response response) { - showLog("----------------",mActivity); + showLog("----------------", mActivity); String result = response.get(); - showLog(result,mActivity); - - if(!TextUtils.isEmpty(result)){ - DeviceAlarmLoginResultBean bean = GsonToBean(result, DeviceAlarmLoginResultBean.class); - if (bean != null) { - if (bean.isSuccess()&&bean.getCode()==20000) {//登录成功 - if(!TextUtils.isEmpty(bean.getData())){ - String jsonDecode = RSAUtils.decryptBASE64StrClient(bean.getData()); - if (TextUtils.isEmpty(jsonDecode)) { - //解密失败 - showLog("APP解密失败",mActivity); - listener.onAuthenticationSuccess(false, ""); + showLog(result, mActivity); + + if (!TextUtils.isEmpty(result)) { + String jsonDecode = RSAUtils.decryptBASE64StrClient(result); + if (TextUtils.isEmpty(jsonDecode)) { + //解密失败 + showLog("APP解密失败", mActivity); + listener.onAuthenticationSuccess(false, ""); + } else { + showLog(jsonDecode, mActivity); + UserAuthenticationAIBean bean = GsonToBean(jsonDecode, UserAuthenticationAIBean.class); + //DeviceAlarmLoginResultBean bean = GsonToBean(result, DeviceAlarmLoginResultBean.class); + if (bean != null) { + if (bean.isSuccess() && bean.getCode() == 20000) {//登录成功 + listener.onAuthenticationSuccess(true, bean.getData().getToken()); + } else { + if (bean.getFlag() == -1) { + if (bean.getMsg() != null && bean.getMsg().equals("用户未注销")) { + String token = (String) SPUtils.get(mActivity, Contans.AUTHENTICATIONLOGINTOKENAI, String.valueOf("")); + listener.onAuthenticationSuccess(true, token); + } } else { - //showLog(jsonDecode,mActivity); - DeviceAlarmLoginResultDataBean beanDecode = GsonToBean(jsonDecode, DeviceAlarmLoginResultDataBean.class); - if(beanDecode!=null&&beanDecode.getMsg()!=null&&"登录成功".equals(beanDecode.getMsg())){ - listener.onAuthenticationSuccess(true, beanDecode.getToken()); - }else{ - showLog("账号或密码错误",mActivity); - listener.onAuthenticationSuccess(false, ""); + listener.onAuthenticationSuccess(false, ""); + if (bean.getFlag() == -2) { + showLog("没有传参", mActivity); + } + if (bean.getFlag() == -3) { + showLog("服务器解密失败", mActivity); + } + if (bean.getFlag() == -4) { + showLog("Json 格式不正确", mActivity); + } + if (bean.getFlag() == -5) { + showLog("账号密码不能为空", mActivity); + } + if (bean.getFlag() == -6) { + showLog("账号或密码错误", mActivity); } - } - } - } else { - if (bean.getFlag() == -1) { - if (bean.getMsg() != null && bean.getMsg().equals("用户未注销")) { - String token = (String) SPUtils.get(mActivity, Contans.AUTHENTICATIONLOGINTOKENAI, String.valueOf("")); - listener.onAuthenticationSuccess(true, token); - } - } else { - listener.onAuthenticationSuccess(false, ""); - if (bean.getFlag() == -2) { - showLog("没有传参",mActivity); - } - if (bean.getFlag() == -3) { - showLog("服务器解密失败",mActivity); - } - if (bean.getFlag() == -4) { - showLog("Json 格式不正确",mActivity); - } - if (bean.getFlag() == -5) { - showLog("账号密码不能为空",mActivity); - } - if (bean.getFlag() == -6) { - showLog("账号或密码错误",mActivity); } } } @@ -426,14 +423,14 @@ public class AuthenticationLoginAIUtils { @Override public void onFailed(int what, Response response) { - showLog("onFailed",mActivity); + showLog("onFailed", mActivity); listener.onAuthenticationSuccess(false, ""); } }); } - public static void showLog(String logText,Context context) { + public static void showLog(String logText, Context context) { if (isApkInDebug(context)) { if (TextUtils.isEmpty(logText)) { Log.i("app", "logText is null");