57 changed files with 3046 additions and 7 deletions
@ -0,0 +1,18 @@ |
|||
using BBWYB.Common.Log; |
|||
using BBWYB.Common.Models; |
|||
using Yitter.IdGenerator; |
|||
|
|||
namespace BBWYB.Server.Business |
|||
{ |
|||
public class PurchaseOrderBusiness : BaseBusiness, IDenpendency |
|||
{ |
|||
public PurchaseOrderBusiness(IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator) : base(fsql, nLogManager, idGenerator) |
|||
{ |
|||
} |
|||
|
|||
public PreviewOrderResponse PreviewPurchaseOrder(PreviewOrderReuqest previewOrderReuqest) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
@ -0,0 +1,28 @@ |
|||
using BBWYB.Common.Http; |
|||
using SDKAdapter.PurchasePlatform.Models; |
|||
|
|||
namespace SDKAdapter.PurchasePlatform.Client |
|||
{ |
|||
public class PP_PlatformClient |
|||
{ |
|||
protected RestApiService restApiService { get; private set; } |
|||
|
|||
public virtual AdapterEnums.PlatformType Platform { get; } |
|||
|
|||
public PP_PlatformClient(RestApiService restApiService) |
|||
{ |
|||
this.restApiService = restApiService; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 预览订单
|
|||
/// </summary>
|
|||
/// <param name="request"></param>
|
|||
/// <returns></returns>
|
|||
/// <exception cref="NotImplementedException"></exception>
|
|||
public virtual PP_PreviewOrderResponse PreviewOrder(PP_PreviewOrderRequest request) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,23 @@ |
|||
using BBWYB.Common.Http; |
|||
|
|||
namespace SDKAdapter.PurchasePlatform.Client |
|||
{ |
|||
public class PP_PlatformClientFactory |
|||
{ |
|||
private IList<PP_PlatformClient> clients; |
|||
|
|||
public PP_PlatformClientFactory(RestApiService restApiService) |
|||
{ |
|||
clients = new List<PP_PlatformClient>(); |
|||
clients.Add(new PP_1688Client(restApiService)); |
|||
} |
|||
|
|||
public PP_PlatformClient GetClient(AdapterEnums.PlatformType platform) |
|||
{ |
|||
var client = clients.FirstOrDefault(c => c.Platform == platform); |
|||
if (client == null) |
|||
throw new Exception("不支持的平台"); |
|||
return client; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,127 @@ |
|||
using BBWYB.Common.Http; |
|||
using com.alibaba.openapi.client; |
|||
using com.alibaba.openapi.client.entity; |
|||
using com.alibaba.openapi.client.policy; |
|||
using Newtonsoft.Json.Linq; |
|||
using SDKAdapter.PurchasePlatform.Models; |
|||
|
|||
namespace SDKAdapter.PurchasePlatform.Client |
|||
{ |
|||
public class PP_1688Client : PP_PlatformClient |
|||
{ |
|||
private _1688TradeTypeCompare _1688TradeTypeCompare; |
|||
public PP_1688Client(RestApiService restApiService) : base(restApiService) |
|||
{ |
|||
_1688TradeTypeCompare = new _1688TradeTypeCompare(); |
|||
} |
|||
|
|||
private SyncAPIClient GetSyncAPIClient(string appKey, string appSecret) |
|||
{ |
|||
return new SyncAPIClient(appKey, appSecret, restApiService); |
|||
} |
|||
|
|||
public override PP_PreviewOrderResponse PreviewOrder(PP_PreviewOrderRequest request) |
|||
{ |
|||
var client = GetSyncAPIClient(request.AppKey, request.AppSecret); |
|||
RequestPolicy reqPolicy = new RequestPolicy(); |
|||
reqPolicy.HttpMethod = "POST"; |
|||
reqPolicy.NeedAuthorization = false; |
|||
reqPolicy.RequestSendTimestamp = false; |
|||
reqPolicy.UseHttps = false; |
|||
reqPolicy.UseSignture = true; |
|||
reqPolicy.AccessPrivateApi = false; |
|||
|
|||
Request _request = new Request(); |
|||
APIId apiId = new APIId(); |
|||
apiId.Name = "alibaba.createOrder.preview"; |
|||
apiId.NamespaceValue = "com.alibaba.trade"; |
|||
apiId.Version = 1; |
|||
_request.ApiId = apiId; |
|||
|
|||
var param = new CreateOrderPreview() |
|||
{ |
|||
addressParam = new AddressParam() |
|||
{ |
|||
fullName = request.Consignee.ContactName, |
|||
mobile = request.Consignee.Mobile, |
|||
phone = request.Consignee.TelePhone, |
|||
postCode = "000000", |
|||
address = request.Consignee.Address, |
|||
provinceText = request.Consignee.Province, |
|||
cityText = request.Consignee.City, |
|||
areaText = request.Consignee.County, |
|||
townText = request.Consignee.Town |
|||
}, |
|||
cargoParamList = new List<CargoParam>(), |
|||
flow = request.PurchaseMode == AdapterEnums.PurchaseMode.批发 ? "general" : "saleproxy" |
|||
}; |
|||
foreach (var cargo in request.OrderProductParamList) |
|||
{ |
|||
param.cargoParamList.Add(new CargoParam() |
|||
{ |
|||
offerId = long.Parse(cargo.ProductId), |
|||
specId = cargo.SpecId, |
|||
quantity = cargo.Quantity |
|||
}); |
|||
} |
|||
_request.RequestEntity = param; |
|||
if (!string.IsNullOrEmpty(request.AppToken)) |
|||
_request.AccessToken = request.AppToken; |
|||
JObject result = null; |
|||
try |
|||
{ |
|||
result = client.NewRequest(_request, reqPolicy); |
|||
if (result.Value<bool>("success") != true) |
|||
throw new Exception(result.Value<string>("errorMsg")); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
throw new Exception(ex.Message); |
|||
} |
|||
|
|||
var orderPreviewResuslt = (JArray)result["orderPreviewResuslt"]; |
|||
List<JToken> intersectTradeModeList = new List<JToken>(); |
|||
|
|||
foreach (var orderPreviewJToken in orderPreviewResuslt) |
|||
{ |
|||
if (orderPreviewJToken["tradeModelList"] == null) |
|||
throw new Exception("当前交易不可通过API下单,请使用1688网页交易 [交易模式列表为空]"); |
|||
var tradeModeJArray = ((JArray)orderPreviewJToken["tradeModelList"]).Where(tradeJToken => tradeJToken.Value<bool>("opSupport")); |
|||
if (tradeModeJArray.Count() == 0) |
|||
throw new Exception("当前交易不可通过API下单,请使用1688网页交易 [没有支持开放平台下单的交易模式]"); |
|||
|
|||
if (intersectTradeModeList.Count() == 0) |
|||
intersectTradeModeList.AddRange(tradeModeJArray); |
|||
else |
|||
intersectTradeModeList = intersectTradeModeList.Intersect(tradeModeJArray, _1688TradeTypeCompare).ToList(); |
|||
} |
|||
|
|||
if (intersectTradeModeList.Count() == 0) |
|||
throw new Exception("当前交易不可通过API下单,请使用1688网页交易 [多个拆单之间没有相同的交易模式]"); |
|||
return new PP_PreviewOrderResponse() |
|||
{ |
|||
FreightAmount = orderPreviewResuslt.Sum(jt => jt.Value<decimal>("sumCarriage")) / 100M, |
|||
ProductAmount = orderPreviewResuslt.Sum(jt => jt.Value<decimal>("sumPaymentNoCarriage")) / 100M, |
|||
TotalAmount = orderPreviewResuslt.Sum(jt => jt.Value<decimal>("sumPayment")) / 100M, |
|||
//OrderTradeType = new OrderTradeTypeResponse()
|
|||
//{
|
|||
// Code = intersectTradeModeList.First().Value<string>("tradeType"),
|
|||
// Name = intersectTradeModeList.First().Value<string>("name"),
|
|||
//}
|
|||
}; |
|||
} |
|||
} |
|||
|
|||
public class _1688TradeTypeCompare : IEqualityComparer<JToken> |
|||
{ |
|||
public bool Equals(JToken x, JToken y) |
|||
{ |
|||
return x.Value<string>("tradeType").Equals(y.Value<string>("tradeType")); |
|||
} |
|||
|
|||
public int GetHashCode(JToken obj) |
|||
{ |
|||
return obj.GetHashCode(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,45 @@ |
|||
namespace SDKAdapter.PurchasePlatform.Models |
|||
{ |
|||
public class PP_ConsigneeRequest |
|||
{ |
|||
/// <summary>
|
|||
/// 联系人名称
|
|||
/// </summary>
|
|||
public string ContactName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 座机
|
|||
/// </summary>
|
|||
public string TelePhone { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 手机
|
|||
/// </summary>
|
|||
public string Mobile { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 详细地址
|
|||
/// </summary>
|
|||
public string Address { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 省
|
|||
/// </summary>
|
|||
public string Province { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 市
|
|||
/// </summary>
|
|||
public string City { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 县
|
|||
/// </summary>
|
|||
public string County { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 镇
|
|||
/// </summary>
|
|||
public string Town { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,10 @@ |
|||
namespace SDKAdapter.PurchasePlatform.Models |
|||
{ |
|||
public class PP_OrderProductParamRequest |
|||
{ |
|||
public string ProductId { get; set; } |
|||
public string SkuId { get; set; } |
|||
public string SpecId { get; set; } |
|||
public int Quantity { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,18 @@ |
|||
namespace SDKAdapter.PurchasePlatform.Models |
|||
{ |
|||
public class PP_PreviewOrderRequest : BasePlatformRequest |
|||
{ |
|||
/// <summary>
|
|||
/// 采购模式
|
|||
/// </summary>
|
|||
public AdapterEnums.PurchaseMode PurchaseMode { get; set; } |
|||
/// <summary>
|
|||
/// 收货信息
|
|||
/// </summary>
|
|||
public PP_ConsigneeRequest Consignee { get; set; } |
|||
/// <summary>
|
|||
/// 产品参数列表
|
|||
/// </summary>
|
|||
public IList<PP_OrderProductParamRequest> OrderProductParamList { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,25 @@ |
|||
namespace SDKAdapter.PurchasePlatform.Models |
|||
{ |
|||
public class PP_PreviewOrderResponse |
|||
{ |
|||
/// <summary>
|
|||
/// 总额
|
|||
/// </summary>
|
|||
public decimal TotalAmount { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 货款总额
|
|||
/// </summary>
|
|||
public decimal ProductAmount { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 运费
|
|||
/// </summary>
|
|||
public decimal FreightAmount { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 扩展数据
|
|||
/// </summary>
|
|||
public string Extensions { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,39 @@ |
|||
using com.alibaba.openapi.client; |
|||
using com.alibaba.openapi.client.entity; |
|||
using com.alibaba.openapi.client.policy; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace NetSdkClient.sdk |
|||
{ |
|||
public class APIFacade |
|||
{ |
|||
private ClientPolicy clientPolicy; |
|||
|
|||
public APIFacade(ClientPolicy clientPolicy) |
|||
{ |
|||
this.clientPolicy = clientPolicy; |
|||
} |
|||
|
|||
|
|||
private SyncAPIClient getAPIClient() |
|||
{ |
|||
return new SyncAPIClient(clientPolicy); |
|||
} |
|||
|
|||
public AuthorizationToken getToken(string code) |
|||
{ |
|||
|
|||
return getAPIClient().getToken(code); |
|||
|
|||
} |
|||
|
|||
public AuthorizationToken refreshToken(String refreshToken) |
|||
{ |
|||
return getAPIClient().refreshToken(refreshToken); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,43 @@ |
|||
using System; |
|||
|
|||
namespace com.alibaba.openapi.client |
|||
{ |
|||
public class APIId |
|||
{ |
|||
public APIId() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public APIId(String namespaceValue,String name, int version) |
|||
{ |
|||
this.NamespaceValue = namespaceValue; |
|||
this.Name = name; |
|||
this.version = version; |
|||
} |
|||
|
|||
private String namespaceValue; |
|||
|
|||
public String NamespaceValue |
|||
{ |
|||
get { return namespaceValue; } |
|||
set { namespaceValue = value; } |
|||
} |
|||
private String name; |
|||
|
|||
public String Name |
|||
{ |
|||
get { return name; } |
|||
set { name = value; } |
|||
} |
|||
private int version; |
|||
|
|||
public int Version |
|||
{ |
|||
get { return version; } |
|||
set { version = value; } |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,23 @@ |
|||
using com.alibaba.openapi.client.entity; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Runtime.Serialization; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client |
|||
{ |
|||
public class GatewayAPIRequest |
|||
{ |
|||
[DataMember(Order = 0)] |
|||
private APIId apiId; |
|||
|
|||
public APIId ApiId |
|||
{ |
|||
get { return apiId; } |
|||
set { apiId = value; } |
|||
} |
|||
|
|||
} |
|||
} |
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Runtime.Serialization; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client |
|||
{ |
|||
[DataContract(Namespace = "com.alibaba.openapi.client")] |
|||
public class GatewayAPIResponse |
|||
{ |
|||
} |
|||
} |
@ -0,0 +1,66 @@ |
|||
using com.alibaba.openapi.client.entity; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Runtime.Serialization; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client |
|||
{ |
|||
[DataContract(Namespace = "com.alibaba.openapi.client")] |
|||
public class Request |
|||
{ |
|||
[DataMember(Order = 0)] |
|||
private APIId apiId; |
|||
|
|||
public APIId ApiId |
|||
{ |
|||
get { return apiId; } |
|||
set { apiId = value; } |
|||
} |
|||
private Dictionary<String, Object> addtionalParams = new Dictionary<String, Object>(); |
|||
|
|||
public Dictionary<String, Object> AddtionalParams |
|||
{ |
|||
get { return addtionalParams; } |
|||
set { addtionalParams = value; } |
|||
} |
|||
private Object requestEntity; |
|||
|
|||
public Object RequestEntity |
|||
{ |
|||
get { return requestEntity; } |
|||
set { requestEntity = value; } |
|||
} |
|||
private Dictionary<String, String> attachments; |
|||
|
|||
public Dictionary<String, String> Attachments |
|||
{ |
|||
get { return attachments; } |
|||
set { attachments = value; } |
|||
} |
|||
private String authCodeKey; |
|||
|
|||
public String AuthCodeKey |
|||
{ |
|||
get { return authCodeKey; } |
|||
set { authCodeKey = value; } |
|||
} |
|||
[DataMember(Order = 1)] |
|||
private String accessToken; |
|||
|
|||
public String AccessToken |
|||
{ |
|||
get { return accessToken; } |
|||
set { accessToken = value; } |
|||
} |
|||
private AuthorizationToken authToken; |
|||
|
|||
internal AuthorizationToken AuthToken |
|||
{ |
|||
get { return authToken; } |
|||
set { authToken = value; } |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,56 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using com.alibaba.openapi.client.entity; |
|||
|
|||
namespace com.alibaba.openapi.client |
|||
{ |
|||
public class Response |
|||
{ |
|||
private int statusCode; |
|||
|
|||
public int StatusCode |
|||
{ |
|||
get { return statusCode; } |
|||
set { statusCode = value; } |
|||
} |
|||
private Object result; |
|||
|
|||
public Object Result |
|||
{ |
|||
get { return result; } |
|||
set { result = value; } |
|||
} |
|||
private Exception exception; |
|||
|
|||
public Exception Exception |
|||
{ |
|||
get { return exception; } |
|||
set { exception = value; } |
|||
} |
|||
private String charset = "UTF-8"; |
|||
|
|||
public String Charset |
|||
{ |
|||
get { return charset; } |
|||
set { charset = value; } |
|||
} |
|||
private String encoding; |
|||
|
|||
public String Encoding |
|||
{ |
|||
get { return encoding; } |
|||
set { encoding = value; } |
|||
} |
|||
|
|||
private ResponseWrapper responseWrapper; |
|||
|
|||
internal ResponseWrapper ResponseWrapper |
|||
{ |
|||
get { return responseWrapper; } |
|||
set { responseWrapper = value; } |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,115 @@ |
|||
using BBWYB.Common.Http; |
|||
using com.alibaba.openapi.client.entity; |
|||
using com.alibaba.openapi.client.policy; |
|||
using Newtonsoft.Json.Linq; |
|||
|
|||
namespace com.alibaba.openapi.client |
|||
{ |
|||
public class SyncAPIClient |
|||
{ |
|||
private ClientPolicy clientPolicy; |
|||
private RestApiService restApiService; |
|||
private http.HttpClient alibabaHttpClient; |
|||
|
|||
public SyncAPIClient(String appKey, String appSecret) |
|||
{ |
|||
this.clientPolicy = new ClientPolicy(); |
|||
this.clientPolicy.AppKey = appKey; |
|||
this.clientPolicy.SecretKey = appSecret; |
|||
} |
|||
|
|||
public SyncAPIClient(String appKey, String appSecret, RestApiService restApiService) |
|||
{ |
|||
this.clientPolicy = new ClientPolicy(); |
|||
this.clientPolicy.AppKey = appKey; |
|||
this.clientPolicy.SecretKey = appSecret; |
|||
this.restApiService = restApiService; |
|||
this.alibabaHttpClient = new http.HttpClient(clientPolicy, restApiService); |
|||
} |
|||
|
|||
public SyncAPIClient(String appKey, String appSecret, String gatewayHost) |
|||
{ |
|||
this.clientPolicy = new ClientPolicy(); |
|||
this.clientPolicy.AppKey = appKey; |
|||
this.clientPolicy.SecretKey = appSecret; |
|||
this.clientPolicy.ServerHost = gatewayHost; |
|||
} |
|||
|
|||
public SyncAPIClient(ClientPolicy clientPolicy) |
|||
{ |
|||
this.clientPolicy = clientPolicy; |
|||
} |
|||
|
|||
public JObject NewRequest(Request request, RequestPolicy policy) |
|||
{ |
|||
return alibabaHttpClient.NewRequest(request, policy); |
|||
} |
|||
|
|||
public T send<T>(Request request, RequestPolicy policy) |
|||
{ |
|||
http.HttpClient httpClient = new http.HttpClient(clientPolicy); |
|||
T result = httpClient.request<T>(request, policy); |
|||
return result; |
|||
} |
|||
|
|||
public Res execute<Res>(GatewayAPIRequest gatewayAPIRequest, String accessToken) |
|||
{ |
|||
http.HttpClient httpClient = new http.HttpClient(clientPolicy); |
|||
RequestPolicy policy = new RequestPolicy(); |
|||
policy.UseHttps = true; |
|||
Request request = new Request(); |
|||
request.ApiId = gatewayAPIRequest.ApiId; |
|||
request.RequestEntity = gatewayAPIRequest; |
|||
request.AccessToken = accessToken; |
|||
Res result = httpClient.request<Res>(request, policy); |
|||
return result; |
|||
} |
|||
|
|||
public AuthorizationToken getToken(String code) |
|||
{ |
|||
|
|||
APIId apiId = new APIId(); |
|||
apiId.Name = "getToken"; |
|||
apiId.NamespaceValue = "system.oauth2"; |
|||
apiId.Version = 1; |
|||
|
|||
Request request = new Request(); |
|||
request.ApiId = apiId; |
|||
|
|||
request.AddtionalParams["code"] = code; |
|||
request.AddtionalParams["grant_type"] = "authorization_code"; |
|||
request.AddtionalParams["need_refresh_token"] = true; |
|||
request.AddtionalParams["client_id"] = clientPolicy.AppKey; |
|||
request.AddtionalParams["client_secret"] = clientPolicy.SecretKey; |
|||
request.AddtionalParams["redirect_uri"] = "default"; |
|||
RequestPolicy oauthPolicy = new RequestPolicy(); |
|||
oauthPolicy.UseHttps = true; |
|||
|
|||
return this.send<AuthorizationToken>(request, oauthPolicy); |
|||
} |
|||
|
|||
public AuthorizationToken refreshToken(String refreshToken) |
|||
{ |
|||
|
|||
APIId apiId = new APIId(); |
|||
apiId.Name = "getToken"; |
|||
apiId.NamespaceValue = "system.oauth2"; |
|||
apiId.Version = 1; |
|||
|
|||
Request request = new Request(); |
|||
request.ApiId = apiId; |
|||
|
|||
request.AddtionalParams["refreshToken"] = refreshToken; |
|||
request.AddtionalParams["grant_type"] = "refresh_token"; |
|||
request.AddtionalParams["client_id"] = clientPolicy.AppKey; |
|||
request.AddtionalParams["client_secret"] = clientPolicy.SecretKey; |
|||
request.AddtionalParams["redirect_uri"] = "default"; |
|||
RequestPolicy oauthPolicy = new RequestPolicy(); |
|||
oauthPolicy.UseHttps = true; |
|||
return this.send<AuthorizationToken>(request, oauthPolicy); |
|||
|
|||
|
|||
} |
|||
} |
|||
} |
|||
|
@ -0,0 +1,159 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Runtime.Serialization; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.entity |
|||
{ |
|||
[DataContract(Namespace = "com.alibaba.openapi.client")] |
|||
public class AuthorizationToken |
|||
{ |
|||
[DataMember(Order = 0)] |
|||
private String access_token; |
|||
[DataMember(Order = 1)] |
|||
private String refresh_token; |
|||
[DataMember(Order = 2)] |
|||
private long expires_in; |
|||
[DataMember(Order = 3)] |
|||
private DateTime expires_time; |
|||
[DataMember(Order = 4)] |
|||
private DateTime refresh_token_timeout; |
|||
[DataMember(Order = 5)] |
|||
private String resource_owner; |
|||
[DataMember(Order = 6)] |
|||
private String uid; |
|||
[DataMember(Order = 7)] |
|||
private long aliId; |
|||
[DataMember(Order = 8)] |
|||
private String memberId; |
|||
|
|||
/** |
|||
* 获取access_token |
|||
* |
|||
* @return the accessToken |
|||
*/ |
|||
public String getAccess_token() |
|||
{ |
|||
return access_token; |
|||
} |
|||
|
|||
/** |
|||
* 获取access_token过期时间 |
|||
* |
|||
* @return the accessTokenTimeout |
|||
*/ |
|||
public long getExpires_in() |
|||
{ |
|||
return expires_in; |
|||
} |
|||
|
|||
/** |
|||
* 获取refresh_token |
|||
* |
|||
* @return the refreshToken |
|||
*/ |
|||
public String getRefresh_token() |
|||
{ |
|||
return refresh_token; |
|||
} |
|||
|
|||
/** |
|||
* 获取refresh_token过期时间 |
|||
* |
|||
* @return the refreshTokenTimeout |
|||
*/ |
|||
public DateTime getRefresh_token_timeout() |
|||
{ |
|||
return refresh_token_timeout; |
|||
} |
|||
|
|||
public String getMemberId() |
|||
{ |
|||
return memberId; |
|||
} |
|||
|
|||
public void setMemberId(String memberId) |
|||
{ |
|||
this.memberId = memberId; |
|||
} |
|||
|
|||
/** |
|||
* 获取resource_owner |
|||
* |
|||
* @return the resourceOwnerId |
|||
*/ |
|||
public String getResource_owner() |
|||
{ |
|||
return resource_owner; |
|||
} |
|||
|
|||
/** |
|||
* 获取uid |
|||
* |
|||
* @return the uid |
|||
*/ |
|||
public String getUid() |
|||
{ |
|||
return uid; |
|||
} |
|||
|
|||
/** |
|||
* 获取aliId |
|||
* |
|||
* @return the aliId |
|||
*/ |
|||
public long getAliId() |
|||
{ |
|||
return aliId; |
|||
} |
|||
|
|||
public void setAccess_token(String accessToken) |
|||
{ |
|||
this.access_token = accessToken; |
|||
} |
|||
|
|||
public void setRefresh_token(String refreshToken) |
|||
{ |
|||
this.refresh_token = refreshToken; |
|||
} |
|||
|
|||
public void setExpires_in(long accessTokenTimeout) |
|||
{ |
|||
this.expires_in = accessTokenTimeout; |
|||
DateTime now = new DateTime(); |
|||
this.expires_time = now.AddSeconds(accessTokenTimeout); |
|||
} |
|||
|
|||
public void setRefresh_token_timeout(DateTime refresh_token_timeout) |
|||
{ |
|||
this.refresh_token_timeout = refresh_token_timeout; |
|||
} |
|||
|
|||
public void setResource_owner(String resourceOwnerId) |
|||
{ |
|||
this.resource_owner = resourceOwnerId; |
|||
} |
|||
|
|||
public void setUid(String uid) |
|||
{ |
|||
this.uid = uid; |
|||
} |
|||
|
|||
public void setAliId(long aliId) |
|||
{ |
|||
this.aliId = aliId; |
|||
} |
|||
|
|||
/** |
|||
* 获取access_token过期时间,Date格式 |
|||
* |
|||
* @return the accessTokenTimeout |
|||
*/ |
|||
public DateTime getExpires_time() |
|||
{ |
|||
return expires_time; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,35 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Runtime.Serialization; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.entity |
|||
{ |
|||
[DataContract(Namespace = "com.alibaba.openapi.client")] |
|||
public class ErrorExceptionDesc |
|||
{ |
|||
[DataMember(Order = 0)] |
|||
private string error_code; |
|||
[DataMember(Order = 1)] |
|||
private string error_message; |
|||
[DataMember(Order = 2)] |
|||
private string exception; |
|||
|
|||
public string getError_code() |
|||
{ |
|||
return this.error_code; |
|||
} |
|||
|
|||
public string getError_message() |
|||
{ |
|||
return this.error_message; |
|||
} |
|||
|
|||
public string getException() |
|||
{ |
|||
return this.exception; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,48 @@ |
|||
using System.Runtime.Serialization; |
|||
|
|||
namespace com.alibaba.openapi.client.entity |
|||
{ |
|||
[DataContract] |
|||
public class CreateOrderPreview |
|||
{ |
|||
[DataMember] |
|||
public AddressParam addressParam { get; set; } |
|||
[DataMember] |
|||
public IList<CargoParam> cargoParamList { get; set; } |
|||
[DataMember] |
|||
public string flow { get; set; } |
|||
} |
|||
[DataContract] |
|||
public class AddressParam |
|||
{ |
|||
[DataMember] |
|||
public string fullName { get; set; } |
|||
[DataMember] |
|||
public string mobile { get; set; } |
|||
[DataMember] |
|||
public string phone { get; set; } |
|||
[DataMember] |
|||
public string postCode { get; set; } |
|||
[DataMember] |
|||
public string address { get; set; } |
|||
[DataMember] |
|||
public string provinceText { get; set; } |
|||
[DataMember] |
|||
public string cityText { get; set; } |
|||
[DataMember] |
|||
public string areaText { get; set; } |
|||
[DataMember] |
|||
public string townText { get; set; } |
|||
|
|||
} |
|||
[DataContract] |
|||
public class CargoParam |
|||
{ |
|||
[DataMember] |
|||
public long offerId { get; set; } |
|||
[DataMember] |
|||
public string specId { get; set; } |
|||
[DataMember] |
|||
public int quantity { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,28 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.entity |
|||
{ |
|||
public class ResponseStatus |
|||
{ |
|||
private String code; |
|||
|
|||
public String Code |
|||
{ |
|||
get { return code; } |
|||
set { code = value; } |
|||
} |
|||
private String message; |
|||
|
|||
public String Message |
|||
{ |
|||
get { return message; } |
|||
set { message = value; } |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,40 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.entity |
|||
{ |
|||
public class ResponseWrapper |
|||
{ |
|||
private String invokeStartTime; |
|||
|
|||
public String InvokeStartTime |
|||
{ |
|||
get { return invokeStartTime; } |
|||
set { invokeStartTime = value; } |
|||
} |
|||
private long invokeCostTime; |
|||
|
|||
public long InvokeCostTime |
|||
{ |
|||
get { return invokeCostTime; } |
|||
set { invokeCostTime = value; } |
|||
} |
|||
private ResponseStatus status; |
|||
|
|||
internal ResponseStatus Status |
|||
{ |
|||
get { return status; } |
|||
set { status = value; } |
|||
} |
|||
private Object result; |
|||
|
|||
public Object Result |
|||
{ |
|||
get { return result; } |
|||
set { result = value; } |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,88 @@ |
|||
using com.alibaba.openapi.client; |
|||
using com.alibaba.openapi.client.entity; |
|||
using com.alibaba.openapi.client.policy; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
using com.alibaba.china.openapi.client.example.param.apiexample; |
|||
|
|||
namespace com.alibaba.china.openapi.client.example |
|||
{ |
|||
|
|||
public class ExampleFacade |
|||
{ |
|||
private ClientPolicy clientPolicy; |
|||
|
|||
public ExampleFacade(ClientPolicy clientPolicy) |
|||
{ |
|||
this.clientPolicy = clientPolicy; |
|||
} |
|||
|
|||
private SyncAPIClient getAPIClient() |
|||
{ |
|||
return new SyncAPIClient(clientPolicy); |
|||
} |
|||
|
|||
public AuthorizationToken getToken(string code) |
|||
{ |
|||
|
|||
return getAPIClient().getToken(code); |
|||
|
|||
} |
|||
|
|||
public AuthorizationToken refreshToken(String refreshToken) |
|||
{ |
|||
return getAPIClient().refreshToken(refreshToken); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
public ExampleFamilyGetResult exampleFamilyGet(ExampleFamilyGetParam param) { |
|||
RequestPolicy reqPolicy = new RequestPolicy(); |
|||
reqPolicy.HttpMethod="POST"; |
|||
reqPolicy.NeedAuthorization=false; |
|||
reqPolicy.RequestSendTimestamp=false; |
|||
reqPolicy.UseHttps=false; |
|||
reqPolicy.UseSignture=false; |
|||
reqPolicy.AccessPrivateApi=false; |
|||
|
|||
Request request = new Request (); |
|||
APIId apiId = new APIId(); |
|||
apiId.Name = "example.family.get"; |
|||
apiId.NamespaceValue = "api.example"; |
|||
apiId.Version = 1; |
|||
request.ApiId = apiId; |
|||
|
|||
request.RequestEntity=param; |
|||
|
|||
return this.getAPIClient().send<ExampleFamilyGetResult>(request, reqPolicy); |
|||
} |
|||
|
|||
|
|||
|
|||
public ExampleFamilyPostResult exampleFamilyPost(ExampleFamilyPostParam param, string accessToken) { |
|||
RequestPolicy reqPolicy = new RequestPolicy(); |
|||
reqPolicy.HttpMethod="POST"; |
|||
reqPolicy.NeedAuthorization=false; |
|||
reqPolicy.RequestSendTimestamp=false; |
|||
reqPolicy.UseHttps=false; |
|||
reqPolicy.UseSignture=true; |
|||
reqPolicy.AccessPrivateApi=false; |
|||
|
|||
Request request = new Request (); |
|||
APIId apiId = new APIId(); |
|||
apiId.Name = "example.family.post"; |
|||
apiId.NamespaceValue = "api.example"; |
|||
apiId.Version = 1; |
|||
request.ApiId = apiId; |
|||
|
|||
request.RequestEntity=param; |
|||
request.AccessToken=accessToken; |
|||
return this.getAPIClient().send<ExampleFamilyPostResult>(request, reqPolicy); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,160 @@ |
|||
using com.alibaba.openapi.client.primitive; |
|||
using com.alibaba.openapi.client.util; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Runtime.Serialization; |
|||
using System.Text; |
|||
|
|||
|
|||
namespace com.alibaba.china.openapi.client.example.param.apiexample |
|||
{ |
|||
[DataContract(Namespace = "com.alibaba.openapi.client")] |
|||
public class ExampleCar { |
|||
|
|||
[DataMember(Order = 1)] |
|||
private string builtDate; |
|||
|
|||
/** |
|||
* @return |
|||
*/ |
|||
public DateTime? getBuiltDate() { |
|||
if (builtDate != null) |
|||
{ |
|||
DateTime datetime = DateUtil.formatFromStr(builtDate); |
|||
return datetime; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
/** |
|||
* 设置 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setBuiltDate(DateTime builtDate) { |
|||
this.builtDate = DateUtil.format(builtDate); |
|||
} |
|||
|
|||
[DataMember(Order = 2)] |
|||
private string boughtDate; |
|||
|
|||
/** |
|||
* @return |
|||
*/ |
|||
public DateTime? getBoughtDate() { |
|||
if (boughtDate != null) |
|||
{ |
|||
DateTime datetime = DateUtil.formatFromStr(boughtDate); |
|||
return datetime; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
/** |
|||
* 设置 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setBoughtDate(DateTime boughtDate) { |
|||
this.boughtDate = DateUtil.format(boughtDate); |
|||
} |
|||
|
|||
[DataMember(Order = 3)] |
|||
private string name; |
|||
|
|||
/** |
|||
* @return |
|||
*/ |
|||
public string getName() { |
|||
return name; |
|||
} |
|||
|
|||
/** |
|||
* 设置 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setName(string name) { |
|||
this.name = name; |
|||
} |
|||
|
|||
[DataMember(Order = 4)] |
|||
private string builtArea; |
|||
|
|||
/** |
|||
* @return |
|||
*/ |
|||
public string getBuiltArea() { |
|||
return builtArea; |
|||
} |
|||
|
|||
/** |
|||
* 设置 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setBuiltArea(string builtArea) { |
|||
this.builtArea = builtArea; |
|||
} |
|||
|
|||
[DataMember(Order = 5)] |
|||
private string carNumber; |
|||
|
|||
/** |
|||
* @return |
|||
*/ |
|||
public string getCarNumber() { |
|||
return carNumber; |
|||
} |
|||
|
|||
/** |
|||
* 设置 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setCarNumber(string carNumber) { |
|||
this.carNumber = carNumber; |
|||
} |
|||
|
|||
[DataMember(Order = 6)] |
|||
private double? price; |
|||
|
|||
/** |
|||
* @return |
|||
*/ |
|||
public double? getPrice() { |
|||
return price; |
|||
} |
|||
|
|||
/** |
|||
* 设置 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setPrice(double price) { |
|||
this.price = price; |
|||
} |
|||
|
|||
[DataMember(Order = 7)] |
|||
private int? seats; |
|||
|
|||
/** |
|||
* @return |
|||
*/ |
|||
public int? getSeats() { |
|||
return seats; |
|||
} |
|||
|
|||
/** |
|||
* 设置 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setSeats(int seats) { |
|||
this.seats = seats; |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,144 @@ |
|||
using com.alibaba.openapi.client.primitive; |
|||
using com.alibaba.openapi.client.util; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Runtime.Serialization; |
|||
using System.Text; |
|||
|
|||
|
|||
namespace com.alibaba.china.openapi.client.example.param.apiexample |
|||
{ |
|||
[DataContract(Namespace = "com.alibaba.openapi.client")] |
|||
public class ExampleFamily |
|||
{ |
|||
|
|||
[DataMember(Order = 1)] |
|||
private int? familyNumber; |
|||
|
|||
/** |
|||
* @return 家庭编号 |
|||
*/ |
|||
public int? getFamilyNumber() |
|||
{ |
|||
return familyNumber; |
|||
} |
|||
|
|||
/** |
|||
* 设置家庭编号 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setFamilyNumber(int familyNumber) |
|||
{ |
|||
this.familyNumber = familyNumber; |
|||
} |
|||
|
|||
[DataMember(Order = 2)] |
|||
private ExamplePerson father; |
|||
|
|||
/** |
|||
* @return 父亲对象,可以为空 |
|||
*/ |
|||
public ExamplePerson getFather() |
|||
{ |
|||
return father; |
|||
} |
|||
|
|||
/** |
|||
* 设置父亲对象,可以为空 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setFather(ExamplePerson father) |
|||
{ |
|||
this.father = father; |
|||
} |
|||
|
|||
[DataMember(Order = 3)] |
|||
private ExamplePerson mother; |
|||
|
|||
/** |
|||
* @return 母亲对象,可以为空 |
|||
*/ |
|||
public ExamplePerson getMother() |
|||
{ |
|||
return mother; |
|||
} |
|||
|
|||
/** |
|||
* 设置母亲对象,可以为空 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setMother(ExamplePerson mother) |
|||
{ |
|||
this.mother = mother; |
|||
} |
|||
|
|||
[DataMember(Order = 4)] |
|||
private ExamplePerson[] children; |
|||
|
|||
/** |
|||
* @return 孩子列表 |
|||
*/ |
|||
public ExamplePerson[] getChildren() |
|||
{ |
|||
return children; |
|||
} |
|||
|
|||
/** |
|||
* 设置孩子列表 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setChildren(ExamplePerson[] children) |
|||
{ |
|||
this.children = children; |
|||
} |
|||
|
|||
[DataMember(Order = 5)] |
|||
private ExampleCar[] ownedCars; |
|||
|
|||
/** |
|||
* @return 拥有的汽车信息 |
|||
*/ |
|||
public ExampleCar[] getOwnedCars() |
|||
{ |
|||
return ownedCars; |
|||
} |
|||
|
|||
/** |
|||
* 设置拥有的汽车信息 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setOwnedCars(ExampleCar[] ownedCars) |
|||
{ |
|||
this.ownedCars = ownedCars; |
|||
} |
|||
|
|||
[DataMember(Order = 6)] |
|||
private ExampleHouse myHouse; |
|||
|
|||
/** |
|||
* @return 所住的房屋信息 |
|||
*/ |
|||
public ExampleHouse getMyHouse() |
|||
{ |
|||
return myHouse; |
|||
} |
|||
|
|||
/** |
|||
* 设置所住的房屋信息 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setMyHouse(ExampleHouse myHouse) |
|||
{ |
|||
this.myHouse = myHouse; |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,41 @@ |
|||
using com.alibaba.openapi.client.primitive; |
|||
using com.alibaba.openapi.client.util; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Runtime.Serialization; |
|||
using System.Text; |
|||
using com.alibaba.openapi.client; |
|||
|
|||
namespace com.alibaba.china.openapi.client.example.param.apiexample |
|||
{ |
|||
[DataContract(Namespace = "com.alibaba.openapi.client")] |
|||
public class ExampleFamilyGetParam : GatewayAPIRequest |
|||
{ |
|||
public ExampleFamilyGetParam() |
|||
{ |
|||
this.ApiId = new APIId("api.example", "example.family.get",1); |
|||
} |
|||
|
|||
[DataMember(Order = 1)] |
|||
private int? familyNumber; |
|||
|
|||
/** |
|||
* @return 可接受参数1或者2,其余参数无法找到family对象 |
|||
*/ |
|||
public int? getFamilyNumber() { |
|||
return familyNumber; |
|||
} |
|||
|
|||
/** |
|||
* 设置可接受参数1或者2,其余参数无法找到family对象 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setFamilyNumber(int familyNumber) { |
|||
this.familyNumber = familyNumber; |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,37 @@ |
|||
using com.alibaba.openapi.client.primitive; |
|||
using com.alibaba.openapi.client.util; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Runtime.Serialization; |
|||
using System.Text; |
|||
using com.alibaba.openapi.client; |
|||
|
|||
namespace com.alibaba.china.openapi.client.example.param.apiexample |
|||
{ |
|||
[DataContract(Namespace = "com.alibaba.openapi.client")] |
|||
public class ExampleFamilyGetResult : GatewayAPIResponse |
|||
{ |
|||
|
|||
[DataMember(Order = 1)] |
|||
private ExampleFamily result; |
|||
|
|||
/** |
|||
* @return |
|||
*/ |
|||
public ExampleFamily getResult() { |
|||
return result; |
|||
} |
|||
|
|||
/** |
|||
* 设置 * |
|||
|
|||
* 此参数必填 |
|||
*/ |
|||
public void setResult(ExampleFamily result) { |
|||
this.result = result; |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,81 @@ |
|||
using com.alibaba.openapi.client.primitive; |
|||
using com.alibaba.openapi.client.util; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Runtime.Serialization; |
|||
using System.Text; |
|||
|
|||
|
|||
namespace com.alibaba.china.openapi.client.example.param.apiexample |
|||
{ |
|||
[DataContract(Namespace = "com.alibaba.openapi.client")] |
|||
public class ExampleFamilyPostParam |
|||
{ |
|||
|
|||
[DataMember(Order = 1)] |
|||
private ExampleFamily family; |
|||
|
|||
/** |
|||
* @return 上传Family对象信息 |
|||
*/ |
|||
public ExampleFamily getFamily() |
|||
{ |
|||
return family; |
|||
} |
|||
|
|||
/** |
|||
* 设置上传Family对象信息 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setFamily(ExampleFamily family) |
|||
{ |
|||
this.family = family; |
|||
} |
|||
|
|||
[DataMember(Order = 2)] |
|||
private string comments; |
|||
|
|||
/** |
|||
* @return 备注信息 |
|||
*/ |
|||
public string getComments() |
|||
{ |
|||
return comments; |
|||
} |
|||
|
|||
/** |
|||
* 设置备注信息 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setComments(string comments) |
|||
{ |
|||
this.comments = comments; |
|||
} |
|||
|
|||
[DataMember(Order = 3)] |
|||
private byte[] houseImg; |
|||
|
|||
/** |
|||
* @return 房屋信息 |
|||
*/ |
|||
public byte[] getHouseImg() |
|||
{ |
|||
return houseImg; |
|||
} |
|||
|
|||
/** |
|||
* 设置房屋信息 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setHouseImg(byte[] houseImg) |
|||
{ |
|||
this.houseImg = houseImg; |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,56 @@ |
|||
using com.alibaba.openapi.client.primitive; |
|||
using com.alibaba.openapi.client.util; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Runtime.Serialization; |
|||
using System.Text; |
|||
|
|||
|
|||
namespace com.alibaba.china.openapi.client.example.param.apiexample |
|||
{ |
|||
[DataContract(Namespace = "com.alibaba.openapi.client")] |
|||
public class ExampleFamilyPostResult |
|||
{ |
|||
|
|||
[DataMember(Order = 1)] |
|||
private ExampleFamily result; |
|||
|
|||
/** |
|||
* @return 返回的接听信息 |
|||
*/ |
|||
public ExampleFamily getResult() { |
|||
return result; |
|||
} |
|||
|
|||
/** |
|||
* 设置返回的接听信息 * |
|||
|
|||
* 此参数必填 |
|||
*/ |
|||
public void setResult(ExampleFamily result) { |
|||
this.result = result; |
|||
} |
|||
|
|||
[DataMember(Order = 2)] |
|||
private string resultDesc; |
|||
|
|||
/** |
|||
* @return 返回结果描述 |
|||
*/ |
|||
public string getResultDesc() { |
|||
return resultDesc; |
|||
} |
|||
|
|||
/** |
|||
* 设置返回结果描述 * |
|||
|
|||
* 此参数必填 |
|||
*/ |
|||
public void setResultDesc(string resultDesc) { |
|||
this.resultDesc = resultDesc; |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,102 @@ |
|||
using com.alibaba.openapi.client.primitive; |
|||
using com.alibaba.openapi.client.util; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Runtime.Serialization; |
|||
using System.Text; |
|||
|
|||
|
|||
namespace com.alibaba.china.openapi.client.example.param.apiexample |
|||
{ |
|||
[DataContract(Namespace = "com.alibaba.openapi.client")] |
|||
public class ExampleHouse |
|||
{ |
|||
|
|||
[DataMember(Order = 1)] |
|||
private string location; |
|||
|
|||
/** |
|||
* @return |
|||
*/ |
|||
public string getLocation() |
|||
{ |
|||
return location; |
|||
} |
|||
|
|||
/** |
|||
* 设置 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setLocation(string location) |
|||
{ |
|||
this.location = location; |
|||
} |
|||
|
|||
[DataMember(Order = 2)] |
|||
private int? areaSize; |
|||
|
|||
/** |
|||
* @return |
|||
*/ |
|||
public int? getAreaSize() |
|||
{ |
|||
return areaSize; |
|||
} |
|||
|
|||
/** |
|||
* 设置 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setAreaSize(int areaSize) |
|||
{ |
|||
this.areaSize = areaSize; |
|||
} |
|||
|
|||
[DataMember(Order = 3)] |
|||
private bool? rent; |
|||
|
|||
/** |
|||
* @return |
|||
*/ |
|||
public bool? getRent() |
|||
{ |
|||
return rent; |
|||
} |
|||
|
|||
/** |
|||
* 设置 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setRent(bool rent) |
|||
{ |
|||
this.rent = rent; |
|||
} |
|||
|
|||
[DataMember(Order = 4)] |
|||
private int? rooms; |
|||
|
|||
/** |
|||
* @return |
|||
*/ |
|||
public int? getRooms() |
|||
{ |
|||
return rooms; |
|||
} |
|||
|
|||
/** |
|||
* 设置 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setRooms(int rooms) |
|||
{ |
|||
this.rooms = rooms; |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,99 @@ |
|||
using com.alibaba.openapi.client.primitive; |
|||
using com.alibaba.openapi.client.util; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Runtime.Serialization; |
|||
using System.Text; |
|||
|
|||
|
|||
namespace com.alibaba.china.openapi.client.example.param.apiexample |
|||
{ |
|||
[DataContract(Namespace = "com.alibaba.openapi.client")] |
|||
public class ExamplePerson |
|||
{ |
|||
|
|||
[DataMember(Order = 1)] |
|||
private string name; |
|||
|
|||
/** |
|||
* @return |
|||
*/ |
|||
public string getName() { |
|||
return name; |
|||
} |
|||
|
|||
/** |
|||
* 设置 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setName(string name) { |
|||
this.name = name; |
|||
} |
|||
|
|||
[DataMember(Order = 2)] |
|||
private int? age; |
|||
|
|||
/** |
|||
* @return |
|||
*/ |
|||
public int? getAge() { |
|||
return age; |
|||
} |
|||
|
|||
/** |
|||
* 设置 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setAge(int age) { |
|||
this.age = age; |
|||
} |
|||
|
|||
[DataMember(Order = 3)] |
|||
private string birthday; |
|||
|
|||
/** |
|||
* @return |
|||
*/ |
|||
public DateTime? getBirthday() { |
|||
if (birthday != null) |
|||
{ |
|||
DateTime datetime = DateUtil.formatFromStr(birthday); |
|||
return datetime; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
/** |
|||
* 设置 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setBirthday(DateTime birthday) { |
|||
this.birthday = DateUtil.format(birthday); |
|||
} |
|||
|
|||
[DataMember(Order = 4)] |
|||
private string mobileNumber; |
|||
|
|||
/** |
|||
* @return |
|||
*/ |
|||
public string getMobileNumber() { |
|||
return mobileNumber; |
|||
} |
|||
|
|||
/** |
|||
* 设置 * |
|||
* 参数示例:<pre></pre> |
|||
* 此参数必填 |
|||
*/ |
|||
public void setMobileNumber(string mobileNumber) { |
|||
this.mobileNumber = mobileNumber; |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,58 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Runtime.Serialization; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.exception |
|||
{ |
|||
public class OceanException : Exception |
|||
{ |
|||
public OceanException(string mess) |
|||
: base(mess) |
|||
{ |
|||
|
|||
} |
|||
public OceanException() |
|||
{ |
|||
|
|||
} |
|||
private string error_code; |
|||
|
|||
private string error_message; |
|||
|
|||
private string exception; |
|||
|
|||
public string getError_code() |
|||
{ |
|||
return this.error_code; |
|||
} |
|||
|
|||
public void setError_code(string error_code) |
|||
{ |
|||
this.error_code = error_code; |
|||
} |
|||
|
|||
public string getError_message() |
|||
{ |
|||
return this.error_message; |
|||
} |
|||
|
|||
public void setError_message(string error_message) |
|||
{ |
|||
this.error_message = error_message; |
|||
} |
|||
|
|||
public string getException() |
|||
{ |
|||
return this.exception; |
|||
} |
|||
|
|||
public void setException(String exception) |
|||
{ |
|||
this.exception = exception; |
|||
} |
|||
|
|||
} |
|||
} |
@ -0,0 +1,239 @@ |
|||
using BBWYB.Common.Http; |
|||
using com.alibaba.openapi.client.entity; |
|||
using com.alibaba.openapi.client.policy; |
|||
using com.alibaba.openapi.client.serialize; |
|||
using com.alibaba.openapi.client.util; |
|||
using Newtonsoft.Json.Linq; |
|||
using System.Net; |
|||
using System.Text; |
|||
using System.Web; |
|||
|
|||
namespace com.alibaba.openapi.client.http |
|||
{ |
|||
public class HttpClient |
|||
{ |
|||
private ClientPolicy clientPolicy; |
|||
private RestApiService restApiService; |
|||
private IDictionary<string, string> requestHeader; |
|||
|
|||
public HttpClient(ClientPolicy clientPolicy) |
|||
{ |
|||
this.clientPolicy = clientPolicy; |
|||
} |
|||
|
|||
public HttpClient(ClientPolicy clientPolicy, RestApiService restApiService) |
|||
{ |
|||
this.clientPolicy = clientPolicy; |
|||
this.restApiService = restApiService; |
|||
this.requestHeader = new Dictionary<string, string>() |
|||
{ |
|||
{ "User-Agent","Ocean/NET-SDKClient"} |
|||
}; |
|||
} |
|||
|
|||
public JObject NewRequest(Request request, RequestPolicy requestPolicy) |
|||
{ |
|||
StringBuilder path = createProtocolRequestPath(requestPolicy, request); |
|||
Dictionary<string, object> parameters = createParameterDictionary(requestPolicy, request); |
|||
signature(path.ToString(), parameters, requestPolicy, clientPolicy); |
|||
string paramString = createParameterStr(parameters); |
|||
Uri uri = new Uri(buildRequestUri(requestPolicy, request)); |
|||
|
|||
var result = restApiService.SendRequest($"{uri.Scheme}://{uri.Host}", |
|||
uri.LocalPath, |
|||
paramString, |
|||
requestHeader, |
|||
requestPolicy.HttpMethod.Equals("GET") ? HttpMethod.Get : HttpMethod.Post, |
|||
RestApiService.ContentType_Form); |
|||
if (result.StatusCode != HttpStatusCode.OK) |
|||
throw new Exception(result.Content.ToString()); |
|||
return JObject.Parse(result.Content); |
|||
} |
|||
|
|||
public T request<T>(Request request, RequestPolicy requestPolicy) |
|||
{ |
|||
StringBuilder path = createProtocolRequestPath(requestPolicy, request); |
|||
Dictionary<String, Object> parameters = createParameterDictionary(requestPolicy, request); |
|||
StringBuilder queryBuilder = new StringBuilder(); |
|||
signature(path.ToString(), parameters, requestPolicy, clientPolicy); |
|||
if ("GET".Equals(requestPolicy.HttpMethod)) |
|||
{ |
|||
|
|||
String queryString = createParameterStr(parameters); |
|||
String uriStr = buildRequestUri(requestPolicy, request); |
|||
uriStr = uriStr + "?" + queryString; |
|||
Uri uri = new Uri(uriStr); |
|||
HttpWebRequest httpWebRequest = WebRequest.Create(uri) as HttpWebRequest; |
|||
|
|||
httpWebRequest.Method = "GET"; |
|||
httpWebRequest.KeepAlive = false; |
|||
httpWebRequest.AllowAutoRedirect = true; |
|||
httpWebRequest.ContentType = "application/x-www-form-urlencoded"; |
|||
httpWebRequest.UserAgent = "Ocean/NET-SDKClient"; |
|||
|
|||
HttpWebResponse response = httpWebRequest.GetResponse() as HttpWebResponse; |
|||
Stream responseStream = response.GetResponseStream(); |
|||
|
|||
DeSerializer deSerializer = SerializerProvider.getInstance().getDeSerializer(requestPolicy.ResponseProtocol); |
|||
ResponseWrapper rw = deSerializer.deSerialize(responseStream, typeof(T), Encoding.UTF8.EncodingName); |
|||
return (T)rw.Result; |
|||
} |
|||
else |
|||
{ |
|||
String postString = createParameterStr(parameters); |
|||
byte[] postData = Encoding.UTF8.GetBytes(postString); |
|||
String uriStr = buildRequestUri(requestPolicy, request); |
|||
Uri uri = new Uri(uriStr); |
|||
HttpWebRequest httpWebRequest = WebRequest.Create(uri) as HttpWebRequest; |
|||
|
|||
httpWebRequest.Method = "POST"; |
|||
httpWebRequest.KeepAlive = false; |
|||
httpWebRequest.AllowAutoRedirect = true; |
|||
httpWebRequest.ContentType = "application/x-www-form-urlencoded"; |
|||
httpWebRequest.UserAgent = "Ocean/NET-SDKClient"; |
|||
httpWebRequest.ContentLength = postData.Length; |
|||
|
|||
System.IO.Stream outputStream = httpWebRequest.GetRequestStream(); |
|||
outputStream.Write(postData, 0, postData.Length); |
|||
outputStream.Close(); |
|||
try |
|||
{ |
|||
HttpWebResponse response = httpWebRequest.GetResponse() as HttpWebResponse; |
|||
Stream responseStream = response.GetResponseStream(); |
|||
|
|||
|
|||
DeSerializer deSerializer = SerializerProvider.getInstance().getDeSerializer(requestPolicy.ResponseProtocol); |
|||
ResponseWrapper rw = deSerializer.deSerialize(responseStream, typeof(T), Encoding.UTF8.EncodingName); |
|||
return (T)rw.Result; |
|||
} |
|||
catch (System.Net.WebException webException) |
|||
{ |
|||
HttpWebResponse response = webException.Response as HttpWebResponse; |
|||
Stream responseStream = response.GetResponseStream(); |
|||
DeSerializer deSerializer = SerializerProvider.getInstance().getDeSerializer(requestPolicy.ResponseProtocol); |
|||
Exception rw = deSerializer.buildException(responseStream, 500, Encoding.UTF8.EncodingName); |
|||
throw rw; |
|||
} |
|||
} |
|||
} |
|||
|
|||
private String buildRequestUri(RequestPolicy requestPolicy, Request request) |
|||
{ |
|||
String schema = "http"; |
|||
int port = clientPolicy.HttpPort; |
|||
if (requestPolicy.UseHttps) |
|||
{ |
|||
schema = "https"; |
|||
port = clientPolicy.HttpsPort; |
|||
} |
|||
StringBuilder relativeBuilder = new StringBuilder(schema); |
|||
relativeBuilder.Append("://"); |
|||
relativeBuilder.Append(clientPolicy.ServerHost); |
|||
if (port != 80 && port != 443) |
|||
{ |
|||
relativeBuilder.Append(":"); |
|||
relativeBuilder.Append(port); |
|||
} |
|||
|
|||
if (requestPolicy.AccessPrivateApi) |
|||
{ |
|||
relativeBuilder.Append("/api"); |
|||
} |
|||
else |
|||
{ |
|||
relativeBuilder.Append("/openapi"); |
|||
} |
|||
|
|||
relativeBuilder.Append("/"); |
|||
relativeBuilder.Append(createProtocolRequestPath(requestPolicy, request)); |
|||
return relativeBuilder.ToString(); |
|||
} |
|||
|
|||
private StringBuilder createProtocolRequestPath(RequestPolicy requestPolicy, Request request) |
|||
{ |
|||
|
|||
StringBuilder relativeBuilder = new StringBuilder(); |
|||
|
|||
relativeBuilder.Append(requestPolicy.RequestProtocol); |
|||
relativeBuilder.Append("/").Append(request.ApiId.Version); |
|||
relativeBuilder.Append("/").Append(request.ApiId.NamespaceValue); |
|||
relativeBuilder.Append("/").Append(request.ApiId.Name); |
|||
relativeBuilder.Append("/").Append(clientPolicy.AppKey); |
|||
return relativeBuilder; |
|||
|
|||
} |
|||
|
|||
private String createParameterStr(Dictionary<String, Object> parameters) |
|||
{ |
|||
StringBuilder paramBuilder = new StringBuilder(); |
|||
foreach (KeyValuePair<string, object> kvp in parameters) |
|||
{ |
|||
String encodedValue = null; |
|||
if (kvp.Value != null) |
|||
{ |
|||
String tempValue = kvp.Value.ToString(); |
|||
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(tempValue); |
|||
encodedValue = HttpUtility.UrlEncode(byteArray, 0, byteArray.Length); |
|||
} |
|||
paramBuilder.Append(kvp.Key).Append("=").Append(encodedValue); |
|||
paramBuilder.Append("&"); |
|||
} |
|||
return paramBuilder.ToString(); |
|||
} |
|||
|
|||
private Dictionary<String, Object> createParameterDictionary(RequestPolicy requestPolicy, Request request) |
|||
{ |
|||
|
|||
Serializer serializer = SerializerProvider.getInstance().getSerializer(requestPolicy.RequestProtocol); |
|||
|
|||
Dictionary<String, Object> parameters = serializer.serialize(request.RequestEntity); |
|||
if (!requestPolicy.RequestProtocol.Equals(requestPolicy.ResponseProtocol)) |
|||
{ |
|||
parameters.Add("_aop_responseFormat", requestPolicy.ResponseProtocol); |
|||
} |
|||
if (requestPolicy.RequestSendTimestamp) |
|||
{ |
|||
parameters.Add("_aop_timestamp", DateUtil.currentTimeMillis()); |
|||
} |
|||
parameters.Add("_aop_datePattern", DateUtil.getDatePattern()); |
|||
foreach (KeyValuePair<string, object> kvp in request.AddtionalParams) |
|||
{ |
|||
parameters.Add(kvp.Key, kvp.Value); |
|||
} |
|||
if (request.AccessToken != null) |
|||
{ |
|||
parameters.Add("access_token", request.AccessToken); |
|||
} |
|||
return parameters; |
|||
} |
|||
|
|||
private void signature(String path, Dictionary<String, Object> parameters, RequestPolicy requestPolicy, ClientPolicy clientPolicy) |
|||
{ |
|||
if (!requestPolicy.UseSignture) |
|||
{ |
|||
return; |
|||
} |
|||
if (clientPolicy.AppKey == null |
|||
|| clientPolicy.SecretKey == null) |
|||
{ |
|||
return; |
|||
} |
|||
byte[] sign = SignatureUtil.hmacSha1(path, parameters, clientPolicy.SecretKey); |
|||
String signStr = SignatureUtil.toHex(sign); |
|||
if (signStr != null) |
|||
{ |
|||
parameters.Add("_aop_signature", signStr); |
|||
} |
|||
} |
|||
|
|||
|
|||
private WebClient createWebClient() |
|||
{ |
|||
|
|||
WebClient client = new WebClient(); |
|||
client.Headers.Add("user-agent", "Ocean/SDK Client"); |
|||
|
|||
return client; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,70 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.policy |
|||
{ |
|||
public class ClientPolicy |
|||
{ |
|||
private string serverHost = "gw.open.1688.com"; |
|||
|
|||
public string ServerHost |
|||
{ |
|||
get { return serverHost; } |
|||
set { serverHost = value; } |
|||
} |
|||
private int httpPort = 80; |
|||
|
|||
public int HttpPort |
|||
{ |
|||
get { return httpPort; } |
|||
set { httpPort = value; } |
|||
} |
|||
private int httpsPort = 443; |
|||
|
|||
public int HttpsPort |
|||
{ |
|||
get { return httpsPort; } |
|||
set { httpsPort = value; } |
|||
} |
|||
private string appKey; |
|||
|
|||
public string AppKey |
|||
{ |
|||
get { return appKey; } |
|||
set { appKey = value; } |
|||
} |
|||
private string secretKey; |
|||
|
|||
public string SecretKey |
|||
{ |
|||
get { return secretKey; } |
|||
set { secretKey = value; } |
|||
} |
|||
private int defaultTimeout = 5000; |
|||
|
|||
public int DefaultTimeout |
|||
{ |
|||
get { return defaultTimeout; } |
|||
set { defaultTimeout = value; } |
|||
} |
|||
private string defaultContentCharset = "UTF-8"; |
|||
|
|||
public string DefaultContentCharset |
|||
{ |
|||
get { return defaultContentCharset; } |
|||
set { defaultContentCharset = value; } |
|||
} |
|||
private bool defaultUseHttps = true; |
|||
|
|||
public bool DefaultUseHttps |
|||
{ |
|||
get { return defaultUseHttps; } |
|||
set { defaultUseHttps = value; } |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,17 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.policy |
|||
{ |
|||
public class GrantType |
|||
{ |
|||
public const string refresh_token="refresh_token"; |
|||
/** |
|||
* 请求参数通过json串的方式传递,默认格式_data_={"key":"value"} |
|||
*/ |
|||
public const string get_token = "get_token"; |
|||
} |
|||
} |
@ -0,0 +1,26 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.policy |
|||
{ |
|||
public class Protocol |
|||
{ |
|||
public const string param2 = "param2"; |
|||
/** |
|||
* 请求参数通过json串的方式传递,默认格式_data_={"key":"value"} |
|||
*/ |
|||
public const string json2 = "json2"; |
|||
/** |
|||
* |
|||
* 请求参数通过xml的方式传递,默认格式_data_=<test>data</test> |
|||
*/ |
|||
public const string xml2 = "xml2"; |
|||
public const string param = "param"; |
|||
public const string json = "json"; |
|||
public const string xml = "xml"; |
|||
public const string http = "http"; |
|||
} |
|||
} |
@ -0,0 +1,113 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.policy |
|||
{ |
|||
public class RequestPolicy |
|||
{ |
|||
private bool requestSendTimestamp = false; |
|||
|
|||
public bool RequestSendTimestamp |
|||
{ |
|||
get { return requestSendTimestamp; } |
|||
set { requestSendTimestamp = value; } |
|||
} |
|||
private bool useHttps = false; |
|||
|
|||
public bool UseHttps |
|||
{ |
|||
get { return useHttps; } |
|||
set { useHttps = value; } |
|||
} |
|||
private string requestProtocol = Protocol.param2; |
|||
|
|||
internal string RequestProtocol |
|||
{ |
|||
get { return requestProtocol; } |
|||
set { requestProtocol = value; } |
|||
} |
|||
private string responseProtocol = Protocol.json2; |
|||
|
|||
internal string ResponseProtocol |
|||
{ |
|||
get { return responseProtocol; } |
|||
set { responseProtocol = value; } |
|||
} |
|||
private bool responseCompress = true; |
|||
|
|||
public bool ResponseCompress |
|||
{ |
|||
get { return responseCompress; } |
|||
set { responseCompress = value; } |
|||
} |
|||
private int requestCompressThreshold = -1; |
|||
|
|||
public int RequestCompressThreshold |
|||
{ |
|||
get { return requestCompressThreshold; } |
|||
set { requestCompressThreshold = value; } |
|||
} |
|||
private int timeout = 5000; |
|||
|
|||
public int Timeout |
|||
{ |
|||
get { return timeout; } |
|||
set { timeout = value; } |
|||
} |
|||
private string httpMethod = "POST"; |
|||
|
|||
public string HttpMethod |
|||
{ |
|||
get { return httpMethod; } |
|||
set { httpMethod = value; } |
|||
} |
|||
private String queryStringCharset = "GB18030"; |
|||
|
|||
public String QueryStringCharset |
|||
{ |
|||
get { return queryStringCharset; } |
|||
set { queryStringCharset = value; } |
|||
} |
|||
private String contentCharset = "UTF-8"; |
|||
|
|||
public String ContentCharset |
|||
{ |
|||
get { return contentCharset; } |
|||
set { contentCharset = value; } |
|||
} |
|||
private bool useSignture = true; |
|||
|
|||
public bool UseSignture |
|||
{ |
|||
get { return useSignture; } |
|||
set { useSignture = value; } |
|||
} |
|||
private bool needAuthorization = false; |
|||
|
|||
public bool NeedAuthorization |
|||
{ |
|||
get { return needAuthorization; } |
|||
set { needAuthorization = value; } |
|||
} |
|||
private bool accessPrivateApi = false; |
|||
|
|||
public bool AccessPrivateApi |
|||
{ |
|||
get { return accessPrivateApi; } |
|||
set { accessPrivateApi = value; } |
|||
} |
|||
private int defaultApiVersion = 1; |
|||
|
|||
public int DefaultApiVersion |
|||
{ |
|||
get { return defaultApiVersion; } |
|||
set { defaultApiVersion = value; } |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.primitive |
|||
{ |
|||
public class NullableBool : NullablePrimitiveObject |
|||
{ |
|||
public NullableBool(bool value) |
|||
{ |
|||
this.value = value; |
|||
this.isNull = false; |
|||
} |
|||
|
|||
bool value; |
|||
private Boolean isNull = true; |
|||
|
|||
public Boolean IsNull |
|||
{ |
|||
get { return isNull; } |
|||
} |
|||
|
|||
public void setValue(bool value) |
|||
{ |
|||
this.value = value; |
|||
this.isNull = false; |
|||
} |
|||
|
|||
public bool getValue() |
|||
{ |
|||
return this.value; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.primitive |
|||
{ |
|||
public class NullableByte : NullablePrimitiveObject |
|||
{ |
|||
public NullableByte(byte value) |
|||
{ |
|||
this.value = value; |
|||
this.isNull = false; |
|||
} |
|||
|
|||
byte value; |
|||
private Boolean isNull; |
|||
|
|||
public Boolean IsNull |
|||
{ |
|||
get { return isNull; } |
|||
} |
|||
|
|||
public void setValue(byte value) |
|||
{ |
|||
this.value = value; |
|||
this.isNull = false; |
|||
} |
|||
|
|||
public byte getValue() |
|||
{ |
|||
return this.value; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.primitive |
|||
{ |
|||
public class NullableChar : NullablePrimitiveObject |
|||
{ |
|||
public NullableChar(char value) |
|||
{ |
|||
this.value = value; |
|||
this.isNull = false; |
|||
} |
|||
|
|||
char value; |
|||
private Boolean isNull = true; |
|||
|
|||
public Boolean IsNull |
|||
{ |
|||
get { return isNull; } |
|||
} |
|||
|
|||
public void setValue(char value) |
|||
{ |
|||
this.value = value; |
|||
this.isNull = false; |
|||
} |
|||
|
|||
public char getValue() |
|||
{ |
|||
return this.value; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.primitive |
|||
{ |
|||
public class NullableDateTime : NullablePrimitiveObject |
|||
{ |
|||
public NullableDateTime(DateTime value) |
|||
{ |
|||
this.value = value; |
|||
this.isNull = false; |
|||
} |
|||
|
|||
DateTime value; |
|||
private Boolean isNull; |
|||
|
|||
public Boolean IsNull |
|||
{ |
|||
get { return isNull; } |
|||
} |
|||
|
|||
public void setValue(DateTime value) |
|||
{ |
|||
this.value = value; |
|||
this.isNull = false; |
|||
} |
|||
|
|||
public DateTime getValue() |
|||
{ |
|||
return this.value; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.primitive |
|||
{ |
|||
public class NullableDouble : NullablePrimitiveObject |
|||
{ |
|||
public NullableDouble(double value) |
|||
{ |
|||
this.value = value; |
|||
this.isNull = false; |
|||
} |
|||
|
|||
double value; |
|||
private Boolean isNull; |
|||
|
|||
public Boolean IsNull |
|||
{ |
|||
get { return isNull; } |
|||
} |
|||
|
|||
public void setValue(double value) |
|||
{ |
|||
this.value = value; |
|||
this.isNull = false; |
|||
} |
|||
|
|||
public double getValue() |
|||
{ |
|||
return this.value; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.primitive |
|||
{ |
|||
public class NullableFloat : NullablePrimitiveObject |
|||
{ |
|||
public NullableFloat(float value) |
|||
{ |
|||
this.value = value; |
|||
this.isNull = false; |
|||
} |
|||
|
|||
float value; |
|||
private Boolean isNull; |
|||
|
|||
public Boolean IsNull |
|||
{ |
|||
get { return isNull; } |
|||
} |
|||
|
|||
public void setValue(float value) |
|||
{ |
|||
this.value = value; |
|||
this.isNull = false; |
|||
} |
|||
|
|||
public float getValue() |
|||
{ |
|||
return this.value; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.primitive |
|||
{ |
|||
public class NullableInt : NullablePrimitiveObject |
|||
{ |
|||
public NullableInt(int value) |
|||
{ |
|||
this.value = value; |
|||
this.isNull = false; |
|||
} |
|||
|
|||
int value; |
|||
private Boolean isNull; |
|||
|
|||
public Boolean IsNull |
|||
{ |
|||
get { return isNull; } |
|||
} |
|||
|
|||
public void setValue(int value) |
|||
{ |
|||
this.value = value; |
|||
this.isNull = false; |
|||
} |
|||
|
|||
public int getValue() |
|||
{ |
|||
return this.value; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.primitive |
|||
{ |
|||
public class NullableLong : NullablePrimitiveObject |
|||
{ |
|||
public NullableLong(long value) |
|||
{ |
|||
this.value = value; |
|||
this.isNull = false; |
|||
} |
|||
|
|||
long value; |
|||
private Boolean isNull; |
|||
|
|||
public Boolean IsNull |
|||
{ |
|||
get { return isNull; } |
|||
} |
|||
|
|||
public void setValue(long value) |
|||
{ |
|||
this.value = value; |
|||
this.isNull = false; |
|||
} |
|||
|
|||
public long getValue() |
|||
{ |
|||
return this.value; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,12 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.primitive |
|||
{ |
|||
public class NullablePrimitiveObject |
|||
{ |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
using com.alibaba.openapi.client.entity; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.serialize |
|||
{ |
|||
public interface DeSerializer |
|||
{ |
|||
//返回该反序列化接口支持的数据协议.
|
|||
String supportedContentType(); |
|||
|
|||
ResponseWrapper deSerialize(Stream istream, Type resultType, String charSet); |
|||
|
|||
Exception buildException(Stream inputStream, int statusCode, String charSet); |
|||
|
|||
} |
|||
} |
@ -0,0 +1,56 @@ |
|||
using com.alibaba.openapi.client.entity; |
|||
using com.alibaba.openapi.client.exception; |
|||
using com.alibaba.openapi.client.policy; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Runtime.Serialization.Json; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.serialize |
|||
{ |
|||
public class Json2Deserializer : DeSerializer |
|||
{ |
|||
//返回该反序列化接口支持的数据协议.
|
|||
public String supportedContentType() |
|||
{ |
|||
return Protocol.json2; |
|||
} |
|||
|
|||
public ResponseWrapper deSerialize(Stream istream, Type resultType, String charSet) |
|||
{ |
|||
StreamReader sr = new StreamReader(istream, Encoding.UTF8); |
|||
string strhtml = sr.ReadToEnd(); |
|||
using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(strhtml))) |
|||
{ |
|||
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(resultType); |
|||
object result = jsonSerializer.ReadObject(ms); |
|||
ResponseWrapper responseWrapper = new ResponseWrapper(); |
|||
responseWrapper.Result = result; |
|||
|
|||
return responseWrapper; |
|||
} |
|||
} |
|||
|
|||
public Exception buildException(Stream istream, int statusCode, String charSet) |
|||
{ |
|||
|
|||
|
|||
//istream.Position = 0;
|
|||
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(ErrorExceptionDesc)); |
|||
object resultObj = jsonSerializer.ReadObject(istream); |
|||
ErrorExceptionDesc result = (ErrorExceptionDesc)resultObj; |
|||
String errorCodeStr = result.getError_code(); |
|||
String errorMesage = result.getError_message(); |
|||
|
|||
OceanException oceanException = new OceanException(errorMesage); |
|||
oceanException.setError_code(errorCodeStr); |
|||
oceanException.setError_message(errorMesage); |
|||
return oceanException; |
|||
|
|||
|
|||
} |
|||
} |
|||
} |
@ -0,0 +1,137 @@ |
|||
using com.alibaba.openapi.client.policy; |
|||
using com.alibaba.openapi.client.primitive; |
|||
using com.alibaba.openapi.client.util; |
|||
using Newtonsoft.Json; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Globalization; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using System.Runtime.Serialization.Json; |
|||
using System.Text; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.serialize |
|||
{ |
|||
public class Param2RequestSerializer : Serializer |
|||
{ |
|||
public String supportedContentType() |
|||
{ |
|||
return Protocol.param2; |
|||
} |
|||
|
|||
public Dictionary<String, Object> serialize(Object serializer) |
|||
{ |
|||
//Dictionary<String, Object> result = serializeNest(serializer);
|
|||
//return result;
|
|||
return serializeParam(serializer); |
|||
} |
|||
|
|||
private Dictionary<String, Object> serializeNest(Object serializer) |
|||
{ |
|||
Dictionary<String, Object> result = new Dictionary<String, Object>(); |
|||
if (serializer == null) |
|||
{ |
|||
return result; |
|||
} |
|||
Type type = serializer.GetType(); |
|||
|
|||
IEnumerable<FieldInfo> fis = type.GetRuntimeFields(); |
|||
TextInfo tInfo = Thread.CurrentThread.CurrentCulture.TextInfo; |
|||
|
|||
foreach (FieldInfo fi in fis) |
|||
{ |
|||
Type fieldType = fi.FieldType; |
|||
|
|||
String piName = fi.Name; |
|||
String firstCharacter = piName.Substring(0, 1); |
|||
String upperFirstCharacter = firstCharacter.ToUpper(Thread.CurrentThread.CurrentCulture); |
|||
String tempName = upperFirstCharacter + piName.Substring(1); |
|||
if (!"ApiId".Equals(tempName)) |
|||
{ |
|||
MethodInfo mi = type.GetMethod("get" + tempName); |
|||
object value = mi.Invoke(serializer, null); |
|||
if (value != null) |
|||
{ |
|||
object trueValue = null; |
|||
if (fieldType.IsAssignableFrom(typeof(bool?)) |
|||
|| fieldType.IsAssignableFrom(typeof(byte?)) |
|||
|| fieldType.IsAssignableFrom(typeof(char?)) |
|||
|| fieldType.IsAssignableFrom(typeof(double?)) |
|||
|| fieldType.IsAssignableFrom(typeof(float?)) |
|||
|| fieldType.IsAssignableFrom(typeof(int?)) |
|||
|| fieldType.IsAssignableFrom(typeof(long?))) |
|||
{ |
|||
trueValue = value; |
|||
} |
|||
else if (fieldType.IsAssignableFrom(typeof(String))) |
|||
{ |
|||
if (value.GetType().IsAssignableFrom(typeof(DateTime))) |
|||
{ |
|||
DateTime dateTime = (DateTime)value; |
|||
trueValue = DateUtil.formatForOcean(dateTime); |
|||
} |
|||
else |
|||
{ |
|||
trueValue = value; |
|||
} |
|||
} |
|||
else if (fieldType.IsAssignableFrom(typeof(DateTime?))) |
|||
{ |
|||
DateTime dateTime = (DateTime)value; |
|||
trueValue = DateUtil.format(dateTime); |
|||
} |
|||
else if (fieldType.IsAssignableFrom(typeof(Byte[])) || fieldType.IsAssignableFrom(typeof(byte[]))) |
|||
{ |
|||
trueValue = Convert.ToBase64String((byte[])value); |
|||
} |
|||
else |
|||
{ |
|||
DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(fieldType); |
|||
MemoryStream stream = new MemoryStream(); |
|||
dataContractJsonSerializer.WriteObject(stream, value); |
|||
byte[] dataBytes = new byte[stream.Length]; |
|||
stream.Position = 0; |
|||
stream.Read(dataBytes, 0, (int)stream.Length); |
|||
|
|||
string dataString = Encoding.UTF8.GetString(dataBytes); |
|||
trueValue = dataString; |
|||
} |
|||
result.Add(piName, trueValue); |
|||
} |
|||
|
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
private Dictionary<string, object> serializeParam(object param) |
|||
{ |
|||
Dictionary<string, object> result = new Dictionary<string, object>(); |
|||
Type type = param.GetType(); |
|||
var properties = type.GetProperties(); |
|||
foreach (var property in properties) |
|||
{ |
|||
var value = property.GetValue(param); |
|||
var valueType = value.GetType(); |
|||
if (valueType.IsAssignableFrom(typeof(string)) || |
|||
valueType.IsAssignableFrom(typeof(bool?)) || |
|||
valueType.IsAssignableFrom(typeof(byte?)) || |
|||
valueType.IsAssignableFrom(typeof(char?)) || |
|||
valueType.IsAssignableFrom(typeof(double?)) || |
|||
valueType.IsAssignableFrom(typeof(float?)) || |
|||
valueType.IsAssignableFrom(typeof(int?)) || |
|||
valueType.IsAssignableFrom(typeof(long?))) |
|||
result.Add(property.Name, value); |
|||
else |
|||
{ |
|||
result.Add(property.Name, JsonConvert.SerializeObject(value)); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
} |
|||
} |
@ -0,0 +1,18 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.serialize |
|||
{ |
|||
public interface Serializer |
|||
{ |
|||
|
|||
//返回该反序列化接口支持的数据协议.
|
|||
String supportedContentType(); |
|||
|
|||
//序列化方法
|
|||
Dictionary<String, Object> serialize(Object serializer); |
|||
} |
|||
} |
@ -0,0 +1,60 @@ |
|||
using com.alibaba.openapi.client.policy; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.serialize |
|||
{ |
|||
public class SerializerProvider |
|||
{ |
|||
private static SerializerProvider instance; |
|||
private static Object lockObject=new Object(); |
|||
public static SerializerProvider getInstance() |
|||
{ |
|||
if (instance == null) |
|||
{ |
|||
lock (lockObject) |
|||
{ |
|||
if (instance == null) |
|||
{ |
|||
instance = new SerializerProvider(); |
|||
instance.initial(); |
|||
} |
|||
} |
|||
} |
|||
return instance; |
|||
} |
|||
|
|||
private SerializerProvider() |
|||
{ |
|||
|
|||
} |
|||
|
|||
private void initial() |
|||
{ |
|||
serializerStore.Add(Protocol.param2, new Param2RequestSerializer()); |
|||
deSerializerStore.Add(Protocol.param2, new Json2Deserializer()); |
|||
deSerializerStore.Add(Protocol.json2, new Json2Deserializer()); |
|||
} |
|||
|
|||
private Dictionary<String, Serializer> serializerStore = new Dictionary<String, Serializer>(); |
|||
|
|||
public Serializer getSerializer(String contentType) |
|||
{ |
|||
return serializerStore[contentType]; |
|||
} |
|||
|
|||
private Dictionary<String, DeSerializer> deSerializerStore = new Dictionary<String, DeSerializer>(); |
|||
|
|||
public DeSerializer getDeSerializer(String contentType) |
|||
{ |
|||
return deSerializerStore[contentType]; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,66 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Globalization; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.util |
|||
{ |
|||
public class DateUtil |
|||
{ |
|||
//这里定义两个日期格式,由于.Net平台的毫秒格式用fff表示,Ocean平台(Java)的毫秒格式用SSS表示。
|
|||
private static string Date_Pattern = "yyyyMMddHHmmssfff"; |
|||
|
|||
private static string Date_PatternForOcean = "yyyyMMddHHmmssSSS"; |
|||
|
|||
|
|||
public static String getDatePattern() |
|||
{ |
|||
return Date_PatternForOcean; |
|||
} |
|||
|
|||
public static String format(DateTime date) |
|||
{ |
|||
return date.ToString(Date_Pattern); |
|||
} |
|||
|
|||
public static String formatForOcean(DateTime date) |
|||
{ |
|||
String value = date.ToString("yyyyMMddHHmmssfffzzz"); |
|||
String newValue = value.Replace(":", ""); |
|||
return newValue; |
|||
} |
|||
|
|||
public static DateTime formatFromStr(String dateDesc) |
|||
{ |
|||
if (dateDesc.Contains("+") || dateDesc.Contains("-")) |
|||
{ |
|||
try |
|||
{ |
|||
IFormatProvider culture = new CultureInfo("zh-CN", true); |
|||
DateTime datetime = DateTime.ParseExact(dateDesc, "yyyyMMddHHmmssfffzzz", culture); |
|||
return datetime; |
|||
} |
|||
catch (Exception x) |
|||
{ |
|||
String message = x.Message; |
|||
} |
|||
} |
|||
IFormatProvider newculture = new CultureInfo("zh-CN", true); |
|||
DateTime newdatetime = DateTime.ParseExact(dateDesc, Date_Pattern, newculture); |
|||
return newdatetime; |
|||
} |
|||
|
|||
|
|||
|
|||
public static long currentTimeMillis() |
|||
{ |
|||
System.DateTime current = new DateTime(); |
|||
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); |
|||
double ms = (current - startTime).TotalMilliseconds; |
|||
long b = Convert.ToInt64(ms); |
|||
return b; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,74 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Security.Cryptography; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace com.alibaba.openapi.client.util |
|||
{ |
|||
public class SignatureUtil |
|||
{ |
|||
public static byte[] hmacSha1(String path, Dictionary<String, Object> parameters, String signingKey) |
|||
{ |
|||
List<String> lists = new List<String>(); |
|||
foreach (KeyValuePair<string, object> kvp in parameters) |
|||
{ |
|||
lists.Add(kvp.Key + kvp.Value); |
|||
} |
|||
lists.Sort(StringComparer.Ordinal); |
|||
StringBuilder sb = new StringBuilder(); |
|||
sb.Append(path); |
|||
foreach (String param in lists) |
|||
{ |
|||
sb.Append(param); |
|||
} |
|||
String contentToHmac = sb.ToString(); |
|||
byte[] byteToHmac = System.Text.Encoding.UTF8.GetBytes(contentToHmac); |
|||
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(signingKey); |
|||
HMACSHA1 hmac = new HMACSHA1(byteArray); |
|||
byte[] hashValue = hmac.ComputeHash(byteToHmac, 0, byteToHmac.Length); |
|||
return hashValue; |
|||
} |
|||
|
|||
public static string toHex( byte[] bytes) |
|||
{ |
|||
char[] c = new char[bytes.Length * 2]; |
|||
|
|||
byte b; |
|||
|
|||
for (int bx = 0, cx = 0; bx < bytes.Length; ++bx, ++cx) |
|||
{ |
|||
b = ((byte)(bytes[bx] >> 4)); |
|||
c[cx] = (char)(b > 9 ? b + 0x37 + 0x20 : b + 0x30); |
|||
|
|||
b = ((byte)(bytes[bx] & 0x0F)); |
|||
c[++cx] = (char)(b > 9 ? b + 0x37 + 0x20 : b + 0x30); |
|||
} |
|||
|
|||
return new string(c).ToUpper(); |
|||
} |
|||
|
|||
public static byte[] hexToBytes( string str) |
|||
{ |
|||
if (str.Length == 0 || str.Length % 2 != 0) |
|||
return new byte[0]; |
|||
|
|||
byte[] buffer = new byte[str.Length / 2]; |
|||
char c; |
|||
for (int bx = 0, sx = 0; bx < buffer.Length; ++bx, ++sx) |
|||
{ |
|||
// Convert first half of byte
|
|||
c = str[sx]; |
|||
buffer[bx] = (byte)((c > '9' ? (c > 'Z' ? (c - 'a' + 10) : (c - 'A' + 10)) : (c - '0')) << 4); |
|||
|
|||
// Convert second half of byte
|
|||
c = str[++sx]; |
|||
buffer[bx] |= (byte)(c > '9' ? (c > 'Z' ? (c - 'a' + 10) : (c - 'A' + 10)) : (c - '0')); |
|||
} |
|||
|
|||
return buffer; |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue