123456789 |
- {
- "code": "var Event = Laya.Event;\r\nvar HttpRequest = Laya.HttpRequest;\r\nimport { Main } from \"../../Main\";\r\nimport { PlayerAccount } from \"./PlayerAccount\";\r\nimport WxApi from \"../../WXSDK/wxsdk\";\r\nconst PROTOCOL_URL = \"https://fallraceapi.94xj.net/\";\r\nexport class PROTOCOLS {\r\n}\r\nPROTOCOLS.Login = \"user/login\";\r\nPROTOCOLS.game = \"game/start\";\r\nPROTOCOLS.end = \"game/play\";\r\nPROTOCOLS.Sign = \"sign/sign\";\r\nPROTOCOLS.EquipHero = \"theme/equipHero\";\r\nPROTOCOLS.BuyHero = \"theme/buyHero\";\r\nPROTOCOLS.EquipHat = \"theme/equipHat\";\r\nPROTOCOLS.BuyHat = \"theme/buyHat\";\r\nPROTOCOLS.BuyDance = \"theme/buyDance\";\r\nPROTOCOLS.EquipDance = \"theme/equipDance\";\r\nPROTOCOLS.share = \"fission/share\";\r\nPROTOCOLS.vd = \"fission/vd\";\r\nPROTOCOLS.revival = \"game/revival\";\r\nPROTOCOLS.fissionhat = \"fission/hat\";\r\nPROTOCOLS.fissionhero = \"fission/hero\";\r\nPROTOCOLS.fissiondance = \"fission/dance\";\r\nPROTOCOLS.treasure = \"treasure/click\";\r\nPROTOCOLS.Config = \"config/table\";\r\n;\r\nexport class NetworkManager {\r\n static get Instance() {\r\n if (NetworkManager.instance) {\r\n return NetworkManager.instance;\r\n }\r\n else {\r\n return new NetworkManager();\r\n }\r\n }\r\n constructor() {\r\n NetworkManager.instance = this;\r\n }\r\n login(progresscb, completecb, errorcb) {\r\n var userInfor = PlayerAccount.CurrentAccount;\r\n var ver = Main.Ver;\r\n let args = `code=${userInfor.Code}&nickname=${userInfor.NickName}&avatar=${userInfor.Avatar}&gender=${userInfor.Gender}&country=${userInfor.Country}&province=${userInfor.Province}&city=${userInfor.City}& device=${userInfor.Device}$&share_id=${userInfor.ShareId}&scene=${userInfor.Scene}&v=${ver}`;\r\n let httpRequest = new HttpRequest();\r\n httpRequest.once(Event.PROGRESS, this, this.onHttpRequestProgress, [progresscb, httpRequest]);\r\n httpRequest.once(Event.COMPLETE, this, this.onLoginRequestComplete, [completecb, httpRequest]);\r\n httpRequest.once(Event.ERROR, this, this.onHttpRequestError, [errorcb, httpRequest]);\r\n httpRequest.send(PROTOCOL_URL + PROTOCOLS.Login, args, \"post\", \"text\");\r\n }\r\n onHttpRequestProgress(progresscb, httpRequest) {\r\n if (progresscb) {\r\n console.log(\"HttpRequestProgress:...\");\r\n progresscb.run();\r\n }\r\n }\r\n onLoginRequestComplete(completecb, httpRequest) {\r\n let data = JSON.parse(httpRequest.data);\r\n if (data[\"code\"] != \"0\") {\r\n console.log(\"登录异常错误!错误信息:\", httpRequest.data);\r\n return;\r\n }\r\n PlayerAccount.ServerTime = data[\"t\"];\r\n PlayerAccount.CurrentAccount.SetAccountData(data);\r\n completecb.runWith(data);\r\n }\r\n onHttpRequestError(errorcb, httpRequest) {\r\n if (errorcb != null) {\r\n errorcb.runWith(httpRequest);\r\n }\r\n console.log(\"Error! Http request error...\" + httpRequest.data);\r\n }\r\n HttpPostRequest(protocol, param, completecb, errorcb, hasToken = true) {\r\n let args = \"\";\r\n let url = PROTOCOL_URL + protocol;\r\n var account = PlayerAccount.CurrentAccount;\r\n var accountdata = account.CurAccountData;\r\n if (hasToken == true) {\r\n args = `token=${accountdata.m_token}&`;\r\n }\r\n WxApi.ShowLoading(\"连接网络中...\");\r\n if (protocol == PROTOCOLS.game || protocol == PROTOCOLS.end || protocol == PROTOCOLS.fissionhat || protocol == PROTOCOLS.fissionhero || protocol == PROTOCOLS.fissiondance || protocol == PROTOCOLS.vd) {\r\n let str = \"abcdefghijkimnopqrstuvwxyz0123456789\";\r\n let code = \"{\";\r\n let mask = \"\";\r\n for (let i = 0; i < 4; i++) {\r\n mask += str[Math.floor(Math.random() * 100) % str.length];\r\n }\r\n for (let i = 0; i < param.length; i++) {\r\n for (let key in param[i]) {\r\n code += `\\\"${key}\\\":\\\"${param[i][key]}\\\"`;\r\n }\r\n if (i < param.length - 1) {\r\n code += \",\";\r\n }\r\n else {\r\n code += \"}\";\r\n }\r\n }\r\n args += \"_r=\" + mask + this.base64Encode(code);\r\n }\r\n else {\r\n if (param != null) {\r\n for (let i = 0; i < param.length; i++) {\r\n for (let key in param[i]) {\r\n let val = param[i][key];\r\n args += `${key}=${val}`;\r\n if (i < param.length - 1) {\r\n args += \"&\";\r\n }\r\n }\r\n }\r\n }\r\n }\r\n let httpRequest = new HttpRequest();\r\n httpRequest.once(Event.COMPLETE, this, this.onHttpRequestComplete, [completecb, errorcb, httpRequest]);\r\n httpRequest.once(Event.ERROR, this, this.onHttpRequestError, [errorcb, httpRequest]);\r\n httpRequest.send(url, args, \"post\", \"text\");\r\n }\r\n onHttpRequestComplete(succeedcb, failurecb, httpRequest) {\r\n WxApi.HideLoading();\r\n let data = JSON.parse(httpRequest.data);\r\n if (data[\"code\"] == 0) {\r\n PlayerAccount.CurrentAccount.SetAccountData(data);\r\n if (succeedcb != null) {\r\n succeedcb.runWith(data);\r\n }\r\n }\r\n else {\r\n if (failurecb != null) {\r\n failurecb.runWith(data);\r\n }\r\n Laya.timer.once(5000, this, () => { WxApi.HideLoading(); });\r\n console.log(\"Error! Http request complete error, code: \" + data[\"code\"] + \" message: \" + data[\"message\"]);\r\n }\r\n }\r\n base64Encode(str) {\r\n var c1, c2, c3;\r\n var base64EncodeChars = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\r\n var i = 0, len = str.length, string = '';\r\n while (i < len) {\r\n c1 = str.charCodeAt(i++) & 0xff;\r\n if (i == len) {\r\n string += base64EncodeChars.charAt(c1 >> 2);\r\n string += base64EncodeChars.charAt((c1 & 0x3) << 4);\r\n string += \"==\";\r\n break;\r\n }\r\n c2 = str.charCodeAt(i++);\r\n if (i == len) {\r\n string += base64EncodeChars.charAt(c1 >> 2);\r\n string += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));\r\n string += base64EncodeChars.charAt((c2 & 0xF) << 2);\r\n string += \"=\";\r\n break;\r\n }\r\n c3 = str.charCodeAt(i++);\r\n string += base64EncodeChars.charAt(c1 >> 2);\r\n string += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));\r\n string += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));\r\n string += base64EncodeChars.charAt(c3 & 0x3F);\r\n }\r\n return string;\r\n }\r\n}\r\n",
- "references": [
- "C:/Users/admin/Desktop/runner/src/Main.ts",
- "C:/Users/admin/Desktop/runner/src/Scripts/Network/PlayerAccount.ts",
- "C:/Users/admin/Desktop/runner/src/WXSDK/wxsdk.ts"
- ]
- }
|