489 lines
16 KiB
C#
489 lines
16 KiB
C#
using System;
|
||
using System.Runtime.InteropServices;
|
||
using UnityEngine;
|
||
|
||
namespace tysdk
|
||
{
|
||
|
||
public static class UnityBridgeFunc
|
||
{
|
||
|
||
#if UNITY_EDITOR
|
||
//初始化sdk
|
||
public static void InitSDK(string channel){}
|
||
|
||
//更新登录支付域名
|
||
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){}
|
||
//支付new
|
||
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 ConsumePurchase(string token) { }
|
||
|
||
public static string GetPendingPurchases() => "[]";
|
||
|
||
public static void RefreshBillingService() { }
|
||
|
||
//打点
|
||
public static void SetGaUserInfo(string userId){}
|
||
public static void SetGaCommonInfo(string SetGaCommonInfo){}
|
||
|
||
public static void GAReportParams(int type, string eventstr, string paramstr){}
|
||
|
||
//ATT
|
||
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";
|
||
|
||
//初始化sdk
|
||
public static void InitSDK(string channel){
|
||
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
||
{
|
||
using(var activityCls = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
|
||
{
|
||
var activity = activityCls.GetStatic<AndroidJavaObject>("currentActivity");
|
||
sdkManager.CallStatic("InitSDK", activity, 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)
|
||
{
|
||
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
||
{
|
||
sdkManager.CallStatic("UnityLogin", accoutType.ToString());
|
||
}
|
||
}
|
||
|
||
public static void UnityGetIdentityFun(string type)
|
||
{
|
||
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
||
{
|
||
sdkManager.CallStatic("UnityGetIdentityFun", type);
|
||
}
|
||
}
|
||
|
||
public static void UnityLogOutByChannel(EAccoutType accoutType)
|
||
{
|
||
|
||
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
||
{
|
||
sdkManager.CallStatic("UnityLogOutByChannel", accoutType.ToString());
|
||
}
|
||
}
|
||
|
||
public static void LinkAccount(EAccoutType accoutType)
|
||
{
|
||
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
||
{
|
||
string userId = TYSdkFacade.TYAccountInfo.strUserId;
|
||
sdkManager.CallStatic("LinkAccount", accoutType.ToString(), userId);
|
||
}
|
||
}
|
||
|
||
public static void CleanLinkTmpSnsInfo(){
|
||
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
||
{
|
||
using(var activityCls = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
|
||
{
|
||
sdkManager.CallStatic("CleanLinkTmpSnsInfo");
|
||
}
|
||
}
|
||
}
|
||
|
||
public static void ChangeLinkAccount(EAccoutType accoutType, int oldUserId, int newUserId)
|
||
{
|
||
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
||
{
|
||
sdkManager.CallStatic("ChangeLinkAccount", accoutType.ToString(), oldUserId, newUserId);
|
||
}
|
||
}
|
||
|
||
public static void LinkCheck(EAccoutType accoutType)
|
||
{
|
||
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
||
{
|
||
sdkManager.CallStatic("LinkCheck", accoutType.ToString());
|
||
}
|
||
}
|
||
|
||
//支付new
|
||
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 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");
|
||
}
|
||
}
|
||
|
||
//通过商品ID列表获取商品详情(Flexion 渠道使用)
|
||
public static void GetSKUListByIapIds(string productIds)
|
||
{
|
||
UnityEngine.Debug.Log("UnityBridgeFunc.GetSKUListByIapIds(productIds)");
|
||
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
||
{
|
||
sdkManager.CallStatic("queryProductsByIDs", productIds);
|
||
}
|
||
}
|
||
|
||
public static void ConsumePurchase(string token)
|
||
{
|
||
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
||
{
|
||
sdkManager.CallStatic("ConsumePurchase", token);
|
||
}
|
||
}
|
||
|
||
public static string GetPendingPurchases()
|
||
{
|
||
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
||
{
|
||
return sdkManager.CallStatic<string>("GetPendingPurchases");
|
||
}
|
||
}
|
||
|
||
public static void RefreshBillingService()
|
||
{
|
||
UnityEngine.Debug.Log("UnityBridgeFunc.RefreshBillingService");
|
||
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
||
{
|
||
sdkManager.CallStatic("RefreshBillingService");
|
||
}
|
||
}
|
||
|
||
public static void CancelBillingFlow()
|
||
{
|
||
UnityEngine.Debug.Log("UnityBridgeFunc.CancelBillingFlow");
|
||
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
||
{
|
||
sdkManager.CallStatic("CancelBillingFlow");
|
||
}
|
||
}
|
||
|
||
//打点
|
||
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);
|
||
}
|
||
}
|
||
|
||
|
||
//ATT
|
||
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;
|
||
}
|
||
|
||
// Convert C string to C# string
|
||
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);
|
||
|
||
//ATT
|
||
[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);
|
||
|
||
public static void ConsumePurchase(string token) { }
|
||
|
||
public static string GetPendingPurchases() => "[]";
|
||
|
||
public static void RefreshBillingService() { }
|
||
|
||
#endif
|
||
}
|
||
}
|