|
|
|
@ -1,10 +1,14 @@
|
|
|
|
|
package com.idormy.sms.forwarder.server.component
|
|
|
|
|
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import com.idormy.sms.forwarder.utils.Base64
|
|
|
|
|
import com.idormy.sms.forwarder.utils.HttpServerUtils
|
|
|
|
|
import com.idormy.sms.forwarder.utils.RSACrypt
|
|
|
|
|
import com.yanzhenjie.andserver.annotation.Resolver
|
|
|
|
|
import com.yanzhenjie.andserver.error.HttpException
|
|
|
|
|
import com.yanzhenjie.andserver.framework.ExceptionResolver
|
|
|
|
|
import com.yanzhenjie.andserver.framework.body.JsonBody
|
|
|
|
|
import com.yanzhenjie.andserver.framework.body.StringBody
|
|
|
|
|
import com.yanzhenjie.andserver.http.HttpRequest
|
|
|
|
|
import com.yanzhenjie.andserver.http.HttpResponse
|
|
|
|
|
import com.yanzhenjie.andserver.http.StatusCode
|
|
|
|
@ -12,6 +16,8 @@ import com.yanzhenjie.andserver.http.StatusCode
|
|
|
|
|
@Resolver
|
|
|
|
|
class AppExceptionResolver : ExceptionResolver {
|
|
|
|
|
|
|
|
|
|
private val TAG: String = "AppExceptionResolver"
|
|
|
|
|
|
|
|
|
|
override fun onResolve(request: HttpRequest, response: HttpResponse, e: Throwable) {
|
|
|
|
|
e.printStackTrace()
|
|
|
|
|
if (e is HttpException) {
|
|
|
|
@ -23,7 +29,16 @@ class AppExceptionResolver : ExceptionResolver {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//返回统一结构报文
|
|
|
|
|
response.setBody(JsonBody(HttpServerUtils.response(e.message.toString())))
|
|
|
|
|
var resp = HttpServerUtils.response(e.message.toString())
|
|
|
|
|
Log.d(TAG, "resp: $resp")
|
|
|
|
|
if (HttpServerUtils.safetyMeasures != 2) {
|
|
|
|
|
response.setBody(JsonBody(resp))
|
|
|
|
|
} else {
|
|
|
|
|
val privateKey = RSACrypt.getPrivateKey(HttpServerUtils.serverPrivateKey.toString())
|
|
|
|
|
resp = Base64.encode(resp.toByteArray())
|
|
|
|
|
resp = RSACrypt.encryptByPrivateKey(resp, privateKey)
|
|
|
|
|
response.setBody(StringBody(resp))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|