| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 | using UnityEngine;using System;using LitJson;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(ViewName.MODAL_STATUS_VIEW, "连接中...");            ViewManager.Show<ModalStatusView>("连接中...");            Get(API_HI, (LoginResult result) => {                ViewManager.Hide<ModalStatusView>();                if(result.version == GameConst.SERVER_VERSION)                {                    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) => {                ResultHandler(data, callback);            });        }        private static void Post(string methodName, string jsonString, Action<LoginResult> callback)        {            HttpTool.Instance.Post(GameGlobal.loginApiUrl, methodName, jsonString, (string data) => {                ResultHandler(data, callback);            });        }        private static void ResultHandler(string data, Action<LoginResult> callback)        {            LoginResult resultObj = null;            if(data != null)            {                resultObj = JsonMapper.ToObject<LoginResult>(data);            }            if(resultObj != null && resultObj.code != 0 && resultObj.message != null && resultObj.message.Length > 0)            {                PromptController.Instance.ShowFloatTextPrompt(resultObj.message);            }            if (callback != null)            {                callback(resultObj);            }        }    }}
 |