PaymentService.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using FL.Network;
  2. using System.Collections.Generic;
  3. using XGame;
  4. using XGame.Framework;
  5. using XGame.Framework.Data;
  6. using XGame.Framework.Network;
  7. namespace FL.Data
  8. {
  9. public class PaymentService : DataSingleton<PaymentService>
  10. {
  11. /// <summary>
  12. /// 请求开始广告
  13. /// </summary>
  14. /// <param name="param"></param>
  15. /// <param name="context"></param>
  16. public void ReqAdvert(List<string> param, EPayActionType action = EPayActionType.AdvertStart)
  17. {
  18. var payment = PaymentData.Instance;
  19. if (payment.IsBusy)
  20. {
  21. Log.Error($"重复请求广告/支付。Action:{payment.Action}");
  22. return;
  23. }
  24. payment.SetAction(action);
  25. var request = new Kind11XiadanRequest()
  26. {
  27. param = param
  28. };
  29. NetModule.Request(request);
  30. }
  31. /// <summary>
  32. /// 请求开始支付
  33. /// </summary>
  34. public void ReqPay(PayRequestParam pay, EPayActionType action = EPayActionType.PayStart)
  35. {
  36. var payment = PaymentData.Instance;
  37. if (payment.IsBusy)
  38. {
  39. Log.Error($"重复请求广告/支付。Action:{payment.Action}");
  40. return;
  41. }
  42. payment.SetAction(action);
  43. var request = new Kind10XiadanRequest()
  44. {
  45. kid = pay.kid,
  46. hdcid = pay.hdcid,
  47. dc = pay.dc,
  48. dc1 = pay.dc1,
  49. };
  50. NetModule.Request(request);
  51. }
  52. /// <summary>
  53. /// 开始支付
  54. /// </summary>
  55. public void StartPay()
  56. {
  57. var payment = PaymentData.Instance;
  58. var order = payment.goodsOrder;
  59. var action = payment.Action;
  60. Assert.IsTrue(action >= EPayActionType.PayStart, $"准备开始支付,但是状态错误. State:{action}");
  61. Assert.IsTrue(order.hdcid == 1, $"准备开始支付,但是订单信息不是支付.{order.hdcid}");
  62. //TODO 打开支付SDK
  63. // 清空数据
  64. payment.SetAction(EPayActionType.None);
  65. payment.goodsOrder = default;
  66. EventSingle.Instance.Notify(EventDefine.PaySuccess, action);
  67. }
  68. /// <summary>
  69. /// 开始广告
  70. /// </summary>
  71. /// <returns></returns>
  72. public void StartAdvert()
  73. {
  74. var payment = PaymentData.Instance;
  75. var order = payment.goodsOrder;
  76. var action = payment.Action;
  77. Assert.IsTrue(action > EPayActionType.None && action < EPayActionType.PayStart, $"准备开始广告,但是状态错误. State:{action}");
  78. Assert.IsTrue(order.hdcid == 2, $"准备开始广告,但是订单信息不是广告.{order.hdcid}");
  79. //TODO 打开广告、支付SDK
  80. // 广告成功后发送消息给服务端
  81. var request = new UserBillSuccessRequest()
  82. {
  83. xdid = order.id //订单ID
  84. };
  85. NetModule.Request(request);
  86. }
  87. }
  88. }