实现 Flexion 渠道支付验签重构:支付成功后不立即消费,将 purchaseJson/signature/purchaseToken 回调至 Unity,由服务端 SHA1withRSA 验签并校验 developerPayload.playerId 后再调用 consume。 同步更新 SDKManager 接口、UnityBridgeFunc 桥接、TYSdkModel 字段及 ExtraPluginCfgs。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
418 lines
14 KiB
C#
418 lines
14 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
using UnityEngine;
|
|
|
|
namespace tysdk
|
|
{
|
|
public static class UnityBridgeFunc
|
|
{
|
|
#if UNITY_EDITOR
|
|
public static void InitSDK() { }
|
|
|
|
public static void UnityResetServerUrl(string url) { }
|
|
|
|
public static void UnityLoginByTokenFun(string token) { }
|
|
|
|
public static string UnityLoginBySnsInfoFun() => null;
|
|
|
|
public static void UnityLogin(EAccoutType accoutType) { }
|
|
|
|
public static void CleanLinkTmpSnsInfo() { }
|
|
|
|
public static void LinkAccount(EAccoutType accoutType) { }
|
|
public static void ChangeLinkAccount(EAccoutType accoutType, int oldUserId, int newUserId) { }
|
|
public static void LinkCheck(EAccoutType accoutType) { }
|
|
|
|
public static void UnityGetIdentityFun(string type) { }
|
|
|
|
public static void UnityLogOutByChannel(EAccoutType accoutType) { }
|
|
|
|
public static void UnityKnowNew(string productId, string productPrice, string productName,
|
|
string productCount, string prodorderId, string appInfo, string pType) { }
|
|
|
|
public static void UnityKnow(String productId, String productName, String productCount,
|
|
String prodorderId, String appInfo) { }
|
|
|
|
public static void GetSKUList() { }
|
|
|
|
public static void SetGaUserInfo(string userId) { }
|
|
|
|
public static void SetGaCommonInfo(string SetGaCommonInfo) { }
|
|
|
|
public static void GAReportParams(int type, string eventstr, string paramstr) { }
|
|
|
|
public static void RequestATT() { }
|
|
|
|
public static int GetATT() { return 1; }
|
|
|
|
public static void Review() { }
|
|
|
|
public static void FBShareLink(string title, string content, string url) { }
|
|
public static void MessengerShareLink(string title, string content, string url) { }
|
|
|
|
#elif UNITY_ANDROID
|
|
|
|
private static string SDK_CLASS = "com.unity3d.player.SDKManager";
|
|
|
|
private static string EAccountTypeToStr(EAccoutType accoutType)
|
|
{
|
|
return accoutType == EAccoutType.hwVkid ? "vk.global.app" : accoutType.ToString();
|
|
}
|
|
|
|
public static void InitSDK()
|
|
{
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
using (var activityCls = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
|
|
{
|
|
var activity = activityCls.GetStatic<AndroidJavaObject>("currentActivity");
|
|
UnityEngine.Debug.Log("[CHANNEL-VERIFY] C# InitSDK → ChannelConfig.Channel=" + ChannelConfig.Channel);
|
|
sdkManager.CallStatic("InitSDK", activity, ChannelConfig.Channel);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void UnityResetServerUrl(string url)
|
|
{
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
sdkManager.CallStatic("UnityResetServerUrl", url);
|
|
}
|
|
}
|
|
|
|
public static void UnityLoginByTokenFun(string token)
|
|
{
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
sdkManager.CallStatic("UnityLoginByTokenFun", token);
|
|
}
|
|
}
|
|
|
|
public static String UnityLoginBySnsInfoFun()
|
|
{
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
return sdkManager.CallStatic<string>("UnityLoginBySnsInfo");
|
|
}
|
|
}
|
|
|
|
public static void UnityLogin(EAccoutType accoutType)
|
|
{
|
|
var accountInfo = EAccountTypeToStr(accoutType);
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
sdkManager.CallStatic("UnityLogin", accountInfo);
|
|
}
|
|
}
|
|
|
|
public static void UnityGetIdentityFun(string type)
|
|
{
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
sdkManager.CallStatic("UnityGetIdentityFun", type);
|
|
}
|
|
}
|
|
|
|
public static void UnityLogOutByChannel(EAccoutType accoutType)
|
|
{
|
|
var accountInfo = EAccountTypeToStr(accoutType);
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
sdkManager.CallStatic("UnityLogOutByChannel", accountInfo);
|
|
}
|
|
}
|
|
|
|
public static void LinkAccount(EAccoutType accoutType)
|
|
{
|
|
string userId = TYSdkFacade.TYAccountInfo.strUserId;
|
|
var accountInfo = EAccountTypeToStr(accoutType);
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
sdkManager.CallStatic("LinkAccount", accountInfo, userId);
|
|
}
|
|
}
|
|
|
|
public static void CleanLinkTmpSnsInfo()
|
|
{
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
sdkManager.CallStatic("CleanLinkTmpSnsInfo");
|
|
}
|
|
}
|
|
|
|
public static void ChangeLinkAccount(EAccoutType accoutType, int oldUserId, int newUserId)
|
|
{
|
|
var accountInfo = EAccountTypeToStr(accoutType);
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
sdkManager.CallStatic("ChangeLinkAccount", accountInfo, oldUserId, newUserId);
|
|
}
|
|
}
|
|
|
|
public static void LinkCheck(EAccoutType accoutType)
|
|
{
|
|
var accountInfo = EAccountTypeToStr(accoutType);
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
sdkManager.CallStatic("LinkCheck", accountInfo);
|
|
}
|
|
}
|
|
|
|
public static void UnityKnowNew(string productId, string productPrice, string productName,
|
|
string productCount, string prodorderId, string appInfo, string pType)
|
|
{
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
sdkManager.CallStatic("UnityKnowNew", productId, productPrice, productName,
|
|
productCount, prodorderId, appInfo, pType);
|
|
}
|
|
}
|
|
|
|
public static void ConsumeFlexionPurchase(string token)
|
|
{
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
sdkManager.CallStatic("ConsumeFlexionPurchase", token);
|
|
}
|
|
}
|
|
|
|
public static void UnityKnow(String productId, String productName, String productCount, String prodorderId, String appInfo)
|
|
{
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
sdkManager.CallStatic("UnityKnow", productId, productName, productCount, prodorderId, appInfo);
|
|
}
|
|
}
|
|
|
|
public static void GetSKUList()
|
|
{
|
|
UnityEngine.Debug.Log("UnityBridgeFunc.GetSKUList()");
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
sdkManager.CallStatic("thirdExtend");
|
|
}
|
|
}
|
|
|
|
public static void SetGaUserInfo(string userId)
|
|
{
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
sdkManager.CallStatic("SetGaUserInfo", userId);
|
|
}
|
|
}
|
|
|
|
public static void SetGaCommonInfo(string SetGaCommonInfo)
|
|
{
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
sdkManager.CallStatic("SetGaCommonInfo", SetGaCommonInfo);
|
|
}
|
|
}
|
|
|
|
public static void GAReportParams(int type, string eventstr, string paramstr)
|
|
{
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
sdkManager.CallStatic("GAReportParams", type, eventstr, paramstr);
|
|
}
|
|
}
|
|
|
|
public static void RequestATT() { }
|
|
|
|
public static int GetATT() { return 1; }
|
|
|
|
public static void Review()
|
|
{
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
sdkManager.CallStatic("Review");
|
|
}
|
|
}
|
|
|
|
public static void FBShareLink(string title, string content, string url)
|
|
{
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
sdkManager.CallStatic("FBShareLink", title, content, url);
|
|
}
|
|
}
|
|
|
|
public static void MessengerShareLink(string title, string content, string url)
|
|
{
|
|
using (var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
|
{
|
|
sdkManager.CallStatic("MessengerShareLink", title, content, url);
|
|
}
|
|
}
|
|
|
|
#elif UNITY_IOS
|
|
|
|
[DllImport("__Internal")]
|
|
public static extern void UnityResetServerUrl(string url);
|
|
|
|
[DllImport("__Internal")]
|
|
public static extern void UnityLoginByTokenFun(string token);
|
|
|
|
[DllImport("__Internal")]
|
|
private static extern IntPtr UnityLoginBySnsInfo();
|
|
|
|
public static string UnityLoginBySnsInfoFun()
|
|
{
|
|
IntPtr ptr = UnityLoginBySnsInfo();
|
|
|
|
if (ptr == IntPtr.Zero)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
string result = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(ptr);
|
|
return result ?? string.Empty;
|
|
}
|
|
|
|
public static void UnityLogin(EAccoutType accoutType)
|
|
{
|
|
switch (accoutType)
|
|
{
|
|
case EAccoutType.hwGoogle:
|
|
UnityLoginByGoogle();
|
|
break;
|
|
case EAccoutType.hwFacebook:
|
|
UnityLoginByFacebook();
|
|
break;
|
|
case EAccoutType.hwGuest:
|
|
UnityLoginByGuest();
|
|
break;
|
|
case EAccoutType.Apple:
|
|
UnityLoginByApple();
|
|
break;
|
|
}
|
|
}
|
|
|
|
[DllImport("__Internal")]
|
|
private static extern void UnityLoginByGuest();
|
|
|
|
[DllImport("__Internal")]
|
|
private static extern void UnityLoginByGoogle();
|
|
|
|
[DllImport("__Internal")]
|
|
private static extern void UnityLoginByFacebook();
|
|
|
|
[DllImport("__Internal")]
|
|
private static extern void UnityLoginByApple();
|
|
|
|
[DllImport("__Internal")]
|
|
public static extern void UnityGetIdentityFun(string type);
|
|
|
|
[DllImport("__Internal")]
|
|
public static extern void UnityLoginOut();
|
|
|
|
public static void UnityLogOutByChannel(EAccoutType accoutType)
|
|
{
|
|
switch (accoutType)
|
|
{
|
|
case EAccoutType.hwGoogle:
|
|
UnityLogoutGoogle();
|
|
break;
|
|
case EAccoutType.hwFacebook:
|
|
UnityLogoutFacebook();
|
|
break;
|
|
case EAccoutType.hwGuest:
|
|
UnityLogoutGuest();
|
|
break;
|
|
case EAccoutType.Apple:
|
|
UnityLogoutApple();
|
|
break;
|
|
}
|
|
}
|
|
|
|
[DllImport("__Internal")]
|
|
private static extern void UnityLogoutGoogle();
|
|
|
|
[DllImport("__Internal")]
|
|
private static extern void UnityLogoutFacebook();
|
|
|
|
[DllImport("__Internal")]
|
|
private static extern void UnityLogoutGuest();
|
|
|
|
[DllImport("__Internal")]
|
|
private static extern void UnityLogoutApple();
|
|
|
|
public static void LinkAccount(EAccoutType accoutType)
|
|
{
|
|
var userId = TYSdkFacade.TYAccountInfo.userId;
|
|
|
|
switch (accoutType)
|
|
{
|
|
case EAccoutType.hwGoogle:
|
|
LinkGoogle(userId);
|
|
break;
|
|
case EAccoutType.hwFacebook:
|
|
LinkFacebook(userId);
|
|
break;
|
|
case EAccoutType.Apple:
|
|
LinkApple(userId);
|
|
break;
|
|
}
|
|
}
|
|
|
|
[DllImport("__Internal")] private static extern void LinkGoogle(int userId);
|
|
[DllImport("__Internal")] private static extern void LinkFacebook(int userId);
|
|
[DllImport("__Internal")] private static extern void LinkApple(int userId);
|
|
|
|
[DllImport("__Internal")]
|
|
public static extern void ChangeLinkAccount(EAccoutType accoutType, int oldUserId, int newUserId);
|
|
|
|
public static void LinkCheck(EAccoutType accoutType)
|
|
{
|
|
switch (accoutType)
|
|
{
|
|
case EAccoutType.hwGoogle:
|
|
IsLinkedGoogle();
|
|
break;
|
|
case EAccoutType.hwFacebook:
|
|
IsLinkedFacebook();
|
|
break;
|
|
case EAccoutType.Apple:
|
|
IsLinkedApple();
|
|
break;
|
|
}
|
|
}
|
|
|
|
[DllImport("__Internal")] public static extern void CleanLinkTmpSnsInfo();
|
|
|
|
[DllImport("__Internal")] private static extern void IsLinkedGoogle();
|
|
[DllImport("__Internal")] private static extern void IsLinkedFacebook();
|
|
[DllImport("__Internal")] private static extern void IsLinkedApple();
|
|
|
|
[DllImport("__Internal")]
|
|
public static extern void UnityKnow(string userId, string productId, string productPrice, string productName,
|
|
string productCount, string prodorderId, string appInfo);
|
|
|
|
[DllImport("__Internal")]
|
|
public static extern void GetSKUList();
|
|
|
|
[DllImport("__Internal")]
|
|
public static extern void SetGaUserInfo(string userId);
|
|
|
|
[DllImport("__Internal")]
|
|
public static extern void SetGaCommonInfo(string SetGaCommonInfo);
|
|
|
|
[DllImport("__Internal")]
|
|
public static extern void GAReportParams(int type, string eventstr, string paramstr);
|
|
|
|
[DllImport("__Internal")]
|
|
public static extern void RequestATT();
|
|
|
|
[DllImport("__Internal")]
|
|
public static extern int GetATT();
|
|
|
|
[DllImport("__Internal")]
|
|
public static extern void FBShareLink(string title, string content, string url);
|
|
|
|
[DllImport("__Internal")]
|
|
public static extern void MessengerShareLink(string title, string content, string url);
|
|
|
|
#endif
|
|
}
|
|
}
|