Browse Source

1688sdk对接

qianyi
shanji 3 years ago
parent
commit
905d664a34
  1. 39
      BBWY.1688SDK/APIFacade.cs
  2. 43
      BBWY.1688SDK/APIId.cs
  3. 23
      BBWY.1688SDK/GatewayAPIRequest.cs
  4. 14
      BBWY.1688SDK/GatewayAPIResponse.cs
  5. 66
      BBWY.1688SDK/Request.cs
  6. 56
      BBWY.1688SDK/Response.cs
  7. 99
      BBWY.1688SDK/SyncAPIClient.cs
  8. 159
      BBWY.1688SDK/entity/AuthorizationToken.cs
  9. 35
      BBWY.1688SDK/entity/ErrorExceptionDesc.cs
  10. 49
      BBWY.1688SDK/entity/OrderPreview/CreateOrderPreview.cs
  11. 28
      BBWY.1688SDK/entity/ResponseStatus.cs
  12. 40
      BBWY.1688SDK/entity/ResponseWrapper.cs
  13. 88
      BBWY.1688SDK/example/ExampleFacade.cs
  14. 160
      BBWY.1688SDK/example/param/apiexample/ExampleCar.cs
  15. 132
      BBWY.1688SDK/example/param/apiexample/ExampleFamily.cs
  16. 41
      BBWY.1688SDK/example/param/apiexample/ExampleFamilyGetParam.cs
  17. 37
      BBWY.1688SDK/example/param/apiexample/ExampleFamilyGetResult.cs
  18. 75
      BBWY.1688SDK/example/param/apiexample/ExampleFamilyPostParam.cs
  19. 56
      BBWY.1688SDK/example/param/apiexample/ExampleFamilyPostResult.cs
  20. 94
      BBWY.1688SDK/example/param/apiexample/ExampleHouse.cs
  21. 99
      BBWY.1688SDK/example/param/apiexample/ExamplePerson.cs
  22. 58
      BBWY.1688SDK/exception/OceanException.cs
  23. 213
      BBWY.1688SDK/http/HttpClient.cs
  24. 70
      BBWY.1688SDK/policy/ClientPolicy.cs
  25. 17
      BBWY.1688SDK/policy/GrantType.cs
  26. 26
      BBWY.1688SDK/policy/Protocol.cs
  27. 113
      BBWY.1688SDK/policy/RequestPolicy.cs
  28. 36
      BBWY.1688SDK/primitive/NullableBool.cs
  29. 36
      BBWY.1688SDK/primitive/NullableByte.cs
  30. 36
      BBWY.1688SDK/primitive/NullableChar.cs
  31. 36
      BBWY.1688SDK/primitive/NullableDateTime.cs
  32. 36
      BBWY.1688SDK/primitive/NullableDouble.cs
  33. 36
      BBWY.1688SDK/primitive/NullableFloat.cs
  34. 36
      BBWY.1688SDK/primitive/NullableInt.cs
  35. 36
      BBWY.1688SDK/primitive/NullableLong.cs
  36. 12
      BBWY.1688SDK/primitive/NullablePrimitiveObject.cs
  37. 21
      BBWY.1688SDK/serialize/DeSerializer.cs
  38. 56
      BBWY.1688SDK/serialize/Json2Deserializer.cs
  39. 109
      BBWY.1688SDK/serialize/Param2RequestSerializer.cs
  40. 18
      BBWY.1688SDK/serialize/Serializer.cs
  41. 60
      BBWY.1688SDK/serialize/SerializerProvider.cs
  42. 66
      BBWY.1688SDK/util/DateUtil.cs
  43. 74
      BBWY.1688SDK/util/SignatureUtil.cs
  44. 11
      BBWY.Server.API/Controllers/PlatformSDKController.cs
  45. 1
      BBWY.Server.API/Startup.cs
  46. 1
      BBWY.Server.Business/BBWY.Server.Business.csproj
  47. 2
      BBWY.Server.Business/PlatformSDK/JDBusiness.cs
  48. 7
      BBWY.Server.Business/PlatformSDK/PDDBusiness.cs
  49. 14
      BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs
  50. 7
      BBWY.Server.Business/PlatformSDK/TaoBaoBusiness.cs
  51. 85
      BBWY.Server.Business/PlatformSDK/_1688Business.cs
  52. 14
      BBWY.Server.Model/Dto/Request/PurchaseOrder/OnlinePurchase/CargoParamRequest.cs
  53. 43
      BBWY.Server.Model/Dto/Request/PurchaseOrder/OnlinePurchase/ConsigneeRequest.cs
  54. 11
      BBWY.Server.Model/Dto/Request/PurchaseOrder/OnlinePurchase/PreviewOrderReuqest.cs
  55. 20
      BBWY.Server.Model/Dto/Response/PurchaseOrder/OnlinePurchase/PreviewOrderResponse.cs

39
BBWY.1688SDK/APIFacade.cs

@ -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);
}
}
}

43
BBWY.1688SDK/APIId.cs

@ -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; }
}
}
}

23
BBWY.1688SDK/GatewayAPIRequest.cs

@ -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; }
}
}
}

14
BBWY.1688SDK/GatewayAPIResponse.cs

@ -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
{
}
}

66
BBWY.1688SDK/Request.cs

@ -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; }
}
}
}

56
BBWY.1688SDK/Response.cs

@ -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; }
}
}
}

99
BBWY.1688SDK/SyncAPIClient.cs

@ -0,0 +1,99 @@
using com.alibaba.openapi.client.entity;
using com.alibaba.openapi.client.http;
using com.alibaba.openapi.client.policy;
using System;
namespace com.alibaba.openapi.client
{
public class SyncAPIClient
{
private ClientPolicy clientPolicy;
public SyncAPIClient(String appKey, String appSecret)
{
this.clientPolicy = new ClientPolicy();
this.clientPolicy.AppKey = appKey;
this.clientPolicy.SecretKey = appSecret;
}
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 T send<T>(Request request, RequestPolicy policy)
{
HttpClient httpClient = new HttpClient(clientPolicy);
T result = httpClient.request<T>(request, policy);
return result;
}
public Res execute<Res>(GatewayAPIRequest gatewayAPIRequest, String accessToken)
{
HttpClient httpClient = new 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);
}
}
}

159
BBWY.1688SDK/entity/AuthorizationToken.cs

@ -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;
}
}
}

35
BBWY.1688SDK/entity/ErrorExceptionDesc.cs

@ -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;
}
}
}

49
BBWY.1688SDK/entity/OrderPreview/CreateOrderPreview.cs

@ -0,0 +1,49 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace BBWY._1688SDK.entity.OrderPreview
{
[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; }
}
}

28
BBWY.1688SDK/entity/ResponseStatus.cs

@ -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; }
}
}
}

40
BBWY.1688SDK/entity/ResponseWrapper.cs

@ -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; }
}
}
}

88
BBWY.1688SDK/example/ExampleFacade.cs

@ -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);
}
}
}

160
BBWY.1688SDK/example/param/apiexample/ExampleCar.cs

@ -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;
}
}
}

132
BBWY.1688SDK/example/param/apiexample/ExampleFamily.cs

@ -0,0 +1,132 @@
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;
}
}
}

41
BBWY.1688SDK/example/param/apiexample/ExampleFamilyGetParam.cs

@ -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 12family对象
*/
public int? getFamilyNumber() {
return familyNumber;
}
/**
* 12family对象 *
* <pre></pre>
*
*/
public void setFamilyNumber(int familyNumber) {
this.familyNumber = familyNumber;
}
}
}

37
BBWY.1688SDK/example/param/apiexample/ExampleFamilyGetResult.cs

@ -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;
}
}
}

75
BBWY.1688SDK/example/param/apiexample/ExampleFamilyPostParam.cs

@ -0,0 +1,75 @@
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;
}
}
}

56
BBWY.1688SDK/example/param/apiexample/ExampleFamilyPostResult.cs

@ -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;
}
}
}

94
BBWY.1688SDK/example/param/apiexample/ExampleHouse.cs

@ -0,0 +1,94 @@
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;
}
}
}

99
BBWY.1688SDK/example/param/apiexample/ExamplePerson.cs

@ -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;
}
}
}

58
BBWY.1688SDK/exception/OceanException.cs

@ -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;
}
}
}

213
BBWY.1688SDK/http/HttpClient.cs

@ -0,0 +1,213 @@
using com.alibaba.openapi.client.policy;
using com.alibaba.openapi.client.util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization.Json;
using System.IO;
using com.alibaba.openapi.client.serialize;
using com.alibaba.openapi.client.entity;
using System.Collections;
using System.Web;
namespace com.alibaba.openapi.client.http
{
public class HttpClient
{
private ClientPolicy clientPolicy;
public HttpClient(ClientPolicy clientPolicy)
{
this.clientPolicy = clientPolicy;
}
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;
}
}
}

70
BBWY.1688SDK/policy/ClientPolicy.cs

@ -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; }
}
}
}

17
BBWY.1688SDK/policy/GrantType.cs

@ -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";
}
}

26
BBWY.1688SDK/policy/Protocol.cs

@ -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_=&lt;test>data&lt;/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";
}
}

113
BBWY.1688SDK/policy/RequestPolicy.cs

@ -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; }
}
}
}

36
BBWY.1688SDK/primitive/NullableBool.cs

@ -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;
}
}
}

36
BBWY.1688SDK/primitive/NullableByte.cs

@ -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;
}
}
}

36
BBWY.1688SDK/primitive/NullableChar.cs

@ -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;
}
}
}

36
BBWY.1688SDK/primitive/NullableDateTime.cs

@ -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;
}
}
}

36
BBWY.1688SDK/primitive/NullableDouble.cs

@ -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;
}
}
}

36
BBWY.1688SDK/primitive/NullableFloat.cs

@ -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;
}
}
}

36
BBWY.1688SDK/primitive/NullableInt.cs

@ -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;
}
}
}

36
BBWY.1688SDK/primitive/NullableLong.cs

@ -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;
}
}
}

12
BBWY.1688SDK/primitive/NullablePrimitiveObject.cs

@ -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
{
}
}

21
BBWY.1688SDK/serialize/DeSerializer.cs

@ -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);
}
}

56
BBWY.1688SDK/serialize/Json2Deserializer.cs

@ -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;
}
}
}

109
BBWY.1688SDK/serialize/Param2RequestSerializer.cs

@ -0,0 +1,109 @@
using com.alibaba.openapi.client.policy;
using com.alibaba.openapi.client.primitive;
using com.alibaba.openapi.client.util;
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;
}
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;
}
}
}

18
BBWY.1688SDK/serialize/Serializer.cs

@ -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);
}
}

60
BBWY.1688SDK/serialize/SerializerProvider.cs

@ -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];
}
}
}

66
BBWY.1688SDK/util/DateUtil.cs

@ -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;
}
}
}

74
BBWY.1688SDK/util/SignatureUtil.cs

@ -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;
}
}
}

11
BBWY.Server.API/Controllers/PlatformSDKController.cs

@ -119,5 +119,16 @@ namespace BBWY.Server.API.Controllers
{
platformSDKBusinessList.FirstOrDefault(p => p.Platform == outStockRequest.Platform).OutStock(outStockRequest);
}
/// <summary>
/// 订单预览
/// </summary>
/// <param name="previewOrderReuqest"></param>
/// <returns></returns>
[HttpPost]
public PreviewOrderResponse PreviewOrder(PreviewOrderReuqest previewOrderReuqest)
{
return platformSDKBusinessList.FirstOrDefault(p => p.Platform == previewOrderReuqest.Platform).PreviewOrder(previewOrderReuqest);
}
}
}

1
BBWY.Server.API/Startup.cs

@ -67,6 +67,7 @@ namespace BBWY.Server.API
});
services.BatchRegisterServices(new Assembly[] { Assembly.Load("BBWY.Server.Business") }, typeof(IDenpendency));
services.AddSingleton<PlatformSDKBusiness, JDBusiness>();
services.AddSingleton<PlatformSDKBusiness, _1688Business>();
//var stores = Configuration.GetSection("Stores").Get<IList<Store>>();

1
BBWY.Server.Business/BBWY.Server.Business.csproj

@ -15,6 +15,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BBWY.1688SDK\BBWY.1688SDK.csproj" />
<ProjectReference Include="..\BBWY.Common\BBWY.Common.csproj" />
<ProjectReference Include="..\BBWY.JDSDK\BBWY.JDSDK.csproj" />
<ProjectReference Include="..\BBWY.Server.Model\BBWY.Server.Model.csproj" />

2
BBWY.Server.Business/PlatformSDK/JDBusiness.cs

@ -34,7 +34,7 @@ namespace BBWY.Server.Business
};
public JDBusiness(IMemoryCache memoryCache, ILogger logger) : base(memoryCache) { this.logger = logger; }
public JDBusiness(IMemoryCache memoryCache, ILogger logger) : base(memoryCache, logger) { }
private IJdClient GetJdClient(string appKey, string appSecret)
{

7
BBWY.Server.Business/PlatformSDK/PDDBusiness.cs

@ -1,4 +1,6 @@
using Microsoft.Extensions.Caching.Memory;
using BBWY.Server.Model;
using Microsoft.Extensions.Caching.Memory;
using NLog;
using System;
using System.Collections.Generic;
using System.Text;
@ -7,7 +9,8 @@ namespace BBWY.Server.Business
{
public class PDDBusiness : PlatformSDKBusiness
{
public PDDBusiness(IMemoryCache memoryCache) : base(memoryCache)
public override Enums.Platform Platform => Enums.Platform.;
public PDDBusiness(IMemoryCache memoryCache, ILogger logger) : base(memoryCache, logger)
{
}
}

14
BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs

@ -2,6 +2,7 @@
using BBWY.Server.Model.Dto;
using Microsoft.Extensions.Caching.Memory;
using Newtonsoft.Json.Linq;
using NLog;
using System;
using System.Collections.Generic;
@ -11,16 +12,20 @@ namespace BBWY.Server.Business
{
protected IMemoryCache memoryCache;
protected TimeSpan expirationTimeSpan = TimeSpan.FromMinutes(60);
protected TimeSpan expirationTimeSpan;
/// <summary>
/// 产品平台
/// </summary>
public virtual Enums.Platform Platform { get; }
public PlatformSDKBusiness(IMemoryCache memoryCache)
protected ILogger logger;
public PlatformSDKBusiness(IMemoryCache memoryCache, ILogger logger)
{
this.memoryCache = memoryCache;
this.logger = logger;
this.expirationTimeSpan = TimeSpan.FromMinutes(60);
}
public virtual ProductListResponse GetProductList(SearchProductRequest searchProductRequest)
@ -67,5 +72,10 @@ namespace BBWY.Server.Business
{
throw new NotImplementedException();
}
public virtual PreviewOrderResponse PreviewOrder(PreviewOrderReuqest previewOrderReuqest)
{
throw new NotImplementedException();
}
}
}

7
BBWY.Server.Business/PlatformSDK/TaoBaoBusiness.cs

@ -1,5 +1,6 @@
using BBWY.Server.Model;
using Microsoft.Extensions.Caching.Memory;
using NLog;
using System;
using System.Collections.Generic;
using System.Text;
@ -8,10 +9,10 @@ namespace BBWY.Server.Business
{
public class TaoBaoBusiness : PlatformSDKBusiness
{
public override Enums.Platform Platform => Enums.Platform.;
public TaoBaoBusiness(IMemoryCache memoryCache) : base(memoryCache)
public TaoBaoBusiness(IMemoryCache memoryCache, ILogger logger) : base(memoryCache, logger)
{
}
public override Enums.Platform Platform => Enums.Platform.;
}
}

85
BBWY.Server.Business/PlatformSDK/_1688Business.cs

@ -0,0 +1,85 @@
using BBWY._1688SDK.entity.OrderPreview;
using BBWY.Server.Model;
using BBWY.Server.Model.Dto;
using com.alibaba.openapi.client;
using com.alibaba.openapi.client.policy;
using Microsoft.Extensions.Caching.Memory;
using Newtonsoft.Json.Linq;
using NLog;
using System.Collections.Generic;
namespace BBWY.Server.Business
{
public class _1688Business : PlatformSDKBusiness
{
public override Enums.Platform Platform => Enums.Platform.;
public _1688Business(IMemoryCache memoryCache, ILogger logger) : base(memoryCache, logger)
{
}
private SyncAPIClient GetSyncAPIClient(string appKey, string appSecret)
{
if (!memoryCache.TryGetValue(appKey, out SyncAPIClient syncAPIClient))
{
syncAPIClient = new SyncAPIClient(appKey, appSecret);
memoryCache.Set(appKey, syncAPIClient, expirationTimeSpan);
}
return syncAPIClient;
}
public override PreviewOrderResponse PreviewOrder(PreviewOrderReuqest previewOrderReuqest)
{
var client = GetSyncAPIClient(previewOrderReuqest.AppKey, previewOrderReuqest.AppSecret);
RequestPolicy reqPolicy = new RequestPolicy();
reqPolicy.HttpMethod = "POST";
reqPolicy.NeedAuthorization = false;
reqPolicy.RequestSendTimestamp = true;
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 = previewOrderReuqest.ConsigneeRequest.ContactName,
mobile = previewOrderReuqest.ConsigneeRequest.Mobile,
phone = previewOrderReuqest.ConsigneeRequest.TelePhone,
postCode = "000000",
address = previewOrderReuqest.ConsigneeRequest.Address,
provinceText = previewOrderReuqest.ConsigneeRequest.Province,
cityText = previewOrderReuqest.ConsigneeRequest.City,
areaText = previewOrderReuqest.ConsigneeRequest.County,
townText = previewOrderReuqest.ConsigneeRequest.Town
},
cargoParamList = new List<CargoParam>(),
flow = "general"
};
foreach (var cargo in previewOrderReuqest.CargoParamList)
{
param.cargoParamList.Add(new CargoParam()
{
offerId = long.Parse(cargo.SkuId),
specId = cargo.SpecId,
quantity = cargo.Quantity
});
}
request.RequestEntity = param;
var result = client.send<JObject>(request, reqPolicy);
return new PreviewOrderResponse()
{
};
}
}
}

14
BBWY.Server.Model/Dto/Request/PurchaseOrder/OnlinePurchase/CargoParamRequest.cs

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace BBWY.Server.Model.Dto
{
public class CargoParamRequest
{
public string ProductId { get; set; }
public string SkuId { get; set; }
public string SpecId { get; set; }
public int Quantity { get; set; }
}
}

43
BBWY.Server.Model/Dto/Request/PurchaseOrder/OnlinePurchase/ConsigneeRequest.cs

@ -0,0 +1,43 @@
namespace BBWY.Server.Model.Dto
{
public class ConsigneeRequest
{
/// <summary>
/// 联系人名称
/// </summary>
public string ContactName { get; set; }
/// <summary>
/// 座机
/// </summary>
public string TelePhone { get; set; }
/// <summary>
/// 手机
/// </summary>
public string Mobile { get; set; }
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; }
}
}

11
BBWY.Server.Model/Dto/Request/PurchaseOrder/OnlinePurchase/PreviewOrderReuqest.cs

@ -0,0 +1,11 @@
using System.Collections.Generic;
namespace BBWY.Server.Model.Dto
{
public class PreviewOrderReuqest: PlatformRequest
{
public ConsigneeRequest ConsigneeRequest { get; set; }
public IList<CargoParamRequest> CargoParamList { get; set; }
}
}

20
BBWY.Server.Model/Dto/Response/PurchaseOrder/OnlinePurchase/PreviewOrderResponse.cs

@ -0,0 +1,20 @@
namespace BBWY.Server.Model.Dto
{
public class PreviewOrderResponse
{
/// <summary>
/// 总额
/// </summary>
public decimal TotalAmount { get; set; }
/// <summary>
/// 货款总额
/// </summary>
public decimal ProductAmount { get; set; }
/// <summary>
/// 运费
/// </summary>
public decimal FreightAmount { get; set; }
}
}
Loading…
Cancel
Save