|
@@ -1,6 +1,7 @@
|
|
|
using RestSharp;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Drawing.Printing;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading;
|
|
@@ -14,17 +15,78 @@ using XYY.Service.Standard.ChannelApi.PSE;
|
|
|
|
|
|
namespace XYY.Service.Standard.ChannelApi.JD
|
|
|
{
|
|
|
+
|
|
|
+ public class JDConfig
|
|
|
+ {
|
|
|
+ public string customerCode
|
|
|
+ {
|
|
|
+ get; set;
|
|
|
+ }
|
|
|
+
|
|
|
+ public string app_key
|
|
|
+ {
|
|
|
+ get; set;
|
|
|
+ }
|
|
|
+
|
|
|
+ public string access_token
|
|
|
+ {
|
|
|
+ get; set;
|
|
|
+ }
|
|
|
+
|
|
|
+ public string app_secret
|
|
|
+ {
|
|
|
+ get; set;
|
|
|
+ }
|
|
|
+
|
|
|
+ public string pin
|
|
|
+ {
|
|
|
+ get; set;
|
|
|
+ }
|
|
|
+
|
|
|
+ public string @operator
|
|
|
+ {
|
|
|
+ get; set;
|
|
|
+ }
|
|
|
+
|
|
|
+ public string sourceSystem
|
|
|
+ {
|
|
|
+ get; set;
|
|
|
+ }
|
|
|
+
|
|
|
+ public string host
|
|
|
+ {
|
|
|
+ get; set;
|
|
|
+ }
|
|
|
+
|
|
|
+ public string companyCode
|
|
|
+ {
|
|
|
+ get; set;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public partial class Api : IBaseApi
|
|
|
{
|
|
|
- private const string customerCode = "KH20000001419";
|
|
|
- private const string app_key = "ef729d8a2f184af7a81fce1a5fd9dc82";
|
|
|
- //access_token获取方式请参考《【商家版】-FOP跨境开发者文档-中文版v2.3.doc》手册第6章
|
|
|
- private const string access_token = "81140bd0e98e4ebbb54b8d1c1b5f3b21";
|
|
|
- private const string app_secret = "17d26ade49404d1497f0a2a3a1b193f9";
|
|
|
- private const string pin = "jdhk_bBGtofutWiKH";
|
|
|
- private const string @operator = "admin";
|
|
|
- private const string sourceSystem = "LMJ";
|
|
|
- private const string host = "https://us-api.jd.com/routerjson";
|
|
|
+ //private const string customerCode = "KH20000001419";
|
|
|
+ //private const string app_key = "ef729d8a2f184af7a81fce1a5fd9dc82";
|
|
|
+ ////access_token获取方式请参考《【商家版】-FOP跨境开发者文档-中文版v2.3.doc》手册第6章
|
|
|
+ //private const string access_token = "81140bd0e98e4ebbb54b8d1c1b5f3b21";
|
|
|
+ //private const string app_secret = "17d26ade49404d1497f0a2a3a1b193f9";
|
|
|
+ //private const string pin = "jdhk_bBGtofutWiKH";
|
|
|
+ //private const string @operator = "admin";
|
|
|
+ //private const string sourceSystem = "LMJ";
|
|
|
+ //private const string host = "https://us-api.jd.com/routerjson";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ ///*测试环境*/
|
|
|
+ //private const string testAccess_token = "700f619aa8d7440e90fb51c4b7d7d01e";
|
|
|
+ //private const string testCustomerCode = "KH20000000115";
|
|
|
+ //private const string testApp_key = "b2e6e6e768c04db39c0abc583504ba38";
|
|
|
+ //private const string testApp_secret = "477a0df2d8bc41188c4489c8097991bc";
|
|
|
+ //private const string testPin = "jdhk_CkhiBmNvFdWP";
|
|
|
+ //private const string testOperator = "test operator";
|
|
|
+ //private const string testSourceSystem = "testKJ";
|
|
|
+ //private const string testHost = "https://uat-us-api.jd.com/routerjson";
|
|
|
|
|
|
|
|
|
|
|
@@ -84,21 +146,28 @@ namespace XYY.Service.Standard.ChannelApi.JD
|
|
|
{
|
|
|
string method = "jingdong.fop.service.cancelServiceBill";
|
|
|
RestRequest restRequest = new RestRequest();
|
|
|
+
|
|
|
+ var config = GetConfig(logistics_ChannelCancel.ApiSecret);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
dynamic[] reqData = new dynamic[] { new
|
|
|
{
|
|
|
- gatewayUser = pin,
|
|
|
- customerCode = customerCode,
|
|
|
- @operator = @operator,
|
|
|
- sourceSystem = sourceSystem,
|
|
|
+ gatewayUser = config.pin,
|
|
|
+ customerCode = config.customerCode,
|
|
|
+ @operator = config.@operator,
|
|
|
+ sourceSystem = config.sourceSystem,
|
|
|
systemType = "10",
|
|
|
- customerBillCode = logistics_ChannelCancel.SystemNo.Replace("XYY", "LMJ")
|
|
|
+ customerBillCode = logistics_ChannelCancel.SystemNo.Replace("XYY", config.companyCode)
|
|
|
}};
|
|
|
string parjosn = Newtonsoft.Json.JsonConvert.SerializeObject(reqData);
|
|
|
|
|
|
restRequest.Method = Method.POST;
|
|
|
restRequest.AddParameter("application/json;charset=UTF-8", parjosn, ParameterType.RequestBody);
|
|
|
|
|
|
- RestClient client = createRestClient(method, parjosn);
|
|
|
+ RestClient client = createRestClient(method, parjosn, config);
|
|
|
var result = client.Execute(restRequest, Method.POST);
|
|
|
if (!result.IsSuccessful)
|
|
|
throw new Exception(result.ErrorMessage);
|
|
@@ -115,6 +184,13 @@ namespace XYY.Service.Standard.ChannelApi.JD
|
|
|
throw new Exception($"取消订单api失败,{data.response.content.errorMsg}");
|
|
|
}
|
|
|
|
|
|
+ private JDConfig GetConfig(string channelApiSecret)
|
|
|
+ {
|
|
|
+ JDConfig config = new JDConfig();
|
|
|
+ config = Newtonsoft.Json.JsonConvert.DeserializeObject<JDConfig>(channelApiSecret);
|
|
|
+ return config;
|
|
|
+ }
|
|
|
+
|
|
|
public Task<List<string>> Confims(List<OrderConfimRequest> order, Logistics_Channel channel)
|
|
|
{
|
|
|
throw new NotImplementedException();
|
|
@@ -122,11 +198,12 @@ namespace XYY.Service.Standard.ChannelApi.JD
|
|
|
|
|
|
public async Task<UploadResult> DataUpload(Order_Order order, List<Order_OrderGoods> goods, Logistics_Channel channel, ExtendArg arg)
|
|
|
{
|
|
|
+ var config = GetConfig(channel.ApiSecret);
|
|
|
string sellerId = "";
|
|
|
string storeId = "";
|
|
|
int printQty = _order_OrderPrintQtyRepository.GetPackagePrintQty(order.SystemNo);
|
|
|
- string orderNumber = order.TransferNumber.Replace("XYY", "LMJ")+"-"+ printQty;//不要出现XYY字眼
|
|
|
- var wayBillDto = CreateWayBillDto(customerCode, sellerId, storeId, order, goods, channel, orderNumber);
|
|
|
+ string orderNumber = order.TransferNumber.Replace("XYY", config.companyCode) + "-" + printQty;//不要出现XYY字眼
|
|
|
+ var wayBillDto = CreateWayBillDto(config.customerCode, sellerId, storeId, order, goods, channel, orderNumber, config);
|
|
|
RequestInfo requestInfo = CreateRequestInfo();
|
|
|
|
|
|
//string wayBillJson = Newtonsoft.Json.JsonConvert.SerializeObject(wayBillDto);
|
|
@@ -136,7 +213,7 @@ namespace XYY.Service.Standard.ChannelApi.JD
|
|
|
RestRequest request = CreateRestRequst(requestInfo, wayBillDto, out string paramJson);
|
|
|
string method = "jingdong.fop.service.deliveryWaybill";
|
|
|
|
|
|
- RestClient client = createRestClient(method, paramJson);
|
|
|
+ RestClient client = createRestClient(method, paramJson, config);
|
|
|
//RestClient client = new RestClient(url);
|
|
|
//RestRequest request = new RestRequest();
|
|
|
//request.Method = Method.POST;
|
|
@@ -168,7 +245,7 @@ namespace XYY.Service.Standard.ChannelApi.JD
|
|
|
if (!string.IsNullOrWhiteSpace(serviceOrderNumber))
|
|
|
{
|
|
|
await _orderRepository.AddChannelOrderInfoRecord(channel.Id, serviceOrderNumber, orderNumber);
|
|
|
- var uploadResult = await RequestLabel(serviceOrderNumber, orderNumber);
|
|
|
+ var uploadResult = await RequestLabel(config, serviceOrderNumber, orderNumber);
|
|
|
return uploadResult;
|
|
|
}
|
|
|
else
|
|
@@ -181,19 +258,19 @@ namespace XYY.Service.Standard.ChannelApi.JD
|
|
|
//单号重复
|
|
|
if (msg.Contains($"Issue:Parameter validation failed: {orderNumber}"))
|
|
|
{
|
|
|
- UploadResult uploadResult2 = await RetryRequestLabel(channel.Id, orderNumber);
|
|
|
+ UploadResult uploadResult2 = await RetryRequestLabel(channel.Id, orderNumber, config);
|
|
|
return uploadResult2;
|
|
|
}
|
|
|
//单号重复
|
|
|
- else if (msg.Contains("Issue:Waybill Customer Pack Code Duplicates")||msg.Contains("Issue:Customer bill code duplicates"))
|
|
|
+ else if (msg.Contains("Issue:Waybill Customer Pack Code Duplicates") || msg.Contains("Issue:Customer bill code duplicates"))
|
|
|
{
|
|
|
//再次查询订单
|
|
|
- var billInfo = await GetWayBillResult(orderNumber);
|
|
|
+ var billInfo = await GetWayBillResult(config, orderNumber);
|
|
|
serviceOrderNumber = billInfo.response.content.data;
|
|
|
if (!string.IsNullOrEmpty(serviceOrderNumber))
|
|
|
{
|
|
|
await _orderRepository.AddChannelOrderInfoRecord(channel.Id, serviceOrderNumber, orderNumber);
|
|
|
- var uploadResult = await RequestLabel(serviceOrderNumber, orderNumber);
|
|
|
+ var uploadResult = await RequestLabel(config, serviceOrderNumber, orderNumber);
|
|
|
return uploadResult;
|
|
|
}
|
|
|
else
|
|
@@ -227,22 +304,22 @@ namespace XYY.Service.Standard.ChannelApi.JD
|
|
|
|
|
|
}
|
|
|
|
|
|
- private async Task<UploadResult> RetryRequestLabel(int channelId, string orderNumber)
|
|
|
+ private async Task<UploadResult> RetryRequestLabel(int channelId, string orderNumber, JDConfig config)
|
|
|
{
|
|
|
string serviceNumber = await _orderRepository.GetChannelOrderInfoRecord(channelId, orderNumber);
|
|
|
if (string.IsNullOrEmpty(serviceNumber))
|
|
|
throw new Exception("渠道API提示单号重复,但找不到记录的服务单号");
|
|
|
- var result = await RequestLabel(serviceNumber, orderNumber);
|
|
|
+ var result = await RequestLabel(config, serviceNumber, orderNumber);
|
|
|
return result;
|
|
|
}
|
|
|
- private async Task<WayBillResult> GetWayBillResult(string orderNumber)
|
|
|
+ private async Task<WayBillResult> GetWayBillResult(JDConfig config, string orderNumber)
|
|
|
{
|
|
|
string method = "jingdong.fop.selectWaybillsByParam";
|
|
|
RestRequest restRequest = new RestRequest();
|
|
|
dynamic[] reqData = new dynamic[] { new
|
|
|
{
|
|
|
- pin = pin,
|
|
|
- customerCode = customerCode,
|
|
|
+ pin = config.pin,
|
|
|
+ customerCode = config.customerCode,
|
|
|
customerWaybillNo = orderNumber
|
|
|
}};
|
|
|
string parjosn = Newtonsoft.Json.JsonConvert.SerializeObject(reqData);
|
|
@@ -250,7 +327,7 @@ namespace XYY.Service.Standard.ChannelApi.JD
|
|
|
restRequest.Method = Method.POST;
|
|
|
restRequest.AddParameter("application/json;charset=UTF-8", parjosn, ParameterType.RequestBody);
|
|
|
|
|
|
- RestClient client = createRestClient(method, parjosn);
|
|
|
+ RestClient client = createRestClient(method, parjosn, config);
|
|
|
|
|
|
var result = await client.ExecuteAsync<WayBillResult>(restRequest);
|
|
|
if (result.StatusCode == System.Net.HttpStatusCode.OK)
|
|
@@ -262,14 +339,14 @@ namespace XYY.Service.Standard.ChannelApi.JD
|
|
|
throw new Exception("重新获取订单失败!");
|
|
|
}
|
|
|
}
|
|
|
- private RestClient createRestClient(string method, string paramJson)
|
|
|
+ private RestClient createRestClient(string method, string paramJson, JDConfig config)
|
|
|
{
|
|
|
//string method = "jingdong.fop.service.deliveryWaybill";
|
|
|
string timeStamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
- string sign = SignHelper.CreateSign(paramJson, app_secret, access_token, app_key, method, timeStamp);
|
|
|
+ string sign = SignHelper.CreateSign(paramJson, config.app_secret, config.access_token, config.app_key, method, timeStamp);
|
|
|
|
|
|
- string query = CreateRequestQuery(method, access_token, app_key, sign, timeStamp);
|
|
|
- string url = $"{host}?{query}";
|
|
|
+ string query = CreateRequestQuery(method, config.access_token, config.app_key, sign, timeStamp);
|
|
|
+ string url = $"{config.host}?{query}";
|
|
|
|
|
|
RestClient client = new RestClient(url);
|
|
|
return client;
|
|
@@ -286,13 +363,13 @@ namespace XYY.Service.Standard.ChannelApi.JD
|
|
|
return request;
|
|
|
}
|
|
|
|
|
|
- private async Task<UploadResult> RequestLabel(string serviceOrderNumber, string orderNumber)
|
|
|
+ private async Task<UploadResult> RequestLabel(JDConfig config, string serviceOrderNumber, string orderNumber)
|
|
|
{
|
|
|
- var printDto = CreateWaybillPrintDTO(customerCode, pin, orderNumber);
|
|
|
+ var printDto = CreateWaybillPrintDTO(config.customerCode, config.pin, orderNumber);
|
|
|
RequestInfo requestInfo = CreateRequestInfo();
|
|
|
RestRequest request = CreateRestRequst(requestInfo, printDto, out string paramJson);
|
|
|
string method = "jingdong.fop.waybill.printWaybill";
|
|
|
- RestClient client = createRestClient(method, paramJson);
|
|
|
+ RestClient client = createRestClient(method, paramJson, config);
|
|
|
|
|
|
var result = await client.ExecuteAsync<WayBillPrintResult>(request);
|
|
|
if (result.StatusCode == System.Net.HttpStatusCode.OK)
|
|
@@ -325,7 +402,7 @@ namespace XYY.Service.Standard.ChannelApi.JD
|
|
|
TrackingNumber = val.trackingNo,
|
|
|
DownloadUrl = val.billUrl,
|
|
|
IsSuccess = true,
|
|
|
- ServiceOrderNumber3=orderNumber,
|
|
|
+ ServiceOrderNumber3 = orderNumber,
|
|
|
};
|
|
|
return uploadResult;
|
|
|
}
|