处理订阅相关
This commit is contained in:
parent
2fa583de83
commit
14d97fc5d7
|
@ -0,0 +1 @@
|
|||
{"androidStore":"GooglePlay"}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0acbd98545e2042c7853ae1fe66f1a6b
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -226,6 +226,34 @@ namespace WZ
|
|||
ShuShuEvent.Instance.Track(eventName, para);
|
||||
}
|
||||
|
||||
public static void LogChecingOrderBySdk(string _productName, string _productId, string _orderId, string gameExtra01, string gameExtra02)
|
||||
{
|
||||
var eventName = "IAP_Checking_Order";
|
||||
string price = IAPPurchaseManager.Instance.GetProductInfoByID(_productId).metadata.localizedPrice.ToString();
|
||||
string currency = IAPPurchaseManager.Instance.GetProductInfoByID(_productId).metadata.isoCurrencyCode;
|
||||
string productType = IAPPurchaseManager.Instance.GetProductInfoByID(_productId).definition.type.ToString();
|
||||
float fPrice;
|
||||
if (!float.TryParse(price, out fPrice))
|
||||
{
|
||||
fPrice = 0.0f;
|
||||
}
|
||||
var para = new Dictionary<string, object>
|
||||
{
|
||||
{ "IAP", _productName },
|
||||
{ "product_id", _productId },
|
||||
{ "currency", currency },
|
||||
{ "price", fPrice },
|
||||
{ "order_id", _orderId },
|
||||
{ "is_first", PlayerPrefsUtils.GetPlayerPrefsInt(First_Purchase, 0) == 0 },
|
||||
{ "payment_type", "GooglePlay" },
|
||||
{ "product_type", productType },
|
||||
{ "game_extra01", gameExtra01 },
|
||||
{ "game_extra02", gameExtra02 }
|
||||
};
|
||||
FireBaseAnalyticsManager.Instance.LogEvent(eventName, para);
|
||||
ShuShuEvent.Instance.Track(eventName, para);
|
||||
}
|
||||
|
||||
public static string First_Purchase = "First_purchase";
|
||||
public static string PAY_TIME = "PAY_TIME";
|
||||
public static string PURCHASE_PRICE = "PURCHASE_PRICE";
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
#if UNITY_PURCHASE
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace WZ
|
||||
{
|
||||
public class IAPGoogleJsonInfo
|
||||
{
|
||||
public struct GoogleToken
|
||||
{
|
||||
public string packageName;
|
||||
public string productId;
|
||||
public string token;
|
||||
public string projectId;
|
||||
}
|
||||
|
||||
public class ProductData
|
||||
{
|
||||
public string productId;
|
||||
public int checkStatus;
|
||||
public string timestamp;
|
||||
public string sign;
|
||||
}
|
||||
|
||||
public class GooglePurchaseData
|
||||
{
|
||||
// INAPP_PURCHASE_DATA
|
||||
public string inAppPurchaseData;
|
||||
|
||||
// INAPP_DATA_SIGNATURE
|
||||
public string inAppDataSignature;
|
||||
|
||||
public GooglePurchaseJson json;
|
||||
|
||||
[System.Serializable]
|
||||
private struct GooglePurchaseReceipt
|
||||
{
|
||||
public string Payload;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
private struct GooglePurchasePayload
|
||||
{
|
||||
public string json;
|
||||
public string signature;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public struct GooglePurchaseJson
|
||||
{
|
||||
public string packageName;
|
||||
public string productId;
|
||||
public long purchaseTime;
|
||||
public int purchaseState;
|
||||
public string purchaseToken;
|
||||
public string orderId;
|
||||
|
||||
public bool autoRenewing;
|
||||
}
|
||||
|
||||
public GooglePurchaseData(string receipt)
|
||||
{
|
||||
try
|
||||
{
|
||||
var purchaseReceipt = JsonUtility.FromJson<GooglePurchaseReceipt>(receipt);
|
||||
var purchasePayload = JsonUtility.FromJson<GooglePurchasePayload>(purchaseReceipt.Payload);
|
||||
var inAppJsonData = JsonUtility.FromJson<GooglePurchaseJson>(purchasePayload.json);
|
||||
|
||||
inAppPurchaseData = purchasePayload.json;
|
||||
inAppDataSignature = purchasePayload.signature;
|
||||
json = inAppJsonData;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.Log("Could not parse receipt: " + receipt);
|
||||
inAppPurchaseData = "";
|
||||
inAppDataSignature = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ee6202ee1836a459ab9c0e3311957a1c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -3,6 +3,7 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace WZ
|
||||
|
@ -12,7 +13,6 @@ namespace WZ
|
|||
{
|
||||
private static string _purchaseOrderMap = "PurchaseOrderMap";
|
||||
private List<int> NotRetryCode = new List<int> { 0, 430, 900, 901, 902, 903, 904, 905 };
|
||||
private Dictionary<string, int> mRepeatCountDic;
|
||||
|
||||
#region 订单验证
|
||||
public void VerifyPurchase(IAPDataConfig args)
|
||||
|
@ -21,13 +21,13 @@ namespace WZ
|
|||
if (args.state == IAPDataStateType.def)
|
||||
{
|
||||
// 记录订单处理次数,处理5次还是失败就不处理了
|
||||
if (mRepeatCountDic.ContainsKey(args.info["order_id"]))
|
||||
if (IAPPurchaseManager.Instance._repeatCountDic.ContainsKey(args.info["order_id"]))
|
||||
{
|
||||
mRepeatCountDic[args.info["order_id"]] = mRepeatCountDic[args.info["order_id"]] + 1;
|
||||
IAPPurchaseManager.Instance._repeatCountDic[args.info["order_id"]] = IAPPurchaseManager.Instance._repeatCountDic[args.info["order_id"]] + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
mRepeatCountDic.Add(args.info["order_id"], 1);
|
||||
IAPPurchaseManager.Instance._repeatCountDic.Add(args.info["order_id"], 1);
|
||||
}
|
||||
|
||||
// 开始处理,设置正在处理的状态
|
||||
|
@ -50,14 +50,14 @@ namespace WZ
|
|||
if ((code == 0 || code == 430) && data.illegal_order == 0)
|
||||
{
|
||||
// 将订阅商品信息存储到本地
|
||||
if (!IAPPurchaseManager.Instance._productArgs.ContainsKey(args.info["product_id"].ToString()) && args.info["product_type"].ToString().Equals("Subscription"))
|
||||
if (!IAPSubscribeManager.Instance._productArgs.ContainsKey(args.info["product_id"].ToString()) && args.info["product_type"].ToString().Equals("Subscription"))
|
||||
{
|
||||
IAPPurchaseManager.Instance._productArgs.Add(args.info["product_id"].ToString(), requestArgs);
|
||||
IAPSubscribeManager.Instance._productArgs.Add(args.info["product_id"].ToString(), requestArgs);
|
||||
|
||||
}
|
||||
else if (IAPPurchaseManager.Instance._productArgs.ContainsKey(args.info["product_id"].ToString()) && args.info["product_type"].ToString().Equals("Subscription"))
|
||||
else if (IAPSubscribeManager.Instance._productArgs.ContainsKey(args.info["product_id"].ToString()) && args.info["product_type"].ToString().Equals("Subscription"))
|
||||
{
|
||||
IAPPurchaseManager.Instance._productArgs[args.info["product_id"].ToString()] = requestArgs;
|
||||
IAPSubscribeManager.Instance._productArgs[args.info["product_id"].ToString()] = requestArgs;
|
||||
}
|
||||
RushSDKManager.Instance.OnPurchaseComplete?.Invoke(new PurchaseInfo(
|
||||
productName: args.info["product_name"],
|
||||
|
@ -176,9 +176,31 @@ namespace WZ
|
|||
#endregion
|
||||
|
||||
#region 重置订单状态
|
||||
private void RefreshOrderStatue(IAPDataConfig _productInfo, IAPDataStateType state)
|
||||
public void RefreshOrderStatue()
|
||||
{
|
||||
if (ES3.KeyExists("FailOrderCacheData"))
|
||||
if (ES3.KeyExists(_purchaseOrderMap))
|
||||
{
|
||||
try
|
||||
{
|
||||
List<IAPDataConfig> list = ES3.Load("FailOrderCacheData") as List<IAPDataConfig>;
|
||||
if (list.Count > 0)
|
||||
{
|
||||
foreach (var data in list)
|
||||
{
|
||||
data.state = IAPDataStateType.def;
|
||||
}
|
||||
ES3.Save("FailOrderCacheData", list);
|
||||
}
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
ES3.DeleteKey("FailOrderCacheData");
|
||||
}
|
||||
}
|
||||
}
|
||||
public void RefreshOrderStatue(IAPDataConfig _productInfo, IAPDataStateType state)
|
||||
{
|
||||
if (ES3.KeyExists(_purchaseOrderMap))
|
||||
{
|
||||
List<IAPDataConfig> list = ES3.Load(_purchaseOrderMap) as List<IAPDataConfig>;
|
||||
var value = _productInfo.info["order_id"];
|
||||
|
@ -260,7 +282,7 @@ namespace WZ
|
|||
{
|
||||
list.Add(_productInfo);
|
||||
ES3.Save(_purchaseOrderMap, list);
|
||||
ReadFailOrderId();
|
||||
ProgressCacheOrder();
|
||||
LoggerUtils.Debug("[iap] IAP SaveVerifyFailOrderId 已经有表了,添加失败订单,订单ID:" + _productInfo.info["order_id"] + " 商品类型:" + _productInfo.info["product_type"]);
|
||||
}
|
||||
else
|
||||
|
@ -268,7 +290,7 @@ namespace WZ
|
|||
if (!inDealFailOrder)
|
||||
{
|
||||
inDealFailOrder = true;
|
||||
InvokeRepeating(nameof(ReadFailOrderId), 0, 30);
|
||||
InvokeRepeating(nameof(ProgressCacheOrder), 0, 30);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -279,30 +301,30 @@ namespace WZ
|
|||
_productInfo
|
||||
};
|
||||
ES3.Save(_purchaseOrderMap, tem);
|
||||
ReadFailOrderId();
|
||||
ProgressCacheOrder();
|
||||
LoggerUtils.Debug("[iap] IAP SaveVerifyFailOrderId 第一次存储表 添加失败订单 订单个数:" + tem.Count);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 再次验证订单
|
||||
public void ReadFailOrderId()
|
||||
public void ProgressCacheOrder()
|
||||
{
|
||||
if (ES3.KeyExists(_purchaseOrderMap))
|
||||
{
|
||||
List<IAPDataConfig> list = ES3.Load(_purchaseOrderMap) as List<IAPDataConfig>;
|
||||
LoggerUtils.Debug("[iap] IAP ReadFailOrderId 读取失败订单列表,count:" + list.Count + " mRepeatCountDic" + mRepeatCountDic.Count);
|
||||
LoggerUtils.Debug("[iap] IAP ProgressCacheOrder 读取失败订单列表,count:" + list.Count + " IAPPurchaseManager.Instance._repeatCountDic" + IAPPurchaseManager.Instance._repeatCountDic.Count);
|
||||
if (list.Count > 0)
|
||||
{
|
||||
// 当前进程每条订单校验5次,如果失败则不再处理
|
||||
// 重复校验时判断次数是否大于5,大于5则不再处理
|
||||
IAPDataConfig tempData = null;
|
||||
if (mRepeatCountDic.Count > 0)
|
||||
if (IAPPurchaseManager.Instance._repeatCountDic.Count > 0)
|
||||
{
|
||||
foreach (var data in list)
|
||||
{
|
||||
LoggerUtils.Debug("[iap] iap start verify fail order with repeat dic" + data.info["order_id"] + " count:" + mRepeatCountDic[data.info["order_id"]]);
|
||||
if (mRepeatCountDic.ContainsKey(data.info["order_id"]) && mRepeatCountDic[data.info["order_id"]] <= 5)
|
||||
LoggerUtils.Debug("[iap] iap start verify fail order with repeat dic" + data.info["order_id"] + " count:" + IAPPurchaseManager.Instance._repeatCountDic[data.info["order_id"]]);
|
||||
if (IAPPurchaseManager.Instance._repeatCountDic.ContainsKey(data.info["order_id"]) && IAPPurchaseManager.Instance._repeatCountDic[data.info["order_id"]] <= 5)
|
||||
{
|
||||
tempData = data;
|
||||
break;
|
||||
|
@ -312,7 +334,7 @@ namespace WZ
|
|||
// 如果还有次数不超过5次的订单,则继续校验,否则就不再处理
|
||||
if (tempData != null)
|
||||
{
|
||||
LoggerUtils.Debug("[iap] iap start verify fail order with repeat temp dic" + tempData.info["order_id"] + " count:" + mRepeatCountDic[tempData.info["order_id"]]);
|
||||
LoggerUtils.Debug("[iap] iap start verify fail order with repeat temp dic" + tempData.info["order_id"] + " count:" + IAPPurchaseManager.Instance._repeatCountDic[tempData.info["order_id"]]);
|
||||
VerifyPurchase(tempData);
|
||||
IAPEvent.LogStarVerifyOrderBySdk(new PurchaseInfo(
|
||||
productName: tempData.info["product_name"],
|
||||
|
@ -330,13 +352,13 @@ namespace WZ
|
|||
else
|
||||
{
|
||||
LoggerUtils.Debug("[iap] iap cancel verify fail order");
|
||||
CancelInvoke(nameof(ReadFailOrderId));
|
||||
CancelInvoke(nameof(ProgressCacheOrder));
|
||||
inDealFailOrder = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CancelInvoke(nameof(ReadFailOrderId));
|
||||
CancelInvoke(nameof(ProgressCacheOrder));
|
||||
inDealFailOrder = false;
|
||||
}
|
||||
}
|
||||
|
@ -374,12 +396,12 @@ namespace WZ
|
|||
LoggerUtils.Debug("[iap] IAP 订单还剩余:" + list.Count + " 条未校验");
|
||||
if (list.Count > 0)
|
||||
{
|
||||
ReadFailOrderId();
|
||||
ProgressCacheOrder();
|
||||
}
|
||||
else
|
||||
{
|
||||
inDealFailOrder = false;
|
||||
CancelInvoke(nameof(ReadFailOrderId));
|
||||
CancelInvoke(nameof(ProgressCacheOrder));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace WZ
|
|||
#region API
|
||||
public void BuyProductByID(string productId, string productName, string gameExtraParam)
|
||||
{
|
||||
#if !UNITY_EDITOR
|
||||
#if UNITY_EDITOR
|
||||
RushSDKManager.Instance.OnPurchaseComplete(new PurchaseInfo(
|
||||
productName: productName,
|
||||
productID: productId,
|
||||
|
@ -135,6 +135,23 @@ namespace WZ
|
|||
#endif
|
||||
}
|
||||
|
||||
public string GetProductPriceByID(string pID)
|
||||
{
|
||||
if (_storeController == null && _storeExtensionProvider == null)
|
||||
return "";
|
||||
|
||||
Product[] tProducts = _storeController.products.all;
|
||||
for (int i = 0; i < tProducts.Length; i++)
|
||||
{
|
||||
Product tItem = tProducts[i];
|
||||
if (tItem.definition.id.Equals(pID))
|
||||
{
|
||||
return tItem.metadata.GetGoogleProductMetadata().localizedPriceString;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public Product GetProductInfoByID(string pID)
|
||||
{
|
||||
if (_storeController == null && _storeExtensionProvider == null)
|
||||
|
@ -150,15 +167,23 @@ namespace WZ
|
|||
return null;
|
||||
}
|
||||
|
||||
public void AddProducts(Dictionary<string, ProductType> products, Action<bool, string> onProductsResult = null)
|
||||
public void AddProductsDynamic(Dictionary<string, ProductType> products, Action<bool, string> onProductsResult = null)
|
||||
{
|
||||
_initProductDic = products;
|
||||
|
||||
FetchAdditionalProducts(products, onProductsResult);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void DoConfirmPendingPurchaseByID(string productId)
|
||||
{
|
||||
Product product = _storeController.products.WithID(productId);
|
||||
if (null == product) return;
|
||||
if (string.IsNullOrEmpty(product.transactionID)) return;
|
||||
if (product != null && product.availableToPurchase)
|
||||
{
|
||||
_storeController.ConfirmPendingPurchase(product);
|
||||
_inPurchaseProgress = false;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
@ -250,8 +275,7 @@ namespace WZ
|
|||
#endregion
|
||||
|
||||
#region 动态添加商品
|
||||
private void FetchAdditionalProducts(Dictionary<string, ProductType> ProductDic,
|
||||
Action<bool, string> onProductsResult = null)
|
||||
private void FetchAdditionalProducts(Dictionary<string, ProductType> ProductDic, Action<bool, string> onProductsResult = null)
|
||||
{
|
||||
if (!IsInitialized())
|
||||
{
|
||||
|
@ -376,6 +400,15 @@ namespace WZ
|
|||
_builder ??= ConfigurationBuilder.Instance(_module);
|
||||
|
||||
int productsNum = 0;
|
||||
foreach (string tID in StaticProductDic.Keys)
|
||||
{
|
||||
productsNum++;
|
||||
if (!string.IsNullOrEmpty(tID))
|
||||
{
|
||||
LoggerUtils.Debug($"[iap] Add IAPProducts IAPProducts: {tID}");
|
||||
_builder.AddProduct(tID, StaticProductDic[tID]);
|
||||
}
|
||||
}
|
||||
|
||||
if (_initProductDic != null && _initProductDic.Count > 0)
|
||||
{
|
||||
|
@ -429,7 +462,6 @@ namespace WZ
|
|||
_storeController = controller;
|
||||
_storeExtensionProvider = extensions;
|
||||
|
||||
RushSDKManager.Instance.OnGetProductsInfo?.Invoke(_storeController.products.all);
|
||||
foreach (var product in _storeController.products.all)
|
||||
{
|
||||
LoggerUtils.Debug("[iap] " + product.metadata.localizedTitle
|
||||
|
@ -440,11 +472,11 @@ namespace WZ
|
|||
+ "|" + product.definition.type);
|
||||
}
|
||||
|
||||
// CheckSubscribeReceipt();
|
||||
RushSDKManager.Instance.OnGetProductsInfo?.Invoke(_storeController.products.all);
|
||||
RushSDKManager.Instance.OnPurchaseInitComplete?.Invoke(true, "");
|
||||
IAPEvent.LogPurchaseInit(true);
|
||||
|
||||
IAPSubscribeManager.Instance.CheckSubscribeReceipt();
|
||||
IAPOrderManager.Instance.RefreshOrderStatue();
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -477,6 +509,8 @@ namespace WZ
|
|||
#region 购买失败
|
||||
public void OnPurchaseFailed(Product product, PurchaseFailureDescription failureDescription)
|
||||
{
|
||||
_inPurchaseProgress = false;
|
||||
IAPOrderManager.Instance.ProgressCacheOrder();
|
||||
LoggerUtils.Debug("[iap] OnPurchaseFailed productId : " + failureDescription.productId
|
||||
+ " , transactionID : " + product.transactionID
|
||||
+ " , localizedPrice : " + product.metadata.localizedPriceString
|
||||
|
@ -513,11 +547,13 @@ namespace WZ
|
|||
resultType: (IAPResultType)failureDescription.reason,
|
||||
productType: product.definition.type.ToString()
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
|
||||
{
|
||||
// m_PurchaseInProgress = false;
|
||||
_inPurchaseProgress = false;
|
||||
IAPOrderManager.Instance.ProgressCacheOrder();
|
||||
LoggerUtils.Debug("[iap] OnPurchaseFailed productId -> : " + product.definition.id
|
||||
+ " , transactionID : " + product.transactionID
|
||||
+ " , localizedPrice : " + product.metadata.localizedPriceString
|
||||
|
@ -555,26 +591,34 @@ namespace WZ
|
|||
productType: product.definition.type.ToString()
|
||||
|
||||
));
|
||||
// ReadFailOrderId();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 添加静态商品
|
||||
public static Dictionary<string, ProductType> StaticProductDic = new Dictionary<string, ProductType>()
|
||||
{
|
||||
|
||||
};
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
private StandardPurchasingModule _module;
|
||||
private ConfigurationBuilder _builder;
|
||||
private static IStoreController _storeController;
|
||||
public IStoreController _storeController;
|
||||
private static IExtensionProvider _storeExtensionProvider;
|
||||
public string _gameExtraParam = "";
|
||||
private static string _productName = "";
|
||||
private bool _inPurchaseProgress = false;
|
||||
public Dictionary<string, Dictionary<string, object>> _productArgs = new Dictionary<string, Dictionary<string, object>>();
|
||||
private bool _serviceInit = false;
|
||||
private Dictionary<string, ProductType> _addProductsDic;
|
||||
private Dictionary<string, ProductType> _initProductDic;
|
||||
private Dictionary<string, int> _repeatCountDic;
|
||||
public Dictionary<string, int> _repeatCountDic;
|
||||
private IGooglePlayConfiguration _googlePlayConfiguration;
|
||||
private bool _isFetchingAdditionalProducts = false;
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ using UnityEngine;
|
|||
|
||||
namespace WZ
|
||||
{
|
||||
|
||||
public struct SubscribeInfo
|
||||
{
|
||||
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
#if UNITY_PURCHASE
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Purchasing;
|
||||
|
||||
namespace WZ
|
||||
{
|
||||
public class IAPSubscribeManager : D_MonoSingleton<IAPSubscribeManager>
|
||||
{
|
||||
public Dictionary<string, Dictionary<string, object>> _productArgs = new Dictionary<string, Dictionary<string, object>>();
|
||||
|
||||
public void CheckSubscribeDataByProductId(string productId)
|
||||
{
|
||||
if (_productArgs.ContainsKey(productId))
|
||||
{
|
||||
CheckOrderFromServer(_productArgs[productId],productId);
|
||||
}
|
||||
else
|
||||
{
|
||||
RushSDKManager.Instance.OnSubscriptionQueriedByProductId?.Invoke(productId,new SubscribeInfo(-1, "", "", "", -1, -1, -1, -1, -1, "", "", "", ""));
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckOrderFromServer(Dictionary<string, object> args,string productId)
|
||||
{
|
||||
if (args.Count > 0)
|
||||
{
|
||||
ServerMgr.Instance.CheckOrder(args, (code, msg, data) =>
|
||||
{
|
||||
LoggerUtils.Debug("[iap] ===>CheckOrderFromServer code:"+code+ " illegal_order:"+data.illegal_order + " illegal_msg:" + data.illegal_msg+ " environment:"+data.environment+
|
||||
" purchase_time"+data.purchase_time+ " is_subscribed"+ data.is_subscribed+ " is_expired"+data.is_expired+ " is_cancelled:"+ data.is_cancelled+ " is_free_trial:"+
|
||||
data.is_free_trial+ " is_auto_renewing:"+data.is_auto_renewing+ " remaining_time:"+data.remaining_time+ " expire_time:"+data.expiry_time+ " latest_order_id:"+data.latest_order_id+ " productId:"+ args["product_id"].ToString());
|
||||
|
||||
SubscribeInfo resultData = new SubscribeInfo(
|
||||
data.illegal_order,
|
||||
data.illegal_msg,
|
||||
data.environment,
|
||||
data.purchase_time,
|
||||
data.is_subscribed,
|
||||
data.is_expired,
|
||||
data.is_cancelled,
|
||||
data.is_free_trial,
|
||||
data.is_auto_renewing,
|
||||
data.remaining_time,
|
||||
data.expiry_time,
|
||||
data.latest_order_id,
|
||||
args["product_id"].ToString()
|
||||
);
|
||||
|
||||
RushSDKManager.Instance.OnSubscriptionQueriedByProductId?.Invoke(args["product_id"].ToString(), resultData);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
RushSDKManager.Instance.OnSubscriptionQueriedByProductId?.Invoke(productId,new SubscribeInfo(-1, "", "", "", -1, -1, -1, -1, -1, "", "", "", ""));
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckSubscribeReceipt()
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var product in IAPPurchaseManager.Instance._storeController.products.all)
|
||||
{
|
||||
if (product.availableToPurchase)
|
||||
{
|
||||
if (product.receipt != null)
|
||||
{
|
||||
if (product.definition.type == ProductType.Subscription)
|
||||
{
|
||||
try
|
||||
{
|
||||
IAPGoogleJsonInfo.GooglePurchaseData data = new IAPGoogleJsonInfo.GooglePurchaseData(product.receipt);
|
||||
var args = new Dictionary<string, object>
|
||||
{
|
||||
{ "product_type", "Subscription" },
|
||||
{ "product_id", data.json.productId },
|
||||
{ "order_id", data.json.orderId },
|
||||
{ "currency", product.metadata.isoCurrencyCode },
|
||||
{ "price", product.metadata.localizedPrice.ToString() },
|
||||
{ "purchase_token", data.json.purchaseToken },
|
||||
{ "payment_method", "googleplay" }
|
||||
};
|
||||
if (!_productArgs.ContainsKey(data.json.productId))
|
||||
{
|
||||
_productArgs.Add(data.json.productId, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
_productArgs[data.json.productId] = args;
|
||||
}
|
||||
}
|
||||
catch (Exception e) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exp) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1856159555b2343c1a0d38d88d54af66
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -152,7 +152,7 @@ namespace WZ
|
|||
var builder = new StringBuilder();
|
||||
foreach (var t in hashBytes)
|
||||
{
|
||||
builder.Append(t.ToString("x2")); // Convert byte to hexadecimal string
|
||||
builder.Append(t.ToString("x2"));
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AdjustSdk;
|
||||
using AnyThinkAds.ThirdParty.LitJson;
|
||||
using EFSDK;
|
||||
|
@ -30,6 +31,9 @@ public class RushSDKManager : D_MonoSingleton<RushSDKManager>
|
|||
public void InitializeSdk(Action action, bool showLog)
|
||||
{
|
||||
LoggerUtils.Enabled = showLog;
|
||||
#if UNITY_PURCHASE
|
||||
IAPPurchaseManager.Instance.PreInitialize();
|
||||
#endif
|
||||
FireBaseSDKManager.Instance.Init();
|
||||
ShuShuMangage.Instance.Init();
|
||||
AdmobAdsManager.Instance.RefreshAdsData();
|
||||
|
@ -37,6 +41,10 @@ public class RushSDKManager : D_MonoSingleton<RushSDKManager>
|
|||
AdjustManager.Instance.Init();
|
||||
AdsSDKManager.Instance.InitSDK(action);
|
||||
EFSdkManager.Instance.Init();
|
||||
#if UNITY_PURCHASE
|
||||
IAPPurchaseManager.Instance.Initialize();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#if UNITY_PURCHASE
|
||||
|
@ -75,6 +83,83 @@ public class RushSDKManager : D_MonoSingleton<RushSDKManager>
|
|||
{
|
||||
OnPurchaseComplete = _action;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 订阅查询回调
|
||||
/// </summary>
|
||||
public Action<string, SubscribeInfo> OnSubscriptionQueriedByProductId;
|
||||
public void QuerySubscriptionDataByProductId(string _pID,Action<string,SubscribeInfo> _action)
|
||||
{
|
||||
OnSubscriptionQueriedByProductId = _action;
|
||||
IAPSubscribeManager.Instance.CheckSubscribeDataByProductId(_pID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取商品价格
|
||||
/// </summary>
|
||||
/// <param name="_pID"></param>
|
||||
/// <returns></returns>
|
||||
public string GetProductPriceByID(string _pID)
|
||||
{
|
||||
return IAPPurchaseManager.Instance.GetProductPriceByID(_pID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取商品信息
|
||||
/// </summary>
|
||||
/// <param name="pID"></param>
|
||||
/// <returns></returns>
|
||||
public Product GetProductInfoByID(string _pID)
|
||||
{
|
||||
return IAPPurchaseManager.Instance.GetProductInfoByID(_pID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态添加商品ID
|
||||
/// </summary>
|
||||
/// <param name="_products">Product IDs</param>
|
||||
public void AddProductsDynamic(Dictionary<string, ProductType> _products,Action<bool, string> _onProductsResult = null)
|
||||
{
|
||||
IAPPurchaseManager.Instance.AddProductsDynamic(_products,_onProductsResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化前静态添加商品ID
|
||||
/// </summary>
|
||||
/// <param name="_products">Product IDs</param>
|
||||
public void AddProductsStatic(Dictionary<string, ProductType> _products)
|
||||
{
|
||||
IAPPurchaseManager.StaticProductDic = IAPPurchaseManager.StaticProductDic.Concat(_products).ToDictionary(postParK => postParK.Key, PostParV => PostParV.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 点击购买方法
|
||||
/// </summary>
|
||||
/// <param name="_productId"> 商品SKU </param>
|
||||
/// <param name="_productName"> 商品名称 </param>
|
||||
/// <param name="_gameExtraParam"> 游戏拓展参数 </param>
|
||||
public void PurchaseProductById(string _productId, string _productName, string _gameExtraParam = "")
|
||||
{
|
||||
IAPPurchaseManager.Instance.BuyProductByID(_productId, _productName,_gameExtraParam);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 游戏下发奖励后上报
|
||||
/// </summary>
|
||||
/// <param name="productName">商品名称</param>
|
||||
/// <param name="productID">商品SKU ID</param>
|
||||
/// <param name="orderID">订单ID</param>
|
||||
/// <param name="gameExtra01">游戏拓展字段-购买商品数量</param>
|
||||
/// <param name="gameExtra02">游戏拓展字段</param>
|
||||
public void LogCheckingOrder(string _productName, string _productId, string _orderId, string gameExtra01, string gameExtra02)
|
||||
{
|
||||
|
||||
#if !UNITY_EDITOR
|
||||
IAPOrderManager.Instance.RemoveVerifySuccessOrder(_orderId);
|
||||
IAPPurchaseManager.Instance.DoConfirmPendingPurchaseByID(_productId);
|
||||
IAPEvent.LogChecingOrderBySdk(_productName, _productId, _orderId, gameExtra01, gameExtra02);
|
||||
#endif
|
||||
}
|
||||
#endregion
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue