设备预警信息 登录接口加密

master
wenfei 4 days ago
parent 5c38dcb029
commit 16d47cc936

@ -529,7 +529,7 @@ public class Contans {
//设备状态智能监测及分析平台 登录 //设备状态智能监测及分析平台 登录
public final static String DeviceAlermInfoLoginUrl = "dserver/user/login"; 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 //http://192.168.2.28:1700/dserver/warning/page?v=1765422183414&keyword=&pageNo=1&pageSize=10
public final static String DeviceAlermInfoListUrl = "dserver/warning/page"; public final static String DeviceAlermInfoListUrl = "dserver/warning/page";

@ -6,6 +6,7 @@ import android.content.Context;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.rehome.zhdcoa.Contans; import com.rehome.zhdcoa.Contans;
import com.rehome.zhdcoa.bean.DeviceAlarmLoginResultBean; import com.rehome.zhdcoa.bean.DeviceAlarmLoginResultBean;
import com.rehome.zhdcoa.bean.DeviceAlarmLoginResultDataBean; import com.rehome.zhdcoa.bean.DeviceAlarmLoginResultDataBean;
@ -14,19 +15,22 @@ import com.yolanda.nohttp.NoHttp;
import com.yolanda.nohttp.RequestMethod; import com.yolanda.nohttp.RequestMethod;
import com.yolanda.nohttp.rest.Request; import com.yolanda.nohttp.rest.Request;
import com.yolanda.nohttp.rest.Response; import com.yolanda.nohttp.rest.Response;
import static com.rehome.zhdcoa.utils.GsonUtils.GsonToBean; import static com.rehome.zhdcoa.utils.GsonUtils.GsonToBean;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.SSLSocketFactory;
public class AuthenticationLoginAIUtils { public class AuthenticationLoginAIUtils {
/** /**
* @param mActivity Activity * @param mActivity Activity
* @param account * @param account
* @param password * @param password
* @param listener * @param listener
*/ */
public static void authenticationAILogin(Activity mActivity, String account, String password, OnAuthenticationLoginListener listener) { public static void authenticationAILogin(Activity mActivity, String account, String password, OnAuthenticationLoginListener listener) {
@ -40,7 +44,7 @@ public class AuthenticationLoginAIUtils {
params.put("password", password); params.put("password", password);
String json = GsonUtils.GsonString(params); String json = GsonUtils.GsonString(params);
showLog(json,mActivity); showLog(json, mActivity);
String jsonEncrypt = RSAUtils.encryptBASE64Str(json); String jsonEncrypt = RSAUtils.encryptBASE64Str(json);
//showLog(jsonEncrypt); //showLog(jsonEncrypt);
request.setDefineRequestBodyForJson(jsonEncrypt); request.setDefineRequestBodyForJson(jsonEncrypt);
@ -63,17 +67,17 @@ public class AuthenticationLoginAIUtils {
@Override @Override
public void onSucceed(int what, Response<String> response) { public void onSucceed(int what, Response<String> response) {
showLog("----------------",mActivity); showLog("----------------", mActivity);
String result = response.get(); String result = response.get();
showLog(result,mActivity); showLog(result, mActivity);
String jsonDecode = RSAUtils.decryptBASE64StrClient(result); String jsonDecode = RSAUtils.decryptBASE64StrClient(result);
if (TextUtils.isEmpty(jsonDecode)) { if (TextUtils.isEmpty(jsonDecode)) {
//解密失败 //解密失败
showLog("APP解密失败",mActivity); showLog("APP解密失败", mActivity);
listener.onAuthenticationSuccess(false, ""); listener.onAuthenticationSuccess(false, "");
} else { } else {
showLog(jsonDecode,mActivity); showLog(jsonDecode, mActivity);
UserAuthenticationAIBean bean = GsonToBean(jsonDecode, UserAuthenticationAIBean.class); UserAuthenticationAIBean bean = GsonToBean(jsonDecode, UserAuthenticationAIBean.class);
if (bean != null) { if (bean != null) {
if (bean.isSuccess()) {//登录成功 if (bean.isSuccess()) {//登录成功
@ -88,19 +92,19 @@ public class AuthenticationLoginAIUtils {
} else { } else {
listener.onAuthenticationSuccess(false, ""); listener.onAuthenticationSuccess(false, "");
if (bean.getFlag() == -2) { if (bean.getFlag() == -2) {
showLog("没有传参",mActivity); showLog("没有传参", mActivity);
} }
if (bean.getFlag() == -3) { if (bean.getFlag() == -3) {
showLog("服务器解密失败",mActivity); showLog("服务器解密失败", mActivity);
} }
if (bean.getFlag() == -4) { if (bean.getFlag() == -4) {
showLog("Json 格式不正确",mActivity); showLog("Json 格式不正确", mActivity);
} }
if (bean.getFlag() == -5) { if (bean.getFlag() == -5) {
showLog("账号密码不能为空",mActivity); showLog("账号密码不能为空", mActivity);
} }
if (bean.getFlag() == -6) { if (bean.getFlag() == -6) {
showLog("账号或密码错误",mActivity); showLog("账号或密码错误", mActivity);
} }
} }
} }
@ -136,7 +140,7 @@ public class AuthenticationLoginAIUtils {
@Override @Override
public void onFailed(int what, Response<String> response) { public void onFailed(int what, Response<String> response) {
showLog("onFailed",mActivity); showLog("onFailed", mActivity);
listener.onAuthenticationSuccess(false, ""); listener.onAuthenticationSuccess(false, "");
} }
}); });
@ -177,17 +181,17 @@ public class AuthenticationLoginAIUtils {
@Override @Override
public void onSucceed(int what, Response<String> response) { public void onSucceed(int what, Response<String> response) {
showLog("----------------",mActivity); showLog("----------------", mActivity);
String result = response.get(); String result = response.get();
showLog(result,mActivity); showLog(result, mActivity);
String jsonDecode = RSAUtils.decryptBASE64StrClient(result); String jsonDecode = RSAUtils.decryptBASE64StrClient(result);
if (TextUtils.isEmpty(jsonDecode)) { if (TextUtils.isEmpty(jsonDecode)) {
//解密失败 //解密失败
showLog("APP解密失败",mActivity); showLog("APP解密失败", mActivity);
listener.onAuthenticationSuccess(false, ""); listener.onAuthenticationSuccess(false, "");
} else { } else {
showLog(jsonDecode,mActivity); showLog(jsonDecode, mActivity);
UserAuthenticationAIBean bean = GsonToBean(jsonDecode, UserAuthenticationAIBean.class); UserAuthenticationAIBean bean = GsonToBean(jsonDecode, UserAuthenticationAIBean.class);
if (bean != null) { if (bean != null) {
if (bean.isSuccess()) {//登录成功 if (bean.isSuccess()) {//登录成功
@ -202,19 +206,19 @@ public class AuthenticationLoginAIUtils {
} else { } else {
listener.onAuthenticationSuccess(false, ""); listener.onAuthenticationSuccess(false, "");
if (bean.getFlag() == -2) { if (bean.getFlag() == -2) {
showLog("没有传参",mActivity); showLog("没有传参", mActivity);
} }
if (bean.getFlag() == -3) { if (bean.getFlag() == -3) {
showLog("服务器解密失败",mActivity); showLog("服务器解密失败", mActivity);
} }
if (bean.getFlag() == -4) { if (bean.getFlag() == -4) {
showLog("Json 格式不正确",mActivity); showLog("Json 格式不正确", mActivity);
} }
if (bean.getFlag() == -5) { if (bean.getFlag() == -5) {
showLog("账号密码不能为空",mActivity); showLog("账号密码不能为空", mActivity);
} }
if (bean.getFlag() == -6) { if (bean.getFlag() == -6) {
showLog("账号或密码错误",mActivity); showLog("账号或密码错误", mActivity);
} }
} }
} }
@ -250,7 +254,7 @@ public class AuthenticationLoginAIUtils {
@Override @Override
public void onFailed(int what, Response<String> response) { public void onFailed(int what, Response<String> response) {
showLog("onFailed",mActivity); showLog("onFailed", mActivity);
listener.onAuthenticationSuccess(false, ""); listener.onAuthenticationSuccess(false, "");
} }
}); });
@ -291,14 +295,14 @@ public class AuthenticationLoginAIUtils {
@Override @Override
public void onSucceed(int what, Response<String> response) { public void onSucceed(int what, Response<String> response) {
showLog("----------------",mActivity); showLog("----------------", mActivity);
String result = response.get(); String result = response.get();
showLog(result,mActivity); showLog(result, mActivity);
if(!TextUtils.isEmpty(result)){ if (!TextUtils.isEmpty(result)) {
UserAuthenticationAIBean bean = GsonToBean(result, UserAuthenticationAIBean.class); UserAuthenticationAIBean bean = GsonToBean(result, UserAuthenticationAIBean.class);
if (bean != null) { if (bean != null) {
if (bean.isSuccess()&&bean.getCode()==20000) {//登录成功 if (bean.isSuccess() && bean.getCode() == 20000) {//登录成功
SPUtils.put(mActivity, Contans.AUTHENTICATIONLOGINTOKENAI, bean.getData().getToken()); SPUtils.put(mActivity, Contans.AUTHENTICATIONLOGINTOKENAI, bean.getData().getToken());
listener.onAuthenticationSuccess(true, bean.getData().getToken()); listener.onAuthenticationSuccess(true, bean.getData().getToken());
} else { } else {
@ -310,19 +314,19 @@ public class AuthenticationLoginAIUtils {
} else { } else {
listener.onAuthenticationSuccess(false, ""); listener.onAuthenticationSuccess(false, "");
if (bean.getFlag() == -2) { if (bean.getFlag() == -2) {
showLog("没有传参",mActivity); showLog("没有传参", mActivity);
} }
if (bean.getFlag() == -3) { if (bean.getFlag() == -3) {
showLog("服务器解密失败",mActivity); showLog("服务器解密失败", mActivity);
} }
if (bean.getFlag() == -4) { if (bean.getFlag() == -4) {
showLog("Json 格式不正确",mActivity); showLog("Json 格式不正确", mActivity);
} }
if (bean.getFlag() == -5) { if (bean.getFlag() == -5) {
showLog("账号密码不能为空",mActivity); showLog("账号密码不能为空", mActivity);
} }
if (bean.getFlag() == -6) { if (bean.getFlag() == -6) {
showLog("账号或密码错误",mActivity); showLog("账号或密码错误", mActivity);
} }
} }
} }
@ -332,7 +336,7 @@ public class AuthenticationLoginAIUtils {
@Override @Override
public void onFailed(int what, Response<String> response) { public void onFailed(int what, Response<String> response) {
showLog("onFailed",mActivity); showLog("onFailed", mActivity);
listener.onAuthenticationSuccess(false, ""); listener.onAuthenticationSuccess(false, "");
} }
}); });
@ -349,7 +353,7 @@ public class AuthenticationLoginAIUtils {
String json = GsonUtils.GsonString(params); String json = GsonUtils.GsonString(params);
//showLog(json,mActivity); //showLog(json,mActivity);
String jsonEncrypt = RSAUtils.encryptBASE64Str(json); String jsonEncrypt = RSAUtils.encryptBASE64Str(json);
showLog(jsonEncrypt,mActivity); showLog(jsonEncrypt, mActivity);
request.setDefineRequestBodyForJson(jsonEncrypt); request.setDefineRequestBodyForJson(jsonEncrypt);
if (Contans.IP.equals(Contans.IP_EXTRANET)) { if (Contans.IP.equals(Contans.IP_EXTRANET)) {
@ -370,53 +374,46 @@ public class AuthenticationLoginAIUtils {
@Override @Override
public void onSucceed(int what, Response<String> response) { public void onSucceed(int what, Response<String> response) {
showLog("----------------",mActivity); showLog("----------------", mActivity);
String result = response.get(); String result = response.get();
showLog(result,mActivity); showLog(result, mActivity);
if(!TextUtils.isEmpty(result)){ if (!TextUtils.isEmpty(result)) {
DeviceAlarmLoginResultBean bean = GsonToBean(result, DeviceAlarmLoginResultBean.class); String jsonDecode = RSAUtils.decryptBASE64StrClient(result);
if (bean != null) { if (TextUtils.isEmpty(jsonDecode)) {
if (bean.isSuccess()&&bean.getCode()==20000) {//登录成功 //解密失败
if(!TextUtils.isEmpty(bean.getData())){ showLog("APP解密失败", mActivity);
String jsonDecode = RSAUtils.decryptBASE64StrClient(bean.getData()); listener.onAuthenticationSuccess(false, "");
if (TextUtils.isEmpty(jsonDecode)) { } else {
//解密失败 showLog(jsonDecode, mActivity);
showLog("APP解密失败",mActivity); UserAuthenticationAIBean bean = GsonToBean(jsonDecode, UserAuthenticationAIBean.class);
listener.onAuthenticationSuccess(false, ""); //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 { } else {
//showLog(jsonDecode,mActivity); listener.onAuthenticationSuccess(false, "");
DeviceAlarmLoginResultDataBean beanDecode = GsonToBean(jsonDecode, DeviceAlarmLoginResultDataBean.class); if (bean.getFlag() == -2) {
if(beanDecode!=null&&beanDecode.getMsg()!=null&&"登录成功".equals(beanDecode.getMsg())){ showLog("没有传参", mActivity);
listener.onAuthenticationSuccess(true, beanDecode.getToken()); }
}else{ if (bean.getFlag() == -3) {
showLog("账号或密码错误",mActivity); showLog("服务器解密失败", mActivity);
listener.onAuthenticationSuccess(false, ""); }
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 @Override
public void onFailed(int what, Response<String> response) { public void onFailed(int what, Response<String> response) {
showLog("onFailed",mActivity); showLog("onFailed", mActivity);
listener.onAuthenticationSuccess(false, ""); listener.onAuthenticationSuccess(false, "");
} }
}); });
} }
public static void showLog(String logText,Context context) { public static void showLog(String logText, Context context) {
if (isApkInDebug(context)) { if (isApkInDebug(context)) {
if (TextUtils.isEmpty(logText)) { if (TextUtils.isEmpty(logText)) {
Log.i("app", "logText is null"); Log.i("app", "logText is null");

Loading…
Cancel
Save