package com.shayu.onetoone.manager; import android.content.Context; import android.util.Log; import com.shayu.onetoone.bean.JoinAnchorBean; import com.shayu.onetoone.bean.UserBean; import com.shayu.onetoone.network.API; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.bean.BaseModel; import com.yunbao.common.bean.HttpCallbackModel; import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.http.ResponseModel; import com.yunbao.common.http.base.HttpCallback; import com.yunbao.common.utils.MD5Util; import java.util.List; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.functions.Consumer; import io.reactivex.schedulers.Schedulers; /** * 网络管理类 使用参考{@link com.yunbao.common.http.live.LiveNetManager} */ public class OTONetManager { private static final String TAG = "网络请求"; private static final String SALT = "76576076c1f5f657b634e966c8836a06"; private static final String DEVICE = "android"; private Context mContext; private static OTONetManager mInstance; private OTONetManager(Context context) { this.mContext = context; } public static OTONetManager getInstance(Context context) { if (mInstance == null) { mInstance = new OTONetManager(context); } return mInstance; } /** * 手机号登录 */ public void login(String phoneNum, String pwd, String uuid, HttpCallback callback) { API.get().otoApi(mContext).loginByManager(phoneNum, pwd, uuid, "", "Android") .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer>() { @Override public void accept(ResponseModel imLoginModelResponseModel) throws Exception { if (callback != null) { IMLoginModel model = imLoginModelResponseModel.getData().getInfo(); callback.onSuccess(model); } } }, throwable -> { Log.e(TAG, "accept: ", throwable); if (callback != null) { callback.onError(throwable.getMessage()); } }).isDisposed(); } public void getBaseInfos(boolean isLogin, HttpCallback callback) { API.get().otoApi(mContext) .getBaseInfos(isLogin ? 1 : 0) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer>() { @Override public void accept(ResponseModel liveGiftBeanResponseModel) throws Exception { if (callback != null) { callback.onSuccess(liveGiftBeanResponseModel.getData().getInfo()); } } }, new Consumer() { @Override public void accept(Throwable throwable) throws Exception { Log.e(TAG, "accept: ", throwable); if (callback != null) { callback.onError(mContext.getString(com.yunbao.common.R.string.net_error)); } } }).isDisposed(); } public void getRandJoinAnchor(HttpCallback callback) { API.get().otoApi(mContext) .getRandJoinAnchor() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer>>() { @Override public void accept(ResponseModel> model) throws Exception { if (callback != null) { callback.onSuccess(model.getData().getInfo().get(0)); } } }, new Consumer() { @Override public void accept(Throwable throwable) throws Exception { Log.e(TAG, "accept: ", throwable); if (callback != null) { callback.onError(mContext.getString(com.yunbao.common.R.string.net_error)); } } }).isDisposed(); } public void getCustomerService(HttpCallback callback) { API.get().otoApi(mContext) .getCustomerService() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer>>() { @Override public void accept(ResponseModel> model) throws Exception { if (callback != null) { callback.onSuccess(model.getData().getInfo().get(0)); } } }, new Consumer() { @Override public void accept(Throwable throwable) throws Exception { Log.e(TAG, "accept: ", throwable); if (callback != null) { callback.onError(mContext.getString(com.yunbao.common.R.string.net_error)); } } }).isDisposed(); } public void userLoginByThird(String uid, String openId, String promCode, String uuid, String nickName, String avatar, String type, HttpCallback callback) { String sign = MD5Util.getMD5("openid=" + openId + "&" + SALT); API.get().otoApi(mContext) .userLoginByThird(uid, openId, promCode, uuid, nickName, avatar, CommonAppConfig.IS_GOOGLE_PLAY ? "1" : "3", DEVICE, sign, "Android", type, "" ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer>() { @Override public void accept(ResponseModel model) throws Exception { if (callback != null) { callback.onSuccess(model.getData().getInfo()); } } }, new Consumer() { @Override public void accept(Throwable throwable) throws Exception { Log.e(TAG, "accept: ", throwable); if (callback != null) { callback.onError(mContext.getString(com.yunbao.common.R.string.net_error)); } } }).isDisposed(); } }