|
|
|
using BBWY._1688SDK.entity.OrderPreview;
|
|
|
|
using BBWY.Common.Http;
|
|
|
|
using BBWY.Common.Models;
|
|
|
|
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.阿里巴巴;
|
|
|
|
private RestApiService restApiService;
|
|
|
|
|
|
|
|
public _1688Business(IMemoryCache memoryCache, ILogger logger, RestApiService restApiService) : base(memoryCache, logger)
|
|
|
|
{
|
|
|
|
this.restApiService = restApiService;
|
|
|
|
}
|
|
|
|
|
|
|
|
private SyncAPIClient GetSyncAPIClient(string appKey, string appSecret)
|
|
|
|
{
|
|
|
|
if (!memoryCache.TryGetValue(appKey, out SyncAPIClient syncAPIClient))
|
|
|
|
{
|
|
|
|
syncAPIClient = new SyncAPIClient(appKey, appSecret, restApiService);
|
|
|
|
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 = 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 = 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;
|
|
|
|
if (!string.IsNullOrEmpty(previewOrderReuqest.AppToken))
|
|
|
|
request.AccessToken = previewOrderReuqest.AppToken;
|
|
|
|
var result = client.NewRequest(request, reqPolicy);
|
|
|
|
if (result.Value<bool>("success") != true)
|
|
|
|
{
|
|
|
|
throw new BusinessException(result.Value<string>("errorMsg")) { Code = result.Value<int>("errorCode") };
|
|
|
|
}
|
|
|
|
|
|
|
|
return new PreviewOrderResponse()
|
|
|
|
{
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|