bingo 项目提交
This commit is contained in:
@@ -0,0 +1,550 @@
|
||||
using UnityEngine;
|
||||
using BingoBrain;
|
||||
using DG.Tweening;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using BingoBrain.Core;
|
||||
using BingoBrain;
|
||||
using BingoBrain.HotFix;
|
||||
|
||||
|
||||
public class MaxPayManager
|
||||
{
|
||||
public static readonly MaxPayManager Instance = new MaxPayManager();
|
||||
|
||||
public static bool isPay = false;
|
||||
|
||||
// public static Dictionary<string, int> statusDictionary = new();
|
||||
MaxPayManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static string buy_one = "com.sugar.space.24.99";
|
||||
// public static string buy_gold_1 = "com.sugar.shop.1.99";
|
||||
// public static string buy_gold_2 = "com.sugar.shop.3.99";
|
||||
// public static string buy_gold_3 = "com.sugar.shop.9.99";
|
||||
// public static string buy_gold_4 = "com.sugar.shop.19.99";
|
||||
|
||||
public static string remove_ad = "com.sugar.remove.2.99";
|
||||
public static string battle_pass = "com.sugar.pass.9.99";
|
||||
public static string pack_reward = "com.sugar.reward.1.99";
|
||||
public static string fail_pack = "com.sugar.fail_pack";
|
||||
public string three_days_gift = "com.bingo.3daygift1.1.99";
|
||||
public void Buy(MaxPayClass _data)
|
||||
{
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PayloadingUI_Open);
|
||||
StopPayCoroutine();
|
||||
SaveData.GetSaveobject().max_pay_object = _data;
|
||||
MaxPay(_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发起第三发支付
|
||||
/// </summary>
|
||||
public void MaxPay(MaxPayClass data_)
|
||||
{
|
||||
// Debug.Log($"[UNITY] Purchase;;;;;;{JsonConvert.SerializeObject(data_)}");
|
||||
|
||||
//is debug test--------测试代码
|
||||
if (Application.identifier != NetworkMsg.Identifier)
|
||||
// if (Application.identifier == NetworkMsg.Identifier)
|
||||
{
|
||||
MaxPayClass paydata = data_;
|
||||
SaveData.pay_time = Time.time;
|
||||
|
||||
if (data_.sku == buy_one)
|
||||
{
|
||||
NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, BuriedPointEvent.buy_one_click, 1);
|
||||
}
|
||||
else if (data_.sku == remove_ad)
|
||||
{
|
||||
NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, BuriedPointEvent.remove_ad_click, 1);
|
||||
}
|
||||
else if (data_.sku == pack_reward)
|
||||
{
|
||||
NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, BuriedPointEvent.pack_click, 1);
|
||||
}
|
||||
else if (data_.sku.StartsWith("buy_gold"))
|
||||
{
|
||||
int startIndex = "buy_gold".Length;
|
||||
string suffix = paydata.sku[startIndex..]; // 截取 "gold" 后的所有字符
|
||||
string eventClickName = $"gold_click_{suffix}";
|
||||
NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, eventClickName, 1);
|
||||
|
||||
}
|
||||
else if (data_.sku == battle_pass)
|
||||
{
|
||||
NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, BuriedPointEvent.pass_click, 1);
|
||||
}
|
||||
else if (data_.sku == fail_pack)
|
||||
{
|
||||
NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, BuriedPointEvent.fail_click, 1);
|
||||
}
|
||||
else if (data_.sku == three_days_gift)
|
||||
{
|
||||
NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, BuriedPointEvent.three_days_gift_click, 1);
|
||||
}
|
||||
PayerData test = new PayerData()
|
||||
{
|
||||
amount = data_.amount,
|
||||
};
|
||||
|
||||
//max 支付订单创建
|
||||
NetworkKit.PostWithHeader<orderData>("shop/maxPayIn", test, (isSuccess, obj) =>
|
||||
{
|
||||
if (isSuccess)
|
||||
{
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PayloadingUI_Close);
|
||||
|
||||
Debug.Log($"max 支付订单创建:{JsonConvert.SerializeObject(obj)}");
|
||||
// UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PixPayUI_Open, obj);
|
||||
SaveData.GetSaveobject().max_pay_object.innerOrderId = obj.order_id;
|
||||
paydata.status = 1;
|
||||
SavePayData(obj.order_id, paydata);
|
||||
isPay = true;
|
||||
OpenBrowser.OpenURL(obj.pay_url);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// GameDispatcher.Instance.Dispatch(GameMsg.apple_pay_success, data_.sku);
|
||||
}
|
||||
}
|
||||
|
||||
public void SavePayData(string orderId, MaxPayClass payData)
|
||||
{
|
||||
// Debug.Log($"max 支付 SavePayData: orderId={orderId} status={payData}");
|
||||
// 加载已保存的支付数据
|
||||
var payDataJson = PlayerPrefs.GetString("three_pay_data", "{}");
|
||||
var statusDictionary = JsonConvert.DeserializeObject<Dictionary<string, MaxPayClass>>(payDataJson);
|
||||
|
||||
// Debug.Log($"max 支付 statusDictionary {statusDictionary}");
|
||||
// 判断是否已有相同的 orderId
|
||||
if (statusDictionary.ContainsKey(orderId))
|
||||
{
|
||||
// Debug.Log($"max 支付 statusDictionary 已存在 orderId {orderId}");
|
||||
// 更新现有条目的状态
|
||||
statusDictionary[orderId] = payData;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 添加新的条目
|
||||
// Debug.Log($"max 支付 statusDictionary 不存在 orderId {orderId}");
|
||||
statusDictionary.Add(orderId, payData);
|
||||
}
|
||||
|
||||
// 保存更新后的数据
|
||||
PlayerPrefs.SetString("three_pay_data", JsonConvert.SerializeObject(statusDictionary));
|
||||
// Debug.Log($"max 支付 three_pay_data {JsonConvert.SerializeObject(statusDictionary)}");
|
||||
|
||||
}
|
||||
|
||||
public MaxPayClass GetPayData(string orderId)
|
||||
{
|
||||
var payDataJson = PlayerPrefs.GetString("three_pay_data", "{}");
|
||||
var statusDictionary = JsonConvert.DeserializeObject<Dictionary<string, MaxPayClass>>(payDataJson);
|
||||
|
||||
if (statusDictionary.ContainsKey(orderId))
|
||||
{
|
||||
return statusDictionary[orderId];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool GetPayStatus()
|
||||
{
|
||||
bool isCheck = false;
|
||||
|
||||
var payDataJson = PlayerPrefs.GetString("three_pay_data", "{}");
|
||||
var statusDictionary = JsonConvert.DeserializeObject<Dictionary<string, MaxPayClass>>(payDataJson);
|
||||
if (statusDictionary == null) return false;
|
||||
foreach (var entry in statusDictionary)
|
||||
{
|
||||
if (entry.Value.status == 1)
|
||||
{
|
||||
isCheck = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return isCheck;
|
||||
}
|
||||
|
||||
private int PayStatus = -1;
|
||||
|
||||
private Coroutine PayCoroutine;
|
||||
public IEnumerator ProcessPayData()
|
||||
{
|
||||
var payDataJson = PlayerPrefs.GetString("three_pay_data", "{}");
|
||||
var statusDictionary = JsonConvert.DeserializeObject<Dictionary<string, MaxPayClass>>(payDataJson);
|
||||
|
||||
foreach (var entry in statusDictionary.OrderByDescending(pair => pair.Key))
|
||||
{
|
||||
// Debug.Log($"max 支付 ProcessPayData0======{entry.Key} status:{entry.Value}");
|
||||
if (entry.Value.status == 1)
|
||||
{
|
||||
bool keepRequesting = true;
|
||||
|
||||
while (keepRequesting)
|
||||
{
|
||||
// 发起请求
|
||||
PaySuccess(entry.Key);
|
||||
yield return new WaitForSeconds(5f);
|
||||
// Debug.Log($"max 支付 ProcessPayData1======{entry.Key} status:{PayStatus}");
|
||||
if (PayStatus == 1)
|
||||
{
|
||||
// 如果返回值为1,则等待5秒后再次请求
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果返回值不为1,则停止循环
|
||||
PayStatus = -1;
|
||||
keepRequesting = false;
|
||||
}
|
||||
|
||||
yield return null; // 等待本次请求完成
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void StopPayCoroutine()
|
||||
{
|
||||
if (PayCoroutine != null)
|
||||
{
|
||||
IsfvKit.StopCoroutine(PayCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
public void PaySuccess()
|
||||
{
|
||||
Debug.Log("max 支付 StartCoroutine------");
|
||||
PayCoroutine = IsfvKit.StartCoroutine(ProcessPayData());
|
||||
}
|
||||
public void PaySuccess(string orderId)
|
||||
{
|
||||
var test = new maxOrder();
|
||||
test.order_id = orderId;
|
||||
//max 支付订单查询
|
||||
NetworkKit.PostWithHeader<orderState>("shop/maxPayOrderQuery", test, (isSuccess, obj) =>
|
||||
{
|
||||
Debug.Log($"max 支付订单查询: id= {orderId} is succ={isSuccess}");
|
||||
if (isSuccess)
|
||||
{
|
||||
Debug.Log($"max 支付订单查询: 成功,statu====: {obj.status}");
|
||||
// Debug.Log($"max 支付订单查询: {JsonConvert.SerializeObject(obj)}");
|
||||
PayStatus = obj.status;
|
||||
|
||||
//1:支付中,需要定时查询
|
||||
if (obj.status == 1)
|
||||
{
|
||||
var paydata = GetPayData(orderId);
|
||||
if (paydata != null)
|
||||
{
|
||||
paydata.status = 1;
|
||||
SavePayData(obj.order_id, paydata);
|
||||
}
|
||||
|
||||
// reCreatPur();
|
||||
}
|
||||
//2:支付成功,发奖
|
||||
else if (obj.status == 2)
|
||||
{
|
||||
var paydata = GetPayData(orderId);
|
||||
if (paydata != null)
|
||||
{
|
||||
paydata.status = 2;
|
||||
SavePayData(obj.order_id, paydata);
|
||||
}
|
||||
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PayloadingUI_Close);
|
||||
|
||||
bool isOpen = false;
|
||||
if (paydata.sku == buy_one)
|
||||
{
|
||||
isOpen = HandleSku(paydata.sku, UIConst.BuyslotUI, BuriedPointEvent.buy_one_open, BuriedPointEvent.buy_one_success);
|
||||
}
|
||||
else if (paydata.sku == remove_ad)
|
||||
{
|
||||
isOpen = HandleSku(paydata.sku, UIConst.PackrewardUI, BuriedPointEvent.remove_ad_open, BuriedPointEvent.remove_ad_success);
|
||||
}
|
||||
else if (paydata.sku == pack_reward)
|
||||
{
|
||||
isOpen = HandleSku(paydata.sku, UIConst.PackrewardUI, BuriedPointEvent.pack_open, BuriedPointEvent.pack_success);
|
||||
}
|
||||
else if (paydata.sku.StartsWith("buy_gold"))
|
||||
{
|
||||
int startIndex = "buy_gold".Length;
|
||||
string suffix = paydata.sku[startIndex..]; // 截取 "gold" 后的所有字符
|
||||
string eventOpenName = $"gold_open_{suffix}";
|
||||
string eventSuccessName = $"gold_success_{suffix}";
|
||||
|
||||
isOpen = HandleSku(paydata.sku, UIConst.BuygoldUI, eventOpenName, eventSuccessName);
|
||||
|
||||
}
|
||||
else if (paydata.sku == battle_pass)
|
||||
{
|
||||
isOpen = HandleSku(paydata.sku, UIConst.NewTaskUI, BuriedPointEvent.pass_open, BuriedPointEvent.pass_success);
|
||||
}
|
||||
else if (paydata.sku == fail_pack)
|
||||
{
|
||||
isOpen = HandleSku(paydata.sku, UIConst.PackrewardUI, BuriedPointEvent.fail_show, BuriedPointEvent.fail_buy_success); ;
|
||||
}
|
||||
else if (paydata.sku == three_days_gift)
|
||||
{
|
||||
isOpen = HandleSku(paydata.sku, UIConst.ThreeDaysGiftUI, BuriedPointEvent.three_days_gift_show, BuriedPointEvent.three_days_gift_buy_success);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 处理未知的 sku 值
|
||||
Debug.LogError($"Unknown SKU: {paydata.sku}");
|
||||
throw new ArgumentException("Unknown SKU");
|
||||
}
|
||||
|
||||
// if (isOpen) {
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.apple_pay_success, paydata.sku);
|
||||
// } else {
|
||||
// GetPayPrice(paydata);
|
||||
// }
|
||||
SaveingPotClass taskData = SaveData.GetSaveobject().saveingpot_history.Last();
|
||||
makeup_2 makeupVo = ConfigSystem.GetConfig<MakeupModel_2>().GetData(taskData.tableId);
|
||||
SaveData.GetSaveobject().saveingpot_cash += ((float)paydata.amount) / 100 * makeupVo.PayIncrease; ;
|
||||
if (ConfigSystem.GetConfig<CommonModel>().PiggyBankSwitch == 1 && GameHelper.IsGiftSwitch())
|
||||
{
|
||||
if ((SaveData.GetSaveobject().saveingpot_cash > taskData.amount) && (!taskData.auto_show) && !UI.Instance.IsExistUI(UIConst.H5UI))
|
||||
{
|
||||
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.SaveingPotUI_Open);
|
||||
taskData.auto_show = true;
|
||||
}
|
||||
}
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.RefreshSaveingPot);
|
||||
DOVirtual.DelayedCall(1, () =>
|
||||
{
|
||||
SaveData.GetSaveobject().max_pay_object = null;
|
||||
var paydata = GetPayData(orderId);
|
||||
if (paydata != null)
|
||||
{
|
||||
paydata.status = 4;
|
||||
SavePayData(obj.order_id, paydata);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
//3:支付失败,已领奖或者支付失败,或者查询次数达到上限
|
||||
else if (obj.status == 3)
|
||||
{
|
||||
var paydata = GetPayData(orderId);
|
||||
if (paydata != null)
|
||||
{
|
||||
paydata.status = 3;
|
||||
SavePayData(obj.order_id, paydata);
|
||||
}
|
||||
OnPayFailed(orderId);
|
||||
}
|
||||
//4:已发货,服务端记录已经发过奖,若客户端未发奖可发奖
|
||||
else
|
||||
{
|
||||
DOVirtual.DelayedCall(1, () =>
|
||||
{
|
||||
var paydata = GetPayData(orderId);
|
||||
if (paydata != null)
|
||||
{
|
||||
paydata.status = 4;
|
||||
SavePayData(obj.order_id, paydata);
|
||||
}
|
||||
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PayloadingUI_Close);
|
||||
SaveData.GetSaveobject().max_pay_object = null;
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.apple_pay_success, paydata.sku);
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Debug.Log("max 支付 验证订单失败");
|
||||
// Debug.Log($"max 支付 验证订单失败: {JsonConvert.SerializeObject(obj)}");
|
||||
//验证订单失败
|
||||
// reCreatPur();
|
||||
// status = -1;
|
||||
PayStatus = -1;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
bool HandleSku(string sku, string uiConst, string openEvent, string successEvent)
|
||||
{
|
||||
bool isOpen;
|
||||
try
|
||||
{
|
||||
isOpen = CheckIsOpen(uiConst);
|
||||
// NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, openEvent, 1);
|
||||
NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, successEvent, 1);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 记录异常信息
|
||||
Debug.LogError($"Error handling SKU {sku}: {ex.Message}");
|
||||
// 可以选择重新抛出异常或进行其他处理
|
||||
throw;
|
||||
}
|
||||
|
||||
return isOpen;
|
||||
}
|
||||
|
||||
public void reCreatPur()//重新验证订单
|
||||
{
|
||||
// Debug.Log($"max 支付 reCreatPur 重新验证订单: pay_object_data===: {JsonConvert.SerializeObject(SaveData.GetSaveobject().max_pay_object)}");
|
||||
|
||||
// if (SaveData.GetSaveobject().max_pay_object != null)
|
||||
// {
|
||||
// CrazyAsyKit.StartCoroutine(ProcessPayData());
|
||||
// }
|
||||
}
|
||||
|
||||
public void OnPayFailed(string orderId)
|
||||
{
|
||||
var paydata = GetPayData(orderId);
|
||||
|
||||
if (paydata == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PayloadingUI_Close);
|
||||
// Debug.LogWarning("OnPurchaseFailedproduct:" + product.transactionID + " failureReason:" + failureReason);
|
||||
|
||||
|
||||
DOVirtual.DelayedCall(1, () =>
|
||||
{
|
||||
SaveData.GetSaveobject().max_pay_object = null;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private bool CheckIsOpen(string name)
|
||||
{
|
||||
var isOpen = UI.Instance.IsExistUI(name);
|
||||
|
||||
return isOpen;
|
||||
}
|
||||
|
||||
//适用这个方法领奖,说明购买界面已经关闭
|
||||
private void GetPayPrice(MaxPayClass paydata)
|
||||
{
|
||||
decimal rewardNum = 0;
|
||||
if (paydata.sku == buy_one)
|
||||
{
|
||||
SaveData.GetSaveobject().have_slot = true;
|
||||
}
|
||||
else if (paydata.sku == remove_ad)
|
||||
{
|
||||
var list = ConfigSystem.GetConfig<PaidgiftModel>().dataList;
|
||||
if (list.Count > 0)
|
||||
{
|
||||
rewardNum = list[1].coins_quantity;
|
||||
}
|
||||
|
||||
//标记已经购买过
|
||||
SaveData.GetSaveobject().is_get_packreward = true;
|
||||
|
||||
}
|
||||
else if (paydata.sku == pack_reward)
|
||||
{
|
||||
var list = ConfigSystem.GetConfig<PaidgiftModel>().dataList;
|
||||
if (list.Count > 0)
|
||||
{
|
||||
rewardNum = list[0].coins_quantity;
|
||||
}
|
||||
//标记已经购买过
|
||||
SaveData.GetSaveobject().is_get_removead = true;
|
||||
}
|
||||
else if (paydata.sku.StartsWith("buy_gold"))
|
||||
{
|
||||
int startIndex = "buy_gold".Length;
|
||||
string suffix = paydata.sku[startIndex..]; // 截取 "gold" 后的所有字符
|
||||
rewardNum = GetGoldRewradNum(int.Parse(suffix));
|
||||
}
|
||||
else if (paydata.sku == battle_pass)
|
||||
{
|
||||
//标记已经购买过
|
||||
SaveData.GetSaveobject().is_get_battlepass = true;
|
||||
}
|
||||
if (rewardNum > 0)
|
||||
{
|
||||
GetPayReward(rewardNum);
|
||||
}
|
||||
}
|
||||
|
||||
private static decimal GetGoldRewradNum(int index)
|
||||
{
|
||||
decimal rewardNum = 0;
|
||||
var list = ConfigSystem.GetConfig<PaidcoinsModel>().dataList;
|
||||
if (list.Count > 0 && list.Count > index)
|
||||
{
|
||||
rewardNum = list[index].Actual_coins;
|
||||
}
|
||||
|
||||
return rewardNum;
|
||||
}
|
||||
|
||||
private void GetPayReward(decimal goldNum)
|
||||
{
|
||||
if (goldNum == 0) return;
|
||||
|
||||
var start = new Vector2(540, 960);
|
||||
var rewardData = new RewardData();
|
||||
var rewardSingleData = new Goda(101, goldNum, RewardOrigin.AdTask)
|
||||
{
|
||||
startPosition = start,
|
||||
};
|
||||
rewardData.AddReward(rewardSingleData);
|
||||
rewardData.displayType = RewardDisplayType.RewardFly | RewardDisplayType.ValueChange;
|
||||
|
||||
GameDispatcher.Instance.Dispatch(BingoInfo.GetReward, rewardData);
|
||||
}
|
||||
}
|
||||
|
||||
public class maxOrder
|
||||
{
|
||||
public string order_id;
|
||||
|
||||
}
|
||||
|
||||
public class MaxPayClass
|
||||
{
|
||||
public string innerOrderId;
|
||||
public int amount;
|
||||
public string sku;
|
||||
public string currency = "USD";
|
||||
public int status;
|
||||
}
|
||||
|
||||
public class PayerData
|
||||
{
|
||||
public string name;
|
||||
public string tel;
|
||||
public string email;
|
||||
public int amount;
|
||||
}
|
||||
|
||||
//orderState 是返回对象的类型
|
||||
public class orderState
|
||||
{
|
||||
public string order_id;
|
||||
public int status;
|
||||
}
|
||||
Reference in New Issue
Block a user