支付宝SDK接入测试

main
Yuntao Hu 2024-09-12 14:16:10 +08:00
parent 41ba9457d2
commit 88528ec55f
6 changed files with 66 additions and 9 deletions

View File

@ -0,0 +1,16 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AliPayConnector : MonoBehaviour
{
private void Awake()
{
DontDestroyOnLoad(gameObject);
}
public void AliPayCallback(string msg)
{
DebugUtil.Log("AliPayCallback: " + msg);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 234c6ca597334d54e819a5fd7e7826e8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -168,11 +168,15 @@ public class IAPHandle : IDetailedStoreListener
{
Debug.Log("购买商品: " + productId);
#if !UNITY_EDITOR
if (!_isInitialized || Application.internetReachability == NetworkReachability.NotReachable)
return;
_onPurchaseSuccess = onPurchaseSuccess;
_onPurchaseFail = onPurchaseFail;
_controller.InitiatePurchase(productId, actorId);
#if PLATFORM_ANDROID
AliPayTest(productId);
#else
if (!_isInitialized || Application.internetReachability == NetworkReachability.NotReachable)
return;
_onPurchaseSuccess = onPurchaseSuccess;
_onPurchaseFail = onPurchaseFail;
_controller.InitiatePurchase(productId, actorId);
#endif
#else
DebugUtil.Log("请在真实环境下测试");
#endif
@ -183,7 +187,7 @@ public class IAPHandle : IDetailedStoreListener
/// </summary>
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
{
#if UNITY_IOS||UNITY_ANDROID
#if UNITY_IOS || UNITY_ANDROID
var validator = new CrossPlatformValidator(GooglePlayTangle.Data(),
AppleTangle.Data(), Application.identifier);
DebugUtil.Log("Google Play Public Key: " + GooglePlayTangle.Data());
@ -329,7 +333,7 @@ public class IAPHandle : IDetailedStoreListener
DebugUtil.LogError("Purchase of [{0}] failed for this reason: {1}", product.definition.id, failureReason);
}
#endregion
#endregion
//TODO 待完善 测试
/// <summary>
@ -397,4 +401,25 @@ public class IAPHandle : IDetailedStoreListener
DebugUtil.LogError("Product not found");
return null;
}
public void AliPayTest(string orderInfo)
{
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
if (unityPlayer == null)
{
Debug.LogError("unityPlayer is null");
return;
}
try
{
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
currentActivity.Call("PayDemo", orderInfo, "AliPayListener", "AliPayCallback");
}
catch (Exception e)
{
Debug.LogError(e);
return;
}
}
}

View File

@ -45,6 +45,11 @@ public class IAPManager : Singlenton<IAPManager>
EventManager.Instance.Register<string>(EventManager.EventName.IAPServerVerifySuccessful, SeverVerifySuccess);
_helper = new IAPHandle();
ProductDic = new Dictionary<string, int>();
//创建不销毁的监听器
GameObject AliListener = new GameObject("AliPayListener");
AliListener.AddComponent<AliPayConnector>();
InitIAP();
}

View File

@ -127,7 +127,7 @@ public class UI_BuyDiamondController : UIWindow
{
//TODO 审核包暂时关闭内购功能
UITipsManager.ShowTips("充值未开放");
//IAPManager.Instance.IAPBuyGoods(id);
IAPManager.Instance.IAPBuyGoods(id);
//TODO 打开二次确认购买界面
}

@ -1 +1 @@
Subproject commit d394cd0c6083cf450ec40edacf613a70784ff4e2
Subproject commit 7b9804bd962b3d2313e8ddbb613dd4392c112d35