赞
踩
最近几个项目都是使用的Retofit+OKHttp的来实现接口调用的,再之前的框架中本次加入了from表单的提交方式。为了方便自己以及大家整合了下,方便以后的工作开展
package com.reach.doooly.http.base;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.reach.doooly.bean.RHBaseVo;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
/**
* @author fqming
* <p>
* 公用的返回信息bean
*/
public class CommResultBeanVo extends RHBaseVo {
//错误码
private String code;
//信息
//下面的注释只有在gson中使用才有效
// @Expose
// @SerializedName("msg")
private String msg;
//返回信息
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
private String data;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
/**純屬為了不該其他的方法而添加的方法*/
public String getMessage(){
return msg;
}
@Override
public String toString() {
return "CommResultBeanVo{" +
"code='" + code + '\'' +
",' message='" + msg + '\'' +
", data='" + data + "'\'}";
}
}
该类实为了方便数据解析,尤其是小编很不喜欢写json数据解析,喜欢用GSON,也是谷歌推荐的。
与后台服务端一起约定返回码,然后有下面的类
下面是小编与后端约定的返回码
package com.reach.doooly.http.client;
/**
* Created by tang on 2017/8/3 0003.
*/
public class ClientCode {
//成功
public static final int SUCCESS_CODE=1000;
//token失效
public static final int OUTTOKEN_CODE=40001;
}
package com.reach.doooly.http.client;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.ObservableTransformer;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import okhttp3.ConnectionPool;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.fastjson.FastJsonConverterFactory;
import android.annotation.SuppressLint;
import android.content.Context;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.reach.doooly.http.base.BaseApiService;
import com.reach.doooly.http.base.CommResultBeanVo;
import com.reach.doooly.http.converfactory.StringConverterFactory;
import com.reach.doooly.http.cookie.CookieCacheImpl;
import com.reach.doooly.http.cookie.CookieManager;
import com.reach.doooly.http.cookie.SharedPrefsCookiePersistor;
import com.reach.doooly.http.errorhandler.NetException;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。