QDDouYouManagerIos.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. public void Share()
  128. {
  129. QDManager.PushRoleAction(DouYouRoleLogReportType.ExitGame);
  130. QDDouYouManagerInitIos.Instance.JumpUrl();
  131. }
  132. }
  133. /// <summary>
  134. /// SDK回调
  135. /// </summary>
  136. public class DouYouSDKListenerIos : IDouYouSDKListenerIos
  137. {
  138. /// <summary>
  139. /// SDK实例化成功
  140. /// </summary>
  141. /// <param name="message">SDK 实例化成功</param>
  142. public void InitSuccessAb(string message)
  143. {
  144. Debug.Log("Game.HotUpdate InitSuccessAb: " + message);
  145. }
  146. public void InitErrorAb(string message)
  147. {
  148. Debug.Log("Game.HotUpdate InitErrorAb: " + message);
  149. }
  150. /// <summary>
  151. /// 登录成功
  152. /// </summary>
  153. /// <param name="message">resUid + "|gfg|" + token</param>
  154. public void LoginSuccessAb(string message)
  155. {
  156. Debug.Log("Game.HotUpdate ios LoginSuccessAb: " + message);
  157. DouYouIosSdkLoginResModel douYouIosSdkLoginResModel =
  158. LitJson.JsonMapper.ToObject<DouYouIosSdkLoginResModel>(message);
  159. if (douYouIosSdkLoginResModel == null)
  160. {
  161. Log.Error($"注意,解析登录回调失败,回调的字符串为 {message} douYouIosSdkLoginResModel is null.");
  162. return;
  163. }
  164. QDDouYouManagerIos.Instance.isLogining = false;
  165. QDDouYouManagerIos.Instance.uid = douYouIosSdkLoginResModel.uid;
  166. QDDouYouManagerIos.Instance.token = douYouIosSdkLoginResModel.token;
  167. //登录成功的回调
  168. EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_LOGINED, douYouIosSdkLoginResModel.uid);
  169. }
  170. /// <summary>
  171. /// 登录失败
  172. /// </summary>
  173. /// <param name="message"></param>
  174. public void LoginErrorAb(string message)
  175. {
  176. Debug.Log("Game.HotUpdate LoginErrorAb: " + message);
  177. }
  178. /// <summary>
  179. /// 切换账号回调---先当成退出登录处理
  180. /// </summary>
  181. public void SwitchAccountsAb(string message)
  182. {
  183. Debug.Log("Game.HotUpdate SwitchAccountsAb: " + message);
  184. GameController.QuitToLoginView(false);
  185. EventAgent.DispatchEvent(ConstMessage.OUT_LOGIN);
  186. }
  187. /// <summary>
  188. /// 退出登录后
  189. /// </summary>
  190. /// <param name="message">退出登录成功!</param>
  191. public void LogoutSuccessAb(string message)
  192. {
  193. Debug.Log("Game.HotUpdate LogoutSuccessAb: " + message);
  194. GameController.QuitToLoginView(false);
  195. EventAgent.DispatchEvent(ConstMessage.OUT_LOGIN);
  196. }
  197. /// <summary>
  198. /// 退出登录失败
  199. /// </summary>
  200. /// <param name="message"></param>
  201. public void LogoutErrorAb(string message)
  202. {
  203. Debug.Log("Game.HotUpdate LogoutErrorAb: " + message);
  204. }
  205. /// <summary>
  206. /// 支付失败
  207. /// </summary>
  208. /// <param name="message">code + "|gfg|" + params.toString()</param>
  209. public void PayErrorAb(string message)
  210. {
  211. Debug.Log("Game.HotUpdate PayErrorAb: " + message);
  212. //改变临时订单状态为失败
  213. }
  214. /// <summary>
  215. /// 支付成功
  216. /// </summary>
  217. /// <param name="message">code + "|gfg|" + params.toString()</param>
  218. public void PaySuccessAb(string message)
  219. {
  220. Debug.Log("Game.HotUpdate PaySuccessAb" + message);
  221. //改变临时订单状态为支付成功
  222. QDManager.PushRoleAction(DouYouRoleLogReportType.Pay);
  223. }
  224. //角色升级上报成功回调
  225. public void RoleInfoReportSuccessAb(string message)
  226. {
  227. }
  228. //角色升级上报失败回调
  229. public void RoleInfoReportErrorAb(string message)
  230. {
  231. }
  232. }
  233. }