QDDouYouManagerIos.cs 9.1 KB

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