From b86302465f954da69a8b310bb2ebe895eea99513 Mon Sep 17 00:00:00 2001 From: CHN-STUDENT Date: Sun, 9 Jun 2019 16:39:00 +0800 Subject: [PATCH] =?UTF-8?q?V1.0.1=20=E4=BF=AE=E6=AD=A3=E8=87=AA=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E6=97=A0=E6=B3=95=E7=99=BB=E5=BD=95=E7=9A=84bug=20+?= =?UTF-8?q?=20acid=E8=87=AA=E5=8A=A8=E5=B0=9D=E8=AF=95bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EHAUT/app/build.gradle | 2 +- EHAUT/app/src/main/assets/web/service.html | 257 ++++++++++++++++++ .../java/cn/ehaut/srun3000/LoginActivity.kt | 12 +- .../java/cn/ehaut/srun3000/LogoutActivity.kt | 4 +- .../java/cn/ehaut/srun3000/WebActivity.kt | 109 +++++++- 5 files changed, 368 insertions(+), 16 deletions(-) create mode 100644 EHAUT/app/src/main/assets/web/service.html diff --git a/EHAUT/app/build.gradle b/EHAUT/app/build.gradle index 1850d4b..0152815 100644 --- a/EHAUT/app/build.gradle +++ b/EHAUT/app/build.gradle @@ -19,7 +19,7 @@ android { minSdkVersion 15 targetSdkVersion 28 versionCode 1 - versionName "1.0" + versionName "1.0.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/EHAUT/app/src/main/assets/web/service.html b/EHAUT/app/src/main/assets/web/service.html new file mode 100644 index 0000000..82e06a8 --- /dev/null +++ b/EHAUT/app/src/main/assets/web/service.html @@ -0,0 +1,257 @@ + + + + + + + + + + 移动端校园网客户端自服务系统 + + + + + + + +
+
+

移动端校园网客户端自服务系统

+

+

+ 学号:
+
+
+ 密码:
+
+
+ +
+

声明:本第三方网页仅用于解决移动端无法登录官方自服务情况。
网页不会储存您的个人信息,仅调用接口帮您跳转登录。


+
+ 跳转官方自助服务 +
+
+ +
+ +

+

© Powered By E-HAUT Team

+ + + + + \ No newline at end of file diff --git a/EHAUT/app/src/main/java/cn/ehaut/srun3000/LoginActivity.kt b/EHAUT/app/src/main/java/cn/ehaut/srun3000/LoginActivity.kt index 3e329d1..71a8b94 100644 --- a/EHAUT/app/src/main/java/cn/ehaut/srun3000/LoginActivity.kt +++ b/EHAUT/app/src/main/java/cn/ehaut/srun3000/LoginActivity.kt @@ -7,7 +7,6 @@ import android.content.SharedPreferences import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.os.Handler -import android.os.Looper import android.os.Message import android.util.Log import android.widget.Toast @@ -61,7 +60,11 @@ class LoginActivity : AppCompatActivity() { } else { PostResult.isLoginOK = false if (PostResult.result.contains("login_error#INFO failed, BAS respond timeout.")) { - ServerInfo.acid = "2" + if(ServerInfo.acid == "1"){ + ServerInfo.acid = "2" + } else { + ServerInfo.acid = "1" + } Network.Login(UserInfo.username, UserInfo.password.toCharArray()) } else { @@ -81,6 +84,10 @@ class LoginActivity : AppCompatActivity() { preferences = applicationContext.getSharedPreferences("UserInfo", Context.MODE_PRIVATE) loadUserInfo() link_service1.setOnClickListener{ + val username = input_username.getText().toString() + val password = input_password.getText().toString() + UserInfo.username = username + UserInfo.password = password startActivity(Intent(this, WebActivity::class.java)) } btn_login.setOnClickListener { @@ -171,4 +178,5 @@ class LoginActivity : AppCompatActivity() { override fun onBackPressed() { moveTaskToBack(true) } + } \ No newline at end of file diff --git a/EHAUT/app/src/main/java/cn/ehaut/srun3000/LogoutActivity.kt b/EHAUT/app/src/main/java/cn/ehaut/srun3000/LogoutActivity.kt index 4af9576..e74ac51 100644 --- a/EHAUT/app/src/main/java/cn/ehaut/srun3000/LogoutActivity.kt +++ b/EHAUT/app/src/main/java/cn/ehaut/srun3000/LogoutActivity.kt @@ -9,9 +9,7 @@ import android.os.Message import android.util.Log import android.widget.Toast import kotlinx.android.synthetic.main.activity_logout.* -import java.text.SimpleDateFormat -import java.util.* -import kotlin.concurrent.schedule + class LogoutActivity : AppCompatActivity() { private val TAG = "LogoutActivity" diff --git a/EHAUT/app/src/main/java/cn/ehaut/srun3000/WebActivity.kt b/EHAUT/app/src/main/java/cn/ehaut/srun3000/WebActivity.kt index ddf7731..0b786f1 100644 --- a/EHAUT/app/src/main/java/cn/ehaut/srun3000/WebActivity.kt +++ b/EHAUT/app/src/main/java/cn/ehaut/srun3000/WebActivity.kt @@ -1,32 +1,79 @@ package cn.ehaut.srun3000 import android.os.Bundle +import android.os.Message import android.util.Base64 -import android.webkit.WebView +import android.util.Log +import android.webkit.WebChromeClient import androidx.appcompat.app.AppCompatActivity import kotlinx.android.synthetic.main.activity_web.* -import android.webkit.WebSettings +import java.security.MessageDigest +import java.security.NoSuchAlgorithmException +import android.webkit.WebView import android.webkit.WebViewClient - - - class WebActivity : AppCompatActivity() { + private fun md5Encode(text: String): String { + try { + //获取md5加密对象 + val instance: MessageDigest = MessageDigest.getInstance("MD5") + //对字符串加密,返回字节数组 + val digest:ByteArray = instance.digest(text.toByteArray()) + var sb : StringBuffer = StringBuffer() + for (b in digest) { + //获取低八位有效值 + var i :Int = b.toInt() and 0xff + //将整数转化为16进制 + var hexString = Integer.toHexString(i) + if (hexString.length < 2) { + //如果是一位的话,补0 + hexString = "0" + hexString + } + sb.append(hexString) + } + return sb.toString() + + } catch (e: NoSuchAlgorithmException) { + e.printStackTrace() + } + return "" + } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_web) - var serviceUrl:String = ServerInfo.serviceServerAddr+":"+ServerInfo.serviceServerPort + var url:String = "" + var serviceUrl:String = "" if (OnlineInfo.isOnline) { + serviceUrl = ServerInfo.serviceServerAddr+":"+ServerInfo.serviceServerPort val username:String = OnlineInfo.onlineUsername val data:String = username + ":" + username - val base64String = String(Base64.decode(data,Base64.DEFAULT)) + val base64String = String(Base64.encode(data.toByteArray(),Base64.DEFAULT)) serviceUrl = serviceUrl + "/site/sso?data=" + base64String + url = serviceUrl + } else { + serviceUrl = ServerInfo.serviceServerAddr+":"+ServerInfo.serviceServerPort + val username:String = UserInfo.username + val password:String = UserInfo.password + var data:String = "" + if (!username.isNullOrBlank()) { + if (!password.isNullOrBlank()) { + val pwd:String = md5Encode(password) + data = username+":"+pwd + val base64String = String(Base64.encode(data.toByteArray(),Base64.DEFAULT)) + serviceUrl = serviceUrl + "/site/sso?data=" + base64String + url = serviceUrl + } else { + url = "file:///android_asset/web/service.html" + } + } else { + url = "file:///android_asset/web/service.html" + } } val webSettings = mWebView.settings - + webSettings.setSupportMultipleWindows(true); // 打开JavaScript支持 webSettings.javaScriptEnabled = true webSettings.setSupportZoom(true) @@ -36,8 +83,40 @@ class WebActivity : AppCompatActivity() { webSettings.domStorageEnabled = true webSettings.javaScriptCanOpenWindowsAutomatically = true webSettings.setAppCacheEnabled(false) - mWebView.webViewClient = WebViewClient() - mWebView.loadUrl(serviceUrl) + mWebView.webViewClient = object : WebViewClient() { + override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean { + view?.loadUrl(url) + return true + } + } + mWebView.webChromeClient = object : WebChromeClient() { + override fun onCloseWindow(window: WebView) { + super.onCloseWindow(window) + } + + override fun onCreateWindow( + view: WebView, isDialog: Boolean, + isUserGesture: Boolean, resultMsg: Message + ): Boolean { + + val childView = WebView(this@WebActivity) + childView.webViewClient = object : WebViewClient() { + override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean { + mWebView.loadUrl(url) + return true + } + } + val settings = childView.settings + settings.javaScriptEnabled = true + childView.webChromeClient = this + val transport = resultMsg.obj as WebView.WebViewTransport + transport.webView = childView + resultMsg.sendToTarget() + return true + } + } + //Log.d("url",url) + mWebView.loadUrl(url) } @@ -53,6 +132,16 @@ class WebActivity : AppCompatActivity() { } super.onBackPressed() } + + override fun onDestroy() { + super.onDestroy() + mWebView?.clearCache(true) + mWebView?.stopLoading() + mWebView?.setWebViewClient(null) + mWebView?.setWebChromeClient(null) + mWebView?.removeAllViews() + mWebView?.destroy() + } }