using System; using System.Collections.Generic; using GameWrapper.Pay; using PhxhSDK; using UnityEngine; public class AliPayHandle : MonoBehaviour { private static AliPayHandle _instance; public static AliPayHandle Instance { get { if (_instance is null) { var go = new GameObject("AliPayHandle"); _instance = go.AddComponent(); DontDestroyOnLoad(go); } return _instance; } } private void Awake() { if (_instance == null) { _instance = this; Initialize(); DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } } public void BuyGoods(string currencyID, int count, int itemID, int param = 0, int shopID = 0, int goodsID = 0, int index = 0) { DebugUtil.Log("支付宝支付"); PayRequest(currencyID, count, itemID); } /// /// 初始化支付服务 /// public void Initialize() { PaymentServiceLocator.AliPaymentService.Initialize(); } /// /// 检查支付宝是否已初始化 /// public bool IsInitialized() { return PaymentServiceLocator.AliPaymentService.IsAppInitialized(); return false; } /// /// 是否在支付流程中 /// public bool IsPaying() { return PaymentServiceLocator.AliPaymentService.IsPaying(); return false; } private void PayRequest(string currencyID, int count, int itemID) { PaymentServiceLocator.AliPaymentService.BuyGoods(currencyID, count, itemID); } /// /// 测试用支付按钮,正式环境请调用BuyGoods方法 /// /// public 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("currentActivity"); AndroidJavaObject utils = new AndroidJavaObject("com.phxh.dev.nld.PayActivity"); utils.Call("PayDemo", orderInfo, currentActivity, "AliPayHandle", "OnPaymentCallback"); //AliPay } catch (Exception e) { Debug.LogError(e); return; } } /// /// 支付回调 由java层调用 /// public void OnPaymentCallback(string result) { DebugUtil.Log("AliPayHandle.OnPaymentCallback result: {0}", result); PaymentServiceLocator.AliPaymentService.OnPaymentCallback(result); } }