|
@@ -6,78 +6,7 @@ namespace GFGGame
|
|
|
{
|
|
|
public class LoginProxy
|
|
|
{
|
|
|
- private const string API_HI = "hi";
|
|
|
- private const string API_LOGIN = "login";
|
|
|
- private const string API_LOGIN_AS_VISITOR = "loginAsVisitor";
|
|
|
- private const string API_REGISTER = "register";
|
|
|
-
|
|
|
- public static void SayHi(Action<LoginResult> callback)
|
|
|
- {
|
|
|
- ViewManager.Show<ModalStatusView>("连接中...");
|
|
|
- Get(API_HI, (LoginResult result) => {
|
|
|
- ViewManager.Hide<ModalStatusView>();
|
|
|
- if(result.version == GameConst.SERVER_VERSION || Application.isEditor)
|
|
|
- {
|
|
|
- callback(result);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Alert.Show("版本已更新,请联系研发获取最新版本")
|
|
|
- .SetLeftButton(true, "知道了", (data) => {
|
|
|
- Application.Quit();
|
|
|
- }); ;
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- public static void Login(string account, string password)
|
|
|
- {
|
|
|
- ViewManager.Show<ModalStatusView>("登录中...");
|
|
|
- string data = JsonUtil.createJsonStr("account", account, "password", password);
|
|
|
- Post(API_LOGIN, data, (LoginResult result) => {
|
|
|
- ViewManager.Hide<ModalStatusView>();
|
|
|
- if(result == null || result.code == 0) {
|
|
|
- GameGlobal.isVisitor = false;
|
|
|
- GameController.OnLoginSuccess(result);
|
|
|
- } else {
|
|
|
- GameController.OnLoginFail(result);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- public static void LoginAsVisitor()
|
|
|
- {
|
|
|
- ViewManager.Show<ModalStatusView>("登录中...");
|
|
|
- long id = (long)PlayerPrefs.GetFloat(GameConst.VISITOR_ID_KEY, -1);
|
|
|
- string data = JsonUtil.createJsonStr("id", "" + id);
|
|
|
- Post(API_LOGIN_AS_VISITOR, data, (LoginResult result) => {
|
|
|
- ViewManager.Hide<ModalStatusView>();
|
|
|
- if(result == null || result.code == 0)
|
|
|
- {
|
|
|
- GameGlobal.isVisitor = true;
|
|
|
- GameController.OnLoginSuccess(result);
|
|
|
- } else {
|
|
|
- GameController.OnLoginFail(result);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- public static void Register(string account, string password, string name, string identityNum, string code)
|
|
|
- {
|
|
|
- ViewManager.Show<ModalStatusView>("注册中...");
|
|
|
- string data = JsonUtil.createJsonStr("account", account, "password", password, "name", name, "identityNum", identityNum, "code", code);
|
|
|
- Post(API_REGISTER, data, (LoginResult result) => {
|
|
|
- ViewManager.Hide<ModalStatusView>();
|
|
|
- if(result == null || result.code == 0)
|
|
|
- {
|
|
|
- GameGlobal.isVisitor = false;
|
|
|
- GameController.OnLoginSuccess(result);
|
|
|
- } else {
|
|
|
- GameController.OnLoginFail(result);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
private static void Get(string methodName, Action<LoginResult> callback)
|
|
|
{
|
|
|
HttpTool.Instance.Get(GameGlobal.loginApiUrl, methodName, (string data) => {
|