优化google登陆流程

This commit is contained in:
cebgcontract 2022-10-25 11:21:28 +08:00
parent 80fc141ce0
commit 8f1001d240
3 changed files with 21 additions and 12 deletions

View File

@ -69,7 +69,7 @@ bool AppDelegate::applicationDidFinishLaunching()
jsb_run_script("js/jcwallet.js"); jsb_run_script("js/jcwallet.js");
jsb_run_script("js/platform.js"); jsb_run_script("js/platform.js");
jsb_run_script("js/main.js"); jsb_run_script("js/main.js");
Application::getInstance()->setKeyMaster("1111");
se->addAfterCleanupHook([]() { se->addAfterCleanupHook([]() {
JSBClassType::destroy(); JSBClassType::destroy();
}); });

View File

@ -7,12 +7,11 @@ android {
buildToolsVersion PROP_BUILD_TOOLS_VERSION buildToolsVersion PROP_BUILD_TOOLS_VERSION
defaultConfig { defaultConfig {
applicationId "com.fitchgc.headlesscocos" applicationId "com.fitchgc.jcwallet"
minSdkVersion PROP_MIN_SDK_VERSION minSdkVersion PROP_MIN_SDK_VERSION
targetSdkVersion PROP_TARGET_SDK_VERSION targetSdkVersion PROP_TARGET_SDK_VERSION
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
ndk{ ndk{
abiFilters 'armeabi-v7a','arm64-v8a', 'x86' abiFilters 'armeabi-v7a','arm64-v8a', 'x86'
} }
@ -41,7 +40,7 @@ android {
} }
manifestPlaceholders = [ manifestPlaceholders = [
'appAuthRedirectScheme': 'com.googleusercontent.apps.165555585193-ud80sst45po348ohec2h33t2m6mjnlt0' 'appAuthRedirectScheme': 'com.googleusercontent.apps.165555585193-glmtnb94s3kkq906hal72ppiuoqpjjc5'
] ]
} }

View File

@ -120,6 +120,7 @@ public class MainActivity extends Activity
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE); requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Log.i(TAG, "onCreate: " + getIntent().getDataString());
String cmdLine = updateUnityCommandLineArguments(getIntent().getStringExtra("unity")); String cmdLine = updateUnityCommandLineArguments(getIntent().getStringExtra("unity"));
getIntent().putExtra("unity", cmdLine); getIntent().putExtra("unity", cmdLine);
@ -127,8 +128,7 @@ public class MainActivity extends Activity
mUnityPlayer = new UnityPlayer(this); mUnityPlayer = new UnityPlayer(this);
setContentView(mUnityPlayer); setContentView(mUnityPlayer);
mUnityPlayer.requestFocus(); mUnityPlayer.requestFocus();
// setContentView(R.layout.activity_main);
onLoadNativeLibraries(); onLoadNativeLibraries();
app = this; app = this;
Cocos2dxHelper.init(this); Cocos2dxHelper.init(this);
@ -188,7 +188,7 @@ public class MainActivity extends Activity
break; break;
} }
} else { } else {
JcSDK.csCallback(funId, "{errcode: 0, errmsg: 'cancel'}"); // JcSDK.csCallback(funId, "{errcode: 0, errmsg: 'cancel'}");
funId = ""; funId = "";
} }
} }
@ -411,6 +411,7 @@ public class MainActivity extends Activity
// end of qrcode // end of qrcode
public void signWithGoogle(String funId) { public void signWithGoogle(String funId) {
this.funId = funId;
if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS) { if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS) {
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this); GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
if (account != null) { if (account != null) {
@ -423,7 +424,17 @@ public class MainActivity extends Activity
Log.i(TAG, "no gms, use app auth"); Log.i(TAG, "no gms, use app auth");
AuthState state = mAuthStateManager.getCurrent(); AuthState state = mAuthStateManager.getCurrent();
if (state.isAuthorized() && state.getIdToken() != null) { if (state.isAuthorized() && state.getIdToken() != null) {
Log.w(TAG, "already login: " + state.getIdToken()); Log.w(TAG, "getNeedsTokenRefresh: " + state.getNeedsTokenRefresh());
if (state.getNeedsTokenRefresh()) {
Log.w(TAG, "need refresh accessToken");
TokenRequest tokenRequest = state.createTokenRefreshRequest();
performTokenRequest(
tokenRequest,
this::handleCodeExchangeResponse);
} else {
Log.w(TAG, "already login, accessToken not expired");
Log.w(TAG, "id token : " + state.getIdToken());
}
} else { } else {
mExecutor.submit(this::doAuth); mExecutor.submit(this::doAuth);
} }
@ -441,7 +452,7 @@ public class MainActivity extends Activity
try { try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class); GoogleSignInAccount account = completedTask.getResult(ApiException.class);
Log.w(TAG, "signIn success: "); Log.w(TAG, "signIn success: ");
Log.w(TAG, "idToken: " + account.getIdToken()); Log.w(TAG, "app auth idToken: " + account.getIdToken());
// Signed in successfully, show authenticated UI. // Signed in successfully, show authenticated UI.
} catch (ApiException e) { } catch (ApiException e) {
// The ApiException status code indicates the detailed failure reason. // The ApiException status code indicates the detailed failure reason.
@ -693,10 +704,9 @@ public class MainActivity extends Activity
//noinspection WrongThread //noinspection WrongThread
Log.d(TAG, message); Log.d(TAG, message);
} else { } else {
Log.d(TAG, "success");
AuthState state = mAuthStateManager.getCurrent(); AuthState state = mAuthStateManager.getCurrent();
Log.d(TAG, String.valueOf(state.isAuthorized())); Log.d(TAG, "login success, auth state: " + state.isAuthorized());
Log.d(TAG, String.valueOf(state.getIdToken())); Log.d(TAG, "app auth idToken: " + state.getIdToken());
mAuthStateManager.replace(state); mAuthStateManager.replace(state);
} }
} }