You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
331 lines
19 KiB
C#
331 lines
19 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Web.Services.Protocols;
|
|
using System.IO;
|
|
using NetLibrary.Log;
|
|
using NetLibrary.Data;
|
|
using System.Data.Common;
|
|
using System.Data;
|
|
using TradeManageNew.WebReference2;
|
|
using System.Net;
|
|
|
|
namespace TradeManageNew
|
|
{
|
|
public class FedexRateNew3
|
|
{
|
|
public static string Key = "";
|
|
public static string Password = "";
|
|
public static string AccountNumber = "";
|
|
public static string MeterNumber = "";
|
|
public static string PayAccountNumber = "";
|
|
public static string PostInfo = "";
|
|
public static FedexFeeMdNew ormd = new FedexFeeMdNew();
|
|
public static string FeeHtml = "";
|
|
public static string HubId = "";
|
|
public static decimal Fee = 0;
|
|
public static int PostId = 0;
|
|
public static int Addr2 = 0;
|
|
|
|
public OrderFedexRateFeeDetail GetFee(FedexFeeMdNew md)
|
|
{
|
|
ormd = md;
|
|
Fee = 0;
|
|
var rmodel = new OrderFedexRateFeeDetail();
|
|
RateRequest request = CreateRateRequest();
|
|
RateService service = new RateService();
|
|
service.Url = "https://ws.fedex.com:443/web-services/rate";
|
|
try
|
|
{
|
|
// Call the web service passing in a RateRequest and returning a RateReply
|
|
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
|
|
RateReply reply = service.getRates(request);
|
|
if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
|
|
{
|
|
if(reply.RateReplyDetails!=null && reply.RateReplyDetails.Count() > 0)
|
|
{
|
|
rmodel.ServiceType = reply.RateReplyDetails[0].ServiceType.ToString();
|
|
|
|
if(reply.RateReplyDetails[0].RatedShipmentDetails != null && reply.RateReplyDetails[0].RatedShipmentDetails.Count() > 0)
|
|
{
|
|
var ShipmentDetail = reply.RateReplyDetails[0].RatedShipmentDetails[0];
|
|
if (ShipmentDetail.ShipmentRateDetail != null)
|
|
{
|
|
rmodel.FenQu = ShipmentDetail.ShipmentRateDetail.RateZone;
|
|
rmodel.TotalFee = ShipmentDetail.ShipmentRateDetail.TotalNetCharge != null ? (ShipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount.ToString()) : "";
|
|
rmodel.BaseFee = ShipmentDetail.ShipmentRateDetail.TotalBaseCharge != null ? (ShipmentDetail.ShipmentRateDetail.TotalBaseCharge.Amount.ToString()) : "";
|
|
rmodel.TotalDiscountFee = ShipmentDetail.ShipmentRateDetail.TotalFreightDiscounts != null ? (ShipmentDetail.ShipmentRateDetail.TotalFreightDiscounts.Amount.ToString()) : "";
|
|
|
|
if (ShipmentDetail.ShipmentRateDetail.Surcharges != null)
|
|
{
|
|
var surcharges = ShipmentDetail.ShipmentRateDetail.Surcharges;
|
|
//偏远,超偏远,超级偏远地区附加费
|
|
if(surcharges.Where(r=>r.SurchargeType.ToString()== "OUT_OF_DELIVERY_AREA").FirstOrDefault() != null)
|
|
{
|
|
var surcharge = surcharges.Where(r => r.SurchargeType.ToString() == "OUT_OF_DELIVERY_AREA").First();
|
|
rmodel.PYAreaFee = surcharge.Amount.Amount.ToString();
|
|
rmodel.CPYAreaFee = surcharge.Amount.Amount.ToString();
|
|
rmodel.CJPYAreaFee = surcharge.Amount.Amount.ToString();
|
|
}
|
|
//非机动收费
|
|
if (surcharges.Where(r => r.SurchargeType.ToString() == "SPECIAL_EQUIPMENT").FirstOrDefault() != null)
|
|
{
|
|
var surcharge = surcharges.Where(r => r.SurchargeType.ToString() == "SPECIAL_EQUIPMENT").First();
|
|
rmodel.FJDFee = surcharge.Amount.Amount.ToString();
|
|
}
|
|
|
|
//旺季附加费
|
|
if (surcharges.Where(r=>r.SurchargeType.ToString()== "DEMAND" || r.SurchargeType.ToString() == "DEMAND_ADDITIONAL_HANDLING" || r.SurchargeType.ToString() == "DEMAND_OVERSIZE" || r.SurchargeType.ToString() == "DEMAND_RESIDENTIAL_DELIVERY").FirstOrDefault() != null)
|
|
{
|
|
var _surcharges = surcharges.Where(r => r.SurchargeType.ToString() == "DEMAND" || r.SurchargeType.ToString() == "DEMAND_ADDITIONAL_HANDLING" || r.SurchargeType.ToString() == "DEMAND_OVERSIZE" || r.SurchargeType.ToString() == "DEMAND_RESIDENTIAL_DELIVERY");
|
|
decimal wjfee = 0;
|
|
foreach(var su in _surcharges)
|
|
{
|
|
wjfee += su.Amount.Amount;
|
|
}
|
|
rmodel.WangJiFee = wjfee.ToString();
|
|
}
|
|
//燃油附加费
|
|
if(surcharges.Where(r => r.SurchargeType.ToString() == "FUEL").FirstOrDefault() != null)
|
|
{
|
|
var surcharge = surcharges.Where(r => r.SurchargeType.ToString() == "FUEL").First();
|
|
rmodel.RanYouFee = surcharge.Amount.Amount.ToString();
|
|
}
|
|
|
|
//签收费
|
|
if (surcharges.Where(r => r.SurchargeType.ToString() == "SIGNATURE_OPTION").FirstOrDefault() != null)
|
|
{
|
|
var surcharge = surcharges.Where(r => r.SurchargeType.ToString() == "SIGNATURE_OPTION").First();
|
|
rmodel.QianShouFee = surcharge.Amount.Amount.ToString();
|
|
}
|
|
|
|
//住宅地址附加费
|
|
if (surcharges.Where(r => r.SurchargeType.ToString() == "RESIDENTIAL_DELIVERY" || r.SurchargeType.ToString() == "RESIDENTIAL_PICKUP" ).FirstOrDefault() != null)
|
|
{
|
|
var _surcharges = surcharges.Where(r => r.SurchargeType.ToString() == "RESIDENTIAL_DELIVERY" || r.SurchargeType.ToString() == "RESIDENTIAL_PICKUP");
|
|
decimal zzdzfee = 0;
|
|
foreach (var su in _surcharges)
|
|
{
|
|
zzdzfee += su.Amount.Amount;
|
|
}
|
|
rmodel.ZZFDZFee = zzdzfee.ToString();
|
|
}
|
|
|
|
//OverSize
|
|
if (surcharges.Where(r => r.SurchargeType.ToString() == "OVERSIZE").FirstOrDefault() != null)
|
|
{
|
|
var surcharge = surcharges.Where(r => r.SurchargeType.ToString() == "OVERSIZE").First();
|
|
rmodel.OverSize = surcharge.Amount.Amount.ToString();
|
|
}
|
|
|
|
//超标费
|
|
if (surcharges.Where(r => r.SurchargeType.ToString() == "OVER_DIMENSION" || r.SurchargeType.ToString() == "OVERWEIGHT" || r.SurchargeType.ToString() == "OVER_LENGTH").FirstOrDefault() != null)
|
|
{
|
|
var _surcharges = surcharges.Where(r => r.SurchargeType.ToString() == "OVER_DIMENSION" || r.SurchargeType.ToString() == "OVERWEIGHT" || r.SurchargeType.ToString() == "OVER_LENGTH");
|
|
decimal cbfee = 0;
|
|
foreach (var su in _surcharges)
|
|
{
|
|
cbfee += su.Amount.Amount;
|
|
}
|
|
rmodel.ChaoBiaoFee = cbfee.ToString();
|
|
}
|
|
|
|
var totalSurcharge = 0m;
|
|
foreach(var su in surcharges)
|
|
{
|
|
if(su.Amount!=null)
|
|
totalSurcharge += su.Amount.Amount;
|
|
}
|
|
rmodel.TotalSurchargeFee = totalSurcharge.ToString();
|
|
rmodel.AHS=totalSurcharge.ToString();
|
|
|
|
|
|
}
|
|
|
|
if (ShipmentDetail.ShipmentRateDetail.TotalBillingWeight != null)
|
|
{
|
|
rmodel.TotalBillWeight = ShipmentDetail.ShipmentRateDetail.TotalBillingWeight.Value.ToString() + ShipmentDetail.ShipmentRateDetail.TotalBillingWeight.Units;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (reply.RateReplyDetails[0].DeliveryTimestamp != null)
|
|
{
|
|
rmodel.YuJiSongDa = reply.RateReplyDetails[0].DeliveryTimestamp.ToString("yyyy-MM-dd HH:mm:ss");
|
|
}
|
|
|
|
}
|
|
}
|
|
else
|
|
rmodel = null;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
rmodel = null;
|
|
}
|
|
|
|
return rmodel;
|
|
}
|
|
|
|
private static RateRequest CreateRateRequest()
|
|
{
|
|
// Build the RateRequest
|
|
RateRequest request = new RateRequest();
|
|
//
|
|
request.WebAuthenticationDetail = new WebAuthenticationDetail();
|
|
request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
|
|
request.WebAuthenticationDetail.UserCredential.Key = Key;// "JFnBk9SNRj1JeegZ"; // Replace "XXX" with the Key
|
|
request.WebAuthenticationDetail.UserCredential.Password = Password;// "KE6pVQBrPQWrcXEdv3Gtya6Zy"; // Replace "XXX" with the Password
|
|
//if (usePropertyFile()) //Set values from a file for testing purposes
|
|
//{
|
|
// request.WebAuthenticationDetail.UserCredential.Key = getProperty("key");
|
|
// request.WebAuthenticationDetail.UserCredential.Password = getProperty("password");
|
|
//}
|
|
//
|
|
request.ClientDetail = new ClientDetail();
|
|
request.ClientDetail.AccountNumber = AccountNumber;// "464127968"; // Replace "XXX" with the client's account number
|
|
request.ClientDetail.MeterNumber = MeterNumber;// "112179445"; // Replace "XXX" with the client's meter number
|
|
//if (usePropertyFile()) //Set values from a file for testing purposes
|
|
//{
|
|
// request.ClientDetail.AccountNumber = getProperty("accountnumber");
|
|
// request.ClientDetail.MeterNumber = getProperty("meternumber");
|
|
//}
|
|
//
|
|
request.TransactionDetail = new TransactionDetail();
|
|
request.TransactionDetail.CustomerTransactionId = "***SmartPost Rate 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();
|
|
//
|
|
request.ReturnTransitAndCommit = true;
|
|
request.ReturnTransitAndCommitSpecified = true;
|
|
if (ormd.PostType == "SMART_POST")
|
|
{
|
|
request.CarrierCodes = new CarrierCodeType[1];
|
|
request.CarrierCodes[0] = CarrierCodeType.FXSP; // FXSP is for SmartPost
|
|
}
|
|
else //if (ormd.PostType == "FEDEX_GROUND")
|
|
{
|
|
request.CarrierCodes = new CarrierCodeType[1];
|
|
request.CarrierCodes[0] = CarrierCodeType.FDXG; // FXSP is for SmartPost
|
|
}
|
|
|
|
//
|
|
SetShipmentDetails(request);
|
|
//
|
|
return request;
|
|
}
|
|
|
|
|
|
private static void SetShipmentDetails(RateRequest request)
|
|
{
|
|
request.RequestedShipment = new RequestedShipment();
|
|
request.RequestedShipment.ShipTimestamp = DateTime.Now; // Shipping date and time
|
|
request.RequestedShipment.ShipTimestampSpecified = true;
|
|
request.RequestedShipment.DropoffType = DropoffType.REGULAR_PICKUP;
|
|
if (ormd.PostType == "SMART_POST")
|
|
request.RequestedShipment.ServiceType = ServiceType.SMART_POST; // Service type is SmartPost
|
|
else if (ormd.PostType == "FEDEX_GROUND")
|
|
request.RequestedShipment.ServiceType = ServiceType.FEDEX_GROUND; // Service type is SmartPost
|
|
else if (ormd.PostType == "GROUND_HOME_DELIVERY")
|
|
request.RequestedShipment.ServiceType = ServiceType.GROUND_HOME_DELIVERY;
|
|
else if (ormd.PostType == "FEDEX_2_DAY")
|
|
request.RequestedShipment.ServiceType = ServiceType.FEDEX_2_DAY; // Service type is FEDEX_2_DAY
|
|
else if (ormd.PostType == "Freight_Economy")
|
|
request.RequestedShipment.ServiceType = ServiceType.FEDEX_FREIGHT_ECONOMY; // Service type is FEDEX_2_DAY
|
|
if (ormd.PostType == "GROUND_HOME_DELIVERY")
|
|
request.RequestedShipment.ServiceTypeSpecified = false;
|
|
else
|
|
request.RequestedShipment.ServiceTypeSpecified = true;
|
|
request.RequestedShipment.PackagingType = PackagingType.YOUR_PACKAGING;
|
|
request.RequestedShipment.PackagingTypeSpecified = true;
|
|
//
|
|
SetOrigin(request);
|
|
//
|
|
SetDestination(request);
|
|
|
|
SetSmartPostDetails(request);
|
|
//
|
|
SetPackageLineItems(request);
|
|
//
|
|
request.RequestedShipment.PackageCount = "1";
|
|
}
|
|
|
|
private static void SetOrigin(RateRequest request)
|
|
{
|
|
request.RequestedShipment.Shipper = new Party();
|
|
request.RequestedShipment.Shipper.Address = new Address();
|
|
request.RequestedShipment.Shipper.Address.StreetLines = new string[1] { ormd.SendAddr };
|
|
request.RequestedShipment.Shipper.Address.City = ormd.SendCity;// "COMMERCE";
|
|
request.RequestedShipment.Shipper.Address.StateOrProvinceCode = ormd.SendProv;// "CA";
|
|
request.RequestedShipment.Shipper.Address.PostalCode = ormd.SendPostCode;//"90040";
|
|
request.RequestedShipment.Shipper.Address.CountryCode = ormd.SendCountry;//"US";
|
|
}
|
|
|
|
private static void SetDestination(RateRequest request)
|
|
{
|
|
request.RequestedShipment.Recipient = new Party();
|
|
request.RequestedShipment.Recipient.Address = new Address();
|
|
request.RequestedShipment.Recipient.Address.StreetLines = new string[1] { ormd.RevAddr };
|
|
request.RequestedShipment.Recipient.Address.City = ormd.RevCity;// "Morgantown";
|
|
request.RequestedShipment.Recipient.Address.StateOrProvinceCode = ormd.RevProv;//"WV";
|
|
request.RequestedShipment.Recipient.Address.PostalCode = ormd.RevPostCode;//"26501";
|
|
request.RequestedShipment.Recipient.Address.CountryCode = ormd.RevCountry;// "US";
|
|
if (ormd.PostType == "GROUND_HOME_DELIVERY")
|
|
{
|
|
request.RequestedShipment.Recipient.Address.Residential = true;
|
|
request.RequestedShipment.Recipient.Address.ResidentialSpecified = true;
|
|
request.RequestedShipment.Recipient.Contact = new Contact();
|
|
|
|
if (ormd.RevName != null && ormd.RevName != "")
|
|
request.RequestedShipment.Recipient.Contact.PersonName = ormd.RevName;
|
|
else
|
|
request.RequestedShipment.Recipient.Contact.PersonName = "jacky";
|
|
if (ormd.RevPhone != null && ormd.RevPhone != "")
|
|
request.RequestedShipment.Recipient.Contact.PhoneNumber = ormd.RevPhone;
|
|
else
|
|
request.RequestedShipment.Recipient.Contact.PhoneNumber = "2392276058";
|
|
}
|
|
|
|
}
|
|
|
|
private static void SetSmartPostDetails(RateRequest request)
|
|
{
|
|
request.RequestedShipment.SmartPostDetail = new SmartPostShipmentDetail();
|
|
request.RequestedShipment.SmartPostDetail.Indicia = SmartPostIndiciaType.PARCEL_SELECT;
|
|
request.RequestedShipment.SmartPostDetail.IndiciaSpecified = true;
|
|
request.RequestedShipment.SmartPostDetail.AncillaryEndorsement = SmartPostAncillaryEndorsementType.ADDRESS_CORRECTION; // Replace with a valid ancillary endorsement type
|
|
request.RequestedShipment.SmartPostDetail.AncillaryEndorsementSpecified = true;
|
|
request.RequestedShipment.SmartPostDetail.HubId = HubId;// "5902"; // Replace "XXX" with the hub id
|
|
//if (usePropertyFile()) //Set values from a file for testing purposes
|
|
//{
|
|
// request.RequestedShipment.SmartPostDetail.HubId = getProperty("hubid");
|
|
//}
|
|
}
|
|
|
|
private static void SetPackageLineItems(RateRequest request)
|
|
{
|
|
request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[1];
|
|
request.RequestedShipment.RequestedPackageLineItems[0] = new RequestedPackageLineItem();
|
|
request.RequestedShipment.RequestedPackageLineItems[0].SequenceNumber = "1"; // package sequence number
|
|
request.RequestedShipment.RequestedPackageLineItems[0].GroupPackageCount = "1";
|
|
// package weight
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Weight = new Weight();
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Weight.Units = WeightUnits.LB;
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Weight.UnitsSpecified = true;
|
|
if (ormd.OrderId == 0)
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Weight.Value = ormd.Weight.Value;
|
|
else
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Weight.Value = ormd.Weight.Value * Convert.ToDecimal(0.0625);
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Weight.ValueSpecified = true;
|
|
// package dimensions
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions = new Dimensions();
|
|
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Length = ormd.Lenght;// "50";
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Width = ormd.Width;// "20";
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Height = ormd.Height;// "3";
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Units = LinearUnits.IN;
|
|
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.UnitsSpecified = true;
|
|
}
|
|
}
|
|
} |