NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/GameWrapper/Pay/AliPayHandle.cs

69 lines
1.6 KiB
C#
Raw Normal View History

2025-04-28 16:27:00 +08:00
using System;
using PhxhSDK;
using UnityEngine;
2025-05-08 17:50:37 +08:00
public class AliPayHandle : MonoBehaviour
2025-04-28 16:27:00 +08:00
{
private static AliPayHandle _instance;
2025-05-08 17:50:37 +08:00
public static AliPayHandle Instance
{
get
{
if (_instance == null)
{
var go = new GameObject("AliPayHandle");
_instance = go.AddComponent<AliPayHandle>();
DontDestroyOnLoad(go);
}
return _instance;
}
}
2025-04-28 16:27:00 +08:00
private void Awake()
{
if (_instance == null)
{
_instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
public void BuyGoods(string productId)
{
DebugUtil.Log("支付宝支付");
AliPayTest(productId);
}
private void AliPayTest(string orderInfo)
{
try
{
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
if (unityPlayer == null)
{
Debug.LogError("unityPlayer is null");
return;
}
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject utils = new AndroidJavaObject("com.phxh.dev.nld.PayActivity");
utils.Call("PayDemo", orderInfo, currentActivity, "AliPayListener", "AliPayCallback"); //AliPay
}
catch (Exception e)
{
Debug.LogError(e);
return;
}
}
public void AliPayCallback(string msg)
{
DebugUtil.Log("AliPayCallback: " + msg);
}
2024-12-26 17:26:46 +08:00
}