1.1.8 release
parent
fe4ce4f333
commit
14b88ebee1
@ -0,0 +1,298 @@
|
||||
package com.rehome.dywoa.ui.activity;
|
||||
|
||||
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebResourceRequest;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.just.agentweb.AgentWeb;
|
||||
import com.just.agentweb.DefaultWebClient;
|
||||
import com.just.agentweb.WebChromeClient;
|
||||
import com.just.agentweb.WebViewClient;
|
||||
import com.rehome.dywoa.App;
|
||||
import com.rehome.dywoa.Contans;
|
||||
import com.rehome.dywoa.R;
|
||||
import com.rehome.dywoa.base.BaseAgentWebActivity;
|
||||
import com.rehome.dywoa.bean.FwSingleLoginResult;
|
||||
import com.rehome.dywoa.bean.SisTokenBeanData;
|
||||
import com.rehome.dywoa.utils.GsonUtils;
|
||||
import com.rehome.dywoa.utils.HttpListener;
|
||||
import com.rehome.dywoa.utils.NoProgresshttpUtils;
|
||||
import com.rehome.dywoa.utils.NohttpUtils;
|
||||
import com.rehome.dywoa.utils.RSAUtils;
|
||||
import com.rehome.dywoa.utils.UiUtlis;
|
||||
import com.rehome.dywoa.weiget.WebLayout;
|
||||
import com.yolanda.nohttp.NoHttp;
|
||||
import com.yolanda.nohttp.RequestMethod;
|
||||
import com.yolanda.nohttp.rest.Request;
|
||||
import com.yolanda.nohttp.rest.Response;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.text.ParseException;
|
||||
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 HightRiskActivity extends BaseAgentWebActivity {
|
||||
|
||||
private Toolbar mToolbar;
|
||||
private TextView mTitleTextView;
|
||||
|
||||
private String urlToken = "api/app/login/singleLogin?account=";
|
||||
private String startUrl;
|
||||
|
||||
|
||||
String type;
|
||||
String urlLog;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_hight_risk);
|
||||
|
||||
type = getIntent().getStringExtra("type");
|
||||
urlLog = getIntent().getStringExtra("urlLog");
|
||||
if(TextUtils.isEmpty(type)){
|
||||
type = "";
|
||||
}
|
||||
|
||||
mToolbar = this.findViewById(R.id.toolbar);
|
||||
mToolbar.setTitleTextColor(Color.WHITE);
|
||||
mToolbar.setTitle("");
|
||||
mToolbar.setNavigationIcon(R.drawable.ac_back_icon);
|
||||
mTitleTextView = this.findViewById(R.id.toolbar_title);
|
||||
mTitleTextView.setText(type);
|
||||
this.setSupportActionBar(mToolbar);
|
||||
if (getSupportActionBar() != null) {
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
mToolbar.setNavigationOnClickListener(v -> HightRiskActivity.this.finish());
|
||||
|
||||
|
||||
//支持缩放
|
||||
mAgentWeb.getWebCreator().getWebView().getSettings().setBuiltInZoomControls(true);
|
||||
mAgentWeb.getWebCreator().getWebView().getSettings().setDisplayZoomControls(false);
|
||||
mAgentWeb.getWebCreator().getWebView().getSettings().setSupportZoom(true);
|
||||
|
||||
checkServerConnectStatus();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
//检查服务器连接状态
|
||||
private void checkServerConnectStatus() {
|
||||
Map<String,String> param = new HashMap<>();
|
||||
param.put("login","dywoa");
|
||||
String json = GsonUtils.GsonString(param);
|
||||
String url = Contans.IP + Contans.check_server_connect;
|
||||
showLog(url);
|
||||
showLog(json);
|
||||
Request<String> request = NoHttp.createStringRequest(
|
||||
url,
|
||||
RequestMethod.POST
|
||||
);
|
||||
request.setDefineRequestBodyForJson(json);
|
||||
NoProgresshttpUtils.getInstance().add(this, 0, request, new HttpListener<String>() {
|
||||
|
||||
@Override
|
||||
public void onSucceed(int what, Response<String> response) {
|
||||
String result = response.get();
|
||||
showLog("-----onSucceed----");
|
||||
showLog(result);
|
||||
if(result.equals("1")){
|
||||
showLog("connect server success");
|
||||
//可以连接到服务器,请求数据
|
||||
getSingleLoginToken();
|
||||
}else{
|
||||
showToast("无法连接到服务器,请检查网络环境");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(int what, Response<String> response) {
|
||||
showLog("connect server onFailed");
|
||||
showToast("无法连接到服务器,请检查网络环境");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void getSingleLoginToken() {
|
||||
String url = Contans.IP + urlToken + App.getInstance().getUserInfo().getManid();
|
||||
|
||||
//String url = Contans.IP + urlToken + "803011";
|
||||
|
||||
|
||||
//url = Contans.IP + urlToken + "280846";
|
||||
|
||||
|
||||
Request request = NoHttp.createStringRequest(url, RequestMethod.GET);
|
||||
showLog(url);
|
||||
|
||||
// SSLSocketFactory socketFactory = NohttpUtils.getSisSSLSocketFactory(WaitForToDoActivity.this);
|
||||
// if (socketFactory != null) {
|
||||
// request.setSSLSocketFactory(socketFactory);
|
||||
// request.setHostnameVerifier(new HostnameVerifier() {
|
||||
// @Override
|
||||
// public boolean verify(String s, SSLSession sslSession) {
|
||||
// return true;
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
NohttpUtils.getInstance().add(this,1,request,new HttpListener<String>(){
|
||||
@Override
|
||||
public void onSucceed(int what, Response<String> response) throws ParseException {
|
||||
|
||||
String jsonResult = response.get();
|
||||
showLog("-----login------");
|
||||
showLog(jsonResult);
|
||||
|
||||
String jsonDecode = RSAUtils.decryptBASE64StrClient(jsonResult);
|
||||
if (TextUtils.isEmpty(jsonDecode)) {
|
||||
showToast(UiUtlis.getString(HightRiskActivity.this, R.string.data_error));
|
||||
} else {
|
||||
FwSingleLoginResult loginResult = GsonUtils.GsonToBean(jsonDecode, FwSingleLoginResult.class);
|
||||
showLog(jsonDecode);
|
||||
if (loginResult != null) {
|
||||
if (loginResult.getErrmsg()!=null&&loginResult.getErrmsg().equals("success")) {
|
||||
if(!TextUtils.isEmpty(loginResult.getToken())){
|
||||
loadSisPage(loginResult.getToken());
|
||||
}
|
||||
}else{
|
||||
showToast(loginResult.getErrmsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(int what, Response<String> response) {
|
||||
showLog("getSisToken onFailed");
|
||||
}
|
||||
}, true, true, "请稍候...");
|
||||
}
|
||||
|
||||
private void loadSisPage(String token) {
|
||||
try {
|
||||
var tempUrl = "https://mis.dywzhny.com.cn/papi/open/singleSignon?oauthType=singlesign&singleToken="+ token +"&redirect_uri=";
|
||||
String encodeUrl = URLEncoder.encode(urlLog,"UTF-8");
|
||||
startUrl = tempUrl + encodeUrl;
|
||||
showLog(startUrl);
|
||||
this.mAgentWeb.getUrlLoader().loadUrl(startUrl);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected ViewGroup getAgentWebParent() {
|
||||
return (ViewGroup) this.findViewById(R.id.container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (mAgentWeb != null && mAgentWeb.handleKeyEvent(keyCode, event)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getIndicatorColor() {
|
||||
return Color.parseColor("#ff0000");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setTitle(WebView view, String title) {
|
||||
super.setTitle(view, title);
|
||||
if (!TextUtils.isEmpty(title)) {
|
||||
if (mTitleTextView != null) {
|
||||
mTitleTextView.setText(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getIndicatorHeight() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected String getUrl() {
|
||||
return null;
|
||||
//return "https://www.baidu.com/";
|
||||
}
|
||||
|
||||
|
||||
private void showLog(String logText) {
|
||||
if (isApkInDebug(HightRiskActivity.this)) {
|
||||
if (TextUtils.isEmpty(logText)) {
|
||||
Log.i("app", "logText is null");
|
||||
} else {
|
||||
Log.i("app", logText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断当前应用是否是debug状态
|
||||
*/
|
||||
|
||||
public static boolean isApkInDebug(Context context) {
|
||||
try {
|
||||
ApplicationInfo info = context.getApplicationInfo();
|
||||
return (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void showToast(String msg) {
|
||||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
public void showToast(int strId) {
|
||||
Toast.makeText(this, strId, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="#ffffff"
|
||||
tools:context=".ui.activity.HightRiskActivity">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?android:actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:titleTextColor="@android:color/white"
|
||||
app:theme="@style/Widget.AppCompat.Toolbar"
|
||||
app:titleTextColor="@android:color/white">
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/toolbar_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="10dp"
|
||||
android:singleLine="true"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="20sp"/>
|
||||
</androidx.appcompat.widget.Toolbar>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
Loading…
Reference in New Issue