using FL.Network; using System.Collections.Generic; using XGame; using XGame.Framework; using XGame.Framework.Data; using XGame.Framework.Network; namespace FL.Data { public class PaymentService : DataSingleton { /// /// 请求开始广告 /// /// /// public void ReqAdvert(List param, EPayActionType action = EPayActionType.AdvertStart) { var payment = PaymentData.Instance; if (payment.IsBusy) { Log.Error($"重复请求广告/支付。Action:{payment.Action}"); return; } payment.SetAction(action); var request = new Kind11XiadanRequest() { param = param }; NetModule.Request(request); } /// /// 请求开始支付 /// public void ReqPay(PayRequestParam pay, EPayActionType action = EPayActionType.PayStart) { var payment = PaymentData.Instance; if (payment.IsBusy) { Log.Error($"重复请求广告/支付。Action:{payment.Action}"); return; } payment.SetAction(action); var request = new Kind10XiadanRequest() { kid = pay.kid, hdcid = pay.hdcid, dc = pay.dc, dc1 = pay.dc1, }; NetModule.Request(request); } /// /// 开始支付 /// public void StartPay() { var payment = PaymentData.Instance; var order = payment.goodsOrder; var action = payment.Action; Assert.IsTrue(action >= EPayActionType.PayStart, $"准备开始支付,但是状态错误. State:{action}"); Assert.IsTrue(order.hdcid == 1, $"准备开始支付,但是订单信息不是支付.{order.hdcid}"); //TODO 打开支付SDK // 清空数据 payment.SetAction(EPayActionType.None); payment.goodsOrder = default; EventSingle.Instance.Notify(EventDefine.PaySuccess, action); } /// /// 开始广告 /// /// public void StartAdvert() { var payment = PaymentData.Instance; var order = payment.goodsOrder; var action = payment.Action; Assert.IsTrue(action > EPayActionType.None && action < EPayActionType.PayStart, $"准备开始广告,但是状态错误. State:{action}"); Assert.IsTrue(order.hdcid == 2, $"准备开始广告,但是订单信息不是广告.{order.hdcid}"); //TODO 打开广告、支付SDK // 广告成功后发送消息给服务端 var request = new UserBillSuccessRequest() { xdid = order.id //订单ID }; NetModule.Request(request); } } }