121 lines
3.0 KiB
C#
121 lines
3.0 KiB
C#
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<AliPayHandle>();
|
|
DontDestroyOnLoad(go);
|
|
}
|
|
|
|
return _instance;
|
|
}
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
if (_instance == null)
|
|
{
|
|
_instance = this;
|
|
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("支付宝支付");
|
|
//AliPayTest(currencyID);
|
|
PayRequest(currencyID, count, itemID);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 初始化支付服务
|
|
/// </summary>
|
|
public void Initialize()
|
|
{
|
|
PaymentServiceLocator.AliPaymentService.Initialize();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检查微信是否已初始化
|
|
/// </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);
|
|
}
|
|
|
|
|
|
|
|
private void PayRequest(int actorID)
|
|
{
|
|
//string payUrl = .Instance.PostURL + PAY_SIGN;//PackDataInst.Inst.localInfo.httpUrl
|
|
//DebugUtil.Log($"发送拉起Bilibili支付请求地址: {payUrl}");
|
|
//
|
|
//List<Items> itemsList = new() { new() { product_id = currencyID, count = count } };
|
|
//string itemJsonData = JsonConvert.SerializeObject(itemsList);
|
|
//DebugUtil.Log($"items.jsonData:{itemJsonData}");
|
|
}
|
|
|
|
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);
|
|
}
|
|
} |