18034727885
2026-08-07 bbc64160643c4ed818eb574831dc303b0a979089
app/src/main/java/com/driver/igotrip/netUtls/HttpManager.java
@@ -17,12 +17,12 @@
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import cn.sinata.xldutils.utils.SPUtils;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
@@ -132,9 +132,9 @@
        httpLoggingInterceptor.level(HttpLoggingInterceptor.Level.BODY);
        builder.addInterceptor(httpLoggingInterceptor);
        LoggingInterceptor loggingInterceptor = new LoggingInterceptor();
        loggingInterceptor.setLevel(BuildConfig.DEBUG ? LoggingInterceptor.Level.BODY : LoggingInterceptor.Level.NONE);
        builder.addInterceptor(loggingInterceptor);
        if (BuildConfig.DEBUG) {
            builder.addInterceptor(new LoggingInterceptor());
        }
        Retrofit.Builder builder1 = new Retrofit.Builder()
                .client(builder.build())                                    // 配置监听请求
@@ -197,32 +197,27 @@
//    public <T extends BaseBean> void post(final String action, Map<String, Object> params,
    public void post(final String action, Map<String, Object> params,
                     Observer<ResponseBody> observer) {
        post(action, params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }
    /**
     * Post请求
     *
     * @param action 请求接口的尾址
     * @param params 请求参数
     */
    public Observable<ResponseBody> post(final String action, Map<String, Object> params) {
        if (params == null) {
            params = new HashMap<>();
        }
        int type = getTypeByLanguage();
        params.put(Const.language, type); // 1 中文 2 英文 3 法文
        StringBuilder pwd = new StringBuilder();
        pwd.append(action);
        if (params.size() != 0) {
            pwd.append("?");
        }
        Iterator<Map.Entry<String, Object>> iterator = params.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, Object> entry = iterator.next();
            pwd.append(entry.getKey()).append("=").append(entry.getValue());
            if (iterator.hasNext()) {
                pwd.append("&");
            }
        }
        Map<String, Object> par = new HashMap<>();
        ApiServics jsonService = initBaseData(action).create(ApiServics.class);
        LogUtils.d("post", params.toString());
        jsonService.postResult(action, headerParams, params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
        return jsonService.postResult(action, headerParams, params);
    }
    /**
@@ -242,28 +237,31 @@
     * @param action   请求接口的尾址
     * @param fileName 文件名
     */
    public <T extends BaseBean> void post(final String action, File fileName,
                                          Observer<ResponseBody> observer) {
    public void post(final String action, File fileName, Observer<ResponseBody> observer) {
        post(action, fileName)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }
    /**
     * Post请求
     *
     * @param action 请求接口的尾址
     * @param file   文件
     */
    public Observable<ResponseBody> post(final String action, File file) {
        ApiServics service = initBaseData(action).create(ApiServics.class);
        // https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java
        // use the FileUtils to get the actual file by uri
        File file = fileName;
        // create RequestBody instance from file
        RequestBody requestFile =
                RequestBody.create(MediaType.parse("multipart/form-data"), file);
        RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file);
        // MultipartBody.Part is used to send also the actual file name
        MultipartBody.Part body =
                MultipartBody.Part.createFormData("file", file.getName(), requestFile);
        service.upload(action, body)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
        MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), requestFile);
        return service.upload(action, body);
    }