SecurityHelper.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using System;
  2. using ET;
  3. namespace GFGGame
  4. {
  5. public static class SecurityHelper
  6. {
  7. /// <summary>
  8. /// 未进入游戏前--请求获取验证码
  9. /// </summary>
  10. /// <param name="account"></param>
  11. /// <param name="reqType"></param>
  12. /// <returns></returns>
  13. public static async ETTask<S2C_GetMobileVerificationCode> GetMobileVerificationCode(string account,
  14. SendCodeType reqType)
  15. {
  16. S2C_GetMobileVerificationCode s2CGetMobileVerificationCode = null;
  17. Session session = null;
  18. try
  19. {
  20. session = GameGlobal.zoneScene.GetComponent<NetKcpComponent>()
  21. .Create(NetworkHelper.ToIPEndPoint(GameConfig.LoginAddress));
  22. s2CGetMobileVerificationCode = (S2C_GetMobileVerificationCode)await session.Call(
  23. new C2S_GetMobileVerificationCode()
  24. {
  25. PhoneNumber = account,
  26. ReqType = reqType,
  27. });
  28. }
  29. catch (Exception e)
  30. {
  31. session?.Dispose();
  32. Log.Debug(e.ToString());
  33. return s2CGetMobileVerificationCode;
  34. }
  35. return s2CGetMobileVerificationCode;
  36. }
  37. /// <summary>
  38. /// 账号找回
  39. /// </summary>
  40. /// <param name="code"></param>
  41. /// <param name="phoneNumber"></param>
  42. /// <returns></returns>
  43. public static async ETTask<A2C_GetAccountListByPhone> GetAccountListByPhone(string code,
  44. string phoneNumber)
  45. {
  46. A2C_GetAccountListByPhone res = null;
  47. Session session = null;
  48. try
  49. {
  50. session = GameGlobal.zoneScene.GetComponent<NetKcpComponent>()
  51. .Create(NetworkHelper.ToIPEndPoint(GameConfig.LoginAddress));
  52. res = (A2C_GetAccountListByPhone)await session.Call(
  53. new C2A_GetAccountListByPhone()
  54. {
  55. Code = code,
  56. ChannelId = LauncherConfig.ChannelId,
  57. PhoneNumber = phoneNumber
  58. });
  59. }
  60. catch (Exception e)
  61. {
  62. session?.Dispose();
  63. Log.Debug(e.ToString());
  64. return res;
  65. }
  66. return res;
  67. }
  68. /// <summary>
  69. /// 修改密码
  70. /// </summary>
  71. /// <param name="code"></param>
  72. /// <param name="phoneNumber"></param>
  73. /// <param name="account"></param>
  74. /// <param name="password"></param>
  75. /// <returns></returns>
  76. public static async ETTask<A2C_UpPassword> UpPassword(string code,
  77. string phoneNumber, string account, string password)
  78. {
  79. A2C_UpPassword res = null;
  80. Session session = null;
  81. password = MD5Helper.stringMD5(password);
  82. try
  83. {
  84. session = GameGlobal.zoneScene.GetComponent<NetKcpComponent>()
  85. .Create(NetworkHelper.ToIPEndPoint(GameConfig.LoginAddress));
  86. res = (A2C_UpPassword)await session.Call(
  87. new C2A_UpPassword()
  88. {
  89. Code = code,
  90. ChannelId = LauncherConfig.ChannelId,
  91. PhoneNumber = phoneNumber,
  92. Account = account,
  93. Password = password,
  94. });
  95. }
  96. catch (Exception e)
  97. {
  98. session?.Dispose();
  99. Log.Debug(e.ToString());
  100. return res;
  101. }
  102. return res;
  103. }
  104. /// <summary>
  105. /// 游戏内获取验证码
  106. /// </summary>
  107. /// <param name="phoneNumber"></param>
  108. /// <param name="reqType"></param>
  109. /// <returns></returns>
  110. public static async ETTask<S2C_GetMobileVerificationCodeUnit> GetMobileVerification(string phoneNumber,
  111. SendCodeType reqType)
  112. {
  113. S2C_GetMobileVerificationCodeUnit res = null;
  114. try
  115. {
  116. res = (S2C_GetMobileVerificationCodeUnit)await MessageHelper.SendToServer(
  117. new C2S_GetMobileVerificationCodeUnit() { PhoneNumber = phoneNumber, ReqType = reqType });
  118. }
  119. catch (Exception e)
  120. {
  121. Log.Debug(e.ToString());
  122. return res;
  123. }
  124. return res;
  125. }
  126. /// <summary>
  127. /// 游戏内绑定手机
  128. /// </summary>
  129. /// <param name="phoneNumber"></param>
  130. /// <param name="code"></param>
  131. /// <returns></returns>
  132. public static async ETTask<S2C_BindMobilePhoneNumber> BindMobilePhoneNumber(string phoneNumber, string code)
  133. {
  134. S2C_BindMobilePhoneNumber res = null;
  135. try
  136. {
  137. res = (S2C_BindMobilePhoneNumber)await MessageHelper.SendToServer(new C2S_BindMobilePhoneNumber()
  138. { PhoneNumber = phoneNumber, VerCode = code });
  139. }
  140. catch (Exception e)
  141. {
  142. Log.Debug(e.ToString());
  143. return res;
  144. }
  145. return res;
  146. }
  147. /// <summary>
  148. /// 游戏内解除手机号绑定
  149. /// </summary>
  150. /// <param name="phoneNumber"></param>
  151. /// <param name="code"></param>
  152. /// <returns></returns>
  153. public static async ETTask<S2C_UnbindMobilePhoneNumber> UnbindMobilePhoneNumber(string phoneNumber, string code)
  154. {
  155. S2C_UnbindMobilePhoneNumber res = null;
  156. try
  157. {
  158. res = (S2C_UnbindMobilePhoneNumber)await MessageHelper.SendToServer(new C2S_UnbindMobilePhoneNumber()
  159. { PhoneNumber = phoneNumber, VerCode = code });
  160. }
  161. catch (Exception e)
  162. {
  163. Log.Debug(e.ToString());
  164. return res;
  165. }
  166. return res;
  167. }
  168. }
  169. }