parent
4b6a458396
commit
3649c24d26
|
|
@ -4,19 +4,21 @@ using UnityEngine;
|
||||||
|
|
||||||
namespace Guru
|
namespace Guru
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
public static partial class FirebaseUtil
|
public static partial class FirebaseUtil
|
||||||
{
|
{
|
||||||
public static FirebaseUser CurrentUser => FirebaseAuth.DefaultInstance.CurrentUser;
|
public static FirebaseUser CurrentUser => FirebaseAuth.DefaultInstance.CurrentUser;
|
||||||
|
|
||||||
private static readonly WaitForSeconds _wait = new WaitForSeconds(10);
|
private static readonly WaitForSeconds _wait = new WaitForSeconds(10);
|
||||||
|
|
||||||
public static void AuthUser()
|
public static void AuthUser(Action onSuccessHandler = null)
|
||||||
{
|
{
|
||||||
//FirebaseAuth获取用户验证并同步用户数据
|
//FirebaseAuth获取用户验证并同步用户数据
|
||||||
if (CurrentUser != null)
|
if (CurrentUser != null)
|
||||||
{
|
{
|
||||||
Log.I(LOG_TAG, $"[Auth] user exists,UserId:{CurrentUser.UserId}");
|
Log.I(LOG_TAG, $"[Auth] user exists,UserId:{CurrentUser.UserId}");
|
||||||
OnFirebaseAuthResult?.Invoke(true);
|
OnFirebaseAuthResult?.Invoke(true);
|
||||||
|
onSuccessHandler?.Invoke();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -24,7 +26,7 @@ namespace Guru
|
||||||
Log.I(LOG_TAG, $"[Auth] Firebase Token:{authToken}");
|
Log.I(LOG_TAG, $"[Auth] Firebase Token:{authToken}");
|
||||||
if (string.IsNullOrEmpty(authToken) || !NetworkUtil.IsNetAvaliable)
|
if (string.IsNullOrEmpty(authToken) || !NetworkUtil.IsNetAvaliable)
|
||||||
{
|
{
|
||||||
CoroutineHelper.Instance.StartDelayed(_wait, AuthUser);
|
CoroutineHelper.Instance.StartDelayed(_wait, ()=> AuthUser(onSuccessHandler));
|
||||||
OnFirebaseAuthResult?.Invoke(false);
|
OnFirebaseAuthResult?.Invoke(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -37,18 +39,19 @@ namespace Guru
|
||||||
{
|
{
|
||||||
Log.E(LOG_TAG,"[Auth] SignInWithCustomTokenAsync encountered an error: " + task.Exception);
|
Log.E(LOG_TAG,"[Auth] SignInWithCustomTokenAsync encountered an error: " + task.Exception);
|
||||||
OnFirebaseAuthResult?.Invoke(false);
|
OnFirebaseAuthResult?.Invoke(false);
|
||||||
CoroutineHelper.Instance.StartDelayed(_wait, AuthUser);
|
CoroutineHelper.Instance.StartDelayed(_wait, () => AuthUser(onSuccessHandler));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// ----- User is NULL -----
|
// ----- User is NULL -----
|
||||||
if (CurrentUser == null)
|
if (CurrentUser == null)
|
||||||
{
|
{
|
||||||
OnFirebaseAuthResult?.Invoke(false);
|
OnFirebaseAuthResult?.Invoke(false);
|
||||||
CoroutineHelper.Instance.StartDelayed(_wait, AuthUser);
|
CoroutineHelper.Instance.StartDelayed(_wait, ()=> AuthUser(onSuccessHandler));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// ----- Success -----
|
// ----- Success -----
|
||||||
OnFirebaseAuthResult?.Invoke(true); // 最后判定是成功的
|
OnFirebaseAuthResult?.Invoke(true); // 最后判定是成功的
|
||||||
|
onSuccessHandler?.Invoke();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,7 @@ namespace Guru
|
||||||
.SetSuccessCallBack(() =>
|
.SetSuccessCallBack(() =>
|
||||||
{
|
{
|
||||||
OnUserAuthResult?.Invoke(true);
|
OnUserAuthResult?.Invoke(true);
|
||||||
InitializeMessage();
|
AuthUser(InitializeMessage);
|
||||||
AuthUser();
|
|
||||||
}).SetFailCallBack(() =>
|
}).SetFailCallBack(() =>
|
||||||
{
|
{
|
||||||
OnUserAuthResult?.Invoke(false);
|
OnUserAuthResult?.Invoke(false);
|
||||||
|
|
@ -84,12 +83,12 @@ namespace Guru
|
||||||
//中台firebaseToken失效,从中台重新获取firebaseToken
|
//中台firebaseToken失效,从中台重新获取firebaseToken
|
||||||
new RefreshFirebaseTokenRequest()
|
new RefreshFirebaseTokenRequest()
|
||||||
.SetRetryTimes(-1)
|
.SetRetryTimes(-1)
|
||||||
.SetSuccessCallBack(AuthUser)
|
.SetSuccessCallBack(()=> AuthUser(InitializeMessage))
|
||||||
.Send();
|
.Send();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AuthUser();
|
AuthUser(InitializeMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ namespace Guru
|
||||||
if(!string.IsNullOrEmpty(content))
|
if(!string.IsNullOrEmpty(content))
|
||||||
{
|
{
|
||||||
string[] infos = content.Split('$');
|
string[] infos = content.Split('$');
|
||||||
IPMConfig.SetDeviceId(infos[0]);
|
// IPMConfig.SetDeviceId(infos[0]);
|
||||||
IPMConfig.IPM_APP_VERSION = infos[1];
|
IPMConfig.IPM_APP_VERSION = infos[1];
|
||||||
IPMConfig.IPM_TIMEZONE = infos[2];
|
IPMConfig.IPM_TIMEZONE = infos[2];
|
||||||
IPMConfig.IPM_MODEL = infos[3];
|
IPMConfig.IPM_MODEL = infos[3];
|
||||||
|
|
|
||||||
|
|
@ -127,10 +127,10 @@ namespace Guru
|
||||||
public static readonly string IPM_EVENT_URL = IPM_URL + "push/api/v1/push/app/event";
|
public static readonly string IPM_EVENT_URL = IPM_URL + "push/api/v1/push/app/event";
|
||||||
|
|
||||||
|
|
||||||
public static string UUID
|
public static string IPM_UUID
|
||||||
{
|
{
|
||||||
get => PlayerPrefs.GetString(nameof(UUID), "");
|
get => PlayerPrefs.GetString(nameof(IPM_UUID), "");
|
||||||
set => PlayerPrefs.SetString(nameof(UUID), value);
|
set => PlayerPrefs.SetString(nameof(IPM_UUID), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string IPM_UID
|
public static string IPM_UID
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,9 @@ namespace Guru
|
||||||
public DeviceData()
|
public DeviceData()
|
||||||
{
|
{
|
||||||
DeviceUtil.GetDeviceInfo();
|
DeviceUtil.GetDeviceInfo();
|
||||||
if (string.IsNullOrEmpty(IPMConfig.UUID))
|
if (string.IsNullOrEmpty(IPMConfig.IPM_UUID))
|
||||||
{
|
{
|
||||||
IPMConfig.UUID = IDHelper.GenUUID(IPMConfig.IPM_UID);
|
IPMConfig.IPM_UUID = IDHelper.GenUUID(IPMConfig.IPM_UID);
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceId = IPMConfig.IPM_DEVICE_ID;
|
deviceId = IPMConfig.IPM_DEVICE_ID;
|
||||||
|
|
@ -62,7 +62,7 @@ namespace Guru
|
||||||
idfa = IPMConfig.ADJUST_IDFA;
|
idfa = IPMConfig.ADJUST_IDFA;
|
||||||
adid = IPMConfig.ADJUST_ADID;
|
adid = IPMConfig.ADJUST_ADID;
|
||||||
gpsAdid = IPMConfig.ADJUST_GPSADID;
|
gpsAdid = IPMConfig.ADJUST_GPSADID;
|
||||||
userUuid = IPMConfig.UUID;
|
userUuid = IPMConfig.IPM_UUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ namespace Guru
|
||||||
IPMConfig.IPM_NEWUSER = responseData.data.newUser;
|
IPMConfig.IPM_NEWUSER = responseData.data.newUser;
|
||||||
IPMConfig.IPM_TOKEN_TIME = TimeUtil.GetCurrentTimeStampSecond();
|
IPMConfig.IPM_TOKEN_TIME = TimeUtil.GetCurrentTimeStampSecond();
|
||||||
IPMConfig.IPM_FIREBASE_TOKEN_TIME = TimeUtil.GetCurrentTimeStampSecond();
|
IPMConfig.IPM_FIREBASE_TOKEN_TIME = TimeUtil.GetCurrentTimeStampSecond();
|
||||||
IPMConfig.UUID = IDHelper.GenUUID(responseData.data.uid);
|
IPMConfig.IPM_UUID = IDHelper.GenUUID(responseData.data.uid);
|
||||||
DeviceUtil.Save2AppGroup();
|
DeviceUtil.Save2AppGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ namespace Guru
|
||||||
private byte[] _googlePublicKey;
|
private byte[] _googlePublicKey;
|
||||||
private byte[] _appleRootCert;
|
private byte[] _appleRootCert;
|
||||||
private string _uid;
|
private string _uid;
|
||||||
|
private string _uuid;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 服务初始化回调
|
/// 服务初始化回调
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -157,6 +157,30 @@ namespace Guru
|
||||||
Initialize(uid, showLog);
|
Initialize(uid, showLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void SetUID(string uid)
|
||||||
|
{
|
||||||
|
if (_configBuilder != null && !string.IsNullOrEmpty(uid))
|
||||||
|
{
|
||||||
|
_uid = uid;
|
||||||
|
_configBuilder.Configure<IGooglePlayConfiguration>().SetObfuscatedAccountId(uid);
|
||||||
|
Debug.Log($"[IAP] --- Set UID: {uid}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void SetUUID(string uuid)
|
||||||
|
{
|
||||||
|
if (_appleExtensions != null && !string.IsNullOrEmpty(uuid))
|
||||||
|
{
|
||||||
|
_uuid = uuid;
|
||||||
|
_appleExtensions.SetApplicationUsername(uuid);
|
||||||
|
Debug.Log($"[IAP] --- Set UUID: {uuid}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化支付插件
|
/// 初始化支付插件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -231,14 +255,14 @@ namespace Guru
|
||||||
{
|
{
|
||||||
_storeController = controller;
|
_storeController = controller;
|
||||||
_storeExtensionProvider = extensions;
|
_storeExtensionProvider = extensions;
|
||||||
var uuid = IPMConfig.UUID;
|
var uuid = IPMConfig.IPM_UUID;
|
||||||
if(string.IsNullOrEmpty(_uid)) _uid = IPMConfig.IPM_UID;
|
if(string.IsNullOrEmpty(_uid)) _uid = IPMConfig.IPM_UID;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(_uid) && string.IsNullOrEmpty(uuid))
|
if (!string.IsNullOrEmpty(_uid) && string.IsNullOrEmpty(uuid))
|
||||||
{
|
{
|
||||||
uuid = IDHelper.GenUUID(_uid);
|
uuid = IDHelper.GenUUID(_uid);
|
||||||
}
|
}
|
||||||
LogI($"--- IAP Initialized Success. With UID: {_uid} and UUID: {uuid}");
|
LogI($"--- IAP Initialized Success. With UID: {_uid} UUID: {uuid} DeviceId: {IPMConfig.IPM_DEVICE_ID}");
|
||||||
|
|
||||||
#if UNITY_IOS
|
#if UNITY_IOS
|
||||||
_appleExtensions = extensions.GetExtension<IAppleExtensions>();
|
_appleExtensions = extensions.GetExtension<IAppleExtensions>();
|
||||||
|
|
@ -250,12 +274,22 @@ namespace Guru
|
||||||
LogI("Purchase deferred: " + item.definition.id);
|
LogI("Purchase deferred: " + item.definition.id);
|
||||||
OnAppStorePurchaseDeferred?.Invoke(item);
|
OnAppStorePurchaseDeferred?.Invoke(item);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var appReceipt = _configBuilder.Configure<IAppleConfiguration>().appReceipt;
|
||||||
|
if (!string.IsNullOrEmpty(appReceipt))
|
||||||
|
{
|
||||||
|
LogI($"[IAP] --- AppReceipt: {appReceipt}");
|
||||||
|
}
|
||||||
|
|
||||||
#elif UNITY_ANDROID
|
#elif UNITY_ANDROID
|
||||||
_configBuilder.Configure<IGooglePlayConfiguration>().SetObfuscatedAccountId(_uid); // SetUp UID
|
_configBuilder.Configure<IGooglePlayConfiguration>().SetObfuscatedAccountId(_uid); // SetUp UID
|
||||||
_googlePlayStoreExtensions = extensions.GetExtension<IGooglePlayStoreExtensions>();
|
_googlePlayStoreExtensions = extensions.GetExtension<IGooglePlayStoreExtensions>();
|
||||||
//添加安装游戏后第一次初试化进行恢复购买的回调 只有安卓才有
|
//添加安装游戏后第一次初试化进行恢复购买的回调 只有安卓才有
|
||||||
_googlePlayStoreExtensions.RestoreTransactions(OnRestoreHandle);
|
_googlePlayStoreExtensions.RestoreTransactions(OnRestoreHandle);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach (var product in _storeController.products.all)
|
foreach (var product in _storeController.products.all)
|
||||||
{
|
{
|
||||||
|
|
@ -764,7 +798,11 @@ namespace Guru
|
||||||
appleReceiptString = recp.ToString();
|
appleReceiptString = recp.ToString();
|
||||||
LogI($"--- [{productId}] iOS receipt: {appleReceiptString}");
|
LogI($"--- [{productId}] iOS receipt: {appleReceiptString}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Debug.Log($"[IAP] --- Full receipt: \n{args.purchasedProduct.receipt}");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
allReceipts = _validator.Validate(args.purchasedProduct.receipt);
|
allReceipts = _validator.Validate(args.purchasedProduct.receipt);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue