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.
198 lines
7.5 KiB
C#
198 lines
7.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
|
|
namespace NetLibrary.Express
|
|
{
|
|
public class OneWorldAPI
|
|
{
|
|
public string sendpost(string URL)
|
|
{
|
|
System.Guid ro = Guid.NewGuid();
|
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
|
|
request.Method = "GET";
|
|
request.ContentType = "application/json";
|
|
request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; qihu theworld)";
|
|
request.Headers.Add("Accept-Language: zh-CN");
|
|
request.Headers["Pragma"] = "no-cache"; //禁用缓存
|
|
request.Headers["Cache-Control"] = "no-cache"; //禁用缓存
|
|
request.Headers.Add(HttpRequestHeader.Authorization, "Hc-OweDeveloper " + "OW00046;bsFP6rTPnhAU19m;" + ro.ToString());
|
|
|
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
Stream myResponseStream = response.GetResponseStream();
|
|
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
|
|
string josn = myStreamReader.ReadToEnd();
|
|
|
|
myStreamReader.Close();
|
|
myResponseStream.Close();
|
|
response.Close();
|
|
return josn;
|
|
}
|
|
|
|
public string sendData(string output, string Url)
|
|
{
|
|
string strReturn = "";
|
|
System.Guid ro = Guid.NewGuid();
|
|
|
|
byte[] obtPostData = Encoding.UTF8.GetBytes(output.ToString());
|
|
HttpWebRequest orqRequest = (HttpWebRequest)WebRequest.Create(Url);
|
|
orqRequest.Timeout = 3000;
|
|
|
|
orqRequest.Method = "POST";
|
|
orqRequest.ContentType = "application/json";
|
|
orqRequest.ContentLength = obtPostData.Length;
|
|
orqRequest.Headers.Add(HttpRequestHeader.Authorization, "Hc-OweDeveloper " + "OW00046;bsFP6rTPnhAU19m;" + ro.ToString());
|
|
|
|
Stream stream;
|
|
using (stream = orqRequest.GetRequestStream())
|
|
{
|
|
stream.Write(obtPostData, 0, obtPostData.Length);
|
|
}
|
|
|
|
HttpWebResponse orsResponse = (HttpWebResponse)orqRequest.GetResponse();
|
|
|
|
using (Stream responseStream = orsResponse.GetResponseStream())
|
|
{
|
|
using (StreamReader streamRead = new StreamReader(responseStream, Encoding.UTF8))
|
|
{
|
|
strReturn = streamRead.ReadToEnd();
|
|
}
|
|
}
|
|
return strReturn;
|
|
}
|
|
|
|
public string PutData(string output, string Url)
|
|
{
|
|
string strReturn = "";
|
|
System.Guid ro = Guid.NewGuid();
|
|
|
|
byte[] obtPostData = Encoding.UTF8.GetBytes(output.ToString());
|
|
HttpWebRequest orqRequest = (HttpWebRequest)WebRequest.Create(Url);
|
|
orqRequest.Timeout = 3000;
|
|
|
|
orqRequest.Method = "put";
|
|
orqRequest.ContentType = "application/json";
|
|
orqRequest.ContentLength = obtPostData.Length;
|
|
orqRequest.Headers.Add(HttpRequestHeader.Authorization, "Hc-OweDeveloper " + "OW00046;bsFP6rTPnhAU19m;" + ro.ToString());
|
|
|
|
Stream stream;
|
|
using (stream = orqRequest.GetRequestStream())
|
|
{
|
|
stream.Write(obtPostData, 0, obtPostData.Length);
|
|
}
|
|
|
|
HttpWebResponse orsResponse = (HttpWebResponse)orqRequest.GetResponse();
|
|
|
|
using (Stream responseStream = orsResponse.GetResponseStream())
|
|
{
|
|
using (StreamReader streamRead = new StreamReader(responseStream, Encoding.UTF8))
|
|
{
|
|
strReturn = streamRead.ReadToEnd();
|
|
}
|
|
}
|
|
return strReturn;
|
|
}
|
|
}
|
|
|
|
public class ONEBody
|
|
{
|
|
public ONEBody()
|
|
{
|
|
//
|
|
//TODO: 在此处添加构造函数逻辑
|
|
//
|
|
}
|
|
public string ReferenceId; //客户订单号
|
|
public ShippingAddressClass ShippingAddress = new ShippingAddressClass(); //收件人地址信息
|
|
public double WeightInKg; //包裹重量(单位:KG)
|
|
public List<ItemDetailsClass> ItemDetails = new List<ItemDetailsClass>(); //包裹件内明细
|
|
public TotalValueClass TotalValue = new TotalValueClass(); //包裹总金额
|
|
public TotalVolumeClass TotalVolume = new TotalVolumeClass(); //包裹尺寸
|
|
public string WithBatteryType; //包裹是否含有带电产品
|
|
public string Notes; //包裹备注
|
|
public string BatchNo; //批次号或邮袋号
|
|
public string WarehouseCode; //交货仓库代码,请参考查询仓库接口
|
|
public string ShippingMethod; //发货产品服务代码
|
|
public string ItemType; //包裹类型
|
|
public string DutyPaymentMethod; //结算方式
|
|
public string TrackingNumber; //预分配挂号
|
|
public bool IsMPS; //快递一票多件(multiple package shipment)
|
|
public bool CheckRepeat; //检查包裹是否重复
|
|
public List<CasesClass> Cases = new List<CasesClass>(); //快递一票多件,箱子列表
|
|
public bool AutoConfirm;
|
|
}
|
|
|
|
public class ShippingAddressClass
|
|
{
|
|
public string Company; //公司名称
|
|
public string Street1; //街道1
|
|
public string Street2; //街道2
|
|
public string Street3; //街道3
|
|
public string City; //城市
|
|
public string Province; //省、州
|
|
public string Country; //国家
|
|
public string CountryCode; //国家代码
|
|
public string Postcode; //邮编
|
|
public string Contacter; //联系人
|
|
public string Tel; //电话
|
|
public string Email; //邮箱
|
|
}
|
|
|
|
public class ItemDetailsClass
|
|
{
|
|
public string GoodsId;
|
|
public string GoodsTitle;
|
|
public string DeclaredNameEn;
|
|
public string DeclaredNameCn;
|
|
public DeclaredValueClass DeclaredValue = new DeclaredValueClass();
|
|
public double WeightInKg;
|
|
public int Quantity;
|
|
public string HSCode;
|
|
public string CaseCode;
|
|
}
|
|
|
|
public class DeclaredValueClass
|
|
{
|
|
public string Code;
|
|
public double Value;
|
|
}
|
|
|
|
public class TotalValueClass
|
|
{
|
|
public string Code;
|
|
public double Value;
|
|
}
|
|
|
|
public class TotalVolumeClass
|
|
{
|
|
public double Length;
|
|
public double Width;
|
|
public double Height;
|
|
public string Unit;
|
|
}
|
|
|
|
public class CasesClass
|
|
{
|
|
public string Code;
|
|
public double WeightInKg;
|
|
public VolumeClass Volume = new VolumeClass();
|
|
}
|
|
|
|
public class VolumeClass
|
|
{
|
|
public double Length;
|
|
public double Width;
|
|
public double Height;
|
|
public string Unit;
|
|
}
|
|
|
|
public class ChangeClass
|
|
{
|
|
public string ProcessCode;
|
|
public string WeightInKg;
|
|
}
|
|
}
|