using UnityEngine; namespace GameWrapper.Pay { public class WXPayHandle : MonoBehaviour { private static WXPayHandle _instance; public static WXPayHandle Instance { get { if (_instance is null) { var go = new GameObject("WXPayHandle"); _instance = go.AddComponent(); DontDestroyOnLoad(go); } return _instance; } } private void Awake() { if (_instance == null) { _instance = this; Initialize(); DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } } void OnApplicationPause(bool pauseStatus) { #if WXPay PaymentServiceLocator.WxPaymentService.OnApplicationPause(pauseStatus); #endif } /// /// 初始化支付服务 /// public void Initialize() { #if WXPay PaymentServiceLocator.WxPaymentService.Initialize(); #endif } /// /// 检查微信是否已初始化 /// public bool IsWxInitialized() { #if WXPay return PaymentServiceLocator.WxPaymentService.IsAppInitialized(); #endif DebugUtil.Log("WXPayHandle.IsWxInitialized error, 未开启微信宏"); return false; } /// /// 开始支付 /// public void BuyGoods(string currencyID, int count, int itemID, int shopID = 0, int goodsID = 0, int index = 0) { #if WXPay PaymentServiceLocator.WxPaymentService.BuyGoods(currencyID, count, itemID, shopID, goodsID, index); return; #endif DebugUtil.Log("WXPayHandle.BuyGoods error, 未开启微信宏"); } /// /// 支付回调 由java层调用 /// public void OnPaymentCallback(string result) { #if WXPay DebugUtil.Log("WXPayHandle.OnPaymentCallback result: {0}", result); PaymentServiceLocator.WxPaymentService.OnPaymentCallback(result); #endif } /// /// 是否在支付流程中 /// public bool IsPaying() { #if WXPay return PaymentServiceLocator.WxPaymentService.IsPaying(); #endif DebugUtil.Log("WXPayHandle.IsPaying error, 未开启微信宏"); return false; } } }