182 lines
7.4 KiB
Java
182 lines
7.4 KiB
Java
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<IMLoginModel> callback) {
|
|
API.get().otoApi(mContext).loginByManager(phoneNum, pwd, uuid, "", "Android")
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(new Consumer<ResponseModel<IMLoginModel>>() {
|
|
@Override
|
|
public void accept(ResponseModel<IMLoginModel> 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<UserBean> callback) {
|
|
API.get().otoApi(mContext)
|
|
.getBaseInfos(isLogin ? 1 : 0)
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(new Consumer<ResponseModel<UserBean>>() {
|
|
@Override
|
|
public void accept(ResponseModel<UserBean> liveGiftBeanResponseModel) throws Exception {
|
|
if (callback != null) {
|
|
callback.onSuccess(liveGiftBeanResponseModel.getData().getInfo());
|
|
}
|
|
}
|
|
}, new Consumer<Throwable>() {
|
|
@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<JoinAnchorBean> callback) {
|
|
API.get().otoApi(mContext)
|
|
.getRandJoinAnchor()
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(new Consumer<ResponseModel<List<JoinAnchorBean>>>() {
|
|
@Override
|
|
public void accept(ResponseModel<List<JoinAnchorBean>> model) throws Exception {
|
|
if (callback != null) {
|
|
callback.onSuccess(model.getData().getInfo().get(0));
|
|
}
|
|
}
|
|
}, new Consumer<Throwable>() {
|
|
@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<String> callback) {
|
|
API.get().otoApi(mContext)
|
|
.getCustomerService()
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(new Consumer<ResponseModel<List<String>>>() {
|
|
@Override
|
|
public void accept(ResponseModel<List<String>> model) throws Exception {
|
|
if (callback != null) {
|
|
callback.onSuccess(model.getData().getInfo().get(0));
|
|
}
|
|
}
|
|
}, new Consumer<Throwable>() {
|
|
@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<IMLoginModel> 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<ResponseModel<IMLoginModel>>() {
|
|
@Override
|
|
public void accept(ResponseModel<IMLoginModel> model) throws Exception {
|
|
if (callback != null) {
|
|
callback.onSuccess(model.getData().getInfo());
|
|
}
|
|
}
|
|
}, new Consumer<Throwable>() {
|
|
@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();
|
|
}
|
|
|
|
|
|
}
|