1. Si vous utilisez le package Response dans Observer, vous pouvez obtenir l'en-tête et le corps. Si vous n'utilisez pas le package Response, uniquement BaseResponse <LoginResponse?>?>
Défini en service:
//登录
@POST("/api/v1/auth")
fun login(@Body requestBody: RequestBody?, @Query("app_id") app_id: String?): Observable<Response<BaseResponse<LoginResponse?>?>?>?
val loginRequest = LoginRequest()
loginRequest.deviceSn = DeviceUtil.getDeviceSn(this)
loginRequest.userName = phoneNumber
loginRequest.passWord = password
val requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), Gson().toJson(loginRequest))
getInstance()?.service?.login(requestBody, Constants.APP_ID)?.
compose(RxSchedulers.observableIO2Main())?.subscribe(object : Observer<Response<BaseResponse<LoginResponse?>?>?> {
override fun onSubscribe(d: Disposable) {
}
override fun onNext(t: Response<BaseResponse<LoginResponse?>?>) {
loginButon_loadOver("")
t?.run {
SharePStore.setToken(headers().get("token"))
body()?.run {
when(code){
ErrorCode.SUCCESS->{
cb_remember_password?.isChecked?.let { SharePStore.setLoginPasswordCBIsChecked(it) }
SharePStore.setAccountKey(phoneNumber)
SharePStore.setLoginPassword(password)
data?.run {
}
}
ErrorCode.FAIL-> showFaileToast(getString(R.string.weak_network))
else->{
if(!TextUtils.isEmpty(msg)){
showFaileToast(msg)
}else{
showFaileToast(getString(R.string.weak_network))
}
}
}
}
}
}
override fun onError(e: Throwable) {
showFaileToast(getString(R.string.weak_network))
}
override fun onComplete() {
}
})