QDDouYouManagerIos.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. using System;
  2. using ET;
  3. using UnityEngine;
  4. using GFGGame.Launcher;
  5. namespace GFGGame
  6. {
  7. public class QDDouYouManagerIos : SingletonBase<QDDouYouManagerIos>
  8. {
  9. public bool isLogining;
  10. //ios sdk 返回的
  11. public string uid;
  12. public string account;
  13. public string token;
  14. public void Init()
  15. {
  16. Debug.Log("实例化DouYouSDKListenerIos");
  17. QDDouYouManagerInitIos.Instance.douYouSDKListenerIos = new DouYouSDKListenerIos();
  18. }
  19. public void Login()
  20. {
  21. QDDouYouManagerInitIos.Instance.ShowLogin();
  22. }
  23. public void OnCreateRole()
  24. {
  25. QDManager.PushRoleAction(DouYouRoleLogReportType.CreateRole);
  26. }
  27. public void OnEnterGame()
  28. {
  29. QDManager.PushRoleAction(DouYouRoleLogReportType.EnterGame);
  30. }
  31. public void OnQuitToLoginView()
  32. {
  33. Debug.Log($"DouYou ios OnQuitToLoginView");
  34. }
  35. public void Logout()
  36. {
  37. Debug.Log($"Game.HotUpdate DouYou ios Logout");
  38. QDDouYouManagerInitIos.Instance.Logout();
  39. }
  40. public void LoginOutBefore()
  41. {
  42. QDManager.PushRoleAction(DouYouRoleLogReportType.ExitGame);
  43. }
  44. public void Pay(int buyID, int count, string orderID, long price)
  45. {
  46. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(buyID);
  47. if (shopCfg == null)
  48. {
  49. Log.Error($"recharge {buyID} config not found!");
  50. return;
  51. }
  52. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId);
  53. if (itemCfg == null)
  54. {
  55. Log.Error($"recharge {buyID} itemCfgId:{shopCfg.itemId} config not found!");
  56. return;
  57. }
  58. string currencyName = string.Empty;
  59. if (shopCfg.costType == CostType.FREE)
  60. {
  61. //免费
  62. currencyName = "免费";
  63. }
  64. else if(shopCfg.costType == CostType.ITEM)
  65. {
  66. //货币
  67. ItemCfg costItemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.costId);
  68. if (costItemCfg == null)
  69. {
  70. currencyName = $"货币_{shopCfg.costId}";
  71. }
  72. else
  73. {
  74. currencyName = costItemCfg.name;
  75. }
  76. }
  77. else if(shopCfg.costType == CostType.RMB)
  78. {
  79. //人民币
  80. currencyName = "人民币";
  81. }
  82. else
  83. {
  84. //指定渠道商品id
  85. currencyName = $"指定商品id_{shopCfg.costId}";
  86. }
  87. var zoneScene = GameGlobal.zoneScene;
  88. if (zoneScene == null) return;
  89. if (zoneScene.GetComponent<RoleInfosComponent>() == null ||
  90. zoneScene.GetComponent<RoleInfosComponent>().IsDisposed) return;
  91. var roleInfo = zoneScene.GetComponent<RoleInfosComponent>().GetCurrentRole();
  92. if (roleInfo == null) return;
  93. if (GameGlobal.myNumericComponent == null) return;
  94. int lvl = GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  95. int vipLvl = GameGlobal.myNumericComponent.GetAsInt(NumericType.VipLevel);
  96. if (zoneScene.GetComponent<ServerInfosComponent>() == null) return;
  97. if (zoneScene.GetComponent<ServerInfosComponent>().recentlyServerInfo == null) return;
  98. var serverInfosComponent = zoneScene.GetComponent<ServerInfosComponent>();
  99. //自定义参数
  100. string cpOrderId = orderID;
  101. string productPrice = price.ToString();
  102. string productId = shopCfg.id.ToString();
  103. string productName = shopCfg.productName;
  104. string productDesc = "";
  105. string productCount = count.ToString();
  106. string exchangeRate = 1.ToString();
  107. string serverId = (serverInfosComponent?.CurrentServerId ?? 0).ToString();
  108. string serverName = serverInfosComponent?.recentlyServerInfo?.ServerName ?? "";
  109. string roleId = roleInfo.Id.ToString();
  110. string roleName = roleInfo.Name;
  111. string roleLevel = lvl.ToString();
  112. string roleVip = vipLvl.ToString();
  113. string partyName = LeagueDataManager.Instance.LeagueData?.Name ?? "";
  114. string roleBalence = "0";
  115. string other = orderID + "|gfg|" + roleInfo.Id;
  116. QDDouYouManagerInitIos.Instance.ShowPay(cpOrderId, productPrice, productId, productName, productDesc,
  117. productCount, exchangeRate, currencyName, serverId, serverName, roleId, roleName, roleLevel, roleVip,
  118. partyName, roleBalence, other);
  119. }
  120. public void Exit()
  121. {
  122. QDManager.PushRoleAction(DouYouRoleLogReportType.ExitGame);
  123. QDDouYouManagerInitIos.Instance.Logout();
  124. }
  125. }
  126. /// <summary>
  127. /// SDK回调
  128. /// </summary>
  129. public class DouYouSDKListenerIos : IDouYouSDKListenerIos
  130. {
  131. /// <summary>
  132. /// SDK实例化成功
  133. /// </summary>
  134. /// <param name="message">SDK 实例化成功</param>
  135. public void InitSuccessAb(string message)
  136. {
  137. Debug.Log("Game.HotUpdate InitSuccessAb: " + message);
  138. }
  139. public void InitErrorAb(string message)
  140. {
  141. Debug.Log("Game.HotUpdate InitErrorAb: " + message);
  142. }
  143. /// <summary>
  144. /// 登录成功
  145. /// </summary>
  146. /// <param name="message">resUid + "|gfg|" + token</param>
  147. public void LoginSuccessAb(string message)
  148. {
  149. Debug.Log("Game.HotUpdate ios LoginSuccessAb: " + message);
  150. DouYouIosSdkLoginResModel douYouIosSdkLoginResModel = LitJson.JsonMapper.ToObject<DouYouIosSdkLoginResModel>(message);
  151. if (douYouIosSdkLoginResModel == null)
  152. {
  153. Log.Error($"注意,解析登录回调失败,回调的字符串为 {message} douYouIosSdkLoginResModel is null.");
  154. return;
  155. }
  156. QDDouYouManagerIos.Instance.isLogining = false;
  157. QDDouYouManagerIos.Instance.uid = douYouIosSdkLoginResModel.uid;
  158. QDDouYouManagerIos.Instance.token = douYouIosSdkLoginResModel.token;
  159. //登录成功的回调
  160. EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_LOGINED, douYouIosSdkLoginResModel.uid);
  161. }
  162. /// <summary>
  163. /// 登录失败
  164. /// </summary>
  165. /// <param name="message"></param>
  166. public void LoginErrorAb(string message)
  167. {
  168. Debug.Log("Game.HotUpdate LoginErrorAb: " + message);
  169. }
  170. /// <summary>
  171. /// 切换账号回调---先当成退出登录处理
  172. /// </summary>
  173. public void SwitchAccountsAb(string message)
  174. {
  175. Debug.Log("Game.HotUpdate SwitchAccountsAb: " + message);
  176. GameController.QuitToLoginView(true);
  177. EventAgent.DispatchEvent(ConstMessage.OUT_LOGIN);
  178. }
  179. /// <summary>
  180. /// 退出登录后
  181. /// </summary>
  182. /// <param name="message">退出登录成功!</param>
  183. public void LogoutSuccessAb(string message)
  184. {
  185. Debug.Log("Game.HotUpdate LogoutSuccessAb: " + message);
  186. GameController.QuitToLoginView(true);
  187. EventAgent.DispatchEvent(ConstMessage.OUT_LOGIN);
  188. }
  189. /// <summary>
  190. /// 退出登录失败
  191. /// </summary>
  192. /// <param name="message"></param>
  193. public void LogoutErrorAb(string message)
  194. {
  195. Debug.Log("Game.HotUpdate LogoutErrorAb: " + message);
  196. }
  197. /// <summary>
  198. /// 支付失败
  199. /// </summary>
  200. /// <param name="message">code + "|gfg|" + params.toString()</param>
  201. public void PayErrorAb(string message)
  202. {
  203. Debug.Log("Game.HotUpdate PayErrorAb: " + message);
  204. //改变临时订单状态为失败
  205. }
  206. /// <summary>
  207. /// 支付成功
  208. /// </summary>
  209. /// <param name="message">code + "|gfg|" + params.toString()</param>
  210. public void PaySuccessAb(string message)
  211. {
  212. Debug.Log("Game.HotUpdate PaySuccessAb" + message);
  213. //改变临时订单状态为支付成功
  214. QDManager.PushRoleAction(DouYouRoleLogReportType.Pay);
  215. }
  216. //角色升级上报成功回调
  217. public void RoleInfoReportSuccessAb(string message)
  218. {
  219. }
  220. //角色升级上报失败回调
  221. public void RoleInfoReportErrorAb(string message)
  222. {
  223. }
  224. }
  225. }