|
@@ -11,7 +11,10 @@ import cn.zhxu.okhttps.gson.GsonMsgConvertor
|
|
|
import cn.zhxu.okhttps.okhttp.OkHttpClientWrapper
|
|
import cn.zhxu.okhttps.okhttp.OkHttpClientWrapper
|
|
|
import com.grkj.iscs.R
|
|
import com.grkj.iscs.R
|
|
|
import com.grkj.iscs.model.Constants
|
|
import com.grkj.iscs.model.Constants
|
|
|
|
|
+import com.grkj.iscs.model.IscsToken
|
|
|
import com.grkj.iscs.model.Token
|
|
import com.grkj.iscs.model.Token
|
|
|
|
|
+import com.grkj.iscs.model.UrlConsts
|
|
|
|
|
+import com.grkj.iscs.model.UrlConsts.SIGN_IN
|
|
|
import com.grkj.iscs.util.log.LogUtil
|
|
import com.grkj.iscs.util.log.LogUtil
|
|
|
import okhttp3.logging.HttpLoggingInterceptor
|
|
import okhttp3.logging.HttpLoggingInterceptor
|
|
|
import java.io.IOException
|
|
import java.io.IOException
|
|
@@ -35,7 +38,8 @@ class NetHttpManager {
|
|
|
context = ctx
|
|
context = ctx
|
|
|
myHttp = HTTP.builder()
|
|
myHttp = HTTP.builder()
|
|
|
.addMsgConvertor(GsonMsgConvertor())
|
|
.addMsgConvertor(GsonMsgConvertor())
|
|
|
- .baseUrl(Constants.BASE_URL)
|
|
|
|
|
|
|
+ .bodyType("application/json")
|
|
|
|
|
+ .baseUrl(UrlConsts.BASE_URL)
|
|
|
.responseListener { task: HttpTask<*>?, result: HttpResult? ->
|
|
.responseListener { task: HttpTask<*>?, result: HttpResult? ->
|
|
|
if (result?.status != 200) {
|
|
if (result?.status != 200) {
|
|
|
LogUtil.d(
|
|
LogUtil.d(
|
|
@@ -54,8 +58,12 @@ class NetHttpManager {
|
|
|
itPreChain.proceed()
|
|
itPreChain.proceed()
|
|
|
return@addSerialPreprocessor
|
|
return@addSerialPreprocessor
|
|
|
}
|
|
}
|
|
|
- requestTokenAndRefreshIfExpired {
|
|
|
|
|
- itPreChain.task.addHeader("Access-Token", it)
|
|
|
|
|
|
|
+// requestTokenAndRefreshIfExpired {
|
|
|
|
|
+// itPreChain.task.addHeader("Access-Token", it)
|
|
|
|
|
+// itPreChain.proceed()
|
|
|
|
|
+// }
|
|
|
|
|
+ doLogin {
|
|
|
|
|
+ itPreChain.task.addHeader("Authorization", it)
|
|
|
itPreChain.proceed()
|
|
itPreChain.proceed()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -103,33 +111,34 @@ class NetHttpManager {
|
|
|
.post()
|
|
.post()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// private fun doLogin(callback: (String?) -> Unit) {
|
|
|
|
|
-// myHttp.async(SIGN_IN)
|
|
|
|
|
-// .skipPreproc()
|
|
|
|
|
-// .addBodyPara("username", "IPC")
|
|
|
|
|
-// .addBodyPara("password", "123456")
|
|
|
|
|
-// .nextOnIO()
|
|
|
|
|
-// .setOnResponse {
|
|
|
|
|
-// exceptionCount = 0
|
|
|
|
|
-// if (!it.isSuccessful) {
|
|
|
|
|
-// callback(null)
|
|
|
|
|
-// return@setOnResponse
|
|
|
|
|
-// }
|
|
|
|
|
-// try {
|
|
|
|
|
|
|
+ private fun doLogin(callback: (String?) -> Unit) {
|
|
|
|
|
+ myHttp.async(SIGN_IN)
|
|
|
|
|
+ .skipPreproc()
|
|
|
|
|
+ .addBodyPara("username", "admin")
|
|
|
|
|
+ .addBodyPara("password", "grkj8888")
|
|
|
|
|
+ .nextOnIO()
|
|
|
|
|
+ .setOnResponse {
|
|
|
|
|
+ exceptionCount = 0
|
|
|
|
|
+ if (!it.isSuccessful) {
|
|
|
|
|
+ callback(null)
|
|
|
|
|
+ return@setOnResponse
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
// val newToken = it.body.toBean(Token::class.java)
|
|
// val newToken = it.body.toBean(Token::class.java)
|
|
|
-// newToken.saveToSp(context!!)
|
|
|
|
|
-// callback(newToken.accessToken)
|
|
|
|
|
-// } catch (e: Exception) {
|
|
|
|
|
-// callback(null)
|
|
|
|
|
-// return@setOnResponse
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// .setOnException {
|
|
|
|
|
-// evictHttpConnectPool(it)
|
|
|
|
|
-// callback(null)
|
|
|
|
|
-// }
|
|
|
|
|
-// .post()
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ val newToken = it.body.toBean(IscsToken::class.java)
|
|
|
|
|
+ newToken.saveToSp(context!!)
|
|
|
|
|
+ callback(newToken.token)
|
|
|
|
|
+ } catch (e: Exception) {
|
|
|
|
|
+ callback(null)
|
|
|
|
|
+ return@setOnResponse
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ .setOnException {
|
|
|
|
|
+ evictHttpConnectPool(it)
|
|
|
|
|
+ callback(null)
|
|
|
|
|
+ }
|
|
|
|
|
+ .post()
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
fun doRequestNet(
|
|
fun doRequestNet(
|
|
|
urlStr: String, isSkipPreproc: Boolean,
|
|
urlStr: String, isSkipPreproc: Boolean,
|