更新订单提交流程

This commit is contained in:
木鱼(iFish) 2015-06-05 18:35:25 +08:00
parent f1d21c3317
commit 11a9f06bfa
14 changed files with 126 additions and 73 deletions

15
12306.sln.vsext Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Solution>
<Profile Name="12306网页+扩展" SingleStartProjectGuid="">
<Include>
<Project Guid="6d4588aa-a0fd-4364-972c-22b0ab7938f9" />
<Project Guid="ab7ed70a-3bb7-485a-a93f-05e7a5892086" />
<Project Guid="3d34b2d8-36f9-4e16-bf0f-a8905f8fe8ba" />
<Project Guid="6d27c5ee-d44f-4783-b25e-6165f495349b" />
<Project Guid="d46393a2-aeab-4876-aebf-84b993e66227" />
<Project Guid="56406c67-2b6f-4152-9ec0-e6d80e86b96d" />
<Project Guid="c385d043-316a-4f05-a6b9-e70bf0ed8db6" />
<Project Guid="9d141603-1a9d-4eec-82d8-c473ea436839" />
</Include>
</Profile>
</Solution>

View File

@ -36,15 +36,6 @@ namespace TrainInfomationProviderService
RouteTable.Routes.MapRoute("traintransit", "tt/{action}/{id}", new { area = "", controller = "Transit", id = UrlParameter.Optional }, new { action = "(keepalive|ls|ss|tor|dt|ls2|ssa)" }, new[] { "TrainInfomationProviderService.Web" }); RouteTable.Routes.MapRoute("traintransit", "tt/{action}/{id}", new { area = "", controller = "Transit", id = UrlParameter.Optional }, new { action = "(keepalive|ls|ss|tor|dt|ls2|ssa)" }, new[] { "TrainInfomationProviderService.Web" });
Task.Run(() => Task.Run(() =>
{ {
try
{
Main(new string[0]);
}
catch (Exception ex)
{
File.WriteAllText(HostingEnvironment.MapPath("~/err.log"), ex.ToString());
}
var keepAliveUrl = ConfigurationManager.AppSettings["12306_keepaliveurl"]; var keepAliveUrl = ConfigurationManager.AppSettings["12306_keepaliveurl"];
if (!string.IsNullOrEmpty(keepAliveUrl)) if (!string.IsNullOrEmpty(keepAliveUrl))
{ {
@ -58,13 +49,23 @@ namespace TrainInfomationProviderService
{ {
} }
Trace.TraceInformation("KEEP ALIVE已激活。"); Trace.TraceInformation("KEEP ALIVE已激活。");
}, null, new TimeSpan(0, 0, 20, 0), new TimeSpan(0, 0, 20, 0)); }, null, new TimeSpan(0, 0, 10, 0), new TimeSpan(0, 0, 10, 0));
Trace.TraceInformation("KEEP ALIVE已启用"); Trace.TraceInformation("KEEP ALIVE已启用");
} }
else else
{ {
Trace.TraceInformation("KEEP ALIVE未启用"); Trace.TraceInformation("KEEP ALIVE未启用");
} }
try
{
Main(new string[0]);
}
catch (Exception ex)
{
File.WriteAllText(HostingEnvironment.MapPath("~/err.log"), ex.ToString());
}
}); });
} }

View File

@ -23,11 +23,8 @@ namespace TrainInfomationProviderService.TrainInfo.Entities
[JsonIgnore] [JsonIgnore]
public List<Train> Trains { get; set; } public List<Train> Trains { get; set; }
[JsonIgnore] //[JsonIgnore]
public Dictionary<string, Train[]> TrainsCodeMap { get; private set; } //public Dictionary<string, Train[]> TrainsIdMap { get; private set; }
[JsonIgnore]
public Dictionary<string, Train[]> TrainsIdMap { get; private set; }
/// <summary> /// <summary>
/// 车站-发车车次信息 /// 车站-发车车次信息
@ -66,24 +63,15 @@ namespace TrainInfomationProviderService.TrainInfo.Entities
var store = TrainInfoManager.Instance.DataStore.TrainData; var store = TrainInfoManager.Instance.DataStore.TrainData;
Trains = HashStore.Select(s => store.GetValue(s)).ExceptNull().ToList(); Trains = HashStore.Select(s => store.GetValue(s)).ExceptNull().ToList();
TrainsCodeMap = Trains.GroupBy(s => s.Code).ToDictionary(s => s.Key, s => //TrainsIdMap = Trains.GroupBy(s => s.Id).ToDictionary(s => s.Key, s =>
{
var arr = s.ToArray();
//if (arr.Length > 1)
//{ //{
// Trace.TraceWarning("[TRAIN_INFO_STORAGE] 警告:车次编号 {0} 出现重复数据,请查证,重复次数:{1}", s.Key, arr.Length - 1); // var arr = s.ToArray();
//} // //if (arr.Length > 1)
return arr.ToArray(); // //{
}, StringComparer.OrdinalIgnoreCase); // // Trace.TraceWarning("[TRAIN_INFO_STORAGE] 警告车次ID {0} 出现重复数据,请查证,重复次数:{1}", s.Key, arr.Length - 1);
TrainsIdMap = Trains.GroupBy(s => s.Id).ToDictionary(s => s.Key, s => // //}
{ // return arr;
var arr = s.ToArray(); //}, StringComparer.OrdinalIgnoreCase);
//if (arr.Length > 1)
//{
// Trace.TraceWarning("[TRAIN_INFO_STORAGE] 警告车次ID {0} 出现重复数据,请查证,重复次数:{1}", s.Key, arr.Length - 1);
//}
return arr;
}, StringComparer.OrdinalIgnoreCase);
} }
/// <summary> /// <summary>

View File

@ -284,7 +284,7 @@ namespace TrainInfomationProviderService.TrainInfo.Entities
/// </summary> /// </summary>
void RemoveSmallStation() void RemoveSmallStation()
{ {
var groups = this.GroupBy(s => s.First.Train.Code).Select(s => new { s.Key, Array = s.ToArray() }).ToArray(); var groups = this.GroupBy(s => s.First.Train.Id).Select(s => new { s.Key, Array = s.ToArray() }).ToArray();
foreach (var g in groups) foreach (var g in groups)
{ {
if (g.Array.Length < 2) if (g.Array.Length < 2)
@ -305,7 +305,7 @@ namespace TrainInfomationProviderService.TrainInfo.Entities
} }
} }
groups = this.GroupBy(s => s.Second.Train.Code).Select(s => new { s.Key, Array = s.ToArray() }).ToArray(); groups = this.GroupBy(s => s.Second.Train.Id).Select(s => new { s.Key, Array = s.ToArray() }).ToArray();
foreach (var g in groups) foreach (var g in groups)
{ {
if (g.Array.Length < 2) if (g.Array.Length < 2)

View File

@ -186,10 +186,16 @@ namespace TrainInfomationProviderService.TrainInfo
{ {
Trace.TraceInformation("[TAININFOMANGER] 正在刷新车次信息"); Trace.TraceInformation("[TAININFOMANGER] 正在刷新车次信息");
var loader = new WebDataProvider(); var loader = new WebDataProvider();
var save = new Action(() =>
{
File.WriteAllText(_dataFilePath, JsonConvert.SerializeObject(IndexStorage));
File.WriteAllText(_masterDataStoreFilePath, JsonConvert.SerializeObject(DataStore));
Trace.TraceInformation("[TAININFOMANGER] 车站信息缓存完成。目标文件 {0}", _dataFilePath);
});
try try
{ {
IndexStorage.Version = version; IndexStorage.Version = version;
loader.LoadTrainInfo(IndexStorage); loader.LoadTrainInfo(IndexStorage, save);
IndexStorage.RemoveOutdateStorage(); IndexStorage.RemoveOutdateStorage();
} }
catch (Exception ex) catch (Exception ex)
@ -201,9 +207,7 @@ namespace TrainInfomationProviderService.TrainInfo
Trace.TraceInformation("[TAININFOMANGER] 车次信息分析完成,车站。正在缓存车站信息"); Trace.TraceInformation("[TAININFOMANGER] 车次信息分析完成,车站。正在缓存车站信息");
//save //save
File.WriteAllText(_dataFilePath, JsonConvert.SerializeObject(IndexStorage)); save();
File.WriteAllText(_masterDataStoreFilePath, JsonConvert.SerializeObject(DataStore));
Trace.TraceInformation("[TAININFOMANGER] 车站信息缓存完成。目标文件 {0}", _dataFilePath);
} }
void CheckTrainVersion() void CheckTrainVersion()

View File

@ -98,7 +98,7 @@ namespace TrainInfomationProviderService.TrainInfo
} }
public void LoadTrainInfo(IndexStorage indexStorage) public void LoadTrainInfo(IndexStorage indexStorage, Action saveCallback)
{ {
Trace.TraceInformation("[TRAIN_DATA_WEB_PROVIDER] 正在获得最新车次信息"); Trace.TraceInformation("[TRAIN_DATA_WEB_PROVIDER] 正在获得最新车次信息");
var html = new HttpClient().Create(HttpMethod.Get, "https://kyfw.12306.cn/otn/resources/js/query/train_list.js?scriptVersion=" + (new Random().NextDouble() + 1).ToString("#0.00000"), null, null, "").Send(); var html = new HttpClient().Create(HttpMethod.Get, "https://kyfw.12306.cn/otn/resources/js/query/train_list.js?scriptVersion=" + (new Random().NextDouble() + 1).ToString("#0.00000"), null, null, "").Send();
@ -134,19 +134,19 @@ namespace TrainInfomationProviderService.TrainInfo
indexStorage.TrainInfoStorages.Add(date, curStorage); indexStorage.TrainInfoStorages.Add(date, curStorage);
} }
//fix duplicate key //fix duplicate key
var dd = curStorage.Trains.GroupBy(s => s.Key).Select(s => new {s.Key, list = s.ToArray()}).Where(s => s.list.Length > 1).ToArray(); //var dd = curStorage.Trains.GroupBy(s => s.Key).Select(s => new {s.Key, list = s.ToArray()}).Where(s => s.list.Length > 1).ToArray();
if (dd.Length > 0) //if (dd.Length > 0)
{ //{
foreach (var x1 in dd) // foreach (var x1 in dd)
{ // {
var dfrist = x1.list[0]; // var dfrist = x1.list[0];
foreach (var dt in x1.list.Skip(1).ToArray()) // foreach (var dt in x1.list.Skip(1).ToArray())
{ // {
dfrist.Code = dt.Code; // dfrist.Code = dt.Code;
curStorage.Trains.Remove(dt); // curStorage.Trains.Remove(dt);
} // }
} // }
} //}
var allkeys = curStorage.Trains.ToDictionary(s => s.Key, StringComparer.OrdinalIgnoreCase); var allkeys = curStorage.Trains.ToDictionary(s => s.Key, StringComparer.OrdinalIgnoreCase);
//所有的车次 //所有的车次
var alltrains = dateSt.Values.SelectMany(s => s).Select(s => var alltrains = dateSt.Values.SelectMany(s => s).Select(s =>
@ -182,6 +182,8 @@ namespace TrainInfomationProviderService.TrainInfo
TrainInfoManager.Instance.DataStore.TrainData.AddOrUpdate(train.TrainHash, train); TrainInfoManager.Instance.DataStore.TrainData.AddOrUpdate(train.TrainHash, train);
} }
indexStorage.DateIndices.SafeAdd(date);
indexStorage.TrainInfoStorages.AddOrUpdate(date, curStorage);
if (index > 0) if (index > 0)
{ {
curStorage.Init(); curStorage.Init();
@ -192,15 +194,15 @@ namespace TrainInfomationProviderService.TrainInfo
var filepath = PathUtility.Combine(_dataFolder, date + ".json"); var filepath = PathUtility.Combine(_dataFolder, date + ".json");
File.WriteAllText(filepath, JsonConvert.SerializeObject(curStorage)); File.WriteAllText(filepath, JsonConvert.SerializeObject(curStorage));
Trace.TraceInformation("[TRAIN_DATA_WEB_PROVIDER] 车次数据缓存成功!"); Trace.TraceInformation("[TRAIN_DATA_WEB_PROVIDER] 车次数据缓存成功!");
if (saveCallback != null)
saveCallback();
} }
else else
{ {
Trace.TraceInformation("[TRAIN_DATA_WEB_PROVIDER] 车次 {0} 数据无变化", date); Trace.TraceInformation("[TRAIN_DATA_WEB_PROVIDER] 车次 {0} 数据无变化", date);
} }
indexStorage.DateIndices.SafeAdd(date);
indexStorage.TrainInfoStorages.AddOrUpdate(date, curStorage);
GC.Collect(); GC.Collect();
} }

View File

@ -5,7 +5,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C385D043-316A-4F05-A6B9-E70BF0ED8DB6}</ProjectGuid> <ProjectGuid>{C385D043-316A-4F05-A6B9-E70BF0ED8DB6}</ProjectGuid>
<OutputType>Exe</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TrainInfomationProviderService</RootNamespace> <RootNamespace>TrainInfomationProviderService</RootNamespace>
<AssemblyName>TrainInfomationProviderService</AssemblyName> <AssemblyName>TrainInfomationProviderService</AssemblyName>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
有关如何配置 ASP.NET 应用程序的详细信息,请访问 有关如何配置 ASP.NET 应用程序的详细信息,请访问
http://go.microsoft.com/fwlink/?LinkId=301880 http://go.microsoft.com/fwlink/?LinkId=301880
@ -34,7 +35,8 @@
<add key="12306_trainsuggestion_maxradio" value="0.7" /> <add key="12306_trainsuggestion_maxradio" value="0.7" />
<add key="dataStoragePath" value="~/App_Data/12306" /> <add key="dataStoragePath" value="~/App_Data/12306" />
<add key="12306_keepaliveurl" value="http://test.fishlee.net/tt/keepalive" /> <add key="12306_keepaliveurl" value="http://test.fishlee.net/tt/keepalive" />
<add key="local_disable_train_provider" value="1" /> <add key="local_disable_train_provider" value="0" />
<add key="FSLib.MvcWeb.CsrfDefender.Disabled" value="1" />
</appSettings> </appSettings>
<connectionStrings> <connectionStrings>
<add name="chatroom" connectionString="Server=114.112.68.93;port=11119;Database=gopush;Uid=gopush;Pwd=c8488f421866b23758d52045429437c45;CharSet=utf8;" providerName="MySql.Data.MySqlClient" /> <add name="chatroom" connectionString="Server=114.112.68.93;port=11119;Database=gopush;Uid=gopush;Pwd=c8488f421866b23758d52045429437c45;CharSet=utf8;" providerName="MySql.Data.MySqlClient" />

View File

@ -25,6 +25,7 @@
<RestorePackages>true</RestorePackages> <RestorePackages>true</RestorePackages>
<TypeScriptToolsVersion>1.0</TypeScriptToolsVersion> <TypeScriptToolsVersion>1.0</TypeScriptToolsVersion>
<NuGetPackageImportStamp>16ae31ba</NuGetPackageImportStamp> <NuGetPackageImportStamp>16ae31ba</NuGetPackageImportStamp>
<UseGlobalApplicationHostFile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
@ -324,6 +325,7 @@
<ItemGroup> <ItemGroup>
<Folder Include="App_Data\" /> <Folder Include="App_Data\" />
<Folder Include="js\order\" /> <Folder Include="js\order\" />
<Folder Include="Views\Php\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<TypeScriptCompile Include="Scripts\typings\chrome.d.ts" /> <TypeScriptCompile Include="Scripts\typings\chrome.d.ts" />

View File

@ -15,8 +15,11 @@
}; };
exports.stationReportApi = "http://srv.12306.liebao.cn/tt/ls2"; exports.stationReportApi = "http://srv.12306.liebao.cn/tt/ls2";
exports.trainSuggestApi = "http://srv.12306.liebao.cn/ts"; exports.trainSuggestApi = "http://srv.12306.liebao.cn/ts";
//exports.trainSuggestApi = "http://test.fishlee.net/ts.axd";
exports.onceTransitApi = "http://srv.12306.liebao.cn/tt/tor"; exports.onceTransitApi = "http://srv.12306.liebao.cn/tt/tor";
if (local) {
exports.trainSuggestApi = "/ts.axd";
exports.onceTransitApi = "/tt/tor";
}
exports.chatServerGetAddressApi = "http://12306.liebao.cn/index.php?r=Api/GetRoomKey"; exports.chatServerGetAddressApi = "http://12306.liebao.cn/index.php?r=Api/GetRoomKey";
exports.sysNoticeUrl = "http://12306.liebao.cn/index.php?r=Api/GetNotificationList"; exports.sysNoticeUrl = "http://12306.liebao.cn/index.php?r=Api/GetNotificationList";
exports.sysNoticeLoadInterval = 30 * 60 * 1800; exports.sysNoticeLoadInterval = 30 * 60 * 1800;
@ -323,6 +326,11 @@
exports.chatSendMsgDelay = 5000; exports.chatSendMsgDelay = 5000;
exports.maxRecentCity = 18; exports.maxRecentCity = 18;
exports.suggestRefreshInterval = 60000; exports.suggestRefreshInterval = 60000;
Object.defineProperty(exports, "fastSubmitOrderSkipVc", {
get: function() {
return true;
}
});
Object.defineProperty(exports, "moreOptDefault", { Object.defineProperty(exports, "moreOptDefault", {
get: function () { get: function () {

View File

@ -129,7 +129,7 @@
key_check_isChange: arr[1], key_check_isChange: arr[1],
leftTicketStr: arr[2], leftTicketStr: arr[2],
train_location: arr[0], train_location: arr[0],
async: arr[3] async: arr[3] === '1'
}; };
checkQueueInfo(); checkQueueInfo();
} }
@ -215,11 +215,11 @@
}; };
var submitOrder = function () { var submitOrder = function () {
var url = "confirmPassenger/confirmSingleForQueueAsys"; var url = !submitData.async ? "confirmPassenger/confirmSingle" : "confirmPassenger/confirmSingleForQueueAsys";
var data = { var data = {
passengerTicketStr: pas1, passengerTicketStr: pas1,
oldPassengerStr: pas2, oldPassengerStr: pas2,
randCode: randcode, randCode: param.fastSubmitOrderSkipVc ? "" : randcode,
purpose_codes: profile.studentTicket ? "0X00" : "ADULT", purpose_codes: profile.studentTicket ? "0X00" : "ADULT",
key_check_isChange: submitData["key_check_isChange"], key_check_isChange: submitData["key_check_isChange"],
leftTicketStr: submitData["leftTicketStr"], leftTicketStr: submitData["leftTicketStr"],
@ -250,7 +250,9 @@
} else } else
def.reject({ msg: errMsg }); def.reject({ msg: errMsg });
} else { } else {
if (submitData.async)
waitQueueToComplete(); waitQueueToComplete();
else loadOrderNoFromPayInit();
//report //report
port.track(param.trackTypes.QUEUE_ORDER_SUCCESS, [ port.track(param.trackTypes.QUEUE_ORDER_SUCCESS, [
@ -268,6 +270,26 @@
def.reject({ msg: "12306不给力啊唉。出现网络错误了请重试.." }); def.reject({ msg: "12306不给力啊唉。出现网络错误了请重试.." });
}); });
}; };
var loadOrderNoCount = 0;
var loadOrderNoFromPayInit = function () {
ajax.sendPost("queryOrder/queryMyOrderNoComplete", "queryOrder/initNoComplete", null, "json").done(function (text) {
if (!text.data) {
if (loadOrderNoCount++ < 3) {
setTimeout(loadOrderNoFromPayInit, 2000);
} else {
def.resolve({ orderId: "" });
}
return;
}
try {
def.resolve({ orderId: text.data.orderDBList[0].sequence_no });
} catch (e) {
def.resolve({ orderId: "" });
}
}).fail(function () {
def.resolve({ orderId: "" });
});
};
var waitQueueToComplete = function () { var waitQueueToComplete = function () {
def.notify({ msg: "正在等待订单处理..." }); def.notify({ msg: "正在等待订单处理..." });
@ -310,7 +332,11 @@
sendRequest(); sendRequest();
}; };
if (param.fastSubmitOrderSkipVc) {
submitOrder();
} else {
checkVc(); checkVc();
}
return def.promise(); return def.promise();
}; };

View File

@ -65,12 +65,17 @@
submitProgress.hide(); submitProgress.hide();
$("#ticket-submit-info .ticket-submit-vc").attr("data-target", profile.resign ? "order" : "fastSubmit"); $("#ticket-submit-info .ticket-submit-vc").attr("data-target", profile.resign ? "order" : "fastSubmit");
if (param.fastSubmitOrderSkipVc) {
that.submitOrder();
} else {
if (!vc_inited) { if (!vc_inited) {
vc_inited = true; vc_inited = true;
vc.load($("#ticket-submit-info .ticket-submit-vc")); vc.load($("#ticket-submit-info .ticket-submit-vc"));
} else { } else {
$("#ticket-submit-info .ticket-submit-vc a").click(); $("#ticket-submit-info .ticket-submit-vc a").click();
} }
}
}; };
this.hide = function () { this.hide = function () {
if ($("#ticket-submit-container:visible").length) { if ($("#ticket-submit-container:visible").length) {
@ -81,7 +86,7 @@
media.stop(); media.stop();
var randCode = $("#ticket-submit-info .ticket-submit-vc input:hidden").val(); var randCode = $("#ticket-submit-info .ticket-submit-vc input:hidden").val();
if (!randCode.length) { if (!param.fastSubmitOrderSkipVc && !randCode.length) {
mp.showMessagePopup("error", "请完成验证..."); mp.showMessagePopup("error", "请完成验证...");
return; return;
} }

File diff suppressed because one or more lines are too long