2025-04-28 16:27:00 +08:00
|
|
|
|
using System;
|
2025-10-16 16:27:39 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using GameWrapper.Pay;
|
2025-04-28 16:27:00 +08:00
|
|
|
|
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
|
|
|
|
|
|
{
|
2025-09-13 17:18:26 +08:00
|
|
|
|
if (_instance is null)
|
2025-05-08 17:50:37 +08:00
|
|
|
|
{
|
|
|
|
|
|
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;
|
2025-10-21 19:52:11 +08:00
|
|
|
|
Initialize();
|
2025-04-28 16:27:00 +08:00
|
|
|
|
DontDestroyOnLoad(gameObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-16 16:27:39 +08:00
|
|
|
|
public void BuyGoods(string currencyID, int count, int itemID, int param = 0, int shopID = 0, int goodsID = 0,
|
|
|
|
|
|
int index = 0)
|
2025-04-28 16:27:00 +08:00
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.Log("支付宝支付");
|
2025-10-16 16:27:39 +08:00
|
|
|
|
PayRequest(currencyID, count, itemID);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 初始化支付服务
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
PaymentServiceLocator.AliPaymentService.Initialize();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-10-21 19:52:11 +08:00
|
|
|
|
/// 检查支付宝是否已初始化
|
2025-10-16 16:27:39 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool IsInitialized()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
return PaymentServiceLocator.AliPaymentService.IsAppInitialized();
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 是否在支付流程中
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool IsPaying()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
return PaymentServiceLocator.AliPaymentService.IsPaying();
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void PayRequest(string currencyID, int count, int itemID)
|
|
|
|
|
|
{
|
|
|
|
|
|
PaymentServiceLocator.AliPaymentService.BuyGoods(currencyID, count, itemID);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-21 19:52:11 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 测试用支付按钮,正式环境请调用BuyGoods方法
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="orderInfo"></param>
|
2025-10-21 13:23:55 +08:00
|
|
|
|
public void AliPayTest(string orderInfo)
|
2025-04-28 16:27:00 +08:00
|
|
|
|
{
|
|
|
|
|
|
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");
|
2025-10-22 17:26:23 +08:00
|
|
|
|
utils.Call("PayDemo", orderInfo, currentActivity, "AliPayHandle", "OnPaymentCallback"); //AliPay
|
2025-10-21 13:23:55 +08:00
|
|
|
|
|
2025-04-28 16:27:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError(e);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-22 17:26:23 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 支付回调 由java层调用
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void OnPaymentCallback(string result)
|
2025-04-28 16:27:00 +08:00
|
|
|
|
{
|
2025-10-22 17:26:23 +08:00
|
|
|
|
DebugUtil.Log("AliPayHandle.OnPaymentCallback result: {0}", result);
|
|
|
|
|
|
PaymentServiceLocator.AliPaymentService.OnPaymentCallback(result);
|
2025-04-28 16:27:00 +08:00
|
|
|
|
}
|
2024-12-26 17:26:46 +08:00
|
|
|
|
}
|