空格
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.xscm.moduleutil.http;
|
||||
|
||||
|
||||
public class APIException extends RuntimeException {
|
||||
private int code;
|
||||
|
||||
|
||||
public APIException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public APIException(int code, String message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.xscm.moduleutil.http;
|
||||
|
||||
|
||||
import com.xscm.moduleutil.utils.Sha1Util;
|
||||
import com.xscm.moduleutil.utils.SpUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
|
||||
public class AccessTokenInterceptor implements Interceptor {
|
||||
|
||||
private final static String TAG = AccessTokenInterceptor.class.getCanonicalName();
|
||||
|
||||
private static final Map<String, String> mHeaderMap = new ConcurrentHashMap<>();
|
||||
|
||||
public static String token = "";
|
||||
|
||||
public AccessTokenInterceptor(Map<String, String> headers) {
|
||||
mHeaderMap.putAll(headers);
|
||||
}
|
||||
|
||||
|
||||
public Map<String, String> getHeaders() {
|
||||
return mHeaderMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request request = chain.request();
|
||||
mHeaderMap.put("X-Token", SpUtil.getToken());
|
||||
mHeaderMap.put("token", SpUtil.getToken());
|
||||
long timestamp = System.currentTimeMillis() / 1000;
|
||||
mHeaderMap.put("timestamp", String.valueOf(timestamp));
|
||||
mHeaderMap.put("sign", Sha1Util.shaEncode(timestamp));
|
||||
Request newRequest = request.newBuilder().headers(Headers.of(mHeaderMap)).build();
|
||||
Response response = chain.proceed(newRequest);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
715
moduleUtil/src/main/java/com/xscm/moduleutil/http/ApiServer.java
Normal file
715
moduleUtil/src/main/java/com/xscm/moduleutil/http/ApiServer.java
Normal file
@@ -0,0 +1,715 @@
|
||||
package com.xscm.moduleutil.http;
|
||||
|
||||
|
||||
import com.xscm.moduleutil.bean.AlbumBean;
|
||||
import com.xscm.moduleutil.bean.AppPay;
|
||||
import com.xscm.moduleutil.bean.AppUpdateModel;
|
||||
import com.xscm.moduleutil.bean.BannerModel;
|
||||
import com.xscm.moduleutil.bean.BindType;
|
||||
import com.xscm.moduleutil.bean.BlackUserBean;
|
||||
import com.xscm.moduleutil.bean.CharmRankingResp;
|
||||
import com.xscm.moduleutil.bean.CircleListBean;
|
||||
import com.xscm.moduleutil.bean.CommentBean;
|
||||
import com.xscm.moduleutil.bean.ExpandColumnBean;
|
||||
import com.xscm.moduleutil.bean.FirstChargeBean;
|
||||
import com.xscm.moduleutil.bean.FirstChargeGiftBean;
|
||||
import com.xscm.moduleutil.bean.GiftBoxRecordBean;
|
||||
import com.xscm.moduleutil.bean.GiftLabelBean;
|
||||
import com.xscm.moduleutil.bean.GiftName;
|
||||
import com.xscm.moduleutil.bean.GiftPackBean;
|
||||
import com.xscm.moduleutil.bean.GiftUserWallBean;
|
||||
import com.xscm.moduleutil.bean.HeadlineBean;
|
||||
import com.xscm.moduleutil.bean.HeatedBean;
|
||||
import com.xscm.moduleutil.bean.HostBean;
|
||||
import com.xscm.moduleutil.bean.MusicSongBean;
|
||||
import com.xscm.moduleutil.bean.MyBagDataBean;
|
||||
import com.xscm.moduleutil.bean.MyCpRoom;
|
||||
import com.xscm.moduleutil.bean.MyFootResp;
|
||||
import com.xscm.moduleutil.bean.MyRoomBean;
|
||||
import com.xscm.moduleutil.bean.NewsDataBean;
|
||||
import com.xscm.moduleutil.bean.NewsMessageList;
|
||||
import com.xscm.moduleutil.bean.PersonaltyBean;
|
||||
import com.xscm.moduleutil.bean.PkSwTokenBean;
|
||||
import com.xscm.moduleutil.bean.PlaceholderBean;
|
||||
import com.xscm.moduleutil.bean.RealNameBean;
|
||||
import com.xscm.moduleutil.bean.RechargeBean;
|
||||
import com.xscm.moduleutil.bean.RelationCardBean;
|
||||
import com.xscm.moduleutil.bean.RevenueBean;
|
||||
import com.xscm.moduleutil.bean.RewardUserBean;
|
||||
import com.xscm.moduleutil.bean.RoomBgBean;
|
||||
import com.xscm.moduleutil.bean.RoomCharmRankBean;
|
||||
import com.xscm.moduleutil.bean.RoomDetails;
|
||||
import com.xscm.moduleutil.bean.RoomRelationBean;
|
||||
import com.xscm.moduleutil.bean.RoomSearchResp;
|
||||
import com.xscm.moduleutil.bean.RoomSubsidy;
|
||||
import com.xscm.moduleutil.bean.RoomTime;
|
||||
import com.xscm.moduleutil.bean.RoomTypeModel;
|
||||
import com.xscm.moduleutil.bean.RoonGiftModel;
|
||||
import com.xscm.moduleutil.bean.SongMusicBean;
|
||||
import com.xscm.moduleutil.bean.ThemeBean;
|
||||
import com.xscm.moduleutil.bean.TopRoom;
|
||||
import com.xscm.moduleutil.bean.UserBean;
|
||||
import com.xscm.moduleutil.bean.UserInfo;
|
||||
import com.xscm.moduleutil.bean.UserOnlineStatusBean;
|
||||
import com.xscm.moduleutil.bean.UserTagBean;
|
||||
import com.xscm.moduleutil.bean.WalletBean;
|
||||
import com.xscm.moduleutil.bean.WalletConfig;
|
||||
import com.xscm.moduleutil.bean.WithdrawalBean;
|
||||
import com.xscm.moduleutil.bean.room.AuctionBean;
|
||||
import com.xscm.moduleutil.bean.room.RoomApplyListBean;
|
||||
import com.xscm.moduleutil.bean.room.RoomAuction;
|
||||
import com.xscm.moduleutil.bean.room.RoomBean;
|
||||
import com.xscm.moduleutil.bean.room.RoomInfoResp;
|
||||
import com.xscm.moduleutil.bean.room.RoomOnline;
|
||||
import com.xscm.moduleutil.bean.zhuangb.ZhuangBanShangChengBean;
|
||||
import com.xscm.moduleutil.widget.Constants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface ApiServer {
|
||||
|
||||
|
||||
@FormUrlEncoded //请求验证码
|
||||
@POST(Constants.SEND_CODE)
|
||||
Observable<BaseModel<Object>> sendCode(@Field("mobile") String mobile, @Field("event") String event);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.LOGIN)
|
||||
Observable<BaseModel<List<UserBean>>> login(@Field("user_login") String user_login, @Field("sms_code") String sms_code);
|
||||
@FormUrlEncoded //手机换绑
|
||||
@POST(Constants.MODIFY_MOBILE)
|
||||
Call<BaseModel<String>> mobileView(@Field("mobile") String mobile, @Field("new_mobile") String new_mobile,@Field("sms_code") String sms_code);
|
||||
@FormUrlEncoded //手机绑定
|
||||
@POST(Constants.BIND_MOBILE)
|
||||
Call<BaseModel<String>> mobileView2( @Field("new_mobile") String new_mobile,@Field("sms_code") String sms_code);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.USER_LOGIN)
|
||||
Call<BaseModel<List<UserBean>>> userLogin(@Field("user_login") String user_login, @Field("password") String password);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.EARNINGS_NUM)
|
||||
Call<BaseModel<String>> exchangeCoin(@Field("earnings_num") String earnings_num);
|
||||
|
||||
@GET(Constants.DELETE_ROOM_HISTORY)
|
||||
Call<BaseModel<String>> delfoot();
|
||||
|
||||
@GET(Constants.GET_FIRST_CHARGE)
|
||||
Call<BaseModel<FirstChargeBean>> firstCharge(@Query("uid") String user_id);
|
||||
|
||||
@POST(Constants.UPLOAD_NICK_NAME)
|
||||
Call<ResponseBody> upUserNickname();
|
||||
|
||||
@GET(Constants.GET_APP_UPDATE)
|
||||
Observable<BaseModel<AppUpdateModel>> appUpdate();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.dailyTasksOpenBox)
|
||||
Observable<BaseModel<GiftName>> dailyTasksOpenBox(@Field("gift_box_id") String gift_box_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.dailyTasksReceive)
|
||||
Call<ResponseBody> dailyTasksReceive(@Field("task_id") String task_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.dailyTasksComplete)
|
||||
Call<ResponseBody> dailyTasksComplete(@Field("task_id") String task_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.SEND_HEADLINE)
|
||||
Call<BaseModel<String>> sendHeadine(@Field("content") String content, @Field("money") String money, @Field("room_id") String roomId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_WITHDRAWAL)
|
||||
Call<ResponseBody> withdrawal(@Field("number") String number, @Field("type") String type, @Field("sms_code") String sms_code);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_USER_WALL)
|
||||
Observable<BaseModel<GiftUserWallBean>> giftWall(@Field("user_id")String userId);
|
||||
|
||||
@GET(Constants.CURRENT_HEADLINE)
|
||||
Observable<BaseModel<HeadlineBean>> currentHeadline();
|
||||
|
||||
@GET(Constants.GET_TASKS_LIHEN)
|
||||
Call<ResponseBody> tasksLihen();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_LOG_LIST)
|
||||
Call<BaseModel<List<RevenueBean>>> getRevenueData(@Field("page") String page, @Field("page_limit") String page_limit, @Field("in_out_type") String in_out_type, @Field("start_time") String start_time, @Field("end_time") String end_time, @Field("gift_type") String gift_type);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_WEALTH_RANKING)
|
||||
Observable<BaseModel<PlaceholderBean>> wealthRanking(@Field("ranking_type") String ranking_type, @Field("type") String type);
|
||||
|
||||
@GET(Constants.GUILD_RANKING)
|
||||
Observable<BaseModel<PlaceholderBean>> guildRanking();
|
||||
|
||||
@GET(Constants.GET_WITHDRAWAL_LIST)
|
||||
Observable<BaseModel<List<WithdrawalBean>>> withdrawalList(@Query("page") String page, @Query("page_limit") String page_limit, @Query("search_stime") String search_stime, @Query("search_etime") String search_etime);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_MESSAGE_LIST)
|
||||
Observable<BaseModel<List<NewsMessageList>>> getMessagetitle(@Field("type")String type, @Field("page")String page, @Field("page_limit")String page_limit);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_ROOM_RANK)
|
||||
Observable<BaseModel<List<CharmRankingResp>>> getRoomRank(@Field("room_id") String room_id, @Field("type") String type, @Field("time_type") String time_type, @Field("page") String page, @Field("page_limit") String page_limit);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_ROOM_RANKING)
|
||||
Observable<BaseModel<PlaceholderBean>> roomRanking(@Field("type") String type);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_LOVE_RANKING)
|
||||
Observable<BaseModel<PlaceholderBean>> loveRanking(@Field("type") String type);
|
||||
|
||||
@GET(Constants.GET_REAL_NAME)
|
||||
Observable<BaseModel<RealNameBean>> realNameInfo();
|
||||
|
||||
@GET(Constants.GET_DAILY_TASK_BOX)
|
||||
Observable<BaseModel<List<GiftBoxRecordBean>>> dailyTasksBoxRecord();
|
||||
|
||||
@GET(Constants.GET_MY_BAG_DATA)
|
||||
Observable<BaseModel<List<MyBagDataBean>>> packIncome(@Query("page") String page, @Query("page_limit") String page_size);
|
||||
|
||||
@GET(Constants.GET_MY_BAG_OUTCOME)
|
||||
Observable<BaseModel<List<MyBagDataBean>>> packOutcome(@Query("page") String page, @Query("page_limit") String page_size);
|
||||
|
||||
@GET(Constants.GET_GIFT_PACK)
|
||||
Observable<BaseModel<List<GiftPackBean>>> giftPack();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.ADD_BLACK_LIST)
|
||||
Call<ResponseBody> addBlackList(@Field("user_id") String user_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_SEND_PK)
|
||||
Call<ResponseBody> sendPk(@Field("room_id_a") String room_id_a, @Field("create_user_id") String create_user_id, @Field("room_id_b") String room_id_b);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_REFUSE_PK)
|
||||
Call<ResponseBody> refusePk(@Field("is_pk") String is_pk, @Field("room_id") String room_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_END_PK)
|
||||
Call<ResponseBody> endPk(@Field("pk_id") String is_pk, @Field("type") String type, @Field("user_id") String user_id);
|
||||
|
||||
@GET(Constants.GET_RECHARGE)
|
||||
Observable<BaseModel<List<RechargeBean>>> recharge();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_START_PK)
|
||||
Call<ResponseBody> startPk(@Field("pk_id") String pk_id, @Field("pk_times") String pk_times);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.UPLOAD_USER_PIC)
|
||||
Call<BaseModel<String>> upUserPic(@Field("sex") String sex);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.SWITCH_ACCOUNTS)
|
||||
Observable<BaseModel<List<UserBean>>> switchAccounts(@Field("user_login") String user_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.FORGOT_PASSWORD)
|
||||
Call<BaseModel<String>> forgotPassword(@Field("new_password") String new_password, @Field("mobile") String mobile, @Field("sms_code") String sms_code);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.USER_UPDATE)
|
||||
Observable<BaseModel<UserBean>> userUpdate(@Field("nickname") String nickname, @Field("birthday") String birthday, @Field("sex") String sex, @Field("avatar") String avatar, @Field("init_code") String init_code, @Field("user_id") String user_id);
|
||||
|
||||
@GET(Constants.AUTHORIZATION)
|
||||
Call<ResponseBody> authorization();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.CHANGE_PASSWORD)
|
||||
Call<BaseModel<String>> getPostData(@Field("new_password") String new_password, @Field("mobile") String mobile, @Field("sms_code") String code, @Field("user_id") String userId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.REAL_NAME_RESULT)
|
||||
Call<BaseModel<String>> getRealNameResult(@Field("orderNo") String order_no);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.URL_LOGIN)
|
||||
Call<BaseModel<List<UserBean>>> oauthLogin(@Field("login_token") String login_token);
|
||||
|
||||
@GET(Constants.GET_THEME_DATA)
|
||||
Call<BaseModel<ThemeBean>> getThemeData();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.URL_AUTH_CODE)
|
||||
Observable<BaseModel<List<UserBean>>> authCode(@Field("auth_code") String login_token);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.URL_WX_CODE)
|
||||
Observable<BaseModel<List<UserBean>>> authCode1(@Field("code") String login_token);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.REAL_NAME)
|
||||
Observable<BaseModel<RealNameBean>> realName(@Field("real_name") String real_name, @Field("card_number") String card_number);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.GET_EXPAND_COLUMN)
|
||||
Observable<BaseModel<List<ExpandColumnBean>>> getExpandColumn(@Field("type") String type,@Field("page") String page, @Field("page_limit") String page_limit);
|
||||
|
||||
@GET(Constants.GET_OFFICIAL_NOTICE)
|
||||
Observable<BaseModel<NewsDataBean>> getOfficialNotice();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.GET_ALBUM_LIST)
|
||||
Observable<BaseModel<List<AlbumBean>>> getAlbumList(@Field("page") String page, @Field("page_limit") String page_limit, @Field("user_id") String user_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.CREATE_ALBUM)
|
||||
Call<BaseModel<String>> createAlbum(@Field("name") String name, @Field("pwd") String pwd, @Field("image") String image);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.EDIT_ALBUM)
|
||||
Call<BaseModel<String>> editAlbum(@Field("album_id") String album_id, @Field("name") String name, @Field("pwd") String pwd, @Field("image") String image);
|
||||
|
||||
@GET(Constants.GET_SJ_ROOM_NAME)
|
||||
Call<ResponseBody> sjRoomName();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_FOLLOW_LIST)
|
||||
Observable<BaseModel<List<BlackUserBean>>> getUserFollowList(@Field("page") String page, @Field("page_limit") String page_limit);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_FANS_LIST)
|
||||
Observable<BaseModel<List<BlackUserBean>>> getUserFansList(@Field("page") String page, @Field("page_limit") String page_limit);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_BLACK_LIST)
|
||||
Observable<BaseModel<List<BlackUserBean>>> getBlacklist(@Field("page") String page, @Field("page_limit") String page_limit);
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_LOCK_MI_LIST)
|
||||
Observable<BaseModel<List<BlackUserBean>>> getLockMiniList(@Field("page") String page, @Field("page_limit") String page_limit);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.GET_MY_ROOM)
|
||||
Call<BaseModel<List<MyRoomBean>>> getMyRoom(@Field("type") String type, @Field("page") String page, @Field("page_limit") String page_limit);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_MY_ROOM_BEAN)
|
||||
Call<BaseModel<List<BannerModel>>> getBanners(@Field("type") String type);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.GET_TOP_ROOM)
|
||||
Call<BaseModel<List<TopRoom>>> getTopRooms(@Field("page") String page, @Field("page_limit") String page_limit, @Field("is_top") String is_top, @Field("label_id") String label_id);
|
||||
|
||||
@GET(Constants.GET_ROOM_TYPE)
|
||||
Observable<BaseModel<List<RoomTypeModel>>> getRoomCategories();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.CHECK_TXT)
|
||||
Call<ResponseBody> checkTxt(@Field("room_name") String room_name, @Field("room_cover") String room_cover, @Field("room_intro") String room_intro);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.GET_REWARD_LIST)
|
||||
Observable<BaseModel<List<RewardUserBean>>> getRewardList(@Field("id") String id, @Field("page") String page, @Field("page_limit") String page_limit);
|
||||
|
||||
@GET(Constants.GET_GIFT_LABEL)
|
||||
Observable<BaseModel<List<GiftLabelBean>>> getGiftLabel(@Query("have_hot") String have_hot);
|
||||
|
||||
@GET(Constants.GIFT_LIST)
|
||||
//获取礼物列表
|
||||
Observable<BaseModel<List<RoonGiftModel>>> getGiftList(@Query("label") int label);
|
||||
|
||||
@GET(Constants.TOPIC_LIST)
|
||||
//获取话题
|
||||
Observable<BaseModel<List<HeatedBean>>> topicList(@Query("page") String page, @Query("page_limit") String page_limit);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.PUBLISH_ZONE)
|
||||
Call<BaseModel<String>> publishZone(@Field("images") String images, @Field("content") String content, @Field("topic_id") String topic_id, @Field("room_id") String room_id, @Field("ip") String ip);
|
||||
|
||||
@GET(Constants.GET_CATEGORIES)
|
||||
Observable<BaseModel<List<HeatedBean>>> getCategories();
|
||||
|
||||
@GET(Constants.GET_CIRCLE_LIST)
|
||||
Observable<BaseModel<List<CircleListBean>>> getCircleList(@Query("page") String page, @Query("page_limit") String page_limit);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.GET_USER_HOME_ZONE)
|
||||
Observable<BaseModel<List<CircleListBean>>> getCircleUserList(@Field("user_id") String user_id, @Field("page") String page, @Field("page_limit") String page_limit);
|
||||
|
||||
@GET(Constants.GET_MY_FOOT)
|
||||
Observable<BaseModel<List<MyFootResp>>> getMyFoot(@Query("page") String page, @Query("page_limit") String page_limit);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.LIKE_ZONE)
|
||||
Call<BaseModel<String>> likeZone(@Field("id") String zone_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.TOPIC_ID)
|
||||
Observable<BaseModel<List<CircleListBean>>> topicId(@Field("topic_id") String topic_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.ZONE_DETAIL)
|
||||
Observable<BaseModel<CircleListBean>> zoneDetail(@Field("id") String topic_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.GET_USER_HOME)
|
||||
Observable<BaseModel<UserInfo>> getUserHome(@Field("user_id") String user_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.DELETE_COMMENT)
|
||||
Call<BaseModel<String>> deleteComment(@Field("id") String zone_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.GET_COMMENT_LIST)
|
||||
Observable<BaseModel<CommentBean>> getCommentList(@Field("id") String id, @Field("page") String page, @Field("page_limit") String page_limit);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_SONG)
|
||||
Observable<BaseModel<List<SongMusicBean>>> song(@Field("room_id") String roomId, @Field("user_id") String userId, @Field("song_code") String songCode, @Field("song_name") String songName, @Field("singer") String singer, @Field("poster") String poster, @Field("duration") String duration);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.COMMENT_ZONE)
|
||||
Call<BaseModel<String>> commentZone(@Field("id") String id, @Field("content") String content, @Field("pid") String pid, @Field("reply_to") String reply_to);
|
||||
|
||||
|
||||
@GET(Constants.GET_MY_CP_ROOM_LIST)
|
||||
Call<BaseModel<List<MyCpRoom>>> myCpRoom();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.CLEAR_LOGIN_INFO)
|
||||
Call<BaseModel<String>> clearLoginInfo(@Field("token") String token);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.CANCEL)
|
||||
Call<BaseModel<String>> cancel(@Field("token") String token);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.DELETE_ZONE)
|
||||
Call<BaseModel<String>> deleteZone(@Field("id") String id);
|
||||
|
||||
@GET(Constants.GET_MY_INFO)
|
||||
Observable<BaseModel<UserInfo>> getMyInfo();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.ED_USER_INFO)
|
||||
Call<BaseModel<String>> editUserInfo(@Field("nickname") String nickname, @Field("birthday") String birthday, @Field("sex") String sex, @Field("avatar") String avatar, @Field("images") String images, @Field("profile") String profile, @Field("tag_id") String tag_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.ED_USER_BG)
|
||||
Call<BaseModel<String>> editUserBg(@Field("images") String images);
|
||||
|
||||
@GET(Constants.GET_USER_TAG_LIST)
|
||||
Observable<BaseModel<List<UserTagBean>>> getUserTagList();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.GET_LIKE_LIST)
|
||||
Observable<BaseModel<List<CircleListBean.LikeList>>> getLikeList(@Field("id") String id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.GET_ALBUM_DETAIL)
|
||||
Observable<BaseModel<AlbumBean>> getAlbumDetail(@Field("album_id") String albumId, @Field("pwd") String pwd, @Field("page") String page, @Field("page_limit") String page_limit);
|
||||
|
||||
@GET(Constants.GET_PERSONALTY)
|
||||
Observable<BaseModel<List<PersonaltyBean>>> getPersonaltyList();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.GET_SUBSIDY)
|
||||
Observable<BaseModel<RoomSubsidy>> getSubsidy(@Field("room_id") String roomId);
|
||||
|
||||
@GET(Constants.GET_DECORATE)
|
||||
Observable<BaseModel<List<ZhuangBanShangChengBean>>> getDecorateList(@Query("type") String type);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_GZ)
|
||||
Call<BaseModel<String>> userGuanz(@Field("user_id") String userId, @Field("type") String type);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.ACCEPT_PK)
|
||||
Call<BaseModel<String>> acceptPk(@Field("pk_id") String pk_id, @Field("type") String type);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_CLEAR_USER_CHARM)
|
||||
Call<BaseModel<String>> clearUserCharm(@Field("room_id") String roomId,@Field("user_id") String userId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.REMOVE_BLACK_LIST)
|
||||
Call<BaseModel<String>> removeBlackList(@Field("uid") String userId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_USER_OLINE_STATUS)
|
||||
Call<BaseModel<List<UserOnlineStatusBean>>> userOnlineStatus(@Field("user_id") String userId,@Field("room_id")String roomId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.postRoomSwToken)
|
||||
Call<BaseModel<PkSwTokenBean>> postRoomSwToken(@Field("room_id") String roomId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.SET_USER_DECORATE)
|
||||
Call<BaseModel<String>> setUserDecorate(@Field("udid") String udid);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_CANCEL_USER_DECORATE)
|
||||
Call<BaseModel<String>> cancelUserDecorate(@Field("type") String type);
|
||||
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.UP_ALBUM)
|
||||
Call<BaseModel<String>> upAddAlbum(@Field("album_id") String album_id, @Field("images") String images, @Field("content") String content);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.MOVE_ALBUM)
|
||||
Call<BaseModel<String>> moveAlbum(@Field("id") String id, @Field("new_album_id") String new_album_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.JOIN_ROOM)
|
||||
Observable<BaseModel<RoomInfoResp>> roomGetIn(@Field("room_id") String roomId, @Field("password") String password);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.DELETE_ALBUM_IMAGE)
|
||||
Call<BaseModel<String>> deleteAlbumImage(@Field("id") String id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.DELETE_ALBUM)
|
||||
Call<BaseModel<String>> deleteAlbum(@Field("album_id") String id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.LIKE_ALBUM)
|
||||
Call<BaseModel<String>> likeAlbum(@Field("album_id") String id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.ADDRESS_IP)
|
||||
Call<BaseModel<String>> address_ip(@Field("address_ip") String address_ip);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.UPDATEPASSWORD)
|
||||
Observable<BaseModel<String>> updatePassword(@Field("room_id") String roomId, @Field("password") String password);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.GET_ROOM_ONLINE)
|
||||
Observable<BaseModel<RoomOnline>> getRoomOnline(@Field("room_id") String roomId, @Field("page") String page, @Field("page_limit") String page_limit);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.GET_GIVE_GIFT)
|
||||
Call<BaseModel<String>> giveGift(@Field("user_id") String user_id, @Field("gid") String gid, @Field("num") String num, @Field("to_uid") String to_uid, @Field("gift_type") String gift_type);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.GET_ROOM_GIFT)
|
||||
Call<BaseModel<String>> roomGift(@Field("room_id") String room_id, @Field("gift_id") String gift_id, @Field("gift_num") String num, @Field("to_uid") String to_uid, @Field("type") String gift_type, @Field("pit_number") String pit_number);
|
||||
|
||||
@GET(Constants.GET_FIRST_CHARGE_GIFT)
|
||||
Observable<BaseModel<FirstChargeGiftBean>> firstChargeGift();
|
||||
|
||||
@GET(Constants.GET_WALLET)
|
||||
Observable<BaseModel<WalletBean>> wallet();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_APPLY_Pay)
|
||||
Observable<BaseModel<AppPay>> appPay(@Field("user_id") String user_id, @Field("money") String money, @Field("coin") String coin, @Field("type") String type);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_APPLY_LIST)
|
||||
Observable<BaseModel<RoomApplyListBean>> roomApplyListBean(@Field("room_id") String room_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.GET_ROOM_USER)
|
||||
Observable<BaseModel<UserInfo>> getRoomUserInfo(@Field("room_id") String roomId, @Field("user_id") String userId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_BIND_TYPE)
|
||||
Observable<BaseModel<BindType>> bindType(@Field("user_id") String userId);
|
||||
|
||||
@GET(Constants.GET_WALLET_CONFIG)
|
||||
Observable<BaseModel<WalletConfig>> getWalletConfig();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_BIND)
|
||||
Call<BaseModel<String>> bind(@Field("user_id") String userId, @Field("type") String type, @Field("alipay_account") String alipay_account, @Field("bank_card_number") String bank_card_number, @Field("bank_card") String bank_card, @Field("open_bank") String open_bank);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_SONG_LIST)
|
||||
Observable<BaseModel<List<MusicSongBean>>> songList(@Field("room_id") String room_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.APPLY_PIT)
|
||||
Call<BaseModel<String>> applyPit(@Field("room_id") String room_id, @Field("pit_number") String pit_number);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.START_FRIEND)
|
||||
Call<BaseModel<String>> startFriend(@Field("room_id") String room_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.DOWN_PIT)
|
||||
Call<BaseModel<String>> downPit(@Field("room_id") String room_id, @Field("pit_number") String pit_number);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.REWARD_ZONE)
|
||||
Call<BaseModel<String>> reward_zone(@Field("id") String id, @Field("gift_id") String gift_id, @Field("num") String num, @Field("is_pack") String is_pack);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_UP_SONG)
|
||||
Call<BaseModel<String>> upSong(@Field("did") String did, @Field("type") String type);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_CHANGE_ROOM)
|
||||
Call<BaseModel<String>> changeRoom(@Field("room_id") String room_id, @Field("user_id") String userId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_CHANGE_ROOM_TYPE)
|
||||
Call<BaseModel<String>> changeRoomType(@Field("room_id") String room_id, @Field("type") String type);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.SET_ROOM_APPLY)
|
||||
Call<BaseModel<String>> setRoomApply(@Field("room_id") String room_id, @Field("gift_id") String gift_id, @Field("gift_price") String gift_price);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.CLEAR_APPLY)
|
||||
Call<BaseModel<String>> clearApply(@Field("room_id") String room_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.AGREE_PIT)
|
||||
Call<BaseModel<String>> agreePit(@Field("room_id") String roomId, @Field("user_id") String userId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.REFUSE_PIT)
|
||||
Call<BaseModel<String>> refusePit(@Field("room_id") String roomId, @Field("user_id") String userId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.HELP_APPLY)
|
||||
Call<BaseModel<String>> helpApply(@Field("room_id") String roomId, @Field("user_id") String userId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_APPLY_SONG)
|
||||
Call<BaseModel<String>> applySong(@Field("room_id") String roomId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_AGREE_SONG)
|
||||
Call<BaseModel<String>> agreeSong(@Field("room_id") String roomId, @Field("type") String type);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_END_SONG)
|
||||
Call<BaseModel<String>> endSong(@Field("room_id") String roomId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_ROOM_INFO)
|
||||
Observable<BaseModel<RoomInfoResp>> postRoomInfo(@Field("room_id") String roomId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.CHANGE_SONG)
|
||||
Call<BaseModel<String>> changeSong(@Field("room_id") String roomId, @Field("now_did") String now_did);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_HOST_LIST)
|
||||
Observable<BaseModel<List<HostBean>>> getHostList(@Query("room_id") String room_id, @Field("type") String type);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.GET_CHARM_RANK)
|
||||
Observable<BaseModel<List<RoomCharmRankBean>>> getCharmRank(@Field("room_id") String roomId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_ROOM_RELATION_LIST)
|
||||
Observable<BaseModel<List<RoomRelationBean>>> roomRelationList(@Field("type") String type);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_ROOM_AUCTION_LIST)
|
||||
Observable<BaseModel<List<RoomAuction.AuctionListBean>>> roomAuctionList(@Field("auction_id") String auction_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_SEARCH)
|
||||
Observable<BaseModel<List<RoomSearchResp>>> getSearch(@Query("search") String room_id, @Field("type") String type);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.SET_PRESIDED_RATIO)
|
||||
Call<BaseModel<String>> setPresidedRatio(@Field("room_id") String room_id, @Field("user_id") String userId, @Field("ratio") String ration);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.GET_PRESIDED_RATIO)
|
||||
Call<BaseModel<String>> getPresidedRatio(@Field("room_id") String room_id, @Field("user_id") String userId, @Field("type") String type, @Field("is_add") String is_add);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_ROOM_HOST_PIT)
|
||||
Call<BaseModel<String>> hostUserPit(@Field("room_id") String room_id, @Field("pit_number") String pit_number, @Field("user_id") String userId, @Field("type") String type);
|
||||
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_GIVE_COIN)
|
||||
Call<BaseModel<String>> giveCoin(@Field("user_id") String user_id,@Field("coin") String coin);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_SET_MUTE_PIT)
|
||||
Call<BaseModel<String>> setMutePit(@Field("room_id") String room_id, @Field("user_id") String user_id, @Field("is_mute") String is_mute);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_SET_LOCK_PIT)
|
||||
Call<BaseModel<String>> setLockPit(@Field("room_id") String room_id, @Field("pit_number") String pit_number, @Field("is_lock") String is_lock);
|
||||
|
||||
@GET(Constants.GET_ROOM_BJ)
|
||||
Observable<BaseModel<RoomBgBean>> getBackgroundList();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_CHARM_LIST)
|
||||
Observable<BaseModel<RoomDetails>> getCharmList(@Field("room_id") String room_id, @Field("start_time") String start_time, @Field("end_time") String end_time,@Field("page") String page);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_SET_UPLOAD_BG_IMG)
|
||||
Call<BaseModel<String>> setUploadBgImg(@Field("id") String id, @Field("image_url") String image_url);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_AUCTION_DELAY)
|
||||
Call<BaseModel<String>> auctionDelay(@Field("auction_id") String auction_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_AUCTION_END)
|
||||
Call<BaseModel<String>> auctionEnd(@Field("auction_id") String auction_id,@Field("room_id") String room_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_AUCTION_MODE)
|
||||
Call<BaseModel<String>> auctionMode(@Field("room_id") String room_id, @Field("label_id") String label_id);
|
||||
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_EDIT_ROOM)
|
||||
Call<BaseModel<String>> editRoom(@Field("room_id") String room_id, @Field("room_name") String room_name, @Field("room_cover") String room_cover, @Field("room_intro") String room_intro, @Field("room_background") String room_background);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_KICK_OUT_ROOM)
|
||||
Call<BaseModel<String>> kickOutRoom(@Field("room_id") String room_id, @Field("user_id") String user_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_QUIT_ROOM)
|
||||
Call<ResponseBody> quitRoom(@Field("room_id") String room_id, @Field("user_id") String user_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_RELATION_CARD)
|
||||
Observable<BaseModel<RelationCardBean>> relationCard(@Field("user_id") String user_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_TOP_RELATION_CARD)
|
||||
Call<BaseModel<String>> topRelationCard(@Field("id") String id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_DELETE_RELATION_CARD)
|
||||
Call<BaseModel<String>> deleteRelationCard(@Field("id") String id);
|
||||
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_ROOM_AUCTION)
|
||||
Observable<BaseModel<AuctionBean>> roomAuction(@Field("room_id") String room_id, @Field("user_id") String user_id, @Field("gift_id") String gift_id, @Field("relation_id") String relation_id, @Field("auction_type") String auction_type, @Field("time_day") String time_day);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_ROOM_AUCTION_TIME)
|
||||
Observable<BaseModel<RoomTime>> roomAuctionTime(@Field("gift_id") String gift_id);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_ROOM_AUCTION_JOIN)
|
||||
Observable<BaseModel<RoomAuction.AuctionListBean>> roomAuctionJoin(@Field("auction_id") String auction_id, @Field("user_id") String user_id, @Field("gift_id") String gift_id, @Field("num") String num, @Field("type") String type);
|
||||
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_SEARCH_PK_ROOM)
|
||||
Observable<BaseModel<List<RoomBean>>> searchPkRoom(@Field("room_id") String room_id, @Field("page") String page, @Field("limit") String limit);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.xscm.moduleutil.http;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class BaseModel<T> implements Parcelable {
|
||||
@SerializedName("code")
|
||||
private int code;
|
||||
@SerializedName("data")
|
||||
private T data;
|
||||
@SerializedName("msg")
|
||||
private String msg;
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public BaseModel() {
|
||||
|
||||
}
|
||||
public boolean isSuccess() {
|
||||
return code == 1; // 根据实际业务码判断是否成功
|
||||
}
|
||||
|
||||
public boolean isTokenExpired() {
|
||||
return code == 301; // token过期码
|
||||
}
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(this.code);
|
||||
dest.writeString(this.msg);
|
||||
}
|
||||
|
||||
protected BaseModel(Parcel in) {
|
||||
this.code = in.readInt();
|
||||
this.msg = in.readString();
|
||||
}
|
||||
|
||||
public static final Creator<BaseModel> CREATOR = new Creator<BaseModel>() {
|
||||
@Override
|
||||
public BaseModel createFromParcel(Parcel source) {
|
||||
return new BaseModel(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseModel[] newArray(int size) {
|
||||
return new BaseModel[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.xscm.moduleutil.http;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class BaseModelTypeAdapter<T> extends TypeAdapter<BaseModel<T>> {
|
||||
private final Gson gson;
|
||||
private final TypeAdapter<T> dataAdapter;
|
||||
|
||||
public BaseModelTypeAdapter(Gson gson, TypeAdapter<T> dataAdapter) {
|
||||
this.gson = gson;
|
||||
this.dataAdapter = dataAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(JsonWriter out, BaseModel<T> value) throws IOException {
|
||||
out.beginObject();
|
||||
out.name("code").value(value.getCode());
|
||||
out.name("msg").value(value.getMsg());
|
||||
|
||||
out.name("data");
|
||||
if (value.getData() == null) {
|
||||
out.nullValue();
|
||||
} else {
|
||||
dataAdapter.write(out, value.getData());
|
||||
}
|
||||
|
||||
out.endObject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseModel<T> read(JsonReader reader) throws IOException {
|
||||
BaseModel<T> model = new BaseModel<>();
|
||||
reader.beginObject();
|
||||
|
||||
while (reader.hasNext()) {
|
||||
String name = reader.nextName();
|
||||
|
||||
switch (name) {
|
||||
case "code":
|
||||
model.setCode(reader.nextInt());
|
||||
break;
|
||||
case "msg":
|
||||
model.setMsg(reader.nextString());
|
||||
break;
|
||||
case "data":
|
||||
JsonToken token = reader.peek();
|
||||
Log.d("BaseModelTypeAdapter", "data token: " + token); // 打印 token 类型用于调试
|
||||
|
||||
if (token == JsonToken.NULL) {
|
||||
reader.nextNull();
|
||||
model.setData(null);
|
||||
} else if (token == JsonToken.STRING) {
|
||||
String value = reader.nextString();
|
||||
if ("null".equals(value)) {
|
||||
model.setData(null);
|
||||
} else {
|
||||
// 如果 data 是字符串类型但不是 "null",可根据业务决定是否抛异常或处理
|
||||
reader.skipValue();
|
||||
model.setData(null);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
T data = dataAdapter.read(reader);
|
||||
model.setData(data);
|
||||
} catch (Exception e) {
|
||||
// 捕获解析异常,防止崩溃
|
||||
Log.e("BaseModelTypeAdapter", "解析 data 出错", e);
|
||||
reader.skipValue();
|
||||
model.setData(null);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
reader.skipValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
reader.endObject();
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.xscm.moduleutil.http;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.TypeAdapterFactory;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class BaseModelTypeAdapterFactory implements TypeAdapterFactory {
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Override
|
||||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
|
||||
if (!BaseModel.class.isAssignableFrom(typeToken.getRawType())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取实际类型
|
||||
Type type = typeToken.getType();
|
||||
|
||||
// 确保是 ParameterizedType 类型
|
||||
if (!(type instanceof ParameterizedType)) {
|
||||
return null; // 或者抛出异常,视业务需求而定
|
||||
}
|
||||
|
||||
// 获取泛型参数类型
|
||||
Type[] actualTypeArguments = ((ParameterizedType) type).getActualTypeArguments();
|
||||
if (actualTypeArguments.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Type dataType = actualTypeArguments[0];
|
||||
TypeAdapter<?> dataAdapter = gson.getAdapter(TypeToken.get(dataType));
|
||||
|
||||
return new TypeAdapter<T>() {
|
||||
private final BaseModelTypeAdapter baseModelAdapter = new BaseModelTypeAdapter(gson, dataAdapter);
|
||||
|
||||
@Override
|
||||
public void write(JsonWriter out, T value) throws IOException {
|
||||
baseModelAdapter.write(out, (BaseModel) value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T read(JsonReader in) throws IOException {
|
||||
return (T) baseModelAdapter.read(in);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.xscm.moduleutil.http;
|
||||
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.blankj.utilcode.util.ThreadUtils;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import com.xscm.moduleutil.base.CommonAppContext;
|
||||
import com.xscm.moduleutil.event.LogOutEvent;
|
||||
import com.xscm.moduleutil.utils.DialogUtils;
|
||||
import com.xscm.moduleutil.utils.logger.Logger;
|
||||
|
||||
import org.apache.http.conn.ConnectTimeoutException;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.net.ConnectException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import io.reactivex.Observer;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2017/11/22.
|
||||
*/
|
||||
|
||||
public abstract class BaseObserver<T> implements Observer<T> {
|
||||
|
||||
private boolean showErrMsg;
|
||||
|
||||
public BaseObserver() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
public BaseObserver(boolean showErrMsg) {
|
||||
this.showErrMsg = showErrMsg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
if (e instanceof SocketTimeoutException) {
|
||||
ToastUtils.show("网络中断,请检查您的网络状态");
|
||||
} else if (e instanceof ConnectException) {
|
||||
ToastUtils.show("网络中断,请检查您的网络状态");
|
||||
} else if (e instanceof ConnectTimeoutException) {
|
||||
ToastUtils.show("网络中断,请检查您的网络状态");
|
||||
} else if (e instanceof UnknownHostException) {
|
||||
ToastUtils.show("网络中断,请检查您的网络状态");
|
||||
} else if (e instanceof IllegalStateException) {
|
||||
ToastUtils.show("解析失败");
|
||||
} else if (e instanceof APIException) {
|
||||
APIException apiException = (APIException) e;
|
||||
if (apiException.getCode() == 301) {
|
||||
EventBus.getDefault().post(new LogOutEvent());
|
||||
try {
|
||||
CommonAppContext.getInstance().clearLoginInfo();
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
if (showErrMsg && !TextUtils.isEmpty(apiException.getMessage())) {
|
||||
// ToastUtils.show(extractChinese(apiException.getMessage()));
|
||||
}
|
||||
} else if (e instanceof APIException) {
|
||||
APIException apiException = (APIException) e;
|
||||
if (showErrMsg && !TextUtils.isEmpty(apiException.getMessage())) {
|
||||
// ToastUtils.show(apiException.getMessage());
|
||||
}
|
||||
} else if (e instanceof JsonSyntaxException) {
|
||||
ToastUtils.show("网络请求错误……");
|
||||
}
|
||||
else {
|
||||
// ToastUtils.show(e.getMessage());
|
||||
// CrashReport.postCatchedException(e); //bugly收集错误信息
|
||||
}
|
||||
e.printStackTrace();
|
||||
onComplete();
|
||||
}
|
||||
|
||||
private String extractChinese(String message) {
|
||||
// 使用正则表达式提取中文字符
|
||||
StringBuilder chinesePart = new StringBuilder();
|
||||
Pattern pattern = Pattern.compile("[\\u4e00-\\u9fa5]+");
|
||||
Matcher matcher = pattern.matcher(message);
|
||||
while (matcher.find()) {
|
||||
chinesePart.append(matcher.group());
|
||||
}
|
||||
return chinesePart.toString();
|
||||
}
|
||||
|
||||
public void onErrorCode(int code) {
|
||||
Logger.e("onErrorCode", code);
|
||||
if (code == 2) {
|
||||
ThreadUtils.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DialogUtils.showNoBalance();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void onComplete() {
|
||||
Logger.i("onComplete");
|
||||
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void onNext(BaseModel<T> response) {
|
||||
// if (response.isSuccess()) {
|
||||
// onSuccess(response.getData());
|
||||
// } else if (response.isTokenExpired()) {
|
||||
// // 触发退出登录
|
||||
// handleTokenExpired();
|
||||
// } else {
|
||||
// onError(response.getMsg());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// protected abstract void onSuccess(T data);
|
||||
// protected abstract void onError(String msg);
|
||||
// protected abstract void onFail(String error);
|
||||
//
|
||||
// @SneakyThrows
|
||||
// private void handleTokenExpired() {
|
||||
// // 退出登录逻辑
|
||||
// ToastUtils.show("登录已过期,请重新登录");
|
||||
// // 示例:跳转到登录页
|
||||
// CommonAppContext.getInstance().clearLoginInfo();
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.xscm.moduleutil.http;
|
||||
|
||||
|
||||
|
||||
import com.xscm.moduleutil.base.CommonAppContext;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableSource;
|
||||
import io.reactivex.ObservableTransformer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
public class DefaultTransformer<T> implements ObservableTransformer<BaseModel<T>, T> {
|
||||
|
||||
// @Override
|
||||
// public ObservableSource<R> apply(Observable<T> upstream) {
|
||||
// return upstream.compose(SchedulerTransformer.<T>create())
|
||||
// .compose(new ErrorCheckerTransformer<T, R>());
|
||||
// }
|
||||
|
||||
@Override
|
||||
public ObservableSource<T> apply(Observable<BaseModel<T>> upstream) {
|
||||
return upstream
|
||||
.map(response -> {
|
||||
if (response.isTokenExpired()) {
|
||||
// 触发登出事件(EventBus)
|
||||
CommonAppContext.getInstance().clearLoginInfo();
|
||||
throw new APIException(-1, "登录已过期");
|
||||
}
|
||||
|
||||
if (!response.isSuccess()) {
|
||||
throw new APIException(response.getCode(), response.getMsg());
|
||||
}
|
||||
|
||||
return response.getData();
|
||||
})
|
||||
.onErrorResumeNext(throwable -> {
|
||||
// 可以在这里统一处理异常
|
||||
if (throwable instanceof APIException && ((APIException) throwable).getCode() == -1) {
|
||||
// 已经触发过登出事件
|
||||
}
|
||||
return Observable.error(throwable);
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.xscm.moduleutil.http;
|
||||
|
||||
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableSource;
|
||||
import io.reactivex.ObservableTransformer;
|
||||
import io.reactivex.functions.Function;
|
||||
|
||||
|
||||
public class ErrorCheckerTransformer<T extends BaseModel<R>, R>
|
||||
implements ObservableTransformer<T, R> {
|
||||
|
||||
@Override
|
||||
public ObservableSource<R> apply(Observable<T> upstream) {
|
||||
return upstream.map(new Function<T, R>() {
|
||||
@Override
|
||||
public R apply(T t) throws Exception {
|
||||
if (t != null) {
|
||||
int code = t.getCode();
|
||||
String msg = t.getMsg();
|
||||
if (code == 1) {//请求成功
|
||||
return t.getData();
|
||||
} else if (code == 301) {
|
||||
throw new APIException(code, msg);
|
||||
} else {
|
||||
String message = ErrorMessage.get(code);
|
||||
if (message != null) {
|
||||
throw new APIException(code, message);
|
||||
} else {
|
||||
throw new APIException(code, t.getMsg());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.xscm.moduleutil.http;
|
||||
|
||||
/**
|
||||
* 常见错误码对应的错误信息
|
||||
* Created by dmx on 16/12/1.
|
||||
*/
|
||||
|
||||
public class ErrorMessage {
|
||||
|
||||
|
||||
/**
|
||||
* 根据编码获取对应的错误信息,没有对应编码则返回null
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
public static String get(int code) {
|
||||
switch (code) {
|
||||
|
||||
case 0:
|
||||
return "失败";
|
||||
//
|
||||
case 203:
|
||||
return "系统维护中";
|
||||
|
||||
case 301:
|
||||
return "token失效";
|
||||
case 204:
|
||||
return "账号封禁";
|
||||
case 205:
|
||||
return "设备封禁";
|
||||
case 206:
|
||||
return "Ip封禁";
|
||||
|
||||
//
|
||||
// case 20:
|
||||
// return "用户不存在";
|
||||
//
|
||||
// case 21:
|
||||
// return "用户已经存在";
|
||||
//
|
||||
// case 22:
|
||||
// return "用户状态已改变,请刷新重试";
|
||||
//
|
||||
// case 100:
|
||||
// return "验证码获取太频繁";
|
||||
//
|
||||
// case 101:
|
||||
// return "获取验证码次数限制";
|
||||
//
|
||||
// case 102:
|
||||
// return "验证码错误";
|
||||
// case 103:
|
||||
// return "密码错误";
|
||||
// case 104:
|
||||
// return "第一次登录需要设置密码";
|
||||
// case 500:
|
||||
// return "接口不存在";
|
||||
//
|
||||
// case 502:
|
||||
// return "已经提交代理申请";
|
||||
//
|
||||
// case 504:
|
||||
// return "已经是雇员了";
|
||||
//// case 528:
|
||||
//// return "不在续保期内,无法续保";
|
||||
// case 661:
|
||||
// return "客户身份证重复";
|
||||
//
|
||||
// case 1000:
|
||||
// return "employeeId错误或者缺少";
|
||||
//
|
||||
//
|
||||
// case 1009:
|
||||
// return "手机号错误";
|
||||
//
|
||||
// case 1020:
|
||||
// return "参数pwd错误或者缺失";
|
||||
//
|
||||
// case 1022:
|
||||
// return "参数id错误或者缺失";
|
||||
default:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.xscm.moduleutil.http;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.lzf.easyfloat.EasyFloat;
|
||||
import com.lzf.easyfloat.enums.ShowPattern;
|
||||
import com.lzf.easyfloat.enums.SidePattern;
|
||||
import com.xscm.moduleutil.R;
|
||||
|
||||
public class FloatingWindowService extends Service {
|
||||
|
||||
private static final int NOTIFICATION_ID = 1;
|
||||
private View floatView;
|
||||
|
||||
@SuppressLint("WrongConstant")
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
||||
// Android 14(API 34)及以上需要指定具体的 foregroundServiceType
|
||||
startForeground(NOTIFICATION_ID, buildNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE);
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
// Android 10 - 13 使用通用类型
|
||||
startForeground(NOTIFICATION_ID, buildNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST);
|
||||
} else {
|
||||
startForeground(NOTIFICATION_ID, buildNotification());
|
||||
}
|
||||
// 初始化浮窗(建议使用 ApplicationContext)
|
||||
if (floatView == null) {
|
||||
EasyFloat.with(getApplicationContext())
|
||||
.setLayout(R.layout.floating_layout)
|
||||
.setTag("testFloat")
|
||||
.setShowPattern(ShowPattern.ALL_TIME)
|
||||
.setDragEnable(true)
|
||||
.setSidePattern(SidePattern.RESULT_HORIZONTAL)
|
||||
.setGravity(Gravity.END)
|
||||
.show();
|
||||
}
|
||||
|
||||
// 创建通知防止服务被杀死
|
||||
// Notification notification = new Notification.Builder(this, "channel_id")
|
||||
// .setContentTitle("浮窗运行中")
|
||||
// .setSmallIcon(R.mipmap.ic_launcher)
|
||||
// .build();
|
||||
// startForeground(NOTIFICATION_ID, notification);
|
||||
}
|
||||
private Notification buildNotification() {
|
||||
String channelId = "floating_window_service";
|
||||
String channelName = "悬浮窗服务";
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
NotificationChannel channel = new NotificationChannel(
|
||||
channelId,
|
||||
channelName,
|
||||
NotificationManager.IMPORTANCE_LOW
|
||||
);
|
||||
channel.setShowBadge(false); // 不显示角标
|
||||
channel.setSound(null, null); // 禁止声音
|
||||
channel.enableVibration(false); // 禁止震动
|
||||
|
||||
NotificationManager manager = getSystemService(NotificationManager.class);
|
||||
if (manager != null) {
|
||||
manager.createNotificationChannel(channel);
|
||||
}
|
||||
}
|
||||
|
||||
Notification.Builder builder = null;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
builder = new Notification.Builder(this, channelId)
|
||||
.setContentTitle("悬浮窗运行中")
|
||||
.setContentText("点击打开应用")
|
||||
.setSmallIcon(R.mipmap.default_avatar) // ✅ 必须有效存在
|
||||
.setAutoCancel(true)
|
||||
.setOngoing(true);
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
// 停止浮窗
|
||||
EasyFloat.dismiss("testFloat");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.xscm.moduleutil.http;
|
||||
|
||||
import android.app.Dialog;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2017/8/7.
|
||||
*/
|
||||
|
||||
public abstract class HttpCallback {
|
||||
|
||||
private Dialog mLoadingDialog;
|
||||
|
||||
public abstract void onSuccess(int code, String msg, String[] info);
|
||||
|
||||
public void onError() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录过期
|
||||
*/
|
||||
public void onLoginInvalid() {
|
||||
|
||||
}
|
||||
|
||||
public void onStart() {
|
||||
try {
|
||||
if (showLoadingDialog()) {
|
||||
if (mLoadingDialog == null) {
|
||||
mLoadingDialog = createLoadingDialog();
|
||||
}
|
||||
mLoadingDialog.show();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void onFinish() {
|
||||
if (showLoadingDialog() && mLoadingDialog != null) {
|
||||
mLoadingDialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
public Dialog createLoadingDialog() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean showLoadingDialog() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isUseLoginInvalid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.xscm.moduleutil.http;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.xscm.moduleutil.utils.GsonUtils;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Converter;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class MyConverterFactory extends Converter.Factory {
|
||||
|
||||
/**
|
||||
* Create an instance using a default {@link Gson} instance for conversion. Encoding to JSON and
|
||||
* decoding from JSON (when no charset is specified by a header) will use UTF-8.
|
||||
*/
|
||||
public static MyConverterFactory create() {
|
||||
return create(GsonUtils.getGSON());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance using {@code gson} for conversion. Encoding to JSON and
|
||||
* decoding from JSON (when no charset is specified by a header) will use UTF-8.
|
||||
*/
|
||||
@SuppressWarnings("ConstantConditions") // Guarding public API nullability.
|
||||
public static MyConverterFactory create(Gson gson) {
|
||||
if (gson == null) {
|
||||
throw new NullPointerException("gson == null");
|
||||
}
|
||||
return new MyConverterFactory(gson);
|
||||
}
|
||||
|
||||
private final Gson gson;
|
||||
|
||||
private MyConverterFactory(Gson gson) {
|
||||
this.gson = gson;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
|
||||
TypeAdapter<?> adapter = gson.getAdapter(TypeToken.get(type));
|
||||
return new RequestBodyConverter<>(gson, adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
|
||||
TypeAdapter<?> adapter = gson.getAdapter(TypeToken.get(type));
|
||||
return new ResponseBodyConverter<>(gson, adapter);
|
||||
// return new ResponseBodyConverter<>(gson, TypeToken.get(type));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.xscm.moduleutil.http;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okio.Buffer;
|
||||
import retrofit2.Converter;
|
||||
|
||||
public class RequestBodyConverter<T> implements Converter<T, RequestBody> {
|
||||
|
||||
private static final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=UTF-8");
|
||||
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
|
||||
private final Gson gson;
|
||||
private final TypeAdapter<T> adapter;
|
||||
|
||||
RequestBodyConverter(Gson gson, TypeAdapter<T> adapter) {
|
||||
this.gson = gson;
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
@Override public RequestBody convert(@NonNull T value) throws IOException {
|
||||
Buffer buffer = new Buffer();
|
||||
Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
|
||||
JsonWriter jsonWriter = gson.newJsonWriter(writer);
|
||||
adapter.write(jsonWriter, value);
|
||||
jsonWriter.close();
|
||||
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.xscm.moduleutil.http;
|
||||
|
||||
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.xscm.moduleutil.utils.GsonUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import io.reactivex.annotations.NonNull;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Converter;
|
||||
|
||||
public class ResponseBodyConverter<T> implements Converter<ResponseBody, T> {
|
||||
|
||||
private final Gson gson;
|
||||
private final TypeAdapter<T> adapter;
|
||||
|
||||
ResponseBodyConverter(Gson gson, TypeAdapter<T> adapter) {
|
||||
this.gson = gson;
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T convert(@NonNull ResponseBody value) throws IOException {
|
||||
String json = value.string();
|
||||
BaseModel obj = GsonUtils.GsonToBean(json, BaseModel.class);
|
||||
if (obj.getCode() != 1) {
|
||||
String info = obj.getMsg();
|
||||
if ("当前余额不足".equals(info)) {
|
||||
value.close();
|
||||
return adapter.fromJson(json);
|
||||
} else {
|
||||
if(!info.contains("更新失败")) {
|
||||
ToastUtils.showShort(info);
|
||||
}
|
||||
// throw new APIException(obj.getCode(), info);
|
||||
}
|
||||
}
|
||||
value.close();
|
||||
return adapter.fromJson(json);
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,25 @@
|
||||
package com.xscm.moduleutil.http;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableSource;
|
||||
import io.reactivex.ObservableTransformer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* 默认线程调度
|
||||
* Created by dmx on 16/12/1.
|
||||
*/
|
||||
|
||||
public class SchedulerTransformer<T> implements ObservableTransformer<T, T> {
|
||||
|
||||
public static <T> SchedulerTransformer<T> create() {
|
||||
return new SchedulerTransformer<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObservableSource<T> apply(Observable<T> upstream) {
|
||||
return upstream.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user