fix:1、添加支付,使用sdk的支付方案
This commit is contained in:
+176
-119
@@ -1,30 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
// using SGModule.ApplePay;
|
||||
using SGModule.NetKit;
|
||||
using UnityEngine;
|
||||
using RedHotRoast;
|
||||
// using UnityEngine.Purchasing;
|
||||
using Newtonsoft.Json;
|
||||
using SGModule.Net;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public enum PayType
|
||||
{
|
||||
buy_one,
|
||||
buy_one_off,
|
||||
buy_gold_1,
|
||||
buy_gold_2,
|
||||
buy_gold_3,
|
||||
buy_gold_4,
|
||||
buy_gold_5,
|
||||
remove_ad,
|
||||
battle_pass,
|
||||
pack_reward,
|
||||
fail_pack,
|
||||
three_days_gift,
|
||||
weekly_subscription,
|
||||
monthly_subscription,
|
||||
yearly_subscription,
|
||||
}
|
||||
// public enum PayType
|
||||
// {
|
||||
// buy_one,
|
||||
// buy_one_off,
|
||||
// buy_gold_1,
|
||||
// buy_gold_2,
|
||||
// buy_gold_3,
|
||||
// buy_gold_4,
|
||||
// buy_gold_5,
|
||||
// remove_ad,
|
||||
// battle_pass,
|
||||
// pack_reward,
|
||||
// fail_pack,
|
||||
// three_days_gift,
|
||||
// weekly_subscription,
|
||||
// monthly_subscription,
|
||||
// yearly_subscription,
|
||||
// }
|
||||
|
||||
public class PurchasingManager
|
||||
{
|
||||
@@ -32,42 +31,42 @@ public class PurchasingManager
|
||||
private static readonly List<ApplePay> PayConfig = ConfigSystem.GetConfig<ApplePay>();
|
||||
private static readonly List<ApplePay2> PayConfig2 = ConfigSystem.GetConfig<ApplePay2>();
|
||||
|
||||
public static string GetPaySku(PayType key)
|
||||
{
|
||||
string keys = "";
|
||||
|
||||
if (PayConfig != null)
|
||||
{
|
||||
foreach (var data in PayConfig)
|
||||
{
|
||||
if (data.payKey != key.ToString()) continue;
|
||||
keys = data.sku;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
public static int GetVipLvFormConfig(string sku)
|
||||
{
|
||||
var lv = 1;
|
||||
|
||||
if (GetPaySku(PayType.weekly_subscription) == sku)
|
||||
{
|
||||
lv = 1;
|
||||
}
|
||||
else if (GetPaySku(PayType.monthly_subscription) == sku)
|
||||
{
|
||||
lv = 2;
|
||||
}
|
||||
else if (GetPaySku(PayType.yearly_subscription) == sku)
|
||||
{
|
||||
lv = 3;
|
||||
}
|
||||
|
||||
return lv;
|
||||
}
|
||||
// public static string GetPaySku(PayType key)
|
||||
// {
|
||||
// string keys = "";
|
||||
//
|
||||
// if (PayConfig != null)
|
||||
// {
|
||||
// foreach (var data in PayConfig)
|
||||
// {
|
||||
// if (data.payKey != key.ToString()) continue;
|
||||
// keys = data.sku;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return keys;
|
||||
// }
|
||||
//
|
||||
// public static int GetVipLvFormConfig(string sku)
|
||||
// {
|
||||
// var lv = 1;
|
||||
//
|
||||
// if (GetPaySku(PayType.weekly_subscription) == sku)
|
||||
// {
|
||||
// lv = 1;
|
||||
// }
|
||||
// else if (GetPaySku(PayType.monthly_subscription) == sku)
|
||||
// {
|
||||
// lv = 2;
|
||||
// }
|
||||
// else if (GetPaySku(PayType.yearly_subscription) == sku)
|
||||
// {
|
||||
// lv = 3;
|
||||
// }
|
||||
//
|
||||
// return lv;
|
||||
// }
|
||||
|
||||
|
||||
public static void Purchase(ApplePayData payData)
|
||||
@@ -75,13 +74,28 @@ public class PurchasingManager
|
||||
//本地测试
|
||||
// TestIOSPay(payData);
|
||||
// return;
|
||||
|
||||
|
||||
|
||||
|
||||
Debug.Log($"[Apple Pay] unity Purchase--0-----: {payData.sku}");
|
||||
// ApplePayManager.Instance.Purchase(payData.sku, ApplePaySuccessCallback(payData), message =>
|
||||
// {
|
||||
// Debug.Log("purchase fail------- reason: " + message);
|
||||
// });
|
||||
|
||||
if (payData.sku.Contains("sub"))
|
||||
{
|
||||
IAPPayManager.Instance.SubscribeProduct(payData.sku, "",() =>
|
||||
{
|
||||
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
IAPPayManager.Instance.BuyProduct(payData.sku, "",() =>
|
||||
{
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// public static Action<ApplePayBackType, AppleResponseData> ApplePaySuccessCallback(ApplePayData payData)
|
||||
@@ -112,7 +126,7 @@ public class PurchasingManager
|
||||
// var sku = SetSku(payData);
|
||||
//
|
||||
// Debug.Log($"[Apple Pay] Check sku===2===== {sku}");
|
||||
// GameDispatcher.Instance.Dispatch(GameMsg.apple_pay_success, sku);
|
||||
// GameDispatcher.Instance.Dispatch(GameMsg.IAP_PAY_SUCCESS, sku);
|
||||
// Debug.Log($"[Apple Pay] Check sku===3===== {sku}");
|
||||
//
|
||||
// SendEventClickByName(sku, "open");
|
||||
@@ -148,31 +162,69 @@ public class PurchasingManager
|
||||
// ApplePayManager.Instance.ApplePayTest(types, payData.sku, tranId, ApplePaySuccessCallback(payData));
|
||||
// }
|
||||
|
||||
private static string SetSku(ApplePayData data)
|
||||
// private static string SetSku(ApplePayData data)
|
||||
// {
|
||||
// string sku = "";
|
||||
// if (data.type != null && data.type == GetPaySku(PayType.remove_ad))
|
||||
// {
|
||||
// sku = data.type;
|
||||
// }
|
||||
// else if (data.sku.Contains("shop"))
|
||||
// {
|
||||
// sku = data.shopName;
|
||||
// }
|
||||
// else if (data.sku.Contains("sub"))
|
||||
// {
|
||||
// sku = data.shopName;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// sku = data.sku;
|
||||
// }
|
||||
//
|
||||
// return sku;
|
||||
// }
|
||||
|
||||
// 商店商品映射表
|
||||
public static readonly Dictionary<string, string> ShopProductMap = new Dictionary<string, string>
|
||||
{
|
||||
string sku = "";
|
||||
if (data.type != null && data.type == GetPaySku(PayType.remove_ad))
|
||||
{
|
||||
sku = data.type;
|
||||
}
|
||||
else if (data.sku.Contains("shop"))
|
||||
{
|
||||
sku = data.shopName;
|
||||
}
|
||||
else if (data.sku.Contains("sub"))
|
||||
{
|
||||
sku = data.shopName;
|
||||
}
|
||||
else
|
||||
{
|
||||
sku = data.sku;
|
||||
}
|
||||
{ IAPPayManager.PRODUCT_SHOP_1, "0" },
|
||||
{ IAPPayManager.PRODUCT_SHOP_2, "1" },
|
||||
{ IAPPayManager.PRODUCT_SHOP_3, "2" },
|
||||
{ IAPPayManager.PRODUCT_SHOP_4, "3" },
|
||||
{ IAPPayManager.PRODUCT_SHOP_5, "4" }
|
||||
};
|
||||
|
||||
// 订阅商品映射表
|
||||
public static readonly Dictionary<string, string> VipProductMap = new Dictionary<string, string>
|
||||
{
|
||||
{ IAPPayManager.PRODUCT_VIP_WEEK, "0" },
|
||||
{ IAPPayManager.PRODUCT_VIP_MONTH, "1" },
|
||||
{ IAPPayManager.PRODUCT_VIP_YEAR, "2" },
|
||||
};
|
||||
|
||||
return sku;
|
||||
/// <summary>
|
||||
/// 更新map中的value,与配置表的id对应
|
||||
/// _shopProductMap
|
||||
/// </summary>
|
||||
public static void SetShopMapValue()
|
||||
{
|
||||
var list = ConfigSystem.GetConfig<Paidcoins>();
|
||||
if (list is not { Count: > 0 }) return;
|
||||
foreach (var paidcoin in list)
|
||||
{
|
||||
if (string.IsNullOrEmpty(paidcoin.SKU))
|
||||
continue;
|
||||
|
||||
if (ShopProductMap.ContainsKey(paidcoin.SKU))
|
||||
{
|
||||
ShopProductMap[paidcoin.SKU] = (paidcoin.id - 1).ToString();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void SendEventClickByName(string name, string type)
|
||||
|
||||
public static void SendEventClickByName(string name, string type)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
@@ -183,64 +235,60 @@ public class PurchasingManager
|
||||
string successTrackKey = null;
|
||||
string openTrackKey = null;
|
||||
|
||||
if (name == GetPaySku(PayType.pack_reward))
|
||||
if (name == IAPPayManager.PRODUCT_FIRST_GIFT)
|
||||
{
|
||||
clickTrackKey = ADEventTrack.Property.lucky_gift_click;
|
||||
successTrackKey = ADEventTrack.Property.lucky_gift_receive;
|
||||
openTrackKey = ADEventTrack.Property.first_pack_show;
|
||||
}
|
||||
else if (name == GetPaySku(PayType.remove_ad))
|
||||
else if (name == IAPPayManager.PRODUCT_REMOVE_ADS)
|
||||
{
|
||||
clickTrackKey = ADEventTrack.Property.remove_ad_click;
|
||||
successTrackKey = ADEventTrack.Property.remove_ad_receive;
|
||||
openTrackKey = ADEventTrack.Property.gift_show;
|
||||
}
|
||||
else if (name == GetPaySku(PayType.battle_pass))
|
||||
else if (name == IAPPayManager.PRODUCT_PASS_BONUS)
|
||||
{
|
||||
clickTrackKey = ADEventTrack.Property.master_pass_click;
|
||||
successTrackKey = ADEventTrack.Property.master_pass_receive;
|
||||
openTrackKey = ADEventTrack.Property.master_pass_show;
|
||||
}
|
||||
else if (name == GetPaySku(PayType.buy_one))
|
||||
else if (name == IAPPayManager.PRODUCT_SPACE_BONUS)
|
||||
{
|
||||
clickTrackKey = ADEventTrack.Property.buy_one_click;
|
||||
successTrackKey = ADEventTrack.Property.buy_one_success;
|
||||
openTrackKey = ADEventTrack.Property.buy_one_show;
|
||||
}
|
||||
else if (name == GetPaySku(PayType.buy_one_off))
|
||||
{
|
||||
// clickTrackKey = ADEventTrack.Property.BuyOneOffClick;
|
||||
// successTrackKey = ADEventTrack.Property.BuyOneOffSuccess;
|
||||
// openTrackKey = ADEventTrack.Property.BuyOneOffShow;
|
||||
}
|
||||
else if (name == GetPaySku(PayType.fail_pack))
|
||||
{
|
||||
clickTrackKey = ADEventTrack.Property.fail_click;
|
||||
successTrackKey = ADEventTrack.Property.fail_buy_success;
|
||||
openTrackKey = ADEventTrack.Property.fail_show;
|
||||
}
|
||||
else if (name == GetPaySku(PayType.three_days_gift))
|
||||
{
|
||||
clickTrackKey = ADEventTrack.Property.three_days_gift_click;
|
||||
successTrackKey = ADEventTrack.Property.three_days_gift_buy_success;
|
||||
openTrackKey = ADEventTrack.Property.three_days_gift_show;
|
||||
}
|
||||
// else if (name == GetPaySku(PayType.buy_one_off))
|
||||
// {
|
||||
// // clickTrackKey = ADEventTrack.Property.BuyOneOffClick;
|
||||
// // successTrackKey = ADEventTrack.Property.BuyOneOffSuccess;
|
||||
// // openTrackKey = ADEventTrack.Property.BuyOneOffShow;
|
||||
// }
|
||||
// else if (name == GetPaySku(PayType.fail_pack))
|
||||
// {
|
||||
// clickTrackKey = ADEventTrack.Property.fail_click;
|
||||
// successTrackKey = ADEventTrack.Property.fail_buy_success;
|
||||
// openTrackKey = ADEventTrack.Property.fail_show;
|
||||
// }
|
||||
// else if (name == GetPaySku(PayType.three_days_gift))
|
||||
// {
|
||||
// clickTrackKey = ADEventTrack.Property.three_days_gift_click;
|
||||
// successTrackKey = ADEventTrack.Property.three_days_gift_buy_success;
|
||||
// openTrackKey = ADEventTrack.Property.three_days_gift_show;
|
||||
// }
|
||||
|
||||
if (name.StartsWith("buy_gold"))
|
||||
else if (ShopProductMap.TryGetValue(name, out var idx))
|
||||
{
|
||||
int startIndex = "buy_gold".Length;
|
||||
string suffix = name[startIndex..]; // 截取 "gold" 后的所有字符
|
||||
clickTrackKey = ADEventTrack.Property.gold_click_ + suffix;
|
||||
successTrackKey = ADEventTrack.Property.shop_receive_ + suffix;
|
||||
clickTrackKey = ADEventTrack.Property.gold_click_ + idx;
|
||||
successTrackKey = ADEventTrack.Property.shop_receive_ + idx;
|
||||
openTrackKey = ADEventTrack.Property.shop_show;
|
||||
}
|
||||
|
||||
if (name.StartsWith("vip_club"))
|
||||
else if (VipProductMap.TryGetValue(name, out var vipIdx))
|
||||
{
|
||||
int startIndex = "vip_club".Length;
|
||||
string suffix = name[startIndex..]; // 截取 "gold" 后的所有字符
|
||||
clickTrackKey = ADEventTrack.Property.vip_click_ + suffix;
|
||||
successTrackKey = ADEventTrack.Property.vip_success_ + suffix;
|
||||
clickTrackKey = ADEventTrack.Property.vip_click_ + vipIdx;
|
||||
successTrackKey = ADEventTrack.Property.vip_success_ + vipIdx;
|
||||
openTrackKey = ADEventTrack.Property.buy_one_show;
|
||||
}
|
||||
|
||||
@@ -254,13 +302,20 @@ public class PurchasingManager
|
||||
}
|
||||
else if (type == "open" && openTrackKey != null)
|
||||
{
|
||||
// TrackKit.SendEvent(ADEventTrack.IOS_Pay_Event, openTrackKey);
|
||||
TrackKit.SendEvent(ADEventTrack.IOS_Pay_Event, openTrackKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ios支付创建订单接口,改一下用来上传数据给后台统计支付数据
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="onCompleted"></param>
|
||||
public static void ApplePayCreate<T>(ApplePayData data, UnityAction<ResponseData<T>> onCompleted = null)
|
||||
{
|
||||
NetKit.Instance.Post<T>("shop/applePayCreate", data,
|
||||
response => { onCompleted?.Invoke(response); });
|
||||
}
|
||||
|
||||
}
|
||||
public class ApplePayData
|
||||
{
|
||||
@@ -276,6 +331,8 @@ public class ApplePayData
|
||||
public string shopName;
|
||||
[JsonProperty("type")]
|
||||
public string type;
|
||||
[JsonProperty("isCompleted")]
|
||||
public bool isCompleted;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user