|
|
|
|
@ -1,14 +1,18 @@
|
|
|
|
|
package com.rehome.zhdcoa.utils;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import static com.luck.picture.lib.utils.ToastUtils.showToast;
|
|
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.util.Base64;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
import com.rehome.zhdcoa.BuildConfig;
|
|
|
|
|
import com.rehome.zhdcoa.Contans;
|
|
|
|
|
import com.rehome.zhdcoa.base.BaseCallBack;
|
|
|
|
|
import com.rehome.zhdcoa.R;
|
|
|
|
|
import com.rehome.zhdcoa.bean.UserAuthenticationBean;
|
|
|
|
|
import com.yolanda.nohttp.NoHttp;
|
|
|
|
|
import com.yolanda.nohttp.RequestMethod;
|
|
|
|
|
import com.yolanda.nohttp.rest.Request;
|
|
|
|
|
import com.yolanda.nohttp.rest.Response;
|
|
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
@ -22,50 +26,122 @@ public class AuthenticationLoginUtils {
|
|
|
|
|
* @param password 密码
|
|
|
|
|
* @param listener 监听回调
|
|
|
|
|
*/
|
|
|
|
|
public static void authenticationLogin(Context context, String username, String password, OnAuthenticationLoginListener listener) {
|
|
|
|
|
public static void authenticationLogin(Activity context, String username, String password, OnAuthenticationLoginListener listener) {
|
|
|
|
|
Map params = new HashMap<String, String>();
|
|
|
|
|
String base64Password = Base64.encodeToString(password.getBytes(), Base64.DEFAULT);
|
|
|
|
|
//String base64Password = Base64.encodeToString(password.getBytes(), Base64.DEFAULT);
|
|
|
|
|
params.put("userid",username);
|
|
|
|
|
params.put("password",base64Password);
|
|
|
|
|
params.put("password",password);
|
|
|
|
|
String json = GsonUtils.GsonString(params);
|
|
|
|
|
showLog("----------authenticationLogin------------");
|
|
|
|
|
showLog(json);
|
|
|
|
|
showLog(base64Password);
|
|
|
|
|
//showLog(base64Password);
|
|
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
|
|
HttpUtils.getCompanyServerApi().userAuthenticationLogin(username,base64Password).enqueue(new BaseCallBack<UserAuthenticationBean>(context) {
|
|
|
|
|
String jsonEncrypt = RSAUtils.encryptBASE64Str(json);
|
|
|
|
|
|
|
|
|
|
// String jsonDecode1 = RSAUtils.decryptBASE64StrClient("TLSdKxn3slvDpUd3RwXLOviOvltXjIVZjexSy36KLEPkg+saF5yjZf79b1lvHzOHwlnwl9gyizhuAS1jS3Nz3iYkZbo4+JZGk/u4b92Pm9SepUg+61ehfJT6TS9FnIaAzny8nHYEmXePFuejNweXYnGwz2YXuQ9n6REuOx/M5QR5WEyO3W71FarywpZqRkp3gd5QmO97aNfPBXj8M7PGzwosKEX2qHV2q0rMEXhnWIgFlAimHuy4mOmc85LLXfX4nBP+M4j93sVfSufFhAB5i//5E3Q3uBvi0g9KV21kt6e8kQE95umsu3s/glKgx7VtOwSSHMC3fpASftTgGz4GgzGroNaOBVljYYRsXkI2IGwnWSlaTHVZcySK9bLXEh2zURZbW4Vl6tavf0lS76cgtNk7Ptg0LSj7/qMW/Ak4SYzYxVtxrrmImHUnIF2Zhyx415RqgrYdVQSH7DkjTo0O4a1kwBrmPgZiiC9/3Kk2Vleb1rv7ZRiRAboWJeQGz4LA2vcJTyo0bObCPRy59/vNAe4BYjK5IaUgsKXnpfg1LzVCJQeSTtdEu5F32n3ZudZXqLa8Fv8McxKqQbGpTlbciSp3kSP9pe28VQ85tmnSYix9pYZaYrEnZVwsIi19XKa49LcurfEA6YQZ4hWGnX8pQxOlJcq3obF59/TlmMzRarY=");
|
|
|
|
|
// showLog(jsonDecode1);
|
|
|
|
|
//
|
|
|
|
|
// UserAuthenticationBean bean = GsonUtils.GsonToBean(jsonDecode1,UserAuthenticationBean.class);
|
|
|
|
|
// showLog(GsonUtils.GsonString(bean));
|
|
|
|
|
// if (bean != null) {
|
|
|
|
|
// showLog("success");
|
|
|
|
|
// showLog(GsonUtils.GsonString(bean));
|
|
|
|
|
// }else{
|
|
|
|
|
// showLog("fail");
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
showLog(jsonEncrypt);
|
|
|
|
|
|
|
|
|
|
final Request<String> request = NoHttp.createStringRequest(Contans.BASE_URL_COMPANY_SERVER + Contans.ZHAF_LOGIN_URL, RequestMethod.POST);
|
|
|
|
|
|
|
|
|
|
// request.setDefineRequestBodyForJson("\""+jsonEncrypt+"\"");
|
|
|
|
|
request.setDefineRequestBodyForJson(jsonEncrypt);
|
|
|
|
|
|
|
|
|
|
NohttpUtils.getInstance().add(context, 0, request, new HttpListener<String>() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onSuccess(retrofit2.Call<UserAuthenticationBean> call, retrofit2.Response<UserAuthenticationBean> response) {
|
|
|
|
|
UserAuthenticationBean bean = response.body();
|
|
|
|
|
//Log.i("bean:",GsonUtils.GsonString(bean));
|
|
|
|
|
if (bean != null) {
|
|
|
|
|
if (bean.isResult()) {//登录成功
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
int hours = 0;
|
|
|
|
|
if(bean.getData().getExpires()>3600){
|
|
|
|
|
hours= (bean.getData().getExpires()/3600);
|
|
|
|
|
calendar.add(Calendar.HOUR_OF_DAY, +hours);
|
|
|
|
|
}else{
|
|
|
|
|
hours= (bean.getData().getExpires()/60);
|
|
|
|
|
calendar.add(Calendar.MINUTE, +hours);
|
|
|
|
|
public void onSucceed(int what, Response<String> response) {
|
|
|
|
|
String jsonResult = response.get();
|
|
|
|
|
|
|
|
|
|
showLog("----------onSucceed------------");
|
|
|
|
|
showLog(jsonResult);
|
|
|
|
|
String jsonDecode = RSAUtils.decryptBASE64StrClient(jsonResult);
|
|
|
|
|
//String jsonDecode = RSAUtils.decryptBASE64StrClient("ddDHqrKCDOV3XhuiCrTWoksKWc+oh4np6BjS+ETBBa9E07GGUPCjYcuHSPIengyUntr/xz/iKcY93FiF/J+tqvmjtX6vI2OkrRYb79FHPqBdjCAwFz4GO/dRRgmjA9w2y7JL501oArG8Be+rekrNpf2Zr+yxAK9/fR6biDPd9ATsy8E5fOhurJKFYTJnCof+Y5WeP1nijy36K55EUGT5XMbzY92z/f8sXuTe3J3xPsJYNE6taM37op2ErI65dfO9CkIU3q7gxyQFjkz7iQrn6OrEySWtKBFwwvcDUv6VcrFs7vve7jXUkjlSfIN02XXYVBXdFi/mbKuUZVz69UmIxmlL/7yeKyQaiG2dEKCthzhx48F3g/jPRGmdIUJjnw4wdL2fHaDinXJyBGkv+LRKUg77SNzny20qBlyoxhZSO4IUJEbuctQzDt672lBFtfQH8dWgOYC++wfiT8l6hyCfkEFP2MzCBWta1a5UTRDv1gA39Axji7xhR8e+qwNo8QtgYqzI9rusc/g8aRpUDLEeCUVa8xLl2u55n33XR6ZuKRBB8/5ti8cxny4lEIp4kDeyNtgxsDz2HK6rZa8T7541tF/o9g/eKGexppi+8AtIAzC/MJ8cLj55KzCyHvW5IjWb6E9ipLqyqHbDE32K/OlRTM1cuSjod9y00uRy2FqYnbU=");
|
|
|
|
|
|
|
|
|
|
showLog(jsonDecode);
|
|
|
|
|
if (TextUtils.isEmpty(jsonDecode)) {
|
|
|
|
|
showLog(UiUtlis.getString(context, R.string.data_error));
|
|
|
|
|
} else {
|
|
|
|
|
UserAuthenticationBean bean = GsonUtils.GsonToBean(jsonDecode,UserAuthenticationBean.class);
|
|
|
|
|
showLog(GsonUtils.GsonString(bean));
|
|
|
|
|
if (bean != null) {
|
|
|
|
|
if (bean.isResult()) {
|
|
|
|
|
//登录成功
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
int hours = 0;
|
|
|
|
|
if(bean.getData().getExpires()>3600){
|
|
|
|
|
hours= (bean.getData().getExpires()/3600);
|
|
|
|
|
calendar.add(Calendar.HOUR_OF_DAY, +hours);
|
|
|
|
|
}else{
|
|
|
|
|
hours= (bean.getData().getExpires()/60);
|
|
|
|
|
calendar.add(Calendar.MINUTE, +hours);
|
|
|
|
|
}
|
|
|
|
|
SPUtils.put(context, Contans.AUTHENTICATIONLOGINTOKEN, bean.getData().getToken());
|
|
|
|
|
SPUtils.put(context, Contans.AUTHENTICATIONLOGINNEXTDATE, calendar.getTimeInMillis());
|
|
|
|
|
listener.onAuthenticationSuccess(true,bean.getData().getToken());
|
|
|
|
|
} else {
|
|
|
|
|
SPUtils.put(context, Contans.AUTHENTICATIONLOGINTOKEN, "");
|
|
|
|
|
SPUtils.put(context, Contans.AUTHENTICATIONLOGINNEXTDATE, Calendar.getInstance().getTimeInMillis());
|
|
|
|
|
listener.onAuthenticationSuccess(false,"");
|
|
|
|
|
}
|
|
|
|
|
SPUtils.put(context, Contans.AUTHENTICATIONLOGINTOKEN, bean.getData().getToken());
|
|
|
|
|
SPUtils.put(context, Contans.AUTHENTICATIONLOGINNEXTDATE, calendar.getTimeInMillis());
|
|
|
|
|
listener.onAuthenticationSuccess(true,bean.getData().getToken());
|
|
|
|
|
} else {
|
|
|
|
|
SPUtils.put(context, Contans.AUTHENTICATIONLOGINTOKEN, "");
|
|
|
|
|
SPUtils.put(context, Contans.AUTHENTICATIONLOGINNEXTDATE, Calendar.getInstance().getTimeInMillis());
|
|
|
|
|
listener.onAuthenticationSuccess(false,"");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onError(retrofit2.Call<UserAuthenticationBean> call, Throwable t) {
|
|
|
|
|
public void onFailed(int what, Response<String> response) {
|
|
|
|
|
SPUtils.put(context, Contans.AUTHENTICATIONLOGINTOKEN, "");
|
|
|
|
|
SPUtils.put(context, Contans.AUTHENTICATIONLOGINNEXTDATE, Calendar.getInstance().getTimeInMillis());
|
|
|
|
|
listener.onAuthenticationSuccess(false,"");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// HttpUtils.getCompanyServerApi().userAuthenticationLogin(username,base64Password).enqueue(new BaseCallBack<UserAuthenticationBean>(context) {
|
|
|
|
|
// @Override
|
|
|
|
|
// public void onSuccess(retrofit2.Call<UserAuthenticationBean> call, retrofit2.Response<UserAuthenticationBean> response) {
|
|
|
|
|
// UserAuthenticationBean bean = response.body();
|
|
|
|
|
// //Log.i("bean:",GsonUtils.GsonString(bean));
|
|
|
|
|
// if (bean != null) {
|
|
|
|
|
// if (bean.isResult()) {//登录成功
|
|
|
|
|
// Calendar calendar = Calendar.getInstance();
|
|
|
|
|
// int hours = 0;
|
|
|
|
|
// if(bean.getData().getExpires()>3600){
|
|
|
|
|
// hours= (bean.getData().getExpires()/3600);
|
|
|
|
|
// calendar.add(Calendar.HOUR_OF_DAY, +hours);
|
|
|
|
|
// }else{
|
|
|
|
|
// hours= (bean.getData().getExpires()/60);
|
|
|
|
|
// calendar.add(Calendar.MINUTE, +hours);
|
|
|
|
|
// }
|
|
|
|
|
// SPUtils.put(context, Contans.AUTHENTICATIONLOGINTOKEN, bean.getData().getToken());
|
|
|
|
|
// SPUtils.put(context, Contans.AUTHENTICATIONLOGINNEXTDATE, calendar.getTimeInMillis());
|
|
|
|
|
// listener.onAuthenticationSuccess(true,bean.getData().getToken());
|
|
|
|
|
// } else {
|
|
|
|
|
// SPUtils.put(context, Contans.AUTHENTICATIONLOGINTOKEN, "");
|
|
|
|
|
// SPUtils.put(context, Contans.AUTHENTICATIONLOGINNEXTDATE, Calendar.getInstance().getTimeInMillis());
|
|
|
|
|
// listener.onAuthenticationSuccess(false,"");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Override
|
|
|
|
|
// public void onError(retrofit2.Call<UserAuthenticationBean> call, Throwable t) {
|
|
|
|
|
// SPUtils.put(context, Contans.AUTHENTICATIONLOGINTOKEN, "");
|
|
|
|
|
// SPUtils.put(context, Contans.AUTHENTICATIONLOGINNEXTDATE, Calendar.getInstance().getTimeInMillis());
|
|
|
|
|
// listener.onAuthenticationSuccess(false,"");
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
}
|
|
|
|
|
public static void showLog(String logText) {
|
|
|
|
|
if (BuildConfig.LOG_ERROR) {
|
|
|
|
|
|