parent
4b6a458396
commit
3649c24d26
|
|
@ -4,19 +4,21 @@ using UnityEngine;
|
|||
|
||||
namespace Guru
|
||||
{
|
||||
using System;
|
||||
public static partial class FirebaseUtil
|
||||
{
|
||||
public static FirebaseUser CurrentUser => FirebaseAuth.DefaultInstance.CurrentUser;
|
||||
|
||||
private static readonly WaitForSeconds _wait = new WaitForSeconds(10);
|
||||
|
||||
public static void AuthUser()
|
||||
public static void AuthUser(Action onSuccessHandler = null)
|
||||
{
|
||||
//FirebaseAuth获取用户验证并同步用户数据
|
||||
if (CurrentUser != null)
|
||||
{
|
||||
Log.I(LOG_TAG, $"[Auth] user exists,UserId:{CurrentUser.UserId}");
|
||||
OnFirebaseAuthResult?.Invoke(true);
|
||||
onSuccessHandler?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -24,7 +26,7 @@ namespace Guru
|
|||
Log.I(LOG_TAG, $"[Auth] Firebase Token:{authToken}");
|
||||
if (string.IsNullOrEmpty(authToken) || !NetworkUtil.IsNetAvaliable)
|
||||
{
|
||||
CoroutineHelper.Instance.StartDelayed(_wait, AuthUser);
|
||||
CoroutineHelper.Instance.StartDelayed(_wait, ()=> AuthUser(onSuccessHandler));
|
||||
OnFirebaseAuthResult?.Invoke(false);
|
||||
return;
|
||||
}
|
||||
|
|
@ -37,18 +39,19 @@ namespace Guru
|
|||
{
|
||||
Log.E(LOG_TAG,"[Auth] SignInWithCustomTokenAsync encountered an error: " + task.Exception);
|
||||
OnFirebaseAuthResult?.Invoke(false);
|
||||
CoroutineHelper.Instance.StartDelayed(_wait, AuthUser);
|
||||
CoroutineHelper.Instance.StartDelayed(_wait, () => AuthUser(onSuccessHandler));
|
||||
return;
|
||||
}
|
||||
// ----- User is NULL -----
|
||||
if (CurrentUser == null)
|
||||
{
|
||||
OnFirebaseAuthResult?.Invoke(false);
|
||||
CoroutineHelper.Instance.StartDelayed(_wait, AuthUser);
|
||||
CoroutineHelper.Instance.StartDelayed(_wait, ()=> AuthUser(onSuccessHandler));
|
||||
return;
|
||||
}
|
||||
// ----- Success -----
|
||||
OnFirebaseAuthResult?.Invoke(true); // 最后判定是成功的
|
||||
onSuccessHandler?.Invoke();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,8 +61,7 @@ namespace Guru
|
|||
.SetSuccessCallBack(() =>
|
||||
{
|
||||
OnUserAuthResult?.Invoke(true);
|
||||
InitializeMessage();
|
||||
AuthUser();
|
||||
AuthUser(InitializeMessage);
|
||||
}).SetFailCallBack(() =>
|
||||
{
|
||||
OnUserAuthResult?.Invoke(false);
|
||||
|
|
@ -84,12 +83,12 @@ namespace Guru
|
|||
//中台firebaseToken失效,从中台重新获取firebaseToken
|
||||
new RefreshFirebaseTokenRequest()
|
||||
.SetRetryTimes(-1)
|
||||
.SetSuccessCallBack(AuthUser)
|
||||
.SetSuccessCallBack(()=> AuthUser(InitializeMessage))
|
||||
.Send();
|
||||
}
|
||||
else
|
||||
{
|
||||
AuthUser();
|
||||
AuthUser(InitializeMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ namespace Guru
|
|||
if(!string.IsNullOrEmpty(content))
|
||||
{
|
||||
string[] infos = content.Split('$');
|
||||
IPMConfig.SetDeviceId(infos[0]);
|
||||
// IPMConfig.SetDeviceId(infos[0]);
|
||||
IPMConfig.IPM_APP_VERSION = infos[1];
|
||||
IPMConfig.IPM_TIMEZONE = infos[2];
|
||||
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 string UUID
|
||||
public static string IPM_UUID
|
||||
{
|
||||
get => PlayerPrefs.GetString(nameof(UUID), "");
|
||||
set => PlayerPrefs.SetString(nameof(UUID), value);
|
||||
get => PlayerPrefs.GetString(nameof(IPM_UUID), "");
|
||||
set => PlayerPrefs.SetString(nameof(IPM_UUID), value);
|
||||
}
|
||||
|
||||
public static string IPM_UID
|
||||
|
|
|
|||
|
|
@ -37,9 +37,9 @@ namespace Guru
|
|||
public DeviceData()
|
||||
{
|
||||
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;
|
||||
|
|
@ -62,7 +62,7 @@ namespace Guru
|
|||
idfa = IPMConfig.ADJUST_IDFA;
|
||||
adid = IPMConfig.ADJUST_ADID;
|
||||
gpsAdid = IPMConfig.ADJUST_GPSADID;
|
||||
userUuid = IPMConfig.UUID;
|
||||
userUuid = IPMConfig.IPM_UUID;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ namespace Guru
|
|||
IPMConfig.IPM_NEWUSER = responseData.data.newUser;
|
||||
IPMConfig.IPM_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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ namespace Guru
|
|||
private byte[] _googlePublicKey;
|
||||
private byte[] _appleRootCert;
|
||||
private string _uid;
|
||||
|
||||
private string _uuid;
|
||||
/// <summary>
|
||||
/// 服务初始化回调
|
||||
/// </summary>
|
||||
|
|
@ -157,6 +157,30 @@ namespace Guru
|
|||
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>
|
||||
|
|
@ -231,14 +255,14 @@ namespace Guru
|
|||
{
|
||||
_storeController = controller;
|
||||
_storeExtensionProvider = extensions;
|
||||
var uuid = IPMConfig.UUID;
|
||||
var uuid = IPMConfig.IPM_UUID;
|
||||
if(string.IsNullOrEmpty(_uid)) _uid = IPMConfig.IPM_UID;
|
||||
|
||||
if (!string.IsNullOrEmpty(_uid) && string.IsNullOrEmpty(uuid))
|
||||
{
|
||||
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
|
||||
_appleExtensions = extensions.GetExtension<IAppleExtensions>();
|
||||
|
|
@ -250,6 +274,13 @@ namespace Guru
|
|||
LogI("Purchase deferred: " + item.definition.id);
|
||||
OnAppStorePurchaseDeferred?.Invoke(item);
|
||||
});
|
||||
|
||||
var appReceipt = _configBuilder.Configure<IAppleConfiguration>().appReceipt;
|
||||
if (!string.IsNullOrEmpty(appReceipt))
|
||||
{
|
||||
LogI($"[IAP] --- AppReceipt: {appReceipt}");
|
||||
}
|
||||
|
||||
#elif UNITY_ANDROID
|
||||
_configBuilder.Configure<IGooglePlayConfiguration>().SetObfuscatedAccountId(_uid); // SetUp UID
|
||||
_googlePlayStoreExtensions = extensions.GetExtension<IGooglePlayStoreExtensions>();
|
||||
|
|
@ -257,6 +288,9 @@ namespace Guru
|
|||
_googlePlayStoreExtensions.RestoreTransactions(OnRestoreHandle);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
foreach (var product in _storeController.products.all)
|
||||
{
|
||||
if (!product.availableToPurchase)
|
||||
|
|
@ -764,8 +798,12 @@ namespace Guru
|
|||
appleReceiptString = recp.ToString();
|
||||
LogI($"--- [{productId}] iOS receipt: {appleReceiptString}");
|
||||
}
|
||||
|
||||
Debug.Log($"[IAP] --- Full receipt: \n{args.purchasedProduct.receipt}");
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
allReceipts = _validator.Validate(args.purchasedProduct.receipt);
|
||||
|
||||
// ---- Android 订单验证, 上报打点信息 ----
|
||||
|
|
|
|||
Loading…
Reference in New Issue