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

69 lines
1.6 KiB
C#

using System;
using PhxhSDK;
using UnityEngine;
public class AliPayHandle : MonoBehaviour
{
private static AliPayHandle _instance;
public static AliPayHandle Instance
{
get
{
if (_instance == null)
{
var go = new GameObject("AliPayHandle");
_instance = go.AddComponent<AliPayHandle>();
DontDestroyOnLoad(go);
}
return _instance;
}
}
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);
}
}