我正在制作一个网络应用程序,用于跟踪联邦快递的货件,我目前每天大约有10,000-15,000个包裹。 我在我的系统中集成了Fedex Api,但是只需要20分钟就可以获得仅1300个包的状态。有没有办法让这更快?我读到你可以在一个请求中发送30个包,但找不到让它运行的方法。
这是另一个问题的链接,我发现但是没有让它工作
Requesting many tracking numbers with Fedex SOAP API with PHP
CODE
{
TrackRequest request = new TrackRequest();
request.WebAuthenticationDetail = new WebAuthenticationDetail();
request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
request.WebAuthenticationDetail.UserCredential.Key = ""; // Replace "XXX" with the Key
request.WebAuthenticationDetail.UserCredential.Password = ""; // Replace "XXX" with the Password
request.WebAuthenticationDetail.ParentCredential = new WebAuthenticationCredential();
request.WebAuthenticationDetail.ParentCredential.Key = ""; // Replace "XXX" with the Key
request.WebAuthenticationDetail.ParentCredential.Password = ""; // Replace "XXX"
request.ClientDetail = new ClientDetail();
request.ClientDetail.AccountNumber = ""; // Replace "XXX" with the client's account number
request.ClientDetail.MeterNumber = ""; // Replace "XXX" with the client's meter number
request.TransactionDetail = new TransactionDetail();
request.TransactionDetail.CustomerTransactionId = "***Track Request using VC#***"; //This is a reference field for the customer. Any value can be used and will be provided in the response.
request.Version = new VersionId();
// Tracking information
request.SelectionDetails = new TrackSelectionDetail[1] { new TrackSelectionDetail() };
request.SelectionDetails[0].PackageIdentifier = new TrackPackageIdentifier();
request.SelectionDetails[0].PackageIdentifier.Value = TrackNumberGlobal; //"787883551221" Replace "XXX" with tracking number or door tag
request.SelectionDetails[0].PackageIdentifier.Type = TrackIdentifierType.TRACKING_NUMBER_OR_DOORTAG;
request.ProcessingOptions = new TrackRequestProcessingOptionType[1];
request.ProcessingOptions[0] = TrackRequestProcessingOptionType.INCLUDE_DETAILED_SCANS;
return request;
}
private void TrackReplyy(TrackReply reply)
{
foreach (CompletedTrackDetail completedTrackDetail in reply.CompletedTrackDetails)
{
foreach (TrackDetail trackDetail in completedTrackDetail.TrackDetails)
{
SqlCommand cos = new SqlCommand();
cos.CommandText = "Update estatus_fedex SET estadofedex = @estado WHERE fedextracking = @track";
cos.Parameters.AddWithValue("@estado", trackDetail.StatusDetail.Description);
cos.Parameters.AddWithValue("@track", TrackNumberGlobal);
cos.CommandType = CommandType.Text;
cos.Connection = sqlConn;
cos.ExecuteNonQuery();
if (trackDetail.Events != null)
{
foreach (TrackEvent trackevent in trackDetail.Events)
{
if(trackevent.StatusExceptionCode != null)
{
SqlCommand cmd2 = new SqlCommand();
cmd2.CommandText = "UPDATE estatus_fedex SET ExcpetionCode = @codigo WHERE fedextracking = @param2";
cmd2.Parameters.AddWithValue("@codigo", trackevent.StatusExceptionCode);
cmd2.Parameters.AddWithValue("@param2", TrackNumberGlobal);
cmd2.CommandType = CommandType.Text;
cmd2.Connection = sqlConn;
cmd2.ExecuteNonQuery();
if (trackevent.TimestampSpecified)
{
SqlCommand insert = new SqlCommand();
insert.CommandText = "INSERT INTO EstatusFedexHistorial(FedexTracking,EstadoFedex_Hist,ExceptionCode_Hist,Tiempo_Hist,EventDescription) VALUES (@Track,@Estado,@Excepcion,@Tiempo,@Evento)";
insert.Parameters.AddWithValue("@Track", TrackNumberGlobal);
insert.Parameters.AddWithValue("@Estado", trackDetail.StatusDetail.Description);
insert.Parameters.AddWithValue("@Excepcion", trackevent.StatusExceptionCode);
insert.Parameters.AddWithValue("@Tiempo", trackevent.Timestamp);
insert.Parameters.AddWithValue("@Evento", trackevent.EventDescription);
insert.CommandType = CommandType.Text;
insert.Connection = sqlConn;
insert.ExecuteNonQuery();
}
}
else
{
if (trackevent.TimestampSpecified)
{
SqlCommand sqlc = new SqlCommand();
sqlc.CommandText = "INSERT INTO EstatusFedexHistorial(FedexTracking,EstadoFedex_Hist,Tiempo_Hist,EventDescription) VALUES (@Track,@Estado,@Tiempo,@Evento)";
sqlc.Parameters.AddWithValue("@Track", TrackNumberGlobal);
sqlc.Parameters.AddWithValue("@Estado", trackDetail.StatusDetail.Description);
sqlc.Parameters.AddWithValue("@Tiempo", trackevent.Timestamp);
sqlc.Parameters.AddWithValue("@Evento", trackevent.EventDescription);
sqlc.CommandType = CommandType.Text;
sqlc.Connection = sqlConn;
sqlc.ExecuteNonQuery();
}
}
}
}
}
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "UPDATE EstatusFedexHistorial SET Manifiesto = @manifiesto WHERE FedexTracking = @track";
cmd.Parameters.AddWithValue("@manifiesto", manifiesto);
cmd.Parameters.AddWithValue("@track", TrackNumberGlobal);
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConn;
cmd.ExecuteNonQuery();
}
}
答案 0 :(得分:0)
您需要执行类似以下代码的操作,其中trackingNumbers是跟踪编号的数组。
request.SelectionDetails = new TrackSelectionDetail[trackingNumbers.Length];
for (int i = 0; i < trackingNumbers.Length; i++)
{
request.SelectionDetails[i] = new TrackSelectionDetail()
{
PackageIdentifier = new TrackPackageIdentifier
{
Value = trackingNumbers[i],
Type = TrackIdentifierType.TRACKING_NUMBER_OR_DOORTAG
}
};
}