| | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.JsonObject; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.hdl.hdlhttp.HxHttp; |
| | | import com.hdl.hdlhttp.utils.GsonConvert; |
| | | import com.hdl.linkpm.sdk.core.api.HDLCloudUserApi; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.linkpm.sdk.core.response.HDLResponse; |
| | | import com.hdl.linkpm.sdk.user.bean.HDLLoginBean; |
| | | import com.hdl.linkpm.sdk.user.callback.ILoginCallBack; |
| | | import com.hdl.linkpm.sdk.utils.HDLExceptionSubmitUtils; |
| | | import com.hdl.photovoltaic.bean.HttpResponsePack; |
| | | import com.hdl.photovoltaic.config.AppConfigManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | import io.reactivex.rxjava3.disposables.Disposable; |
| | | import okhttp3.Call; |
| | | import okhttp3.Callback; |
| | | import okhttp3.FormBody; |
| | |
| | | |
| | | } |
| | | return sHttpClient; |
| | | } |
| | | |
| | | /** |
| | | * 请求服务器 |
| | | * 底层方法,引用库的方法 |
| | | * |
| | | * @param api 请求接口 |
| | | * @param body 请求参数 |
| | | * @param callBack 回调 |
| | | * @return - |
| | | */ |
| | | private Disposable request(String api, String body, BaseSuccessFailureCallBeak callBack) { |
| | | String requestUrl = HDLCloudUserApi.getRequestUrl(api); |
| | | return HxHttp.builder() |
| | | .url(requestUrl) |
| | | .raw(body) |
| | | .build() |
| | | .post() |
| | | .subscribeWith(new HDLResponse<HttpResponsePack>() { |
| | | @Override |
| | | public void onResponse(HttpResponsePack response) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(response); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HDLExceptionSubmitUtils.submit(requestUrl, body, e); |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 请求服务器 |
| | | * |
| | | * @param api 请求接口 |
| | | * @param body 请求参数(json) |
| | | * @param callBack 回调 |
| | | */ |
| | | public Disposable requestHttp(String api, String body, BaseSuccessFailureCallBeak callBack) { |
| | | return request(api, body, callBack); |
| | | } |
| | | |
| | | /** |
| | |
| | | if (response.isSuccessful()) { |
| | | String s = Objects.requireNonNull(response.body()).string(); |
| | | HttpResponsePack httpResponsePack = new Gson().fromJson(s, HttpResponsePack.class); |
| | | baseSuccessCallBeak.onSuccess(httpResponsePack); |
| | | HdlLogLogic.print("http->回复->", response.request().url() + "\r\n" + s); |
| | | baseSuccessCallBeak.onSuccess(httpResponsePack); |
| | | |
| | | } else { |
| | | //throw new IOException("Unexpected code " + response); |
| | | baseSuccessCallBeak.onFailure(new Exception()); |