You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
4.1 KiB
Java

3 years ago
package com.rehome.zhdcoa.utils;
import android.content.Context;
import android.util.Log;
import com.rehome.zhdcoa.Contans;
import com.rehome.zhdcoa.bean.UserAuthenticationAIBean;
import com.yolanda.nohttp.Headers;
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;
3 years ago
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
3 years ago
public class AuthenticationLoginAIUtils {
/**
* @param context Context
* @param account
* @param password
* @param listener
*/
public static void authenticationAILogin(Context context, String account, String password, OnAuthenticationLoginListener listener) {
Request<String> request = NoHttp.createStringRequest(Contans.BASE_URL_AI_3D_SERVER + Contans.AUTHENTICATIONLOGINAI3D, RequestMethod.POST);
request.add("account", account);
request.add("password", password);
request.addHeader("Content-Type", Headers.HEAD_VALUE_ACCEPT_APPLICATION_X_WWW_FORM_URLENCODED);
3 years ago
if(Contans.BASE_URL_AI_3D_SERVER.equals(Contans.BASE_URL_AI_3D_SERVER_EXTRANET)){
SSLSocketFactory socketFactory = NohttpUtils.getSSLSocketFactory(context);
if (socketFactory != null) {
request.setSSLSocketFactory(socketFactory);
request.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
});
}
}
NohttpUtils.getInstance().addNoProgress(context,0, request, new HttpListener<String>() {
3 years ago
@Override
public void onSucceed(int what, Response<String> response) {
Log.i("app", "----------------");
String result = response.get();
Log.i("app", result);
UserAuthenticationAIBean bean = GsonToBean(result, UserAuthenticationAIBean.class);
if (bean != null) {
if (bean.isSuccess()) {//登录成功
SPUtils.put(context, Contans.AUTHENTICATIONLOGINTOKENAI, bean.getData().getToken());
listener.onAuthenticationSuccess(true, bean.getData().getToken());
} else {
if (bean.getFlag() == -1) {
if (bean.getMsg() != null && bean.getMsg().equals("用户未注销")) {
String token = (String) SPUtils.get(context, Contans.AUTHENTICATIONLOGINTOKENAI, String.valueOf(""));
listener.onAuthenticationSuccess(true, token);
}
} else {
listener.onAuthenticationSuccess(false, "");
}
}
// String cookieId = "";
// // 响应头
// Headers headers = response.getHeaders();
// List<HttpCookie> cookies = headers.getCookies();
// Log.i("app", String.valueOf(cookies.size()));
// for (HttpCookie httpCookie : cookies) {
// String cookieName = httpCookie.getName();
// if ("JSESSIONID".equals(cookieName)) {
// // 这里就拿到了你想那的cookie
// cookieId = httpCookie.getValue();
// }
// }
// if(cookies.size()>0&&!(cookieId.equals(""))){
// SPUtils.put(context, Contans.AUTHENTICATIONLOGINTOKENAI, cookieId);
// }
// listener.onAuthenticationSuccess(false, "");
}
}
@Override
public void onFailed(int what, Response<String> response) {
listener.onAuthenticationSuccess(false, "");
}
});
}
}