TOKEN失效

This commit is contained in:
18401019693 2022-09-29 16:26:10 +08:00
parent 1f0a95ad0f
commit b7129bcbfa
8 changed files with 99 additions and 40 deletions

View File

@ -163,7 +163,7 @@ dependencies {
api 'cn.rongcloud.sdk:im_kit:5.2.5' // UI api 'cn.rongcloud.sdk:im_kit:5.2.5' // UI
// //
api 'cn.rongcloud.sdk:sight:5.2.5' api 'cn.rongcloud.sdk:sight:5.2.5'
api 'com.facebook.android:facebook-login:8.2.0' api 'com.facebook.android:facebook-android-sdk:11.3.0'
implementation 'com.facebook.android:facebook-android-sdk:[8,9)' implementation 'com.facebook.android:facebook-android-sdk:[8,9)'
api('com.twitter.sdk.android:twitter-core:3.1.1@aar') { api('com.twitter.sdk.android:twitter-core:3.1.1@aar') {

View File

@ -1,6 +1,7 @@
package com.yunbao.common.http; package com.yunbao.common.http;
import android.content.Context; import android.content.Context;
import android.text.TextUtils;
import com.lzy.okgo.OkGo; import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheMode; import com.lzy.okgo.cache.CacheMode;
@ -12,6 +13,7 @@ import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.CommonAppContext; import com.yunbao.common.CommonAppContext;
import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.IMLoginModel;
import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.utils.RouteUtil;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -72,9 +74,13 @@ public class HttpClient {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
if (IMLoginManager.isLogin(context)) { if (IMLoginManager.isLogin(context)) {
IMLoginModel model = IMLoginManager.get(context).getUserInfo(); IMLoginModel model = IMLoginManager.get(context).getUserInfo();
if (TextUtils.isEmpty(model.getToken())) {
RouteUtil.forwardEntry();
} else {
map.put("uid", String.valueOf(model.getId())); map.put("uid", String.valueOf(model.getId()));
map.put("token", model.getToken()); map.put("token", model.getToken());
} }
}
return OkGo.<JsonBean>get(mUrl + serviceName) return OkGo.<JsonBean>get(mUrl + serviceName)
.params(map, true) .params(map, true)
.headers("Connection", "keep-alive") .headers("Connection", "keep-alive")
@ -90,9 +96,14 @@ public class HttpClient {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
if (IMLoginManager.isLogin(context)) { if (IMLoginManager.isLogin(context)) {
IMLoginModel model = IMLoginManager.get(context).getUserInfo(); IMLoginModel model = IMLoginManager.get(context).getUserInfo();
if (TextUtils.isEmpty(model.getToken())) {
RouteUtil.forwardEntry();
} else {
map.put("uid", String.valueOf(model.getId())); map.put("uid", String.valueOf(model.getId()));
map.put("token", model.getToken()); map.put("token", model.getToken());
} }
}
return OkGo.<JsonBean>get(url + serviceName) return OkGo.<JsonBean>get(url + serviceName)
.headers("Connection", "keep-alive") .headers("Connection", "keep-alive")
.params(map, true) .params(map, true)
@ -105,10 +116,15 @@ public class HttpClient {
//拼装基本信息 //拼装基本信息
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
if (IMLoginManager.isLogin(context)) { if (IMLoginManager.isLogin(context)) {
IMLoginModel model = IMLoginManager.get(context).getUserInfo(); IMLoginModel model = IMLoginManager.get(context).getUserInfo();
if (TextUtils.isEmpty(model.getToken())) {
RouteUtil.forwardEntry();
} else {
map.put("uid", String.valueOf(model.getId())); map.put("uid", String.valueOf(model.getId()));
map.put("token", model.getToken()); map.put("token", model.getToken());
} }
}
return OkGo.<JsonBean>post(mUrl + serviceName) return OkGo.<JsonBean>post(mUrl + serviceName)
.headers("Connection", "keep-alive") .headers("Connection", "keep-alive")
.params(map, true) .params(map, true)

View File

@ -1,9 +1,11 @@
package com.yunbao.common.http.base; package com.yunbao.common.http.base;
import android.content.Context; import android.content.Context;
import android.text.TextUtils;
import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.IMLoginModel;
import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.utils.RouteUtil;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
import okhttp3.Request; import okhttp3.Request;
@ -11,13 +13,14 @@ import okhttp3.Request;
public class GetRequestParams implements IRequestParam { public class GetRequestParams implements IRequestParam {
/** /**
* 构建Request * 构建Request
*
* @param isNeedUid 是否需要添加用户uid参数 * @param isNeedUid 是否需要添加用户uid参数
* @param request * @param request
* @param context * @param context
* @return * @return
*/ */
@Override @Override
public Request getRequest(boolean isNeedUid,Request request, Context context) { public Request getRequest(boolean isNeedUid, Request request, Context context) {
//添加公共参数 //添加公共参数
if (IMLoginManager.isLogin(context)) { if (IMLoginManager.isLogin(context)) {
IMLoginModel model = IMLoginManager.get(context).getUserInfo(); IMLoginModel model = IMLoginManager.get(context).getUserInfo();
@ -26,10 +29,16 @@ public class GetRequestParams implements IRequestParam {
.addQueryParameter("token", model.getToken()) .addQueryParameter("token", model.getToken())
.build();*/ .build();*/
HttpUrl.Builder builder = request.url().newBuilder(); HttpUrl.Builder builder = request.url().newBuilder();
if(isNeedUid) { if (TextUtils.isEmpty(model.getToken())) {
RouteUtil.forwardEntry();
} else {
if (isNeedUid) {
builder.addQueryParameter("uid", String.valueOf(model.getId())); builder.addQueryParameter("uid", String.valueOf(model.getId()));
} }
builder.addQueryParameter("token", model.getToken()); builder.addQueryParameter("token", model.getToken());
}
return request.newBuilder().url(builder.build()).build(); return request.newBuilder().url(builder.build()).build();
} }

View File

@ -1,16 +1,18 @@
package com.yunbao.common.http.base; package com.yunbao.common.http.base;
import android.content.Context; import android.content.Context;
import android.text.TextUtils;
import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.IMLoginModel;
import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.utils.RouteUtil;
import okhttp3.FormBody; import okhttp3.FormBody;
import okhttp3.Request; import okhttp3.Request;
public class PostRequestParams implements IRequestParam { public class PostRequestParams implements IRequestParam {
@Override @Override
public Request getRequest(boolean isNeedUid,Request request, Context context) { public Request getRequest(boolean isNeedUid, Request request, Context context) {
if (request.body() instanceof FormBody) { if (request.body() instanceof FormBody) {
FormBody.Builder bodyBuilder = new FormBody.Builder(); FormBody.Builder bodyBuilder = new FormBody.Builder();
@ -21,15 +23,18 @@ public class PostRequestParams implements IRequestParam {
} }
if (IMLoginManager.isLogin(context)) { if (IMLoginManager.isLogin(context)) {
IMLoginModel model = IMLoginManager.get(context).getUserInfo(); IMLoginModel model = IMLoginManager.get(context).getUserInfo();
if (TextUtils.isEmpty(model.getToken())) {
RouteUtil.forwardEntry();
} else {
/* formBody = bodyBuilder.addEncoded("uid", String.valueOf(model.getId())) /* formBody = bodyBuilder.addEncoded("uid", String.valueOf(model.getId()))
.addEncoded("token", model.getToken()) .addEncoded("token", model.getToken())
.build();*/ .build();*/
if (isNeedUid){ if (isNeedUid) {
bodyBuilder.addEncoded("uid", String.valueOf(model.getId())); bodyBuilder.addEncoded("uid", String.valueOf(model.getId()));
} }
bodyBuilder.addEncoded("token", model.getToken()); bodyBuilder.addEncoded("token", model.getToken());
formBody=bodyBuilder.build(); formBody = bodyBuilder.build();
}
} }
request = request.newBuilder().post(formBody).build(); request = request.newBuilder().post(formBody).build();
} }

View File

@ -24,7 +24,8 @@ public class RouteUtil {
public static final String PATH_MYWEBVIEWACTIVTITY = "/main/MyWebViewActivity"; public static final String PATH_MYWEBVIEWACTIVTITY = "/main/MyWebViewActivity";
public static final String PATH_ZHUANGBANACTIVITY = "/main/ZhuangBanActivity"; public static final String PATH_ZHUANGBANACTIVITY = "/main/ZhuangBanActivity";
public static final String PATH_FACEBOOKACTIVITY = "/baidu/FacebookLoginActivity"; public static final String PATH_FACEBOOKACTIVITY = "/baidu/FacebookLoginActivity";
public static final String PATH_MAIN= "/main/MainActivity"; public static final String PATH_MAIN = "/main/MainActivity";
public static final String PATH_ENTRY = "/main/EntryActivity";
/** /**
* 启动页 * 启动页
@ -44,6 +45,17 @@ public class RouteUtil {
.navigation(); .navigation();
} }
/**
* toke失效重新登录
*/
public static void forwardEntry() {
ARouter.getInstance().build(PATH_ENTRY)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.withBoolean("forwardEntry", true)
.navigation();
}
/** /**
* 跳转到个人主页 * 跳转到个人主页
* intoIndex 2=个人中心进入 1=单聊进入 0=其他 * intoIndex 2=个人中心进入 1=单聊进入 0=其他
@ -68,7 +80,7 @@ public class RouteUtil {
if (!"".equals(Constants.chatActionUrl)) { if (!"".equals(Constants.chatActionUrl)) {
url = Constants.chatActionUrl; url = Constants.chatActionUrl;
} }
Constants.myUrl = url + "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken()+"&t=" + System.currentTimeMillis(); Constants.myUrl = url + "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&t=" + System.currentTimeMillis();
ARouter.getInstance().build(PATH_MYWEBVIEWACTIVTITY) ARouter.getInstance().build(PATH_MYWEBVIEWACTIVTITY)
.navigation(); .navigation();
} }
@ -79,7 +91,7 @@ public class RouteUtil {
public static void forwardZhuangBanActivity(String url) { public static void forwardZhuangBanActivity(String url) {
Constants.myPackageUrl = url; Constants.myPackageUrl = url;
ARouter.getInstance().build(PATH_ZHUANGBANACTIVITY) ARouter.getInstance().build(PATH_ZHUANGBANACTIVITY)
.withString("title","") .withString("title", "")
.navigation(); .navigation();
} }

View File

@ -880,4 +880,24 @@ Limited ride And limited avatar frame</string>
<string name="system_notice">Notice</string> <string name="system_notice">Notice</string>
<string name="online_service">Online Service</string> <string name="online_service">Online Service</string>
<string name="popular_tickets">Hot Ticket</string> <string name="popular_tickets">Hot Ticket</string>
<string name="tell_the_world">Tell the world</string>
<string name="better_emperor_hint">Tell the world! %s recommends anchor %s to everyone!</string>
<string name="emperor_hint">Tell the world! %s recommends the anchor %s to everyone, and the splendid glance is amazing</string>
<string name="try_again_later">Failed to load data, please try again later</string>
<string name="open_noble2">open</string>
<string name="enough_speakers">Not enough speakers</string>
<string name="order_query">order inquiries</string>
<string name="order_query_success">No exception to the order</string>
<string name="login_invalid">Login failed, please log in again</string>
<string name="onlookers">onlookers</string>
<string name="open_noble">的直播間開通了</string>
<string name="baron">baron</string>
<string name="viscount">子爵</string>
<string name="marquis">侯爵</string>
<string name="duke">公爵</string>
<string name="king">国王</string>
<string name="emperor">皇帝</string>
<string name="better_emperor">超皇</string>
</resources> </resources>

View File

@ -911,5 +911,7 @@
<string name="enough_speakers">喇叭數量不足</string> <string name="enough_speakers">喇叭數量不足</string>
<string name="order_query">订单查询中</string> <string name="order_query">订单查询中</string>
<string name="order_query_success">订单无异常</string> <string name="order_query_success">订单无异常</string>
<string name="login_invalid">登錄失效,請重新登錄</string>
</resources> </resources>

View File

@ -1,5 +1,10 @@
package com.yunbao.main.activity; package com.yunbao.main.activity;
import static com.yunbao.common.CommonAppContext.home_zdy_img_cn;
import static com.yunbao.common.CommonAppContext.home_zdy_img_us;
import static com.yunbao.common.CommonAppContext.logger;
import static com.yunbao.common.CommonAppContext.mFirebaseAnalytics;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
@ -13,7 +18,6 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.os.Message;
import android.provider.Settings; import android.provider.Settings;
import android.util.Base64; import android.util.Base64;
import android.util.Log; import android.util.Log;
@ -29,6 +33,7 @@ import androidx.appcompat.app.AppCompatActivity;
import com.adjust.sdk.Adjust; import com.adjust.sdk.Adjust;
import com.adjust.sdk.AdjustEvent; import com.adjust.sdk.AdjustEvent;
import com.alibaba.android.arouter.facade.annotation.Route;
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.DeviceUtils; import com.blankj.utilcode.util.DeviceUtils;
@ -67,7 +72,6 @@ import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.Constants; import com.yunbao.common.Constants;
import com.yunbao.common.HtmlConfig; import com.yunbao.common.HtmlConfig;
import com.yunbao.common.activity.WebViewActivity; import com.yunbao.common.activity.WebViewActivity;
import com.yunbao.common.bean.BaseModel;
import com.yunbao.common.bean.FaceBookUpModel; import com.yunbao.common.bean.FaceBookUpModel;
import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.IMLoginModel;
import com.yunbao.common.bean.LoginData; import com.yunbao.common.bean.LoginData;
@ -75,7 +79,6 @@ import com.yunbao.common.bean.UserBean;
import com.yunbao.common.http.CommonHttpUtil; import com.yunbao.common.http.CommonHttpUtil;
import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.http.HttpClient; import com.yunbao.common.http.HttpClient;
import com.yunbao.common.http.live.LiveNetManager;
import com.yunbao.common.http.main.MainNetManager; import com.yunbao.common.http.main.MainNetManager;
import com.yunbao.common.interfaces.CommonCallback; import com.yunbao.common.interfaces.CommonCallback;
import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.IMLoginManager;
@ -87,35 +90,23 @@ import com.yunbao.live.activity.LiveAudienceActivity;
import com.yunbao.live.bean.LiveBean; import com.yunbao.live.bean.LiveBean;
import com.yunbao.live.http.LiveHttpUtil; import com.yunbao.live.http.LiveHttpUtil;
import com.yunbao.live.presenter.LiveRoomCheckLivePresenter; import com.yunbao.live.presenter.LiveRoomCheckLivePresenter;
import com.yunbao.live.socket.SocketRyClient;
import com.yunbao.main.R; import com.yunbao.main.R;
import com.yunbao.main.dialog.LoginTipsDialog; import com.yunbao.main.dialog.LoginTipsDialog;
import com.yunbao.main.event.RegSuccessEvent;
import com.yunbao.main.http.MainHttpUtil; import com.yunbao.main.http.MainHttpUtil;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode; import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import io.rong.imlib.RongIMClient;
import io.rong.message.TextMessage;
import static com.blankj.utilcode.util.SnackbarUtils.dismiss;
import static com.yunbao.common.CommonAppContext.home_zdy_img_cn;
import static com.yunbao.common.CommonAppContext.home_zdy_img_us;
import static com.yunbao.common.CommonAppContext.logger;
import static com.yunbao.common.CommonAppContext.mFirebaseAnalytics;
/** /**
* 入口 * 入口
*/ */
@Route(path = RouteUtil.PATH_ENTRY)
public class EntryActivity extends AppCompatActivity { public class EntryActivity extends AppCompatActivity {
private VideoView video_view; private VideoView video_view;
@ -180,6 +171,10 @@ public class EntryActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_entry); setContentView(R.layout.activity_entry);
if (getIntent().getBooleanExtra("forwardEntry", false)) {
IMLoginManager.get(this).logout();
ToastUtil.show(R.string.login_invalid);
}
Get_hash_key(); Get_hash_key();
activity = this; activity = this;
@ -286,10 +281,10 @@ public class EntryActivity extends AppCompatActivity {
.FaceBookUp(new com.yunbao.common.http.base.HttpCallback<FaceBookUpModel>() { .FaceBookUp(new com.yunbao.common.http.base.HttpCallback<FaceBookUpModel>() {
@Override @Override
public void onSuccess(FaceBookUpModel data) { public void onSuccess(FaceBookUpModel data) {
if(data.getType().equals("0")){ if (data.getType().equals("0")) {
LoginManager.getInstance().logInWithReadPermissions(EntryActivity.this, Arrays.asList("public_profile")); LoginManager.getInstance().logInWithReadPermissions(EntryActivity.this, Arrays.asList("public_profile"));
}else{ } else {
WebViewActivity.forward(EntryActivity.this, data.getLink()+"?"); WebViewActivity.forward(EntryActivity.this, data.getLink() + "?");
} }
} }
@ -781,7 +776,7 @@ public class EntryActivity extends AppCompatActivity {
IMLoginManager.get(EntryActivity.this).setisNewUserOne(true); IMLoginManager.get(EntryActivity.this).setisNewUserOne(true);
MainActivity.forward(EntryActivity.this, false); MainActivity.forward(EntryActivity.this, false);
gotoLive(obj.getString("anchor_id")); gotoLive(obj.getString("anchor_id"));
if(obj.containsKey("home_zdy_img_us")) { if (obj.containsKey("home_zdy_img_us")) {
home_zdy_img_us = obj.getString("home_zdy_img_us"); home_zdy_img_us = obj.getString("home_zdy_img_us");
home_zdy_img_cn = obj.getString("home_zdy_img_cn"); home_zdy_img_cn = obj.getString("home_zdy_img_cn");
} }