token问题,喇叭

This commit is contained in:
18401019693 2022-08-02 10:27:46 +08:00
parent ab3141f5f5
commit e5cf353597
12 changed files with 223 additions and 26 deletions

View File

@ -169,6 +169,7 @@ public class Constants {
public static final String SOCKET_PRANKTURNTABLE = "prankTurntable";//整蛊消息 public static final String SOCKET_PRANKTURNTABLE = "prankTurntable";//整蛊消息
public static final String SOCKET_USEHOTCARD = "UseHotCard";//热度卡消息 public static final String SOCKET_USEHOTCARD = "UseHotCard";//热度卡消息
public static final String LOVE_CHECK = "LoveCheck";//热度卡消息 public static final String LOVE_CHECK = "LoveCheck";//热度卡消息
public static final String TRUMPET_NOTIFY = "TrumpetNotify";//全栈喇叭
public static final int SOCKET_WHAT_CONN = 0; public static final int SOCKET_WHAT_CONN = 0;
public static final int SOCKET_WHAT_DISCONN = 2; public static final int SOCKET_WHAT_DISCONN = 2;

View File

@ -0,0 +1,81 @@
package com.yunbao.common.bean;
import com.google.gson.annotations.SerializedName;
public class MsgModel extends BaseModel {
/**
* _method_ : TrumpetNotify
* user_id : 97809
* user_name : 严肃苏苏
* noble_id : 5
* trumpet_msg : 估计快了可能吧v
* anchor_id : 97714
*/
@SerializedName("_method_")
private String method = "";
@SerializedName("user_id")
private String userId = "";
@SerializedName("user_name")
private String userName = "";
@SerializedName("noble_id")
private long nobleId = 0;
@SerializedName("trumpet_msg")
private String trumpetMsg = "";
@SerializedName("anchor_id")
private String anchorId = "";
public String getMethod() {
return method;
}
public MsgModel setMethod(String method) {
this.method = method;
return this;
}
public String getUserId() {
return userId;
}
public MsgModel setUserId(String userId) {
this.userId = userId;
return this;
}
public String getUserName() {
return userName;
}
public MsgModel setUserName(String userName) {
this.userName = userName;
return this;
}
public long getNobleId() {
return nobleId;
}
public MsgModel setNobleId(long nobleId) {
this.nobleId = nobleId;
return this;
}
public String getTrumpetMsg() {
return trumpetMsg;
}
public MsgModel setTrumpetMsg(String trumpetMsg) {
this.trumpetMsg = trumpetMsg;
return this;
}
public String getAnchorId() {
return anchorId;
}
public MsgModel setAnchorId(String anchorId) {
this.anchorId = anchorId;
return this;
}
}

View File

@ -0,0 +1,49 @@
package com.yunbao.common.bean;
import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
import java.util.List;
public class SocketModel extends BaseModel {
/**
* retcode : 000000
* retmsg : OK
* msg : [{"_method_":"TrumpetNotify","user_id":"97809","user_name":"严肃苏苏","noble_id":5,"trumpet_msg":"估计快了可能吧v","anchor_id":"97714"}]
*/
@SerializedName("retcode")
private String retcode = "";
@SerializedName("retmsg")
private String retmsg = "";
@SerializedName("msg")
private List<MsgModel> msg = new ArrayList<>();
public String getRetcode() {
return retcode;
}
public SocketModel setRetcode(String retcode) {
this.retcode = retcode;
return this;
}
public String getRetmsg() {
return retmsg;
}
public SocketModel setRetmsg(String retmsg) {
this.retmsg = retmsg;
return this;
}
public List<MsgModel> getMsg() {
return msg;
}
public SocketModel setMsg(List<MsgModel> msg) {
this.msg = msg;
return this;
}
}

View File

@ -47,9 +47,13 @@ public class API extends BaseApi {
Gson gson = new GsonBuilder() Gson gson = new GsonBuilder()
.registerTypeAdapter(Date.class, new DateTypeAdapter()) .registerTypeAdapter(Date.class, new DateTypeAdapter())
.create(); .create();
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor("http");
loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder builder = new OkHttpClient() OkHttpClient.Builder builder = new OkHttpClient()
.newBuilder() .newBuilder()
.addInterceptor(initQuery(CommonAppContext.sInstance.getApplicationContext())); .addInterceptor(initQuery(CommonAppContext.sInstance.getApplicationContext()))
.addInterceptor(loggingInterceptor);
pdLiveApi = create(builder.build(), pdLiveApi = create(builder.build(),
GsonConverterFactory.create(gson), RxJava2CallAdapterFactory.create(), CommonAppConfig.HOST, PDLiveApi.class); GsonConverterFactory.create(gson), RxJava2CallAdapterFactory.create(), CommonAppConfig.HOST, PDLiveApi.class);
} }

View File

@ -1,13 +1,17 @@
package com.yunbao.common.http; package com.yunbao.common.http;
import com.yunbao.common.bean.BaseModel;
import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.IMLoginModel;
import com.yunbao.common.bean.NobleTrumpetModel; import com.yunbao.common.bean.NobleTrumpetModel;
import java.util.List;
import io.reactivex.Observable; import io.reactivex.Observable;
import retrofit2.http.Field; import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded; import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET; import retrofit2.http.GET;
import retrofit2.http.POST; import retrofit2.http.POST;
import retrofit2.http.Query;
/** /**
* PDLive网络接口访问 * PDLive网络接口访问
@ -40,4 +44,16 @@ public interface PDLiveApi {
*/ */
@GET("/api/public/?service=Noble.getNobleTrumpetNum") @GET("/api/public/?service=Noble.getNobleTrumpetNum")
Observable<ResponseModel<NobleTrumpetModel>> getNobleTrumpetNum(); Observable<ResponseModel<NobleTrumpetModel>> getNobleTrumpetNum();
/**
* 贵族使用喇叭
*
* @param trumpetMsg 喇叭内容
* @param anchorid 主播id
* @return
*/
@GET("/api/public/?service=Noble.nobleUseTrumpet")
Observable<ResponseModel<List<BaseModel>>> nobleUseTrumpet(
@Query("trumpet_msg") String trumpetMsg,
@Query("anchor_id") String anchorid);
} }

View File

@ -1,11 +1,14 @@
package com.yunbao.common.http.live; package com.yunbao.common.http.live;
import android.app.Activity; import android.content.Context;
import com.yunbao.common.bean.BaseModel;
import com.yunbao.common.bean.NobleTrumpetModel; import com.yunbao.common.bean.NobleTrumpetModel;
import com.yunbao.common.http.API; import com.yunbao.common.http.API;
import com.yunbao.common.http.base.HttpCallback; import com.yunbao.common.http.base.HttpCallback;
import java.util.List;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
@ -13,10 +16,10 @@ import io.reactivex.schedulers.Schedulers;
* 直播网络请求整合 * 直播网络请求整合
*/ */
public class LiveNetManager { public class LiveNetManager {
private Activity mContext; private Context mContext;
private static LiveNetManager manager; private static LiveNetManager manager;
public LiveNetManager(Activity context) { public LiveNetManager(Context context) {
this.mContext = context; this.mContext = context;
} }
@ -25,7 +28,7 @@ public class LiveNetManager {
* *
* @return * @return
*/ */
public static LiveNetManager get(Activity context) { public static LiveNetManager get(Context context) {
if (null == manager) { if (null == manager) {
manager = new LiveNetManager(context); manager = new LiveNetManager(context);
} }
@ -49,4 +52,29 @@ public class LiveNetManager {
callback.onError(throwable.getMessage()); callback.onError(throwable.getMessage());
}).isDisposed(); }).isDisposed();
} }
/**
* 贵族使用喇叭
*
* @param trumpetMsg 喇叭内容
* @param anchorid 主播id
* @param callback 回调
*/
public void nobleUseTrumpet(String trumpetMsg, String anchorid, HttpCallback<List<BaseModel>> callback) {
API.get().pdLiveApi(mContext).nobleUseTrumpet(trumpetMsg, anchorid)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(baseModelResponseModel -> {
if (baseModelResponseModel.getData().getCode() == 0 && callback != null) {
callback.onSuccess(baseModelResponseModel.getData().getInfo());
} else {
if (callback != null)
callback.onError("发送失败");
}
}, throwable -> {
if (callback != null)
callback.onError(throwable.getMessage());
//java.lang.IllegalStateException: Fragment LiveInputDialogFragment{229db51} (f38ce923-7a48-4c64-925a-bed0edfb7fa7)} not attached to a context.
}).isDisposed();
}
} }

View File

@ -82,6 +82,8 @@ public class IMLoginManager extends BaseCacheManager {
if (null == userInfo) { if (null == userInfo) {
userInfo = new Gson().fromJson( userInfo = new Gson().fromJson(
getString(KEY_USER_INFO), IMLoginModel.class); getString(KEY_USER_INFO), IMLoginModel.class);
if (userInfo != null)
token = userInfo.getToken();
} }
return userInfo; return userInfo;
} }
@ -119,7 +121,9 @@ public class IMLoginManager extends BaseCacheManager {
*/ */
public void upDataUserInfo(@NonNull String json) { public void upDataUserInfo(@NonNull String json) {
userInfo = new Gson().fromJson(json, IMLoginModel.class); userInfo = new Gson().fromJson(json, IMLoginModel.class);
if (!TextUtils.isEmpty(token)) {
userInfo.setToken(token); userInfo.setToken(token);
}
put(KEY_USER_INFO, new Gson().toJson(userInfo)); put(KEY_USER_INFO, new Gson().toJson(userInfo));
//兼容老模块(之后要把用户维护的类更换掉 //兼容老模块(之后要把用户维护的类更换掉
SpUtil.getInstance().setStringValue(SpUtil.USER_INFO, new Gson().toJson(userInfo)); SpUtil.getInstance().setStringValue(SpUtil.USER_INFO, new Gson().toJson(userInfo));
@ -209,7 +213,9 @@ public class IMLoginManager extends BaseCacheManager {
public void onSuccess(int code, String msg, String[] info) { public void onSuccess(int code, String msg, String[] info) {
if (code == 0 && info.length > 0) { if (code == 0 && info.length > 0) {
userInfo = new Gson().fromJson(info[0], IMLoginModel.class); userInfo = new Gson().fromJson(info[0], IMLoginModel.class);
if (!TextUtils.isEmpty(uidAndToken[1])) {
userInfo.setToken(uidAndToken[1]); userInfo.setToken(uidAndToken[1]);
}
EventBus.getDefault().post(new DataUserInfoEvent().setUpDataSuccess(true)); EventBus.getDefault().post(new DataUserInfoEvent().setUpDataSuccess(true));
} else { } else {
EventBus.getDefault().post(new DataUserInfoEvent().setUpDataSuccess(false)); EventBus.getDefault().post(new DataUserInfoEvent().setUpDataSuccess(false));

View File

@ -864,4 +864,5 @@
<string name="site_wide_news_hint2">开通贵族国王、皇帝、超级皇帝免费获得</string> <string name="site_wide_news_hint2">开通贵族国王、皇帝、超级皇帝免费获得</string>
<string name="back">返回</string> <string name="back">返回</string>
<string name="go_nobility">前往贵族</string> <string name="go_nobility">前往贵族</string>
<string name="use_successfully">使用成功</string>
</resources> </resources>

View File

@ -869,6 +869,7 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(Constants.LIVE_DANMU_PRICE, mDanmuPrice); bundle.putString(Constants.LIVE_DANMU_PRICE, mDanmuPrice);
bundle.putString(Constants.COIN_NAME, mCoinName); bundle.putString(Constants.COIN_NAME, mCoinName);
bundle.putString(Constants.LIVE_UID, mLiveUid);
fragment.setArguments(bundle); fragment.setArguments(bundle);
fragment.show(getSupportFragmentManager(), "LiveInputDialogFragment"); fragment.show(getSupportFragmentManager(), "LiveInputDialogFragment");
} }

View File

@ -26,6 +26,7 @@ import android.widget.TextView;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import com.yunbao.common.Constants; import com.yunbao.common.Constants;
import com.yunbao.common.bean.BaseModel;
import com.yunbao.common.bean.NobleTrumpetModel; import com.yunbao.common.bean.NobleTrumpetModel;
import com.yunbao.common.custom.MyRadioButton; import com.yunbao.common.custom.MyRadioButton;
import com.yunbao.common.dialog.AbsDialogFragment; import com.yunbao.common.dialog.AbsDialogFragment;
@ -36,7 +37,6 @@ import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.utils.WordUtil; import com.yunbao.common.utils.WordUtil;
import com.yunbao.live.R; import com.yunbao.live.R;
import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.activity.LiveActivity;
import com.yunbao.live.http.LiveHttpUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -66,6 +66,7 @@ public class LiveInputDialogFragment extends AbsDialogFragment implements View.O
private long nobleId;//贵族等级 private long nobleId;//贵族等级
private long trumpetNum;//喇叭数量 private long trumpetNum;//喇叭数量
private String mLiveUid;//主播ID
@Override @Override
@ -154,6 +155,7 @@ public class LiveInputDialogFragment extends AbsDialogFragment implements View.O
} }
String danmuPrice = bundle.getString(Constants.LIVE_DANMU_PRICE); String danmuPrice = bundle.getString(Constants.LIVE_DANMU_PRICE);
String coinName = bundle.getString(Constants.COIN_NAME); String coinName = bundle.getString(Constants.COIN_NAME);
mLiveUid = bundle.getString(Constants.LIVE_UID);
mHint1 = WordUtil.getString(R.string.live_open_alba) + danmuPrice + coinName + "/" + WordUtil.getString(R.string.live_tiao); mHint1 = WordUtil.getString(R.string.live_open_alba) + danmuPrice + coinName + "/" + WordUtil.getString(R.string.live_tiao);
mHint2 = WordUtil.getString(R.string.live_say_something); mHint2 = WordUtil.getString(R.string.live_say_something);
mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@ -187,8 +189,19 @@ public class LiveInputDialogFragment extends AbsDialogFragment implements View.O
switch (messageType) { switch (messageType) {
case WORLDHORN: case WORLDHORN:
trumpetMsg = content; trumpetMsg = content;
netHandler.post(nobleUseTrumpetRunnable); LiveNetManager.get(getContext())
.nobleUseTrumpet(trumpetMsg, mLiveUid, new HttpCallback<List<BaseModel>>() {
@Override
public void onSuccess(List<BaseModel> data) {
dismiss(); dismiss();
ToastUtil.show(getResources().getString(R.string.use_successfully));
}
@Override
public void onError(String error) {
ToastUtil.show(error);
}
});
break; break;
case POPUPSCREEN: case POPUPSCREEN:
((LiveActivity) mContext).sendDanmuMessage(content); ((LiveActivity) mContext).sendDanmuMessage(content);
@ -221,7 +234,7 @@ public class LiveInputDialogFragment extends AbsDialogFragment implements View.O
public void onCheckedChanged(RadioGroup group, int checkedId) { public void onCheckedChanged(RadioGroup group, int checkedId) {
changeCheckState(checkedId); changeCheckState(checkedId);
if (checkedId == R.id.btn_2) { if (checkedId == R.id.btn_2) {
if (nobleId < 5) { if (nobleId < 5 || trumpetNum < 1) {
imm.hideSoftInputFromWindow(mInput.getWindowToken(), 0); imm.hideSoftInputFromWindow(mInput.getWindowToken(), 0);
HighNobilityDialog fragment = new HighNobilityDialog(); HighNobilityDialog fragment = new HighNobilityDialog();
fragment.show(((FragmentActivity) mContext).getSupportFragmentManager(), "HighNobilityDialog"); fragment.show(((FragmentActivity) mContext).getSupportFragmentManager(), "HighNobilityDialog");
@ -319,16 +332,5 @@ public class LiveInputDialogFragment extends AbsDialogFragment implements View.O
}); });
} }
}; };
//发送全局喇叭
private Runnable nobleUseTrumpetRunnable = new Runnable() {
@Override
public void run() {
LiveHttpUtil.nobleUseTrumpet(trumpetMsg, new com.yunbao.common.http.HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
} }
});
}
};
}

View File

@ -889,9 +889,10 @@ public class LiveHttpUtil {
/** /**
* 获取用户贵族喇叭的数量 * 获取用户贵族喇叭的数量
*/ */
public static void nobleUseTrumpet(String trumpet_msg,HttpCallback callback) { public static void nobleUseTrumpet(String trumpet_msg,String anchor_id,HttpCallback callback) {
HttpClient.getInstance().get("Noble.nobleUseTrumpet", "nobleUseTrumpet") HttpClient.getInstance().get("Noble.nobleUseTrumpet", "nobleUseTrumpet")
.params("trumpet_msg", trumpet_msg) .params("", trumpet_msg)
.params("", anchor_id)
.execute(callback); .execute(callback);
} }
} }

View File

@ -9,10 +9,12 @@ import android.widget.LinearLayout;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.GsonUtils;
import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.CommonAppContext; import com.yunbao.common.CommonAppContext;
import com.yunbao.common.Constants; import com.yunbao.common.Constants;
import com.yunbao.common.bean.FansMedalBean; import com.yunbao.common.bean.FansMedalBean;
import com.yunbao.common.bean.SocketModel;
import com.yunbao.common.bean.UserBean; import com.yunbao.common.bean.UserBean;
import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.http.HttpClient; import com.yunbao.common.http.HttpClient;
@ -437,6 +439,11 @@ public class SocketRyClient {
chatBean3.setHot_num(jsonObject3.getString("gift_name")); chatBean3.setHot_num(jsonObject3.getString("gift_name"));
mListener.onChat(chatBean3, 1); mListener.onChat(chatBean3, 1);
break; break;
case Constants.TRUMPET_NOTIFY://全站喇叭
SocketModel model = GsonUtils.fromJson(socketMsg, SocketModel.class);
Log.e(Constants.TRUMPET_NOTIFY,model.getMsg().get(0).getTrumpetMsg());
Log.e(Constants.TRUMPET_NOTIFY,model.getMsg().get(0).getUserName());
break;
} }
} }