QDDouYouManagerIos.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId);
  57. if (itemCfg == null)
  58. {
  59. Log.Error($"recharge {buyID} itemCfgId:{shopCfg.itemId} config not found!");
  60. return;
  61. }
  62. string currencyName = string.Empty;
  63. if (shopCfg.costType == CostType.FREE)
  64. {
  65. //免费
  66. currencyName = "免费";
  67. }
  68. else if (shopCfg.costType == CostType.ITEM)
  69. {
  70. //货币
  71. ItemCfg costItemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.costId);
  72. if (costItemCfg == null)
  73. {
  74. currencyName = $"货币{shopCfg.costId}";
  75. }
  76. else
  77. {
  78. currencyName = costItemCfg.name;
  79. }
  80. }
  81. else if (shopCfg.costType == CostType.RMB)
  82. {
  83. //人民币
  84. currencyName = "人民币";
  85. }
  86. else
  87. {
  88. //指定渠道商品id
  89. currencyName = $"指定商品id{shopCfg.costId}";
  90. }
  91. var zoneScene = GameGlobal.zoneScene;
  92. if (zoneScene == null) return;
  93. if (zoneScene.GetComponent<RoleInfosComponent>() == null ||
  94. zoneScene.GetComponent<RoleInfosComponent>().IsDisposed) return;
  95. var roleInfo = zoneScene.GetComponent<RoleInfosComponent>().GetCurrentRole();
  96. if (roleInfo == null) return;
  97. if (GameGlobal.myNumericComponent == null) return;
  98. int lvl = GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  99. int vipLvl = GameGlobal.myNumericComponent.GetAsInt(NumericType.VipLevel);
  100. if (zoneScene.GetComponent<ServerInfosComponent>() == null) return;
  101. if (zoneScene.GetComponent<ServerInfosComponent>().recentlyServerInfo == null) return;
  102. var serverInfosComponent = zoneScene.GetComponent<ServerInfosComponent>();
  103. //自定义参数
  104. string cpOrderId = orderID;
  105. string productPrice = price.ToString();
  106. string productId = IAPManager.Instance.GetIosProductId(shopCfg.id);
  107. string productName = shopCfg?.itemName ?? "";
  108. string productDesc = shopCfg?.itemName ?? "";
  109. string productCount = count.ToString();
  110. string exchangeRate = 1.ToString();
  111. string serverId = (serverInfosComponent?.CurrentServerId ?? 0).ToString();
  112. string serverName = serverInfosComponent?.recentlyServerInfo?.ServerName ?? "";
  113. string roleId = roleInfo.Id.ToString();
  114. string roleName = roleInfo.Name;
  115. string roleLevel = lvl.ToString();
  116. string roleVip = vipLvl.ToString();
  117. string partyName = LeagueDataManager.Instance.LeagueData?.Name ?? "";
  118. string roleBalence = "0";
  119. string other = orderID + "|gfg|" + roleInfo.Id;
  120. Debug.Log(
  121. $"Ios ShowPay: cpOrderId:{cpOrderId} productPrice:{productPrice} productId:{productId} productName:{productName} productDesc:{productDesc} " +
  122. $"productCount:{productCount} exchangeRate:{exchangeRate} serverId:{serverId} serverName:{serverName} roleId:{roleId} roleName:{roleName} " +
  123. $"roleLevel:{roleLevel} roleVip:{roleVip} partyName:{partyName} roleBalence:{roleBalence} other:{other} currencyName:{currencyName}");
  124. QDDouYouManagerInitIos.Instance.ShowPay(cpOrderId, productPrice, productId, productName, productDesc,
  125. productCount, exchangeRate, currencyName, serverId, serverName, roleId, roleName, roleLevel, roleVip,
  126. partyName, roleBalence, other);
  127. }
  128. public void Exit()
  129. {
  130. QDManager.PushRoleAction(DouYouRoleLogReportType.ExitGame);
  131. QDDouYouManagerInitIos.Instance.Logout();
  132. }
  133. }
  134. /// <summary>
  135. /// SDK回调
  136. /// </summary>
  137. public class DouYouSDKListenerIos : IDouYouSDKListenerIos
  138. {
  139. /// <summary>
  140. /// SDK实例化成功
  141. /// </summary>
  142. /// <param name="message">SDK 实例化成功</param>
  143. public void InitSuccessAb(string message)
  144. {
  145. Debug.Log("Game.HotUpdate InitSuccessAb: " + message);
  146. }
  147. public void InitErrorAb(string message)
  148. {
  149. Debug.Log("Game.HotUpdate InitErrorAb: " + message);
  150. }
  151. /// <summary>
  152. /// 登录成功
  153. /// </summary>
  154. /// <param name="message">resUid + "|gfg|" + token</param>
  155. public void LoginSuccessAb(string message)
  156. {
  157. Debug.Log("Game.HotUpdate ios LoginSuccessAb: " + message);
  158. DouYouIosSdkLoginResModel douYouIosSdkLoginResModel =
  159. LitJson.JsonMapper.ToObject<DouYouIosSdkLoginResModel>(message);
  160. if (douYouIosSdkLoginResModel == null)
  161. {
  162. Log.Error($"注意,解析登录回调失败,回调的字符串为 {message} douYouIosSdkLoginResModel is null.");
  163. return;
  164. }
  165. QDDouYouManagerIos.Instance.isLogining = false;
  166. QDDouYouManagerIos.Instance.uid = douYouIosSdkLoginResModel.uid;
  167. QDDouYouManagerIos.Instance.token = douYouIosSdkLoginResModel.token;
  168. //登录成功的回调
  169. EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_LOGINED, douYouIosSdkLoginResModel.uid);
  170. }
  171. /// <summary>
  172. /// 登录失败
  173. /// </summary>
  174. /// <param name="message"></param>
  175. public void LoginErrorAb(string message)
  176. {
  177. Debug.Log("Game.HotUpdate LoginErrorAb: " + message);
  178. }
  179. /// <summary>
  180. /// 切换账号回调---先当成退出登录处理
  181. /// </summary>
  182. public void SwitchAccountsAb(string message)
  183. {
  184. Debug.Log("Game.HotUpdate SwitchAccountsAb: " + message);
  185. GameController.QuitToLoginView(false);
  186. EventAgent.DispatchEvent(ConstMessage.OUT_LOGIN);
  187. }
  188. /// <summary>
  189. /// 退出登录后
  190. /// </summary>
  191. /// <param name="message">退出登录成功!</param>
  192. public void LogoutSuccessAb(string message)
  193. {
  194. Debug.Log("Game.HotUpdate LogoutSuccessAb: " + message);
  195. GameController.QuitToLoginView(false);
  196. EventAgent.DispatchEvent(ConstMessage.OUT_LOGIN);
  197. }
  198. /// <summary>
  199. /// 退出登录失败
  200. /// </summary>
  201. /// <param name="message"></param>
  202. public void LogoutErrorAb(string message)
  203. {
  204. Debug.Log("Game.HotUpdate LogoutErrorAb: " + message);
  205. }
  206. /// <summary>
  207. /// 支付失败
  208. /// </summary>
  209. /// <param name="message">code + "|gfg|" + params.toString()</param>
  210. public void PayErrorAb(string message)
  211. {
  212. Debug.Log("Game.HotUpdate PayErrorAb: " + message);
  213. //改变临时订单状态为失败
  214. }
  215. /// <summary>
  216. /// 支付成功
  217. /// </summary>
  218. /// <param name="message">code + "|gfg|" + params.toString()</param>
  219. public void PaySuccessAb(string message)
  220. {
  221. Debug.Log("Game.HotUpdate PaySuccessAb" + message);
  222. //改变临时订单状态为支付成功
  223. QDManager.PushRoleAction(DouYouRoleLogReportType.Pay);
  224. }
  225. //角色升级上报成功回调
  226. public void RoleInfoReportSuccessAb(string message)
  227. {
  228. }
  229. //角色升级上报失败回调
  230. public void RoleInfoReportErrorAb(string message)
  231. {
  232. }
  233. }
  234. }