123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- 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<PaymentService>
- {
- /// <summary>
- /// 请求开始广告
- /// </summary>
- /// <param name="param"></param>
- /// <param name="context"></param>
- public void ReqAdvert(List<string> 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);
- }
- /// <summary>
- /// 请求开始支付
- /// </summary>
- 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);
- }
- /// <summary>
- /// 开始支付
- /// </summary>
- 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);
- }
- /// <summary>
- /// 开始广告
- /// </summary>
- /// <returns></returns>
- 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);
- }
- }
- }
|