From b7129bcbfa23962020e8d0c966bb607c8571e45a Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Thu, 29 Sep 2022 16:26:10 +0800 Subject: [PATCH] =?UTF-8?q?TOKEN=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/build.gradle | 2 +- .../com/yunbao/common/http/HttpClient.java | 28 +++++++++++---- .../common/http/base/GetRequestParams.java | 17 ++++++--- .../common/http/base/PostRequestParams.java | 17 +++++---- .../com/yunbao/common/utils/RouteUtil.java | 18 ++++++++-- common/src/main/res/values-en/strings.xml | 20 +++++++++++ common/src/main/res/values/strings.xml | 2 ++ .../yunbao/main/activity/EntryActivity.java | 35 ++++++++----------- 8 files changed, 99 insertions(+), 40 deletions(-) diff --git a/common/build.gradle b/common/build.gradle index 6e731bb42..48efd0c77 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -163,7 +163,7 @@ dependencies { api 'cn.rongcloud.sdk:im_kit:5.2.5' // 即时通讯 UI 基础组件 //融云小视频模块 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)' api('com.twitter.sdk.android:twitter-core:3.1.1@aar') { diff --git a/common/src/main/java/com/yunbao/common/http/HttpClient.java b/common/src/main/java/com/yunbao/common/http/HttpClient.java index 1b2218350..0378dc175 100644 --- a/common/src/main/java/com/yunbao/common/http/HttpClient.java +++ b/common/src/main/java/com/yunbao/common/http/HttpClient.java @@ -1,6 +1,7 @@ package com.yunbao.common.http; import android.content.Context; +import android.text.TextUtils; import com.lzy.okgo.OkGo; import com.lzy.okgo.cache.CacheMode; @@ -12,6 +13,7 @@ import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppContext; import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.RouteUtil; import java.util.HashMap; import java.util.Map; @@ -72,8 +74,12 @@ public class HttpClient { Map map = new HashMap<>(); if (IMLoginManager.isLogin(context)) { IMLoginModel model = IMLoginManager.get(context).getUserInfo(); - map.put("uid", String.valueOf(model.getId())); - map.put("token", model.getToken()); + if (TextUtils.isEmpty(model.getToken())) { + RouteUtil.forwardEntry(); + } else { + map.put("uid", String.valueOf(model.getId())); + map.put("token", model.getToken()); + } } return OkGo.get(mUrl + serviceName) .params(map, true) @@ -90,8 +96,13 @@ public class HttpClient { Map map = new HashMap<>(); if (IMLoginManager.isLogin(context)) { IMLoginModel model = IMLoginManager.get(context).getUserInfo(); - map.put("uid", String.valueOf(model.getId())); - map.put("token", model.getToken()); + if (TextUtils.isEmpty(model.getToken())) { + RouteUtil.forwardEntry(); + } else { + map.put("uid", String.valueOf(model.getId())); + map.put("token", model.getToken()); + } + } return OkGo.get(url + serviceName) .headers("Connection", "keep-alive") @@ -105,9 +116,14 @@ public class HttpClient { //拼装基本信息 Map map = new HashMap<>(); if (IMLoginManager.isLogin(context)) { + IMLoginModel model = IMLoginManager.get(context).getUserInfo(); - map.put("uid", String.valueOf(model.getId())); - map.put("token", model.getToken()); + if (TextUtils.isEmpty(model.getToken())) { + RouteUtil.forwardEntry(); + } else { + map.put("uid", String.valueOf(model.getId())); + map.put("token", model.getToken()); + } } return OkGo.post(mUrl + serviceName) .headers("Connection", "keep-alive") diff --git a/common/src/main/java/com/yunbao/common/http/base/GetRequestParams.java b/common/src/main/java/com/yunbao/common/http/base/GetRequestParams.java index 1d8860202..002936359 100644 --- a/common/src/main/java/com/yunbao/common/http/base/GetRequestParams.java +++ b/common/src/main/java/com/yunbao/common/http/base/GetRequestParams.java @@ -1,9 +1,11 @@ package com.yunbao.common.http.base; import android.content.Context; +import android.text.TextUtils; import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.RouteUtil; import okhttp3.HttpUrl; import okhttp3.Request; @@ -11,13 +13,14 @@ import okhttp3.Request; public class GetRequestParams implements IRequestParam { /** * 构建Request + * * @param isNeedUid 是否需要添加用户uid参数 * @param request * @param context * @return */ @Override - public Request getRequest(boolean isNeedUid,Request request, Context context) { + public Request getRequest(boolean isNeedUid, Request request, Context context) { //添加公共参数 if (IMLoginManager.isLogin(context)) { IMLoginModel model = IMLoginManager.get(context).getUserInfo(); @@ -26,10 +29,16 @@ public class GetRequestParams implements IRequestParam { .addQueryParameter("token", model.getToken()) .build();*/ HttpUrl.Builder builder = request.url().newBuilder(); - if(isNeedUid) { - builder.addQueryParameter("uid", String.valueOf(model.getId())); + if (TextUtils.isEmpty(model.getToken())) { + RouteUtil.forwardEntry(); + } else { + + if (isNeedUid) { + builder.addQueryParameter("uid", String.valueOf(model.getId())); + } + builder.addQueryParameter("token", model.getToken()); } - builder.addQueryParameter("token", model.getToken()); + return request.newBuilder().url(builder.build()).build(); } diff --git a/common/src/main/java/com/yunbao/common/http/base/PostRequestParams.java b/common/src/main/java/com/yunbao/common/http/base/PostRequestParams.java index 6d7730b45..7c1cf332c 100644 --- a/common/src/main/java/com/yunbao/common/http/base/PostRequestParams.java +++ b/common/src/main/java/com/yunbao/common/http/base/PostRequestParams.java @@ -1,16 +1,18 @@ package com.yunbao.common.http.base; import android.content.Context; +import android.text.TextUtils; import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.RouteUtil; import okhttp3.FormBody; import okhttp3.Request; public class PostRequestParams implements IRequestParam { @Override - public Request getRequest(boolean isNeedUid,Request request, Context context) { + public Request getRequest(boolean isNeedUid, Request request, Context context) { if (request.body() instanceof FormBody) { FormBody.Builder bodyBuilder = new FormBody.Builder(); @@ -21,15 +23,18 @@ public class PostRequestParams implements IRequestParam { } if (IMLoginManager.isLogin(context)) { IMLoginModel model = IMLoginManager.get(context).getUserInfo(); + if (TextUtils.isEmpty(model.getToken())) { + RouteUtil.forwardEntry(); + } else { /* formBody = bodyBuilder.addEncoded("uid", String.valueOf(model.getId())) .addEncoded("token", model.getToken()) .build();*/ - if (isNeedUid){ - bodyBuilder.addEncoded("uid", String.valueOf(model.getId())); + if (isNeedUid) { + bodyBuilder.addEncoded("uid", String.valueOf(model.getId())); + } + bodyBuilder.addEncoded("token", model.getToken()); + formBody = bodyBuilder.build(); } - bodyBuilder.addEncoded("token", model.getToken()); - formBody=bodyBuilder.build(); - } request = request.newBuilder().post(formBody).build(); } diff --git a/common/src/main/java/com/yunbao/common/utils/RouteUtil.java b/common/src/main/java/com/yunbao/common/utils/RouteUtil.java index ee1fddaec..7b4638fc5 100644 --- a/common/src/main/java/com/yunbao/common/utils/RouteUtil.java +++ b/common/src/main/java/com/yunbao/common/utils/RouteUtil.java @@ -24,7 +24,8 @@ public class RouteUtil { public static final String PATH_MYWEBVIEWACTIVTITY = "/main/MyWebViewActivity"; public static final String PATH_ZHUANGBANACTIVITY = "/main/ZhuangBanActivity"; 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(); } + /** + * 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=其他 @@ -68,7 +80,7 @@ public class RouteUtil { if (!"".equals(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) .navigation(); } @@ -79,7 +91,7 @@ public class RouteUtil { public static void forwardZhuangBanActivity(String url) { Constants.myPackageUrl = url; ARouter.getInstance().build(PATH_ZHUANGBANACTIVITY) - .withString("title","") + .withString("title", "") .navigation(); } diff --git a/common/src/main/res/values-en/strings.xml b/common/src/main/res/values-en/strings.xml index 6fac3954f..7e5371430 100644 --- a/common/src/main/res/values-en/strings.xml +++ b/common/src/main/res/values-en/strings.xml @@ -880,4 +880,24 @@ Limited ride And limited avatar frame Notice Online Service Hot Ticket + + Tell the world! + Tell the world! %s recommends anchor %s to everyone! + Tell the world! %s recommends the anchor %s to everyone, and the splendid glance is amazing! + Failed to load data, please try again later + open + Not enough speakers + order inquiries + No exception to the order + Login failed, please log in again + + onlookers + 的直播間開通了 + baron + 子爵 + 侯爵 + 公爵 + 国王 + 皇帝 + 超皇 diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index 491e10f68..99bf1b7c7 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -911,5 +911,7 @@ 喇叭數量不足 订单查询中 订单无异常 + 登錄失效,請重新登錄 + diff --git a/main/src/main/java/com/yunbao/main/activity/EntryActivity.java b/main/src/main/java/com/yunbao/main/activity/EntryActivity.java index 9511637bf..ae6a9b35b 100644 --- a/main/src/main/java/com/yunbao/main/activity/EntryActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/EntryActivity.java @@ -1,5 +1,10 @@ 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.app.Activity; import android.content.Context; @@ -13,7 +18,6 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Environment; -import android.os.Message; import android.provider.Settings; import android.util.Base64; import android.util.Log; @@ -29,6 +33,7 @@ import androidx.appcompat.app.AppCompatActivity; import com.adjust.sdk.Adjust; import com.adjust.sdk.AdjustEvent; +import com.alibaba.android.arouter.facade.annotation.Route; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.blankj.utilcode.util.DeviceUtils; @@ -67,7 +72,6 @@ import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; import com.yunbao.common.HtmlConfig; import com.yunbao.common.activity.WebViewActivity; -import com.yunbao.common.bean.BaseModel; import com.yunbao.common.bean.FaceBookUpModel; import com.yunbao.common.bean.IMLoginModel; 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.HttpCallback; import com.yunbao.common.http.HttpClient; -import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.http.main.MainNetManager; import com.yunbao.common.interfaces.CommonCallback; 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.http.LiveHttpUtil; import com.yunbao.live.presenter.LiveRoomCheckLivePresenter; -import com.yunbao.live.socket.SocketRyClient; import com.yunbao.main.R; import com.yunbao.main.dialog.LoginTipsDialog; -import com.yunbao.main.event.RegSuccessEvent; import com.yunbao.main.http.MainHttpUtil; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import org.json.JSONException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; 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 { private VideoView video_view; @@ -180,6 +171,10 @@ public class EntryActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_entry); + if (getIntent().getBooleanExtra("forwardEntry", false)) { + IMLoginManager.get(this).logout(); + ToastUtil.show(R.string.login_invalid); + } Get_hash_key(); activity = this; @@ -286,10 +281,10 @@ public class EntryActivity extends AppCompatActivity { .FaceBookUp(new com.yunbao.common.http.base.HttpCallback() { @Override public void onSuccess(FaceBookUpModel data) { - if(data.getType().equals("0")){ + if (data.getType().equals("0")) { LoginManager.getInstance().logInWithReadPermissions(EntryActivity.this, Arrays.asList("public_profile")); - }else{ - WebViewActivity.forward(EntryActivity.this, data.getLink()+"?"); + } else { + WebViewActivity.forward(EntryActivity.this, data.getLink() + "?"); } } @@ -781,7 +776,7 @@ public class EntryActivity extends AppCompatActivity { IMLoginManager.get(EntryActivity.this).setisNewUserOne(true); MainActivity.forward(EntryActivity.this, false); 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_cn = obj.getString("home_zdy_img_cn"); }