| | |
| | | import com.hdl.photovoltaic.config.AppConfigManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.listener.BaseSuccessFailureCallBeak; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | import com.hdl.photovoltaic.other.HdlLogLogic; |
| | | import com.hdl.photovoltaic.utils.HDLMD5Utils; |
| | | |
| | |
| | | * @param callBack 回调 |
| | | * @return - |
| | | */ |
| | | private Disposable request(String api, String body, BaseSuccessFailureCallBeak callBack) { |
| | | private Disposable request(String api, String body, CloudCallBeak<String> callBack) { |
| | | String requestUrl = HDLCloudUserApi.getRequestUrl(api); |
| | | return HxHttp.builder() |
| | | .url(requestUrl) |
| | | .raw(body) |
| | | .build() |
| | | .post() |
| | | .subscribeWith(new HDLResponse<HttpResponsePack>() { |
| | | .subscribeWith(new HDLResponse<String>() { |
| | | @Override |
| | | public void onResponse(HttpResponsePack response) { |
| | | public void onResponse(String str) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(response); |
| | | callBack.onSuccess(str); |
| | | } |
| | | } |
| | | |
| | |
| | | * @param body 请求参数(json) |
| | | * @param callBack 回调 |
| | | */ |
| | | public Disposable requestHttp(String api, String body, BaseSuccessFailureCallBeak callBack) { |
| | | public Disposable requestHttp(String api, String body, CloudCallBeak<String> callBack) { |
| | | return request(api, body, callBack); |
| | | } |
| | | |
| | | /** |
| | | * 请求服务器的方法 |
| | | * 请求服务器的方法(已弃用) |
| | | * |
| | | * @param requestUrl 请求接口 |
| | | * @param json 请求数据 |
| | | * @param isBasicService 是否是基础服务的接口(基础服务的接口需要 appKey,timestamp,sign这三个参数,当为true时,内部会自动添加) |
| | | * @param isExecute 是否是同步(true=同步,false=异步) |
| | | */ |
| | | public void requestHttp(String requestUrl, String json, boolean isBasicService, boolean isExecute, BaseSuccessFailureCallBeak baseSuccessCallBeak) { |
| | | @Deprecated |
| | | private void requestHttp(String requestUrl, String json, boolean isBasicService, boolean isExecute, BaseSuccessFailureCallBeak baseSuccessCallBeak) { |
| | | String fullUrl = AppConfigManage.getUserRegionUrl() + requestUrl; |
| | | this.requestHttps(fullUrl, json, isBasicService, isExecute, baseSuccessCallBeak); |
| | | } |
| | | |
| | | /** |
| | | * 请求服务器的方法(目前只用在获取获取账号区域信息) |
| | | * 请求服务器的方法(已弃用) |
| | | * 目前只用在获取获取账号区域信息 |
| | | * |
| | | * @param fullUrl 绝对地址(地址+接口) |
| | | * @param json 请求数据 |
| | | * @param isBasicService 是否是基础服务的接口(基础服务的接口需要 appKey,timestamp,sign这三个参数,当为true时,内部会自动添加) |
| | | * @param isExecute 是否是同步(true=同步,false=异步) |
| | | */ |
| | | public void requestFullHttp(String fullUrl, String json, boolean isBasicService, boolean isExecute, BaseSuccessFailureCallBeak baseSuccessCallBeak) { |
| | | @Deprecated |
| | | private void requestFullHttp(String fullUrl, String json, boolean isBasicService, boolean isExecute, BaseSuccessFailureCallBeak baseSuccessCallBeak) { |
| | | this.requestHttps(fullUrl, json, isBasicService, isExecute, baseSuccessCallBeak); |
| | | } |
| | | |
| | |
| | | |
| | | } else { |
| | | //throw new IOException("Unexpected code " + response); |
| | | baseSuccessCallBeak.onFailure(new Exception()); |
| | | baseSuccessCallBeak.onFailure(new HDLException(response.code(), response.message())); |
| | | } |
| | | } else { |
| | | |
| | |
| | | baseSuccessCallBeak.onSuccess(httpResponsePack); |
| | | HdlLogLogic.print("http->回复->", "\r\n" + s); |
| | | } else { |
| | | baseSuccessCallBeak.onFailure(new Exception()); |
| | | baseSuccessCallBeak.onFailure(new HDLException(response.code(), response.message())); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | } catch (Exception e) { |
| | | baseSuccessCallBeak.onFailure(e); |
| | | baseSuccessCallBeak.onFailure(new HDLException(-100, e.getMessage())); |
| | | HdlLogLogic.print("http->回复->", "\r\n" + e.getMessage()); |
| | | } |
| | | |