using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XYY.Model.Standard.OrderAddressCheck;
namespace XYY.Service.Standard.AddressCheck
{
//如果好用,请收藏地址,帮忙分享。
public class ZipCode
{
///
///
///
public string ID { get; set; }
///
///
///
public string Zip5 { get; set; }
///
///
///
public string City { get; set; }
///
///
///
public string State { get; set; }
}
public class CityStateLookupResponse
{
///
///
///
public ZipCode ZipCode { get; set; }
}
public class LockupRoot
{
///
///
///
public CityStateLookupResponse CityStateLookupResponse { get; set; }
}
public class UspsCityDto
{
public string resultStatus { get; set; }
public string zip5 { get; set; }
public string defaultCity { get; set; }
public string defaultState { get; set; }
public string defaultRecordType { get; set; }
public List citiesList { get; set; }
public List nonAcceptList { get; set; }
}
public class USPUAddressService : IAdderssService
{
public int ChannelId => throw new NotImplementedException();
public string CountryCode => "US";
public async Task GetRecommendedAddresses(OrderAddress address)
{
var RecommendedAddress = new RecommendedAddress
{
CityRecommendedAddress = new List(),
ZipCodeRecommendedAddress = new List()
};
if (string.IsNullOrEmpty(address.ZipCode))
return null;
string url = $"http://production.shippingapis.com/ShippingAPI.dll?API=CityStateLookup&XML={address.ZipCode}";
RestClient client = new RestClient(url);
RestRequest req = new RestRequest(Method.POST);
req.AddParameter("zip", address.ZipCode);
client.Execute(req);
var resp = await client.ExecuteAsync(req);
if (resp.StatusCode == System.Net.HttpStatusCode.OK)
{
string content = resp.Content;
System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(CityStateLookupResponse));
var result = (CityStateLookupResponse)xmlSerializer.Deserialize(new System.IO.StringReader(content));
RecommendedAddress.ZipCodeRecommendedAddress = new List
{
new RecommendedAddressItem
{
ZipCode = address.ZipCode,
City = result.ZipCode.City,
State = result.ZipCode.State
}
};
return RecommendedAddress;
}
else
return RecommendedAddress;
}
private RecommendedAddressItem ConvertAddress(FRSLAreas area)
{
return new RecommendedAddressItem { City = area.AreaName, ZipCode = area.ZipCode };
}
public Task Verify(OrderAddress address)
{
throw new NotImplementedException();
}
}
}