diff --git a/Runtime/GuruCore/Runtime/IPM/Scripts/IPMConfig.cs b/Runtime/GuruCore/Runtime/IPM/Scripts/IPMConfig.cs
index 68016b7..d4a5e73 100644
--- a/Runtime/GuruCore/Runtime/IPM/Scripts/IPMConfig.cs
+++ b/Runtime/GuruCore/Runtime/IPM/Scripts/IPMConfig.cs
@@ -127,7 +127,11 @@ namespace Guru
public static readonly string IPM_EVENT_URL = IPM_URL + "push/api/v1/push/app/event";
-
+ public static string UUID
+ {
+ get => PlayerPrefs.GetString(nameof(UUID), "");
+ set => PlayerPrefs.SetString(nameof(UUID), value);
+ }
public static string IPM_UID
{
diff --git a/Runtime/GuruCore/Runtime/IPM/Scripts/RequestData/DeviceData.cs b/Runtime/GuruCore/Runtime/IPM/Scripts/RequestData/DeviceData.cs
index f8efc60..873b73b 100644
--- a/Runtime/GuruCore/Runtime/IPM/Scripts/RequestData/DeviceData.cs
+++ b/Runtime/GuruCore/Runtime/IPM/Scripts/RequestData/DeviceData.cs
@@ -32,10 +32,16 @@ namespace Guru
public string idfa; // 可选, ios广告id
public string adid; // 可选, adjust id
public string gpsAdid; // 可选, android广告id
+ public string userUuid; // 可选, 用户唯一ID,由 uid 关联生成的 uuid
public DeviceData()
{
DeviceUtil.GetDeviceInfo();
+ if (string.IsNullOrEmpty(IPMConfig.UUID))
+ {
+ IPMConfig.UUID = IDHelper.GenUUID(IPMConfig.IPM_UID);
+ }
+
deviceId = IPMConfig.IPM_DEVICE_ID;
uid = IPMConfig.IPM_UID;
androidId = SystemInfo.deviceUniqueIdentifier; // Unity get AndroidID
@@ -56,6 +62,7 @@ namespace Guru
idfa = IPMConfig.ADJUST_IDFA;
adid = IPMConfig.ADJUST_ADID;
gpsAdid = IPMConfig.ADJUST_GPSADID;
+ userUuid = IPMConfig.UUID;
}
public override string ToString()
diff --git a/Runtime/GuruCore/Runtime/IPM/Scripts/Requests/AuthUserRequest.cs b/Runtime/GuruCore/Runtime/IPM/Scripts/Requests/AuthUserRequest.cs
index 5935b97..2a87a51 100644
--- a/Runtime/GuruCore/Runtime/IPM/Scripts/Requests/AuthUserRequest.cs
+++ b/Runtime/GuruCore/Runtime/IPM/Scripts/Requests/AuthUserRequest.cs
@@ -55,7 +55,9 @@ 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);
DeviceUtil.Save2AppGroup();
}
+
}
}
\ No newline at end of file
diff --git a/Runtime/GuruCore/Runtime/Utils.meta b/Runtime/GuruCore/Runtime/Utils.meta
new file mode 100644
index 0000000..5a52880
--- /dev/null
+++ b/Runtime/GuruCore/Runtime/Utils.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: da0e89af84894267b29675e22a97856d
+timeCreated: 1716337392
\ No newline at end of file
diff --git a/Runtime/GuruCore/Runtime/Utils/IDHelper.cs b/Runtime/GuruCore/Runtime/Utils/IDHelper.cs
new file mode 100644
index 0000000..97bd26e
--- /dev/null
+++ b/Runtime/GuruCore/Runtime/Utils/IDHelper.cs
@@ -0,0 +1,85 @@
+namespace Guru
+{
+ using System;
+ using UnityEngine;
+ using System.Linq;
+
+ ///
+ /// IDHelper 生成器
+ ///
+ public static class IDHelper
+ {
+ private const string UUID_PREFIX = "1b6eb1"; // 6 bytes
+ private const string UUID_NAMESCPACE = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
+
+ ///
+ /// 通过给定字符串生成固定的 UUID
+ ///
+ ///
+ ///
+ public static string GenUUID(string key)
+ {
+ if (string.IsNullOrEmpty(key))
+ {
+ Debug.Log("Invalid Key");
+ return "";
+ }
+
+ var uid_code = key;
+ if(key.Contains('-')) uid_code = key.Split('-').Last();
+ if (uid_code.Length > 13)
+ {
+ return MakeUUIDV5(key);
+ }
+ return MakeGuruKeyUUID(uid_code);
+ }
+
+
+ public static string MakeUUIDV5(string key)
+ {
+ // 使用DNS命名空间的GUID
+ Guid namespaceId = Guid.Parse(UUID_NAMESCPACE);
+ byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(key);
+
+ // 计算MD5散列
+ byte[] hashBytes = System.Security.Cryptography.MD5.Create().ComputeHash(nameBytes);
+
+ // 将命名空间GUID的二进制值与散列值的前16个字节连接起来
+ byte[] guidBytes = new byte[16];
+ Array.Copy(namespaceId.ToByteArray(), guidBytes, 16);
+ Array.Copy(hashBytes, 0, guidBytes, 0, 16);
+
+ // 设置版本号和变体以生成V5 UUID
+ guidBytes[6] &= 0x0F; // 清除版本位
+ guidBytes[6] |= 0x50; // 设置版本和变体位
+
+ return new Guid(guidBytes).ToString("D");
+ }
+
+ public static string MakeGuruKeyUUID(string uidCode, string prefix = "")
+ {
+ // 使用MD5创建一个散列值
+ if(string.IsNullOrEmpty(prefix)) prefix = UUID_PREFIX; // 6 bytes
+ string haxString = ""; // should be less than 26 bytes
+
+ for(int i =0; i < uidCode.Length; i++){
+ int charCode = (int)(uidCode[i]);
+ // Debug.Log($"charCode: {charCode}");
+ if (charCode > 0xFF)
+ {
+ return "";
+ }
+ haxString += $"{charCode:X2}";
+ }
+ var padNum = 32 - prefix.Length;
+ if (haxString.Length > padNum)
+ {
+ return "";
+ }
+ // Debug.Log($"haxString: {haxString} len: {haxString.Length}");
+ string final = prefix + haxString.PadLeft(padNum, '0');
+ return new Guid(final).ToString("D");
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/Runtime/GuruCore/Runtime/Utils/IDHelper.cs.meta b/Runtime/GuruCore/Runtime/Utils/IDHelper.cs.meta
new file mode 100644
index 0000000..6283eff
--- /dev/null
+++ b/Runtime/GuruCore/Runtime/Utils/IDHelper.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 88ede6c4c4614fd98f070b1275bc9282
+timeCreated: 1716337403
\ No newline at end of file