diff --git a/app/src/main/java/com/gh/common/provider/BuildConfigImpl.kt b/app/src/main/java/com/gh/common/provider/BuildConfigImpl.kt
index 1f35b6a8b9..9104d63c98 100644
--- a/app/src/main/java/com/gh/common/provider/BuildConfigImpl.kt
+++ b/app/src/main/java/com/gh/common/provider/BuildConfigImpl.kt
@@ -32,5 +32,6 @@ class BuildConfigImpl : IBuildConfigProvider {
override fun getVApiHost(): String = BuildConfig.VAPI_HOST
override fun getVDevApiHost(): String = BuildConfig.DEV_VAPI_HOST
+
override fun getLogProducerProject(): String = BuildConfig.LOG_HUB_PROJECT
}
\ No newline at end of file
diff --git a/app/src/main/java/com/gh/common/util/DirectUtils.kt b/app/src/main/java/com/gh/common/util/DirectUtils.kt
index ab02c47f8d..1c9804bb66 100644
--- a/app/src/main/java/com/gh/common/util/DirectUtils.kt
+++ b/app/src/main/java/com/gh/common/util/DirectUtils.kt
@@ -1988,7 +1988,7 @@ object DirectUtils {
val qGameProvider = ARouter
.getInstance()
.build(RouteConsts.provider.qGame)
- .navigation() as IQGameProvider<*>
+ .navigation() as IQGameProvider
qGameProvider.setLoginInfo(activity, userId, userName, userToken)
qGameProvider.launchGame(activity, qqGameId) { _, _ ->
RetrofitManager
diff --git a/app/src/main/java/com/gh/gamecenter/qgame/QGameViewModel.kt b/app/src/main/java/com/gh/gamecenter/qgame/QGameViewModel.kt
index 526bf288cd..5863c6dfb1 100644
--- a/app/src/main/java/com/gh/gamecenter/qgame/QGameViewModel.kt
+++ b/app/src/main/java/com/gh/gamecenter/qgame/QGameViewModel.kt
@@ -1,21 +1,16 @@
package com.gh.gamecenter.qgame
import android.app.Application
-import android.content.Context
import android.text.TextUtils
import androidx.collection.ArrayMap
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
-import com.alibaba.android.arouter.launcher.ARouter
-import com.gh.common.constant.Config
import com.gh.common.filter.RegionSettingHelper
import com.gh.common.util.GameSubstituteRepositoryHelper
import com.gh.common.util.GameUtils
import com.gh.gamecenter.common.baselist.LoadStatus
-import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.common.entity.LinkEntity
import com.gh.gamecenter.common.retrofit.Response
-import com.gh.gamecenter.core.provider.IQGameProvider
import com.gh.gamecenter.core.utils.RandomUtils
import com.gh.gamecenter.entity.SubjectEntity
import com.gh.gamecenter.entity.SubjectRecommendEntity
@@ -53,7 +48,6 @@ class QGameViewModel(application: Application, blockData: SubjectRecommendEntity
private var mIsLoading = false
init {
- initQQMiniGameSDK(application)
initData()
EventBus.getDefault().register(this)// 为了减少对原有逻辑的影响,把EventBus注册在这里
}
@@ -557,21 +551,6 @@ class QGameViewModel(application: Application, blockData: SubjectRecommendEntity
companion object {
- private var isQQMiniSDKInit = false
-
- /**
- * QQ小游戏SDK初始化
- */
- private fun initQQMiniGameSDK(context: Context) {
- if (isQQMiniSDKInit) return
- val provider = ARouter
- .getInstance()
- .build(RouteConsts.provider.qGame)
- .navigation() as IQGameProvider<*>
- provider.init(context, Config.WECHAT_APPID, Config.TENCENT_APPID)
- isQQMiniSDKInit = true
- }
-
fun notifyQGameSubjectUpdate() {
EventBus.getDefault().post(QGameSubjectUpdateEvent())
}
diff --git a/app/src/main/java/com/halo/assistant/HaloApp.java b/app/src/main/java/com/halo/assistant/HaloApp.java
index 2af18a8a98..ecf6c1ea68 100644
--- a/app/src/main/java/com/halo/assistant/HaloApp.java
+++ b/app/src/main/java/com/halo/assistant/HaloApp.java
@@ -62,6 +62,7 @@ import com.gh.gamecenter.core.AppExecutor;
import com.gh.gamecenter.core.iinterface.IApplication;
import com.gh.gamecenter.core.provider.IFlavorProvider;
import com.gh.gamecenter.core.provider.IPushProvider;
+import com.gh.gamecenter.core.provider.IQGameProvider;
import com.gh.gamecenter.core.utils.DisplayUtils;
import com.gh.gamecenter.core.utils.GsonUtils;
import com.gh.gamecenter.core.utils.SPUtils;
@@ -347,6 +348,17 @@ public class HaloApp extends MultiDexApplication {
MainWrapperRepository.Companion.getInstance().getDataUnion();
+ // QQ小游戏开放互联初始化
+ IQGameProvider provider = (IQGameProvider) ARouter
+ .getInstance()
+ .build(RouteConsts.provider.qGame)
+ .navigation();
+ provider.initOpenSdkLogin(
+ this,
+ com.gh.common.constant.Config.WECHAT_APPID,
+ com.gh.common.constant.Config.TENCENT_APPID
+ );
+
AppExecutor.getUiExecutor().executeWithDelay(() -> {
FixedRateJobHelper.begin();
diff --git a/dependencies.gradle b/dependencies.gradle
index 1939570c41..657512d050 100644
--- a/dependencies.gradle
+++ b/dependencies.gradle
@@ -131,8 +131,8 @@ ext {
csjVersion = "5.8.0.4.0"
- qGameVersion = "1.57.14"
- qGameAdVersion = "4.520.1390"
+ qGameVersion = "1.70.1"
+ qGameAdVersion = "4.575.1445"
blankjUtilCodex = "1.30.4"
diff --git a/feature/qq_game/src/main/AndroidManifest.xml b/feature/qq_game/src/main/AndroidManifest.xml
index 2d12125731..25c5b887f4 100644
--- a/feature/qq_game/src/main/AndroidManifest.xml
+++ b/feature/qq_game/src/main/AndroidManifest.xml
@@ -6,8 +6,6 @@
-
-
+
+
+
+
+
+
diff --git a/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/HaloApp.kt b/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/HaloApp.kt
index 3034a0a449..2d4dfaf072 100644
--- a/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/HaloApp.kt
+++ b/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/HaloApp.kt
@@ -2,32 +2,23 @@ package com.gh.gamecenter.qgame
import android.app.Application
import android.content.res.Configuration
-import android.util.Log
-import com.alibaba.android.arouter.launcher.ARouter
-import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.core.iinterface.IApplication
-import com.gh.gamecenter.core.provider.IPackageUtilsProvider
-import com.gh.gamecenter.core.provider.IRealNameProvider
import com.google.auto.service.AutoService
@AutoService(IApplication::class)
class HaloApp : IApplication {
+ companion object {
+ lateinit var INSTANCE: Application
+ }
+
override fun attachBaseContext() {
}
override fun onCreate(application: Application) {
-
+ INSTANCE = application
MiniGameWebViewUtils.handleWebViewDir(application)
-
- doOnlyOnMiniProcess(application) {
- val provider = ARouter
- .getInstance()
- .build(RouteConsts.provider.realName)
- .navigation() as IRealNameProvider
- provider.init(application)
- }
}
@@ -46,21 +37,4 @@ class HaloApp : IApplication {
override fun onConfigurationChanged(newConfig: Configuration) {
}
-
- private fun doOnlyOnMiniProcess(application: Application, callback: () -> Unit) {
- val processName = getProcessName(application)
- val processNameSplits = processName.split(":")
- if (processNameSplits.size < 2) return
- val processNameSuffix = processNameSplits[1]
- if (processNameSuffix.startsWith("mini")) {
- Log.d("HaloApp", "doOnlyOnMiniProcess -> $processName")
- callback.invoke()
- }
- }
-
- private fun getProcessName(application: Application): String {
- val packageUtilsConfig =
- ARouter.getInstance().build(RouteConsts.provider.packageUtils).navigation() as? IPackageUtilsProvider
- return packageUtilsConfig?.obtainProcessName() ?: application.packageName
- }
}
\ No newline at end of file
diff --git a/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/MiniGameChannelInfoProxyImpl.java b/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/MiniGameChannelInfoProxyImpl.java
index 24c3169880..75381689c6 100644
--- a/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/MiniGameChannelInfoProxyImpl.java
+++ b/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/MiniGameChannelInfoProxyImpl.java
@@ -1,8 +1,16 @@
package com.gh.gamecenter.qgame;
+import android.app.Application;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.graphics.drawable.Drawable;
+
import androidx.annotation.Keep;
+import androidx.core.content.ContextCompat;
+import androidx.core.content.res.ResourcesCompat;
import com.alibaba.android.arouter.launcher.ARouter;
+import com.blankj.utilcode.util.AppUtils;
import com.gh.gamecenter.common.constant.RouteConsts;
import com.gh.gamecenter.common.utils.PackageFlavorHelper;
import com.gh.gamecenter.core.provider.IAppProvider;
@@ -31,6 +39,18 @@ public class MiniGameChannelInfoProxyImpl extends IMiniGameChannelInfoProxy {
return "光环助手";
}
+ @Override
+ public Drawable getAppIcon() {
+ Application application = HaloApp.INSTANCE;
+ PackageManager pm = application.getPackageManager();
+ try {
+ ApplicationInfo applicationInfo = pm.getApplicationInfo(application.getPackageName(), 0);
+ return applicationInfo.loadIcon(pm);
+ } catch (PackageManager.NameNotFoundException e) {
+ return null;
+ }
+ }
+
/**
* 获取宿主APP的版本信息
*
diff --git a/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/MiniGameOpenSdkProxyImpl.java b/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/MiniGameOpenSdkProxyImpl.java
deleted file mode 100644
index ec93df4d78..0000000000
--- a/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/MiniGameOpenSdkProxyImpl.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.gh.gamecenter.qgame;
-
-import android.content.Context;
-
-import androidx.annotation.Nullable;
-
-import com.tencent.qqmini.minigame.opensdk.proxy.IWXRequestListener;
-import com.tencent.qqmini.minigame.opensdk.proxy.MiniGameOpenSdkProxy;
-import com.tencent.qqmini.minigame.opensdk.wx.WXHttpsRequest;
-
-public class MiniGameOpenSdkProxyImpl implements MiniGameOpenSdkProxy {
-
- private static final String TAG = "MiniGameOpenSdkProxyDefault";
- private static final String wxAppId = "wx3ffd0785fad18396";
- private static final String appSecret = "368b49e8471857575a033b206218f9fb";
-
- public void wxAuth(Context context, String code, @Nullable IWXRequestListener listener) {
- WXHttpsRequest.wxAuth(context, wxAppId, code, appSecret, listener);
- }
-
- public void wxRefreshToken(Context context, @Nullable IWXRequestListener listener) {
- WXHttpsRequest.wxRefreshToken(context, wxAppId, listener);
- }
-}
\ No newline at end of file
diff --git a/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/MiniGameProxyImpl.java b/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/MiniGameProxyImpl.java
deleted file mode 100644
index 12a29b72cd..0000000000
--- a/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/MiniGameProxyImpl.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.gh.gamecenter.qgame;
-
-import android.content.Context;
-
-import androidx.annotation.Nullable;
-
-import com.tencent.qqmini.minigame.opensdk.proxy.MimiGameOpenSdkInfoProxyImpl;
-import com.tencent.qqmini.sdk.launcher.core.proxy.AsyncResult;
-import com.tencent.qqmini.sdk.launcher.model.MiniAppInfo;
-
-public class MiniGameProxyImpl extends MimiGameOpenSdkInfoProxyImpl {
- @Override
- public boolean needCheckAntiAddictionToken() {
- return false;
- }
-
- @Override
- public boolean handleTokenInvalid(Context context, @Nullable MiniAppInfo miniAppInfo, int i, @Nullable AsyncResult asyncResult) {
- return super.handleTokenInvalid(context, miniAppInfo, i, asyncResult);
- }
-}
diff --git a/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/QGameHelper.kt b/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/QGameHelper.kt
index 46d213fa4e..d411081b3b 100644
--- a/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/QGameHelper.kt
+++ b/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/QGameHelper.kt
@@ -8,13 +8,11 @@ import android.os.Handler
import android.os.Looper
import android.os.ResultReceiver
import com.gh.gamecenter.core.utils.ToastUtils
-import com.google.gson.Gson
import com.tencent.qqmini.minigame.opensdk.OpenSdkLoginManager
import com.tencent.qqmini.minigame.opensdk.config.OpenSdkConfig
import com.tencent.qqmini.sdk.MiniSDK
import com.tencent.qqmini.sdk.launcher.model.AccountInfo
import com.tencent.qqmini.sdk.launcher.model.ExtParams
-import com.tencent.qqmini.sdk.launcher.model.LaunchParam
import com.tencent.qqmini.sdk.launcher.model.MiniAppInfo
import com.tencent.tauth.Tencent
@@ -23,20 +21,22 @@ import com.tencent.tauth.Tencent
*/
internal object QGameHelper {
- fun init(context: Context, wxAppId: String, qqAppId: String) {
+ private var isOpenSdkLoginInit = false
+
+ fun initOpenSdkLogin(context: Context, wxAppId: String, qqAppId: String) {
// 若 Android 系统版本低于 5.0 不用初始化
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP || isOpenSdkLoginInit) {
return
}
+ isOpenSdkLoginInit = true
MiniSDK.init(context)
OpenSdkLoginManager.init(
OpenSdkConfig.Builder()
.setUseOauth(false)
.setQqOpenAppId(qqAppId) // QQ互联平台AppId,若不想接入QQ互联,则不设置
.setWxOpenAppId(wxAppId) // 微信互联平台AppId,若不想接入微信互联,则不设置
- .setIsDebugEnv(true)
- .build()
+ .build(context)
)
Tencent.setIsPermissionGranted(true)
}
diff --git a/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/QGameProviderImpl.kt b/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/QGameProviderImpl.kt
index c9dba5b7ae..6ab23591f6 100644
--- a/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/QGameProviderImpl.kt
+++ b/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/QGameProviderImpl.kt
@@ -8,15 +8,15 @@ import com.alibaba.android.arouter.facade.annotation.Route
import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.core.provider.IQGameProvider
import com.tencent.mm.opensdk.modelmsg.SendAuth
-import com.tencent.qqmini.minigame.opensdk.wx.BaseWXEntryActivity
+import com.tencent.qqmini.minigame.opensdk.wx.WXEntryActivityHelper
import com.tencent.qqmini.sdk.launcher.AppLoaderFactory
import com.tencent.qqmini.sdk.launcher.model.ShareData
@Route(path = RouteConsts.provider.qGame, name = "QQ小游戏暴露服务")
-class QGameProviderImpl : IQGameProvider {
+class QGameProviderImpl : IQGameProvider {
- override fun init(context: Context, wxAppId: String, qqAppId: String) {
- QGameHelper.init(context, wxAppId, qqAppId)
+ override fun initOpenSdkLogin(context: Context, wxAppId: String, qqAppId: String) {
+ QGameHelper.initOpenSdkLogin(context, wxAppId, qqAppId)
}
override fun init(context: Context?) {
@@ -43,15 +43,8 @@ class QGameProviderImpl : IQGameProvider {
QGameHelper.launchGameByLink(activity, qqGameLink, resultCallback)
}
- override fun onWechatLogin(context: Context, resp: SendAuth.Resp) {
- // 这里用 WXDelegateEntryActivity 类做了个中转,把数据传递到了底层的 Activity
- val bundle = Bundle()
- resp.toBundle(bundle)
-
- val intent = Intent(context, WXDelegateEntryActivity::class.java)
- intent.putExtras(bundle)
-
- context.startActivity(intent)
+ override fun onWechatLogin(context: Context, content: String, isCanceled: Boolean, message: String) {
+ WXEntryActivityHelper.notifyWxLoginResult(context, content, isCanceled, message)
}
/**
@@ -59,8 +52,8 @@ class QGameProviderImpl : IQGameProvider {
* @param resultType 结果 0 代表失败, -1 代表取消, 1 代表成功
*/
override fun onWechatShare(context: Context, resultType: Int) {
- val tempShareData = BaseWXEntryActivity.sShareData
- BaseWXEntryActivity.sShareData = null
+ val tempShareData = WXEntryActivityHelper.sShareData
+ WXEntryActivityHelper.sShareData = null
if (tempShareData != null) {
when (resultType) {
diff --git a/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/WXDelegateEntryActivity.kt b/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/WXDelegateEntryActivity.kt
deleted file mode 100644
index ec55e68b2b..0000000000
--- a/feature/qq_game/src/main/java/com/gh/gamecenter/qgame/WXDelegateEntryActivity.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.gh.gamecenter.qgame
-
-import android.os.Bundle
-import androidx.annotation.Keep
-import com.tencent.mm.opensdk.modelmsg.SendAuth
-import com.tencent.qqmini.minigame.opensdk.wx.BaseWXEntryActivity
-import com.tencent.qqmini.minigame.opensdk.wx.WXLoginHelper
-
-@Keep
-internal class WXDelegateEntryActivity : BaseWXEntryActivity() {
- override fun onCreate(p0: Bundle?) {
- // 将数据转移给 BaseWXEntryActivity 来规避需要继承 BaseWXEntryActivity 的问题
- // TODO 第二次会无法登录,可能某些地方还需要处理
- val resp = SendAuth.Resp()
- resp.fromBundle(intent.extras)
-
- WXLoginHelper.loginState = resp.state
-
- onResp(resp)
-
- super.onCreate(p0)
-
- finish()
- }
-}
\ No newline at end of file
diff --git a/feature/qq_game/src/main/java/com/tencent/qqmini/sdk/core/generated/ExtProxyServiceScope.java b/feature/qq_game/src/main/java/com/tencent/qqmini/sdk/core/generated/ExtProxyServiceScope.java
index 62fb444c44..f90ac83d47 100644
--- a/feature/qq_game/src/main/java/com/tencent/qqmini/sdk/core/generated/ExtProxyServiceScope.java
+++ b/feature/qq_game/src/main/java/com/tencent/qqmini/sdk/core/generated/ExtProxyServiceScope.java
@@ -3,10 +3,7 @@ package com.tencent.qqmini.sdk.core.generated;
import androidx.annotation.Keep;
import com.gh.gamecenter.qgame.LogProxyImpl;
-import com.gh.gamecenter.qgame.MiniCustomizedProxyImpl;
import com.gh.gamecenter.qgame.MiniGameChannelInfoProxyImpl;
-import com.gh.gamecenter.qgame.MiniGameOpenSdkProxyImpl;
-import com.gh.gamecenter.qgame.MiniGameProxyImpl;
import com.gh.gamecenter.qgame.ShareProxyImpl;
import java.util.HashMap;
@@ -20,8 +17,5 @@ public final class ExtProxyServiceScope {
PROXY_SERVICES.put(com.tencent.qqmini.sdk.launcher.core.proxy.ShareProxy.class, ShareProxyImpl.class);
PROXY_SERVICES.put(com.tencent.qqmini.minigame.external.proxy.IMiniGameChannelInfoProxy.class, MiniGameChannelInfoProxyImpl.class);
PROXY_SERVICES.put(com.tencent.qqmini.sdk.launcher.core.proxy.LogProxy.class, LogProxyImpl.class);
- PROXY_SERVICES.put(com.tencent.qqmini.sdk.launcher.core.proxy.MiniGameProxy.class, MiniGameProxyImpl.class);
- PROXY_SERVICES.put(com.tencent.qqmini.minigame.opensdk.proxy.MiniGameOpenSdkProxy.class, MiniGameOpenSdkProxyImpl.class);
- PROXY_SERVICES.put(com.tencent.qqmini.sdk.launcher.core.proxy.MiniCustomizedProxy.class, MiniCustomizedProxyImpl.class);
}
}
diff --git a/module_common/src/main/java/com/gh/gamecenter/common/base/activity/BaseActivity.java b/module_common/src/main/java/com/gh/gamecenter/common/base/activity/BaseActivity.java
index f1fd4a9d4c..05395cf85d 100644
--- a/module_common/src/main/java/com/gh/gamecenter/common/base/activity/BaseActivity.java
+++ b/module_common/src/main/java/com/gh/gamecenter/common/base/activity/BaseActivity.java
@@ -431,7 +431,7 @@ public abstract class BaseActivity extends BaseAppCompatActivity implements IBus
// }
}
);
- IQGameProvider> qProvider = (IQGameProvider>) ARouter
+ IQGameProvider qProvider = (IQGameProvider) ARouter
.getInstance()
.build(RouteConsts.provider.qGame)
.navigation();
diff --git a/module_core/src/main/java/com/gh/gamecenter/core/provider/IQGameProvider.kt b/module_core/src/main/java/com/gh/gamecenter/core/provider/IQGameProvider.kt
index d26ad91a35..b83514f7fd 100644
--- a/module_core/src/main/java/com/gh/gamecenter/core/provider/IQGameProvider.kt
+++ b/module_core/src/main/java/com/gh/gamecenter/core/provider/IQGameProvider.kt
@@ -5,28 +5,49 @@ import android.content.Context
import android.os.*
import com.alibaba.android.arouter.facade.template.IProvider
-interface IQGameProvider : IProvider {
+interface IQGameProvider : IProvider {
- fun init(context: Context, wxAppId: String, qqAppId: String)
+ /**
+ * 初始化开放互联信息SDK
+ * @param context 上下文
+ * @param wxAppId 微信AppId
+ * @param qqAppId QQAppId
+ */
+ fun initOpenSdkLogin(context: Context, wxAppId: String, qqAppId: String)
/**
* 设置登录信息,与用户相关
*/
fun setLoginInfo(context: Context, userId: String, userName: String, token: String)
+ /**
+ * 启动游戏
+ * @param activity 当前Activity
+ * @param qqGameId QQ游戏ID
+ * @param resultCallback 启动结果回调
+ */
fun launchGame(
activity: Activity,
qqGameId: String,
resultCallback: (resultCode: Int, resultData: Bundle?) -> Unit
)
+ /**
+ * 通过链接启动游戏
+ * @param activity 当前Activity
+ * @param qqGameLink QQ游戏链接
+ * @param resultCallback 启动结果回调
+ */
fun launchGameByLink(
activity: Activity,
qqGameLink: String,
resultCallback: (resultCode: Int, resultData: Bundle?) -> Unit
)
- fun onWechatLogin(context: Context, resp: T)
+ /**
+ * 微信登录回调
+ */
+ fun onWechatLogin(context: Context, content: String, isCanceled: Boolean, message: String)
/**
* 微信分享结果回调
diff --git a/module_login/src/main/java/com/gh/gamecenter/wxapi/WXEntryActivity.java b/module_login/src/main/java/com/gh/gamecenter/wxapi/WXEntryActivity.java
index c867a67ee6..85e609770d 100644
--- a/module_login/src/main/java/com/gh/gamecenter/wxapi/WXEntryActivity.java
+++ b/module_login/src/main/java/com/gh/gamecenter/wxapi/WXEntryActivity.java
@@ -74,10 +74,10 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler, WeC
@Override
public void onResp(BaseResp baseResp) {
+ IQGameProvider iqGameProvider = (IQGameProvider) ARouter.getInstance().build(RouteConsts.provider.qGame).navigation();
// 将分享和 auth 的部分回调抛给 QGameProvider 处理
if (baseResp.getType() == ConstantsAPI.COMMAND_SENDMESSAGE_TO_WX && baseResp instanceof SendMessageToWX.Resp) {
SendMessageToWX.Resp rsp = (SendMessageToWX.Resp) baseResp;
- IQGameProvider iqGameProvider = (IQGameProvider) ARouter.getInstance().build(RouteConsts.provider.qGame).navigation();
if (iqGameProvider != null) {
switch (rsp.errCode) {
@@ -95,14 +95,8 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler, WeC
} else if (baseResp.getType() == ConstantsAPI.COMMAND_SENDAUTH
&& baseResp instanceof SendAuth.Resp
&& ((SendAuth.Resp) baseResp).state != null
- && ((SendAuth.Resp) baseResp).state.contains("qqminigame")
+ && !((SendAuth.Resp) baseResp).state.contains("qqminigame")
) {
- IQGameProvider iqGameProvider = (IQGameProvider) ARouter.getInstance().build(RouteConsts.provider.qGame).navigation();
-
- if (iqGameProvider != null) {
- iqGameProvider.onWechatLogin(this, (SendAuth.Resp) baseResp);
- }
- } else {
WXAPIProxyFactory.getLiveData().postValue(baseResp);
}
@@ -155,7 +149,7 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler, WeC
if (baseResp instanceof SendAuth.Resp) {
SendAuth.Resp resp = (SendAuth.Resp) baseResp;
Utils.log("WXEntryActivity=TOKEN::" + resp.code);
- new WeChatUserInfoThread(WXEntryActivity.this, resp.code, WXEntryActivity.this)
+ new WeChatUserInfoThread(WXEntryActivity.this, resp, WXEntryActivity.this)
.start();
} else {
resultString = "登录失败";
@@ -175,6 +169,12 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler, WeC
}
} else {
resultString = "登录已取消";
+ if (baseResp instanceof SendAuth.Resp
+ && ((SendAuth.Resp) baseResp).state != null
+ && !((SendAuth.Resp) baseResp).state.contains("qqminigame")
+ ) {
+ iqGameProvider.onWechatLogin(this, "", true, resultString);
+ }
}
LoginHelper.onWechatLoginFailure(resultString);
break;
@@ -183,6 +183,12 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler, WeC
resultString = "分享被拒绝";
} else {
resultString = "登录被拒绝";
+ if (baseResp instanceof SendAuth.Resp
+ && ((SendAuth.Resp) baseResp).state != null
+ && !((SendAuth.Resp) baseResp).state.contains("qqminigame")
+ ) {
+ iqGameProvider.onWechatLogin(this, "", true, resultString);
+ }
}
LoginHelper.onWechatLoginFailure(resultString);
break;
@@ -222,6 +228,12 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler, WeC
}
} else {
resultString = "登录错误";
+ if (baseResp instanceof SendAuth.Resp
+ && ((SendAuth.Resp) baseResp).state != null
+ && !((SendAuth.Resp) baseResp).state.contains("qqminigame")
+ ) {
+ iqGameProvider.onWechatLogin(this, "", false, resultString);
+ }
}
LoginHelper.onWechatLoginFailure(resultString);
break;
@@ -233,15 +245,24 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler, WeC
}
@Override
- public void onComplete(final JSONObject content) {
+ public void onComplete(SendAuth.Resp resp, final JSONObject content) {
runOnUiThread(() -> {
LoginHelper.onWechatLoginSuccess(content);
+ if (resp.state != null && resp.state.contains("qqminigame")
+ ) {
+ IQGameProvider iqGameProvider = (IQGameProvider) ARouter
+ .getInstance()
+ .build(RouteConsts.provider.qGame)
+ .navigation();
+ iqGameProvider.onWechatLogin(this, content.toString(), false, "登录成功");
+ }
+
finishActivity();
});
}
@Override
- public void onError() {
+ public void onError(SendAuth.Resp resp) {
LoginHelper.onWechatLoginFailure("登录失败");
finishActivity();
}
diff --git a/module_login/src/main/java/com/gh/gamecenter/wxapi/WeChatUserInfoThread.java b/module_login/src/main/java/com/gh/gamecenter/wxapi/WeChatUserInfoThread.java
index f20d800567..c11afe5243 100644
--- a/module_login/src/main/java/com/gh/gamecenter/wxapi/WeChatUserInfoThread.java
+++ b/module_login/src/main/java/com/gh/gamecenter/wxapi/WeChatUserInfoThread.java
@@ -7,6 +7,7 @@ import com.alibaba.android.arouter.launcher.ARouter;
import com.gh.gamecenter.common.constant.RouteConsts;
import com.gh.gamecenter.core.provider.IConfigProvider;
import com.lightgame.utils.Utils;
+import com.tencent.mm.opensdk.modelmsg.SendAuth;
import org.json.JSONObject;
@@ -25,14 +26,14 @@ public class WeChatUserInfoThread extends Thread {
private Context mContext;
private OnUserInfoCallBackListener listener;
- private String mCode;
+ private SendAuth.Resp mResp;
//刷新access_token有效期
private String refresh_token = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=APPID&grant_type=refresh_token&refresh_token=REFRESH_TOKEN";
- public WeChatUserInfoThread(OnUserInfoCallBackListener listener, String code, Context context) {
+ public WeChatUserInfoThread(OnUserInfoCallBackListener listener, SendAuth.Resp resp, Context context) {
this.listener = listener;
- this.mCode = code;
+ this.mResp = resp;
this.mContext = context;
}
@@ -44,7 +45,7 @@ public class WeChatUserInfoThread extends Thread {
String tokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" +
config.getWechatAppId() + "&secret=" +
config.getWechatSecret() + "&code=" +
- mCode + "&grant_type=authorization_code";
+ mResp.code + "&grant_type=authorization_code";
String jsonResult = getJsonResultByUrlPath(tokenUrl);
JSONObject jsonObject = new JSONObject(jsonResult);
String accessToken = jsonObject.getString("access_token");
@@ -63,16 +64,16 @@ public class WeChatUserInfoThread extends Thread {
// content.put("refresh_token_expire", Utils.getTime(mContext) + 86400 * 30); // 有效期 30天
content.put("unionid", unionid);
- listener.onComplete(content);
+ listener.onComplete(mResp, content);
} else {
if (listener != null) {
- listener.onError();
+ listener.onError(mResp);
}
}
} catch (Exception e) {
e.printStackTrace();
if (listener != null) {
- listener.onError();
+ listener.onError(mResp);
}
}
}
@@ -101,8 +102,8 @@ public class WeChatUserInfoThread extends Thread {
}
public interface OnUserInfoCallBackListener {
- void onComplete(JSONObject content);
+ void onComplete(SendAuth.Resp resp, JSONObject content);
- void onError();
+ void onError(SendAuth.Resp resp);
}
}
diff --git a/module_setting/src/main/java/com/gh/gamecenter/setting/view/SettingsFragment.kt b/module_setting/src/main/java/com/gh/gamecenter/setting/view/SettingsFragment.kt
index 5a4f9b1059..7621125c02 100644
--- a/module_setting/src/main/java/com/gh/gamecenter/setting/view/SettingsFragment.kt
+++ b/module_setting/src/main/java/com/gh/gamecenter/setting/view/SettingsFragment.kt
@@ -417,7 +417,7 @@ class SettingsFragment : ToolbarFragment() {
val qProvider = ARouter
.getInstance()
.build(RouteConsts.provider.qGame)
- .navigation() as IQGameProvider<*>
+ .navigation() as IQGameProvider
qProvider.stopAllMiniApp(true) // 关闭所有QQ小游戏进程
}
},