diff --git a/.gitignore b/.gitignore index 44c9ddb..bc54c9b 100644 --- a/.gitignore +++ b/.gitignore @@ -79,4 +79,6 @@ deploy/ wwwroot/ *.sln.ide wwwroot/ -App_Data/ \ No newline at end of file +App_Data/ +*.Debug/ +*.Release/ \ No newline at end of file diff --git a/12306.sln b/12306.sln index 912771c..c2d778f 100644 --- a/12306.sln +++ b/12306.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 +# Visual Studio 14 +VisualStudioVersion = 14.0.22823.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web12306", "Web12306\Web12306.csproj", "{56406C67-2B6F-4152-9EC0-E6D80E86B96D}" EndProject @@ -44,6 +44,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FSLib.MvcWeb.Net4", "..\..\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FSLib.Web.NET4", "..\..\Private\iFish\FSLib.Web\FSLib.Web.NET4.csproj", "{6D27C5EE-D44F-4783-B25E-6165F495349B}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "聊天室", "聊天室", "{063A8FD8-F5AE-49BD-B68A-A395D64AF2F9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatRoomServer.Main", "ChatRoomServer.Main\ChatRoomServer.Main.csproj", "{928F1064-DAD6-4583-9A7E-C9510ADD94A1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -98,6 +102,10 @@ Global {6D27C5EE-D44F-4783-B25E-6165F495349B}.Debug|Any CPU.Build.0 = Debug|Any CPU {6D27C5EE-D44F-4783-B25E-6165F495349B}.Release|Any CPU.ActiveCfg = Release|Any CPU {6D27C5EE-D44F-4783-B25E-6165F495349B}.Release|Any CPU.Build.0 = Release|Any CPU + {928F1064-DAD6-4583-9A7E-C9510ADD94A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {928F1064-DAD6-4583-9A7E-C9510ADD94A1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {928F1064-DAD6-4583-9A7E-C9510ADD94A1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {928F1064-DAD6-4583-9A7E-C9510ADD94A1}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -115,5 +123,6 @@ Global {6D4588AA-A0FD-4364-972C-22B0AB7938F9} = {5EBCE730-C2C7-478B-BD0C-C4BE3BC69C06} {AB7ED70A-3BB7-485A-A93F-05E7A5892086} = {5EBCE730-C2C7-478B-BD0C-C4BE3BC69C06} {6D27C5EE-D44F-4783-B25E-6165F495349B} = {5EBCE730-C2C7-478B-BD0C-C4BE3BC69C06} + {928F1064-DAD6-4583-9A7E-C9510ADD94A1} = {063A8FD8-F5AE-49BD-B68A-A395D64AF2F9} EndGlobalSection EndGlobal diff --git a/ChatRoomServer.Main/App.config b/ChatRoomServer.Main/App.config new file mode 100644 index 0000000..ceb68c6 --- /dev/null +++ b/ChatRoomServer.Main/App.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/ChatRoomServer.Main/ChatRoomServer.Main.csproj b/ChatRoomServer.Main/ChatRoomServer.Main.csproj new file mode 100644 index 0000000..215e2cc --- /dev/null +++ b/ChatRoomServer.Main/ChatRoomServer.Main.csproj @@ -0,0 +1,108 @@ + + + + + Debug + AnyCPU + {928F1064-DAD6-4583-9A7E-C9510ADD94A1} + Exe + Properties + ChatRoomServer.Main + ChatRoomServer.Main + v4.5.2 + 512 + + + + true + full + false + ..\_.ChatRoomServer.Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\_.ChatRoomServer.Debug\ + TRACE + prompt + 4 + + + + + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + True + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + True + + + ..\..\..\Private\iFishWinForm\12306TOBA\TOBA\TOBA.Server.Release\FSLib.Logs.dll + + + ..\..\..\Private\iFishWinForm\12306TOBA\TOBA\TOBA.Server.Release\FSLib.Network.Log4Net.dll + + + ..\..\..\Private\iFishWinForm\12306TOBA\TOBA\TOBA.Server.Release\FSLib.Network.SuperSocket.dll + + + ..\..\..\Private\iFishWinForm\12306TOBA\TOBA\TOBA.Server.Release\FSLib_SuperSocketService.exe + + + + + + + + + + + + + + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + + + {6d4588aa-a0fd-4364-972c-22b0ab7938f9} + FSLib.Extension + + + {d46393a2-aeab-4876-aebf-84b993e66227} + FSLib_NET4 + + + + + \ No newline at end of file diff --git a/ChatRoomServer.Main/ChatServer.cs b/ChatRoomServer.Main/ChatServer.cs new file mode 100644 index 0000000..3fe97d6 --- /dev/null +++ b/ChatRoomServer.Main/ChatServer.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ChatRoomServer.Main +{ + using System.Collections.Concurrent; + using ChatRoomServer.Main.Room; + using FSLib.Logs.Log4Net; + using FSLib.Network.SuperSocket.Protocols.WebSocket; + using FSLib.Network.SuperSocket.SocketBase; + + class ChatServer : WebSocketServer + { + static ILog _log; + static readonly object _lockObject = new object(); + + static ChatServer() + { + FSLib.Logs.Log4NetBootStraper.Initialize("log4net.server.config", "Server"); + _log = GetLogger(typeof(ChatServer).Name); + } + + ConcurrentDictionary _containers; + ConcurrentDictionary _roomContainers; + + internal static ILog GetLogger(string name) + { + return LogManager.GetLogger("Server", name); + } + + /// + /// Called when [started]. + /// + protected override void OnStarted() + { + base.OnStarted(); + + NewDataReceived += ChatServer_NewDataReceived; + NewSessionConnected += ChatServer_NewSessionConnected; + NewMessageReceived += ChatServer_NewMessageReceived; + NewRequestReceived += ChatServer_NewRequestReceived; + SessionClosed += ChatServer_SessionClosed; + } + + private void ChatServer_SessionClosed(ChatSession session, CloseReason value) + { + RoomContainer roomContainer; + if (_containers.TryRemove(session, out roomContainer)) + { + roomContainer.Remove(session); + + if (roomContainer.SessionCount == 0) + { + _roomContainers.TryRemove(roomContainer.Id, out roomContainer); + } + } + } + + private void ChatServer_NewRequestReceived(ChatSession session, FSLib.Network.SuperSocket.Protocols.WebSocket.Protocol.IWebSocketFragment requestInfo) + { + } + + private void ChatServer_NewMessageReceived(ChatSession session, string value) + { + } + + private void ChatServer_NewSessionConnected(ChatSession session) + { + var cmd = session.Command; + + if (cmd == "room") + { + var roomid = session.Id; + + //TODO check roomid + + var roomCtx = _roomContainers.GetOrAdd(roomid, _ => new RoomContainer(_)); + _containers.AddOrUpdate(session, roomCtx); + roomCtx.Add(session); + + + } + else + { + session.Close(CloseReason.ProtocolError); + } + } + + private void ChatServer_NewDataReceived(ChatSession session, byte[] value) + { + + + } + } +} diff --git a/ChatRoomServer.Main/ChatSession.cs b/ChatRoomServer.Main/ChatSession.cs new file mode 100644 index 0000000..1ec0f59 --- /dev/null +++ b/ChatRoomServer.Main/ChatSession.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ChatRoomServer.Main +{ + using FSLib.Network.SuperSocket.Protocols.WebSocket; + + class ChatSession : WebSocketSession + { + /// + /// 命令 + /// + public string Command { get; private set; } + + /// + /// ID + /// + public string Id { get; private set; } + + /// + /// Called when [init]. + /// + protected override void OnInit() + { + base.OnInit(); + + var path = Path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); + if (path.Length >= 2) + { + Command = path[0]; + Id = path[1]; + } + } + } +} diff --git a/ChatRoomServer.Main/Config/log4net.server.config b/ChatRoomServer.Main/Config/log4net.server.config new file mode 100644 index 0000000..567e12b --- /dev/null +++ b/ChatRoomServer.Main/Config/log4net.server.config @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ChatRoomServer.Main/Config/log4net.supersocket.config b/ChatRoomServer.Main/Config/log4net.supersocket.config new file mode 100644 index 0000000..e62e2ad --- /dev/null +++ b/ChatRoomServer.Main/Config/log4net.supersocket.config @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ChatRoomServer.Main/Entities/EntityUtility.cs b/ChatRoomServer.Main/Entities/EntityUtility.cs new file mode 100644 index 0000000..999c651 --- /dev/null +++ b/ChatRoomServer.Main/Entities/EntityUtility.cs @@ -0,0 +1,162 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ChatRoomServer.Main.Entities +{ + using System.IO; + using System.Threading; + + class EntityUtility + { + static readonly string EncryptKey = "iFishMessagePack"; + static readonly byte[] EncryptKeyBuffer = Encoding.ASCII.GetBytes(EncryptKey); + static readonly int EncStart = 2; + static readonly Random Random = new Random(); + + public static MessageItem FromBuffer(byte[] buffer) + { + if (buffer.Length < 1 + EncryptKeyBuffer.Length || buffer[0] >= EncryptKeyBuffer.Length) + return null; + + //decrypt key + var key = EncryptKeyBuffer[buffer[0]]; + for (int i = EncStart; i < buffer.Length; i++) + { + var tkey = key; + key = buffer[i]; + buffer[i] ^= tkey; + } + + //read prefix + var index = 1; + if (Encoding.ASCII.GetString(buffer, index, EncryptKeyBuffer.Length) != EncryptKey) + return null; + index += EncryptKeyBuffer.Length; + + var item = new MessageItem(); + item.Action = ReadString(buffer, ref index); + item.Success = buffer[index++] == 1; + item.Time = System.FishDateTimeExtension.JsTicksStartBase.AddTicks(BitConverter.ToInt64(buffer, index) * 10000); + index += 8; + item.SystemMessage = buffer[index++] == 1; + item.SysMsgType = (SystemMessageType)BitConverter.ToInt32(buffer, index); + index += 4; + item.UserMsgType = (UserMessageType)BitConverter.ToInt32(buffer, index); + index += 4; + item.Content = ReadString(buffer, ref index); + item.Color = ReadString(buffer, ref index); + //images + var imgCount = BitConverter.ToInt32(buffer, index); + index += 4; + if (imgCount > 0) + { + item.Images = new string[imgCount]; + for (int i = 0; i < imgCount; i++) + { + item.Images[i] = ReadString(buffer, ref index); + } + } + //from + item.From = ReadString(buffer, ref index); + //to + var tousersCount = BitConverter.ToInt32(buffer, index); + index += 4; + if (tousersCount > 0) + { + item.ToUsers = new string[tousersCount]; + for (int i = 0; i < tousersCount; i++) + { + item.ToUsers[i] = ReadString(buffer, ref index); + } + } + + return item; + } + + static string ReadString(byte[] data, ref int index) + { + var unicode = data[index++] == 1; + var length = BitConverter.ToInt32(data, index); + index += 4; + + var result = (unicode ? Encoding.Unicode : Encoding.ASCII).GetString(data, index, length); + index += length; + + return result; + } + + public static byte[] ToBuffer(MessageItem item) + { + var length = (item.Content?.Length ?? 0) * 3 + 100; + var randomKeyIndex = Random.Next(EncryptKey.Length); + var randomKey = (byte)EncryptKey[randomKeyIndex]; + + using (var ms = new MemoryStream(length)) + { + //1. write encrypt key + ms.Write(new byte[] { (byte)randomKeyIndex }); + //1. write package header + ms.Write(EncryptKeyBuffer); + + //3. write action + Write(ms, item.Action, false); + //4. write success + ms.Write(new[] { (byte)(item.Success ? 1 : 0) }); + //5. write time + ms.Write(item.Time.ToJsTicks()); + //6. system message + ms.Write(new[] { (byte)(item.SystemMessage ? 1 : 0) }); + //7. + ms.Write((int)item.SysMsgType); + //8. + ms.Write((int)item.UserMsgType); + //9. content + Write(ms, item.Content, true); + //10. color + Write(ms, item.Color, false); + //11. images + ms.Write(item.Images?.Length ?? 0); + if (item.Images != null) + { + foreach (var image in item.Images) + { + Write(ms, image, false); + } + } + //12. from user + Write(ms, item.From, false); + //13. to user + ms.Write(item.ToUsers?.Length ?? 0); + if (item.ToUsers != null) + { + foreach (var user in item.ToUsers) + { + Write(ms, user, false); + } + } + + + var data = ms.ToArray(); + for (int i = EncStart; i < data.Length; i++) + { + randomKey = data[i] ^= randomKey; + } + + return data; + } + } + + static void Write(Stream stream, string text, bool unicode = true) + { + text = text ?? ""; + + var buffer = unicode ? Encoding.Unicode.GetBytes(text) : Encoding.ASCII.GetBytes(text); + stream.Write(new[] { (byte)(unicode ? 1 : 0) }); + stream.Write(buffer.Length); + stream.Write(buffer); + } + } +} diff --git a/ChatRoomServer.Main/Entities/MessageItem.cs b/ChatRoomServer.Main/Entities/MessageItem.cs new file mode 100644 index 0000000..6a45f10 --- /dev/null +++ b/ChatRoomServer.Main/Entities/MessageItem.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ChatRoomServer.Main.Entities +{ + using System.IO; + + class MessageItem + { + public string Action { get; set; } + + public bool Success { get; set; } + + public DateTime Time { get; set; } + + public bool SystemMessage { get; set; } + + public SystemMessageType SysMsgType { get; set; } + + public UserMessageType UserMsgType { get; set; } + + public string Content { get; set; } + + public string Color { get; set; } + + public string[] Images { get; set; } + + + public string From { get; set; } + + public string[] ToUsers { get; set; } + + public byte[] ToBuffer() => EntityUtility.ToBuffer(this); + + public static MessageItem Decode(byte[] buffer) => EntityUtility.FromBuffer(buffer); + } + + enum SystemMessageType + { + Unknown = 0, + UserEnter = 1, + UserExit = 2, + Disconnect = 3, + UpdateStat = 4, + SendFailed = 5 + } + + enum UserMessageType + { + Unknown = 0, + Send, + Receive + } +} diff --git a/ChatRoomServer.Main/FSLib_SuperSocketService.exe.config b/ChatRoomServer.Main/FSLib_SuperSocketService.exe.config new file mode 100644 index 0000000..ee887b5 --- /dev/null +++ b/ChatRoomServer.Main/FSLib_SuperSocketService.exe.config @@ -0,0 +1,59 @@ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ChatRoomServer.Main/Progam.cs b/ChatRoomServer.Main/Progam.cs new file mode 100644 index 0000000..c582640 --- /dev/null +++ b/ChatRoomServer.Main/Progam.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ChatRoomServer.Main +{ + using ChatRoomServer.Main.Entities; + + class Progam + { + public static void Main() + { + var data=new MessageItem() + { + Action="test", + Content="Content" + }; + var buffer = data.ToBuffer(); + + var itemback = MessageItem.Decode(buffer); + } + } +} diff --git a/ChatRoomServer.Main/Properties/AssemblyInfo.cs b/ChatRoomServer.Main/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..9f65d4d --- /dev/null +++ b/ChatRoomServer.Main/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("ChatRoomServer.Main")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ChatRoomServer.Main")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("928f1064-dad6-4583-9a7e-c9510add94a1")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ChatRoomServer.Main/Room/RoomContainer.cs b/ChatRoomServer.Main/Room/RoomContainer.cs new file mode 100644 index 0000000..3ee4ff0 --- /dev/null +++ b/ChatRoomServer.Main/Room/RoomContainer.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ChatRoomServer.Main.Room +{ + using System.Collections.Concurrent; + + class RoomContainer + { + ConcurrentDictionary _contexts = new ConcurrentDictionary(); + + /// + /// 获得或设置房间ID + /// + public string Id { get; private set; } + + public RoomContainer(string id) + { + Id = id; + } + + public void Add(ChatSession session) + { + _contexts.GetOrAdd(session, new RoomSessionContext()); + } + + public void Remove(ChatSession session) + { + RoomSessionContext context; + _contexts.TryRemove(session, out context); + } + + /// + /// 获得会话数 + /// + public int SessionCount => _contexts.Count; + } +} diff --git a/ChatRoomServer.Main/Room/RoomSessionContext.cs b/ChatRoomServer.Main/Room/RoomSessionContext.cs new file mode 100644 index 0000000..2208852 --- /dev/null +++ b/ChatRoomServer.Main/Room/RoomSessionContext.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ChatRoomServer.Main.Room +{ + class RoomSessionContext + { + } +} diff --git a/ChatRoomServer.Main/packages.config b/ChatRoomServer.Main/packages.config new file mode 100644 index 0000000..43a8883 --- /dev/null +++ b/ChatRoomServer.Main/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/RwTicketAssistantV2/app/12306/mobileproxy.js b/RwTicketAssistantV2/app/12306/mobileproxy.js index 6eeafca..c516786 100644 --- a/RwTicketAssistantV2/app/12306/mobileproxy.js +++ b/RwTicketAssistantV2/app/12306/mobileproxy.js @@ -166,6 +166,7 @@ $(function () { e.stopPropagation && e.stopPropagation(); }); + var notifyAjaxComplete = function (key) { var e = new CustomEvent("ajaxproxyfinished", { detail: key }); document.dispatchEvent(e); @@ -177,8 +178,8 @@ $(function () { var xhr = new XMLHttpRequest(); xhr.open("GET", ctx.url, true); xhr.onreadystatechange = function () { - if (xhr.readyState == 4) { - if (xhr.status != 200) { + if (xhr.readyState === 4) { + if (xhr.status !== 200) { document.dispatchEvent(new CustomEvent("ajaxproxyfinished", { detail: { url: null, diff --git a/Web12306/Web12306.csproj b/Web12306/Web12306.csproj index 6958fdb..2dea18f 100644 --- a/Web12306/Web12306.csproj +++ b/Web12306/Web12306.csproj @@ -258,6 +258,7 @@ + diff --git a/Web12306/js/data.js b/Web12306/js/data.js index 15f39f1..2d5aae9 100644 --- a/Web12306/js/data.js +++ b/Web12306/js/data.js @@ -328,7 +328,7 @@ exports.suggestRefreshInterval = 60000; Object.defineProperty(exports, "fastSubmitOrderSkipVc", { get: function() { - return true; + return false; } }); diff --git a/Web12306/js/otn/vc.js b/Web12306/js/otn/vc.js index 40769c6..5bedee2 100644 --- a/Web12306/js/otn/vc.js +++ b/Web12306/js/otn/vc.js @@ -13,7 +13,7 @@ myversion: "undefined"//, //randCode_validate: utility.getVcValidate(code) }, "json", function () { - if (!this.model.data || this.model.data.result != 1) + if (!this.model.data || this.model.data.result !== 1) def.reject("验证码错误"); else def.resolve(); }, function () { diff --git a/Web12306/js/platform/messageCoder.js b/Web12306/js/platform/messageCoder.js new file mode 100644 index 0000000..7028d10 --- /dev/null +++ b/Web12306/js/platform/messageCoder.js @@ -0,0 +1,16 @@ +define(function (require, exports, module) { + var keystr = "iFishMessagePack"; + + var decode = function(data) { + var dv = new Uint8Array(data); + var keyIndex = dv.getInt8(0); + var key = keystr.charCodeAt(keyIndex); + + for (var i = 0; i < dv.length; i++) { + var byte = dv.getInt8(); + + } + }; + + +}); diff --git a/Web12306/js/platform/webRequest.js b/Web12306/js/platform/webRequest.js index 42a6472..5a3eed8 100644 --- a/Web12306/js/platform/webRequest.js +++ b/Web12306/js/platform/webRequest.js @@ -2,6 +2,7 @@ define(function (require, exports, module) { var EventObject = require("../platform/EventObject.js"); var config = require("../data.js"); + var lastPromptPlatformError = null; var WebRequest = function () { var that = this; @@ -40,8 +41,21 @@ define(function (require, exports, module) { requestMap[e.detail.index] = { done: function () { var args = [].slice.call(arguments); - done && done.apply(this, args); - def.resolveWith(this, args); + + if (this.headers.indexOf("application/json") !== -1 && this.text.indexOf('"status":false,"httpstatus":200,"messages":["网络繁忙"]') !== -1) { + //被封 + if (!lastPromptPlatformError || (new Date().getTime() - lastPromptPlatformError) > 1000 * 60 * 5) { + lastPromptPlatformError = new Date().getTime(); + document.dispatchEvent(new CustomEvent("ipBlockError")); + } + + failed && failed.apply(this, args); + def.rejectWith(this, args); + } else { + done && done.apply(this, args); + def.resolveWith(this, args); + } + config.debug("done request for " + xhrData.url); }, fail: function () { @@ -89,7 +103,9 @@ define(function (require, exports, module) { /// 要请求的地址 /// 完成请求的回调 /// 请求失败的回调 - return that.send("GET", url, refer, data, responseType, done, failed, appendatt, headers); + var args = [].slice.call(arguments); + args.unshift("GET"); + return that.send.apply(this, args); }; this.sendPost = function (url, refer, data, responseType, done, failed, appendatt, headers) { var args = [].slice.call(arguments); diff --git a/Web12306/js/ui/index.js b/Web12306/js/ui/index.js index c8ff117..b5d978f 100644 --- a/Web12306/js/ui/index.js +++ b/Web12306/js/ui/index.js @@ -293,6 +293,9 @@ closeOnAction: false }); }); + document.addEventListener("ipBlockError", function() { + media.notify("IP被封警告", "检测到12306已封锁您的IP。如果频繁出现此问题请使用代理服务器或重启路由器 :-("); + }); })(); //聊天系统