using NetLibrary; using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; using System.Web.Script.Serialization; using System.Net; using System.IO; using NetLibrary.Data; using System.Data.Common; using System.Data; using NetLibrary.Log; namespace NetLibrary.OnlineTrade { public class AlibabaApiQM { public string gatewayUrl = "http://tqoem55nju.api.taobao.com/router/qm"; public string appkey = "24744952"; public string secretKey = "7fb815f1ac871fb3df8cf6f0a18b8e70"; public Int32? ShopId { get; set; } public string method = "aliexpress.transfer.station"; public string targetAppkey = "24764211"; public string format = "json"; public string signMethod = "md5"; public string apiVersion = "2.0"; public string sdkVersion = "top-sdk-php-20151012"; // public string apimethod { get; set; } public string sessionKey { get; set; } JavaScriptSerializer JsonConvert = null; public AlibabaApiQM() { JsonConvert = new JavaScriptSerializer(); } #region 获取数据 public string GetData(string jsonparam, out string ErrorMessage) { //Dictionary paramDic = new Dictionary(); //paramDic.Add("session_key", sessionKey); //paramDic.Add("method", apimethod); //string token = UserMd5(apimethod + "-api-479fe803d70b9a45100c976628810b27c908fdde"); //paramDic.Add("token", token); Dictionary paramDic2 = new Dictionary(); paramDic2.Add("param", jsonparam); paramDic2.Add("app_key", appkey); paramDic2.Add("method", method); paramDic2.Add("format", format); paramDic2.Add("target_app_key", targetAppkey); paramDic2.Add("api_version", apiVersion); paramDic2.Add("sdk_version", sdkVersion); paramDic2.Add("sign_method", signMethod); paramDic2.Add("timestamp", getTimestamp()); paramDic2.Add("sign", SignTopRequest(paramDic2, secretKey)); string rUrl = gatewayUrl + "?" + GetParam(paramDic2); string XmlContent = CustomIO.HttpRequest(rUrl, "POST", out ErrorMessage); if (string.IsNullOrEmpty(ErrorMessage) == false) return ""; QMResult model = JsonConvert.Deserialize(XmlContent); if (model.response.Ack == "Failure") return model.response.Errors; if (model.response.data != null) return model.response.data; else return model.response.Errors; return ""; } #endregion #region 获取订单 public List GetWaitGoods(string order_status, int OrderState, DateTime? StartTime, DateTime? StopTime, bool IsReadMsg, List OList, out string ErrorMessage) { param_aeop_order_query ppm = new param_aeop_order_query(); ppm.current_page = 1; ppm.page_size = 50; ppm.order_status = order_status; if (OrderState > 1) ppm.modified_date_start = DateTime.Today.AddDays(-7).ToString("yyyy-MM-dd HH:mm:ss"); else { if (StartTime == null) ppm.create_date_start = DateTime.Today.AddDays(-7).ToString("yyyy-MM-dd HH:mm:ss"); else ppm.create_date_start = StartTime.Value.ToString("yyyy-MM-dd HH:mm:ss"); } ppm.create_date_end = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); ppm.modified_date_end = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); string jsonStr1 = JsonConvert.Serialize(ppm); // string apimethod = "aliexpress.trade.redefining.findorderlistquery"; string apimethod = "aliexpress.trade.seller.orderlist.get"; Dictionary paramDic = new Dictionary(); paramDic.Add("session_key", sessionKey); paramDic.Add("method", apimethod); string token = UserMd5(apimethod + "-api-479fe803d70b9a45100c976628810b27c908fdde"); paramDic.Add("token", token); paramDic.Add("param_aeop_order_query", jsonStr1); string jsonStr = JsonConvert.Serialize(paramDic); string XmlContent = GetData(jsonStr, out ErrorMessage); if (string.IsNullOrEmpty(ErrorMessage) == false) return null; data Model = JsonConvert.Deserialize(XmlContent); if (Model.result.target_list == null) return null; // if (Model.result.total_item < 50) return Model.ToListOrderModel(); int PageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(Model.result.total_count) / Convert.ToDecimal(50))); List ListModel = new List(); foreach (var item in Model.result.target_list.aeop_order_item_dto) { int iscz = 0; //是否已经导入过 if (OList != null) { var omd = OList.Find(n => n.OrderCode == item.order_id.ToString()); if (omd != null) iscz = 1; } OrderModel model = new OrderModel(); OrderXXInfoResult mdxx = new OrderXXInfoResult(); if (iscz == 0 && OrderState != 3) { mdxx = GetOrderXXInfo(item.order_id, out ErrorMessage); } if (iscz == 0) model = ToOrderModel(item, OrderState, mdxx); if (iscz == 0 && model != null) ListModel.Add(model); } if (Model.result.total_count < 50) return ListModel; for (int i = 1; i < PageCount; i++) { ppm = new param_aeop_order_query(); ppm.current_page = (i + 1); ppm.page_size = 50; ppm.order_status = order_status; jsonStr1 = JsonConvert.Serialize(ppm); apimethod = "aliexpress.trade.seller.orderlist.get"; paramDic = new Dictionary(); paramDic.Add("session_key", sessionKey); paramDic.Add("method", apimethod); token = UserMd5(apimethod + "-api-479fe803d70b9a45100c976628810b27c908fdde"); paramDic.Add("token", token); paramDic.Add("param_aeop_order_query", jsonStr1); jsonStr = JsonConvert.Serialize(paramDic); XmlContent = GetData(jsonStr, out ErrorMessage); if (string.IsNullOrEmpty(ErrorMessage) == false) return null; data Model2 = JsonConvert.Deserialize(XmlContent); foreach (var item in Model2.result.target_list.aeop_order_item_dto) { int iscz = 0; //是否已经导入过 if (OList != null) { var omd = OList.Find(n => n.OrderCode == item.order_id.ToString()); if (omd != null) iscz = 1; } // int OrderState = 1; if (item.fund_status != "PAY_SUCCESS") OrderState = 2; OrderModel model = new OrderModel(); OrderXXInfoResult mdxx = new OrderXXInfoResult(); if (iscz == 0) { mdxx = GetOrderXXInfo(item.order_id, out ErrorMessage); } if (iscz == 0) model = ToOrderModel(item, OrderState, mdxx); if (iscz == 0 && model != null) ListModel.Add(model); } } return ListModel; } #endregion #region 订单详情 public OrderXXInfoResult GetOrderXXInfo(string ordercode, out string ErrorMessage) { OrderXXParam ppm = new OrderXXParam(); ppm.order_id = ordercode; string jsonStr1 = JsonConvert.Serialize(ppm); string apimethod = "aliexpress.trade.new.redefining.findorderbyid"; Dictionary paramDic = new Dictionary(); paramDic.Add("session_key", sessionKey); paramDic.Add("method", apimethod); string token = UserMd5(apimethod + "-api-479fe803d70b9a45100c976628810b27c908fdde"); paramDic.Add("token", token); paramDic.Add("param1", jsonStr1); string jsonStr = JsonConvert.Serialize(paramDic); string XmlContent = GetData(jsonStr, out ErrorMessage); if (string.IsNullOrEmpty(ErrorMessage) == false) return null; if (XmlContent == null || XmlContent == "") { ErrorFollow.TraceWrite("GetOrderXXInfo", ordercode + " ", DateTime.Now.ToString("HH:mm:ss")); GetOrderXXInfo(ordercode, out ErrorMessage); return null; } OrderXXInfoResult Model = JsonConvert.Deserialize(XmlContent); if (Model.target == null) return null; // if (Model.result.total_item < 50) return Model.ToListOrderModel(); return Model; } #endregion #region 转换成统一的订单对象 public OrderModel ToOrderModel(AeopOrderItemDto md, int OrderState, OrderXXInfoResult mdxx) { try { OrderModel model = new OrderModel(); //if (this.orderId.ToString() == "72860947447064") //{ // string treqq = "72860947447064"; //} model.PlatOrderCode = md.order_id.ToString(); model.OrderCode = md.order_id.ToString(); model.TotalPrice = Convert.ToDecimal(md.pay_amount.amount);// Convert.ToDecimal(md.pay_amount.cent) / Convert.ToDecimal(md.pay_amount.cent_factor); model.MoneyCode = md.pay_amount.currency_code; if (md.gmt_create != null) model.OrderDate = Convert.ToDateTime(md.gmt_create); if (mdxx.target != null && mdxx.target.buyer_signer_fullname != null) model.BuyerID = mdxx.target.buyer_signer_fullname; if (model.BuyerID != null && model.BuyerID.Length > 50) model.BuyerID = model.BuyerID.Substring(0, 50); model.OrderState = OrderState; if (mdxx.target != null && mdxx.target.receipt_address != null) model.BuyerName = mdxx.target.receipt_address.contact_person; if (mdxx.target != null && mdxx.target.receipt_address != null) model.BuyerCountry = mdxx.target.receipt_address.country; if (mdxx.target != null && mdxx.target.receipt_address != null && mdxx.target.receipt_address.detail_address != null) model.BuyerAddr = mdxx.target.receipt_address.detail_address; if (mdxx.target != null && mdxx.target.receipt_address != null && mdxx.target.receipt_address.address != null && mdxx.target.receipt_address.address != "") model.BuyerAddr += " " + mdxx.target.receipt_address.address; if (mdxx.target != null && mdxx.target.receipt_address != null && mdxx.target.receipt_address.address2 != null && mdxx.target.receipt_address.address2 != "") model.BuyerAddr += " " + mdxx.target.receipt_address.address2; model.BuyerPhone = ""; if (mdxx.target != null && mdxx.target.receipt_address != null && mdxx.target.receipt_address.phone_area != null) model.BuyerPhone = mdxx.target.receipt_address.phone_area; // if (mdxx.result.receipt_address != null && this.buyerInfo.receiptAddress.phoneArea != null) // model.BuyerPhone += this.buyerInfo.receiptAddress.phoneArea + "-"; if (mdxx.target != null && mdxx.target.receipt_address != null && mdxx.target.receipt_address.phone_number != null) model.BuyerPhone += mdxx.target.receipt_address.phone_number; if (mdxx.target != null && mdxx.target.receipt_address != null) model.BuyerMobile = mdxx.target.receipt_address.mobile_no; // if (mdxx.result.receipt_address != null && mdxx.result.receipt_address.e != null) model.BuyerMail = ""; //model.logisticsAmount = this.buyerInfo.logisticsAmount; // model.escrowFee = this.buyerInfo.escrowFee; model.BuyerFax = ""; if (mdxx.target != null && mdxx.target.receipt_address != null && mdxx.target.receipt_address.zip != null) model.BuyerZip = mdxx.target.receipt_address.zip; if (mdxx.target != null && mdxx.target.receipt_address != null) model.BuyerProvince = mdxx.target.receipt_address.province; if (mdxx.target != null && mdxx.target.receipt_address != null) model.BuyerCity = mdxx.target.receipt_address.city; model.BuyerArea = ""; if (mdxx.target != null && mdxx.target.memo != null) model.OrderRemark = mdxx.target.memo; else model.OrderRemark = ""; //memo model.LeaveWord = ""; if (mdxx.target != null && mdxx.target.order_msg_list != null && mdxx.target.order_msg_list.tp_open_order_msg_dto != null) { foreach (var item2 in mdxx.target.order_msg_list.tp_open_order_msg_dto) { model.LeaveWord += item2.content + System.Environment.NewLine; } } if (mdxx.target != null && mdxx.target.gmt_pay_success != null && mdxx.target.gmt_pay_success != "") model.PayDate = Convert.ToDateTime(mdxx.target.gmt_pay_success); model.OutOrderDate = DateTime.Now; if (md.left_send_good_day != null && md.left_send_good_day != "") model.OutOrderDate = model.OutOrderDate.Value.AddDays(Convert.ToInt32(md.left_send_good_day)); if (md.left_send_good_hour != null && md.left_send_good_hour != "") model.OutOrderDate = model.OutOrderDate.Value.AddHours(Convert.ToInt32(md.left_send_good_hour)); if (md.left_send_good_min != null && md.left_send_good_min != "") model.OutOrderDate = model.OutOrderDate.Value.AddMinutes(Convert.ToInt32(md.left_send_good_min)); if (model.OutOrderDate == null) model.OutOrderDate = DateTime.Now.AddDays(5); if (md.product_list != null && md.product_list.aeop_order_product_dto != null) model.PostInfo = md.product_list.aeop_order_product_dto[0].logistics_service_name; model.ListModel = new List(); //Alibaba_productAttributes pmd = null; //if (this.buyerInfo != null&&this.buyerInfo.childOrderList!=null) // { // if (this.buyerInfo.childOrderList.productAttributes != null && this.buyerInfo.childOrderList.productAttributes != "") // { // JavaScriptSerializer JsonConvert = new JavaScriptSerializer(); // pmd = JsonConvert.Deserialize(this.buyerInfo.childOrderList.productAttributes); // } // } if (md.product_list != null && md.product_list.aeop_order_product_dto != null) { foreach (var item2 in md.product_list.aeop_order_product_dto) { if (string.IsNullOrEmpty(item2.memo) == false) model.OrderRemark += item2.memo + System.Environment.NewLine; OrderDetailModel model2 = new OrderDetailModel(); string GoodsDesc = ""; if (mdxx.target != null && mdxx.target.child_order_list != null && mdxx.target.child_order_list.aeop_tp_child_order_dto != null) { foreach (var pmd in mdxx.target.child_order_list.aeop_tp_child_order_dto) { if (pmd.product_id == item2.product_id) { JavaScriptSerializer JsonConvert = new JavaScriptSerializer(); Alibaba_productAttributesNew psku = null; psku = JsonConvert.Deserialize(pmd.product_attributes); if (psku != null && psku.sku != null && psku.sku.Count > 0) { string pName = psku.sku[0].pName.Trim(); string pValue = psku.sku[0].pValue.Trim(); if (psku.sku[0].selfDefineValue.ToString() != "") pValue = psku.sku[0].selfDefineValue; GoodsDesc += pName + ":" + pValue; } if (psku != null && psku.sku != null && psku.sku.Count > 1) { string pName = psku.sku[1].pName.Trim(); string pValue = psku.sku[1].pValue.Trim(); GoodsDesc += " " + pName + ":" + pValue; } } } } model2.TypeDesc = GoodsDesc; if (item2.memo != null && item2.memo != "") model2.TypeDesc += "备注:" + item2.memo; model2.productImgUrl = item2.product_img_url; model2.GoodsNum = item2.product_count; if (item2.product_unit_price != null) model2.GoodsPrice = item2.product_unit_price.amount;// Convert.ToDecimal(item2.product_unit_price.cent) / Convert.ToDecimal(item2.product_unit_price.cent_factor); model2.MoneyCode = item2.product_unit_price.currency_code; model2.GoodsName = item2.product_name; model2.GoodsSKU = item2.sku_code; model2.PostInfo = item2.logistics_service_name; model.ListModel.Add(model2); } } return model; } catch (Exception ex) { ErrorFollow.TraceWrite(ex.TargetSite.Name, ex.StackTrace, ex.Message); return null; } } #endregion #region 得到留言的数据 /// /// /// /// /// (站内信)message_center/order_msg(留言) /// /// public List GetMsgData(string channelId, string msgSources, out string ErrorMessage) { try { string apimethod = "aliexpress.message.redefining.versiontwo.querymsgdetaillist"; Dictionary paramDic = new Dictionary(); paramDic.Add("session_key", sessionKey); paramDic.Add("method", apimethod); string token = UserMd5(apimethod + "-api-479fe803d70b9a45100c976628810b27c908fdde"); paramDic.Add("token", token); paramDic.Add("ChannelId", channelId); paramDic.Add("PageSize", "10"); paramDic.Add("CurrentPage", "1"); string jsonStr = JsonConvert.Serialize(paramDic); string XmlContent = GetData(jsonStr, out ErrorMessage); if (string.IsNullOrEmpty(ErrorMessage) == false) return null; OpenApiRelationResult Model = JsonConvert.Deserialize(XmlContent); if (Model != null && Model.is_success == false) return null; return null; } catch (Exception ex) { ErrorMessage = ""; return null; } } #endregion #region 得到留言关系的数据 /// /// /// /// /// (站内信)message_center/order_msg(留言) /// /// public string GetMsgDataRea(string msgSources, out string ErrorMessage) { RelationQueryDto ppm = new RelationQueryDto(); ppm.current_page = 1; ppm.page_size = 500; ppm.only_un_dealed = true; ppm.only_un_readed = true; ppm.start_time = DateTime.Today.AddDays(-7).ToString("MM/dd/yyyy HH:mm:ss"); string jsonStr1 = JsonConvert.Serialize(ppm); string apimethod = "aliexpress.message.redefining.versiontwo.querymsgrelationlist"; Dictionary paramDic = new Dictionary(); paramDic.Add("session_key", sessionKey); paramDic.Add("method", apimethod); string token = UserMd5(apimethod + "-api-479fe803d70b9a45100c976628810b27c908fdde"); paramDic.Add("token", token); paramDic.Add("query", jsonStr1); string jsonStr = JsonConvert.Serialize(paramDic); string XmlContent = GetData(jsonStr, out ErrorMessage); if (string.IsNullOrEmpty(ErrorMessage) == false) return null; OpenApiMessageDetailListResult Model = JsonConvert.Deserialize(XmlContent); if (Model != null && Model.result.is_success == false) return null; return XmlContent; } #endregion #region 声明发货 /// /// /// /// 订单号 /// 跟踪码 /// 物流类型 /// /// /// /// public bool SubmitTrack(string ordercode, string trackno, string serviceName, string shippmark, string trackingWebsite, out string ErrorMessage) { try { string apimethod = "aliexpress.logistics.sellershipmentfortop"; Dictionary paramDic = new Dictionary(); paramDic.Add("session_key", sessionKey); paramDic.Add("method", apimethod); string token = UserMd5(apimethod + "-api-479fe803d70b9a45100c976628810b27c908fdde"); paramDic.Add("token", token); paramDic.Add("logistics_no", trackno); paramDic.Add("description", shippmark); paramDic.Add("send_type", "all"); paramDic.Add("tracking_website", trackingWebsite); paramDic.Add("out_ref", ordercode); paramDic.Add("service_name", serviceName); string jsonStr = JsonConvert.Serialize(paramDic); string XmlContent = GetData(jsonStr, out ErrorMessage); if (string.IsNullOrEmpty(ErrorMessage) == false) return false; expressresult Model = JsonConvert.Deserialize(XmlContent); if (Model.result_success == false) return false; return true; } catch (Exception ex) { ErrorMessage = ex.Message; return false; } //return josn;//SaveData(josn); } #endregion #region 获取买家地址 public string getLogisticsSellerAddresses(out string ErrorMessage) { try { string apimethod = "aliexpress.logistics.redefining.getlogisticsselleraddresses"; // AeopWarehouseOrderQueryPdfRequest ppm = new AeopWarehouseOrderQueryPdfRequest(); // ppm.warehouse_order_query_d_t_os = tracklist; Dictionary paramDic = new Dictionary(); paramDic.Add("session_key", sessionKey); paramDic.Add("method", apimethod); string token = UserMd5(apimethod + "-api-479fe803d70b9a45100c976628810b27c908fdde"); paramDic.Add("token", token); // paramDic.Add("international_logistics_id", "LP102165226SG"); // paramDic.Add("print_detail", "true"); paramDic.Add("seller_address_query", "sender,pickup,refund");// "{\"AeopWarehouseOrderQueryPdfRequest\":[{\"international_logistics_id\":\\\"LP102165226SG\\\"}]}}"); string jsonStr = JsonConvert.Serialize(paramDic); string XmlContent = GetData(jsonStr, out ErrorMessage); if (string.IsNullOrEmpty(ErrorMessage) == false) return ""; OlineAddrId Model = JsonConvert.Deserialize(XmlContent); if (Model == null || Model.pickup_seller_address_list == null) return ""; return Model.sender_seller_address_list.senderselleraddresslist[0].address_id + "," + Model.refund_seller_address_list.refundselleraddresslist[0].address_id + "," + Model.pickup_seller_address_list.pickupselleraddresslist[0].address_id; } catch (Exception ex) { ErrorMessage = ex.Message; return ""; } } #endregion #region 线上发货 public OnlineResult SendOnline(OlineAddressdtos model, out string ErrorMessage) { try { string apimethod = "aliexpress.logistics.createwarehouseorder"; // AeopWarehouseOrderQueryPdfRequest ppm = new AeopWarehouseOrderQueryPdfRequest(); // ppm.warehouse_order_query_d_t_os = tracklist; string jsonStr1 = JsonConvert.Serialize(model.address_d_t_os); Dictionary paramDic = new Dictionary(); paramDic.Add("session_key", sessionKey); paramDic.Add("method", apimethod); string token = UserMd5(apimethod + "-api-479fe803d70b9a45100c976628810b27c908fdde"); paramDic.Add("token", token); // paramDic.Add("international_logistics_id", "LP102165226SG"); // paramDic.Add("print_detail", "true"); paramDic.Add("address_d_t_os", jsonStr1);// "{\"AeopWarehouseOrderQueryPdfRequest\":[{\"international_logistics_id\":\\\"LP102165226SG\\\"}]}}"); string jsonStr2 = JsonConvert.Serialize(model.declare_product_d_t_os); paramDic.Add("declare_product_d_t_os", jsonStr2); paramDic.Add("domestic_logistics_company_id", model.domestic_logistics_company_id.ToString()); paramDic.Add("domestic_logistics_company", model.domestic_logistics_company); paramDic.Add("domestic_tracking_no", model.domestic_tracking_no); paramDic.Add("trade_order_from", model.trade_order_from); paramDic.Add("trade_order_id", model.trade_order_id); paramDic.Add("warehouse_carrier_service", model.warehouse_carrier_service); string jsonStr = JsonConvert.Serialize(paramDic); string XmlContent = GetData(jsonStr, out ErrorMessage); if (string.IsNullOrEmpty(ErrorMessage) == false) return null; OnlineResult Model = JsonConvert.Deserialize(XmlContent); if (Model == null || Model.result == null) return null; return Model; } catch (Exception ex) { ErrorMessage = ex.Message; return null; } } #endregion #region 获取跟踪码 public List getOnlineLogisticsInfo(string orderId, out string ErrorMessage) { try { string apimethod = "aliexpress.logistics.querylogisticsorderdetail"; // AeopWarehouseOrderQueryPdfRequest ppm = new AeopWarehouseOrderQueryPdfRequest(); // ppm.warehouse_order_query_d_t_os = tracklist; Dictionary paramDic = new Dictionary(); paramDic.Add("session_key", sessionKey); paramDic.Add("method", apimethod); string token = UserMd5(apimethod + "-api-479fe803d70b9a45100c976628810b27c908fdde"); paramDic.Add("token", token); // paramDic.Add("international_logistics_id", "LP102165226SG"); // paramDic.Add("print_detail", "true"); paramDic.Add("trade_order_id", orderId);// "{\"AeopWarehouseOrderQueryPdfRequest\":[{\"international_logistics_id\":\\\"LP102165226SG\\\"}]}}"); string jsonStr = JsonConvert.Serialize(paramDic); string XmlContent = GetData(jsonStr, out ErrorMessage); if (string.IsNullOrEmpty(ErrorMessage) == false) return null; OnlineTrackCodeResult Model = JsonConvert.Deserialize(XmlContent); if (Model == null || Model.result == null) return null; if (Model.result.success == false) return null; return Model.result.result_list.aeop_logistics_order_detail_dto; } catch (Exception ex) { ErrorMessage = ex.Message; return null; } } #endregion #region 获取线上发货标签 public string GetPrintInfo(List tracklist, out string ErrorMessage) { try { string apimethod = "aliexpress.logistics.redefining.getprintinfos"; // AeopWarehouseOrderQueryPdfRequest ppm = new AeopWarehouseOrderQueryPdfRequest(); // ppm.warehouse_order_query_d_t_os = tracklist; string jsonStr1 = JsonConvert.Serialize(tracklist); Dictionary paramDic = new Dictionary(); paramDic.Add("session_key", sessionKey); paramDic.Add("method", apimethod); string token = UserMd5(apimethod + "-api-479fe803d70b9a45100c976628810b27c908fdde"); paramDic.Add("token", token); // paramDic.Add("international_logistics_id", "LP102165226SG"); // paramDic.Add("print_detail", "true"); paramDic.Add("warehouse_order_query_d_t_os", jsonStr1);// "{\"AeopWarehouseOrderQueryPdfRequest\":[{\"international_logistics_id\":\\\"LP102165226SG\\\"}]}}"); string jsonStr = JsonConvert.Serialize(paramDic); string XmlContent = GetData(jsonStr, out ErrorMessage); if (string.IsNullOrEmpty(ErrorMessage) == false) return ""; Result2 Model = JsonConvert.Deserialize(XmlContent); if (Model == null || Model.result == null) return ""; pdflabel2 Model2 = JsonConvert.Deserialize(Model.result); byte[] bytes = CustomIO.Base64ToBytes(Model2.body); string dir = AppDomain.CurrentDomain.BaseDirectory + "ServerCookies"; if (System.IO.Directory.Exists(dir) == false) System.IO.Directory.CreateDirectory(dir); string fname = Guid.NewGuid().ToString() + ".pdf"; string filePath = dir + "/" + fname; CustomIO.SetOffice(filePath, bytes); return fname; } catch (Exception ex) { ErrorMessage = ex.Message; return ""; } //return josn;//SaveData(josn); } #endregion #region 获取线上物流渠道 public string GetOnlineList(string ordercode, out string ErrorMessage) { try { string apimethod = "aliexpress.logistics.redefining.getonlinelogisticsservicelistbyorderid"; Dictionary paramDic = new Dictionary(); paramDic.Add("session_key", sessionKey); paramDic.Add("method", apimethod); string token = UserMd5(apimethod + "-api-479fe803d70b9a45100c976628810b27c908fdde"); paramDic.Add("token", token); // paramDic.Add("international_logistics_id", "LP102165226SG"); // paramDic.Add("print_detail", "true"); paramDic.Add("order_id", ordercode);// "{\"AeopWarehouseOrderQueryPdfRequest\":[{\"international_logistics_id\":\\\"LP102165226SG\\\"}]}}"); string jsonStr = JsonConvert.Serialize(paramDic); string XmlContent = GetData(jsonStr, out ErrorMessage); if (string.IsNullOrEmpty(ErrorMessage) == false) return null; return XmlContent; } catch (Exception ex) { ErrorMessage = ex.Message; return ""; } } #endregion public string GetParam(Dictionary dict) { string cs = ""; foreach (KeyValuePair kv in dict) { if (kv.Key != "param") cs += kv.Key + "=" + kv.Value + "&"; else cs += kv.Key + "=" + System.Web.HttpUtility.UrlEncode(kv.Value, System.Text.Encoding.UTF8) + "&"; } cs = cs.TrimEnd('&'); return cs; } /// /// 将字典类型序列化为json字符串 /// /// 字典key /// 字典value /// 要序列化的字典数据 /// json字符串 public string SerializeDictionaryToJsonString(Dictionary dict) { if (dict.Count == 0) return ""; string jsonStr = JsonConvert.Serialize(dict); return jsonStr; } /// /// 将json字符串反序列化为字典类型 /// /// 字典key /// 字典value /// json字符串 /// 字典数据 public Dictionary DeserializeStringToDictionary(string jsonStr) { if (string.IsNullOrEmpty(jsonStr)) return new Dictionary(); Dictionary jsonDict = JsonConvert.Deserialize>(jsonStr); return jsonDict; } public static string SignTopRequest(IDictionary parameters, string secret) { // 第一步:把字典按Key的字母顺序排序 IDictionary sortedParams = new SortedDictionary(parameters, StringComparer.Ordinal); IEnumerator> dem = sortedParams.GetEnumerator(); // 第二步:把所有参数名和参数值串在一起 StringBuilder query = new StringBuilder(); query.Append(secret); while (dem.MoveNext()) { string key = dem.Current.Key; string value = dem.Current.Value; if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value)) { query.Append(key).Append(value); } } // 第三步:使用MD5/HMAC加密 byte[] bytes; query.Append(secret); MD5 md5 = MD5.Create(); bytes = md5.ComputeHash(Encoding.UTF8.GetBytes(query.ToString())); // 第四步:把二进制转化为大写的十六进制 StringBuilder result = new StringBuilder(); for (int i = 0; i < bytes.Length; i++) { result.Append(bytes[i].ToString("X2")); } return result.ToString(); } private string getTimestamp() { string st = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); return st; } public static string UserMd5(string str) { string cl = str; string pwd = ""; MD5 md5 = MD5.Create();//实例化一个md5对像 // 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择  byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl)); // 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得 for (int i = 0; i < s.Length; i++) { // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符 pwd = pwd + s[i].ToString("x2"); } return pwd; } } #region public class expressresult { public string result_error_desc { get; set; } public string result_error_code { get; set; } public Boolean? result_success { get; set; } } #endregion #region public class QMResult { public response response { get; set; } } #endregion #region public class response { public string Ack { get; set; } public string data { get; set; } public string Errors { get; set; } } #endregion #region public class data { public result result { get; set; } } #endregion #region public class result { public target_list target_list { get; set; } public Int32? total_count { get; set; } } #endregion #region public class target_list { public List aeop_order_item_dto { get; set; } } #endregion #region public class AeopOrderItemDto { public string biz_type { get; set; } public Decimal? logisitcs_escrow_fee_rate { get; set; } public string left_send_good_min { get; set; } public string left_send_good_hour { get; set; } public string left_send_good_day { get; set; } public product_list product_list { get; set; } public Boolean? has_request_loan { get; set; } public string gmt_send_goods_time { get; set; } public money escrow_fee { get; set; } public string escrow_fee_rate { get; set; } public string frozen_status { get; set; } public string issue_status { get; set; } public string logistics_status { get; set; } public string fund_status { get; set; } public string payment_type { get; set; } public string gmt_pay_time { get; set; } public string order_status { get; set; } public money loan_amount { get; set; } public money pay_amount { get; set; } public string timeout_left_time { get; set; } public string seller_operator_aliid { get; set; } public string seller_signer_fullname { get; set; } public string seller_aliid { get; set; } public string buyer_signer_fullname { get; set; } public string seller_login_id { get; set; } public string buyer_login_id { get; set; } public string order_detail_url { get; set; } public string gmt_create { get; set; } public string order_id { get; set; } public Boolean? phone { get; set; } } #endregion #region public class product_list { public List aeop_order_product_dto { get; set; } } #endregion #region public class AeopOrderProductDto { public string afflicate_fee_rate { get; set; } public string escrow_fee_rate { get; set; } public string freight_commit_day { get; set; } public string memo { get; set; } public string issue_mode { get; set; } public string sku_code { get; set; } public string order_id { get; set; } public string send_goods_time { get; set; } public string delivery_time { get; set; } public string goods_prepare_time { get; set; } public money logistics_amount { get; set; } public string logistics_service_name { get; set; } public string logistics_type { get; set; } public string seller_signer_last_name { get; set; } public string seller_signer_first_name { get; set; } public string buyer_signer_last_name { get; set; } public string buyer_signer_first_name { get; set; } public string product_id { get; set; } public string child_id { get; set; } public money total_product_amount { get; set; } public string product_unit { get; set; } public Int32? product_count { get; set; } public string product_standard { get; set; } public string product_img_url { get; set; } public string product_snap_url { get; set; } public string product_name { get; set; } public string send_goods_operator { get; set; } public money product_unit_price { get; set; } public Boolean? can_submit_issue { get; set; } public Boolean? money_back3x { get; set; } } #endregion #region public class money { public string currency_code { get; set; } public string cent_factor { get; set; } public string cent { get; set; } public Decimal? amount { get; set; } public currency currency { get; set; } } #endregion #region public class currency { public string display_name { get; set; } public string symbol { get; set; } public string currency_code { get; set; } public string numeric_code { get; set; } public string default_fraction_digits { get; set; } } #endregion public class param_aeop_order_query { public int page_size { get; set; } public string order_status { get; set; } public string create_date_start { get; set; } public string create_date_end { get; set; } public string modified_date_start { get; set; } public string modified_date_end { get; set; } public int current_page { get; set; } } public class param1 { public int page { get; set; } public int page_size { get; set; } public string order_status { get; set; } public string create_date_start { get; set; } public string create_date_end { get; set; } public string modified_date_start { get; set; } public string modified_date_end { get; set; } public int current_page { get; set; } } public class OrderXXParam { public string order_id { get; set; } } /// /// 留言关系条件 /// public class RelationQueryDto { public int current_page { get; set; } public int page_size { get; set; } //每页条数,pageSize取值范围(0~100) 最多返回前5000条数据 public string start_time { get; set; } //会话时间查询范围-截至时间,如果不填则取当前时间,从1970年起计算的毫秒时间戳 public Boolean? only_un_dealed { get; set; }//是否只查询未处理会话 public Boolean? only_un_readed { get; set; }//是否只查询未读会话 } #region public class OpenApiRelationResult { public relation_list result { get; set; } public string error_msg { get; set; } public string error_code { get; set; } public Boolean? is_success { get; set; } } #endregion #region public class relation_list { public List MessageDetail { get; set; } } #endregion #region public class RelationResult { public string deal_stat { get; set; } public string read_stat { get; set; } public string order_id { get; set; } public string channel_id { get; set; } public string child_name { get; set; } public string last_message_id { get; set; } public string other_name { get; set; } public string other_login_id { get; set; } } #endregion #region /// /// 留言内容 /// public class OpenApiMessageDetailListResult { public messresult result { get; set; } } #endregion #region public class messresult { public message_detail_list message_detail_list { get; set; } public string error_msg { get; set; } public string error_code { get; set; } public Boolean? is_success { get; set; } } #endregion #region public class message_detail_list { public List MessageDetail { get; set; } } #endregion #region public class MessageDetail { public summary summary { get; set; } public string content { get; set; } public string message_type { get; set; } public string sender_name { get; set; } public string gmt_create { get; set; } public string id { get; set; } public string sender_ali_id { get; set; } } #endregion #region public class summary { public string sender_login_id { get; set; } public string receiver_ali_id { get; set; } public string sender_ali_id { get; set; } public string receiver_name { get; set; } public string sender_name { get; set; } public string order_url { get; set; } public string product_detail_url { get; set; } public string product_image_url { get; set; } public string product_name { get; set; } } #endregion public class OlineAddrId { public senderOlineAddrIdMd sender_seller_address_list { get; set; } public refundOlineAddrIdMd refund_seller_address_list { get; set; } public pickupOlineAddrIdMd pickup_seller_address_list { get; set; } } public class senderOlineAddrIdMd { public List senderselleraddresslist { get; set; } } public class refundOlineAddrIdMd { public List refundselleraddresslist { get; set; } } public class pickupOlineAddrIdMd { public List pickupselleraddresslist { get; set; } } #region 线上发货 public class address_d_t_os { public AeopWlDeclareAddressDto sender { get; set; } public AeopWlDeclareAddressDto pickup { get; set; } public AeopWlDeclareAddressDto receiver { get; set; } public AeopWlDeclareAddressDto refund { get; set; } } public class declare_product_d_t_os { public List AeopWlDeclareProductForTopDto { get; set; } } public class AeopWlDeclareProductForTopDto { public string aneroid_markup { get; set; } public Boolean? contains_battery { get; set; } public string product_declare_amount { get; set; } public Int64? product_num { get; set; } public string product_weight { get; set; } public string hs_code { get; set; } public string category_cn_desc { get; set; } public string category_en_desc { get; set; } public string sku_code { get; set; } public Int64? product_id { get; set; } public string sku_value { get; set; } } public class AeopWlDeclareAddressDto { public string phone { get; set; } public string fax { get; set; } public string member_type { get; set; } public string trademanage_id { get; set; } public string post_code { get; set; } public string street { get; set; } public string country { get; set; } public string city { get; set; } public string county { get; set; } public string email { get; set; } public Int64? address_id { get; set; } public string name { get; set; } public string province { get; set; } public string street_address { get; set; } public string mobile { get; set; } } #endregion #region 属性信息 public class Alibaba_productAttributesNew { public List sku { get; set; } } #endregion #region 属性信息 public class Alibaba_SKUNew { public string pName { get; set; } public string pValue { get; set; } public string selfDefineValue { get; set; } } #endregion /// /// 线上发货 /// public class OlineAddressdtos { public address_d_t_os address_d_t_os { get; set; } public List declare_product_d_t_os { get; set; } public string domestic_logistics_company { get; set; } public Int64? domestic_logistics_company_id { get; set; } public string domestic_tracking_no { get; set; } public string trade_order_from { get; set; } public string trade_order_id { get; set; } public string warehouse_carrier_service { get; set; } } public class Onlinesender { public OnlineAddr sender { get; set; } public OnlineAddr pickup { get; set; } public OnlineAddr receiver { get; set; } public OnlineAddr refund { get; set; } } public class OnlineAddr { public Int64? address_id { get; set; } } public class OnlineGoods { public string category_cn_desc { get; set; } public string category_en_desc { get; set; } public Boolean? contains_battery { get; set; } public string hs_code { get; set; } public string product_id { get; set; } public Int32? product_num { get; set; } public Decimal? product_weight { get; set; } public Decimal? productDeclareAmount { get; set; } public Boolean? only_battery { get; set; } public string sku_value { get; set; } } public class OnlineResult { public OnlineResultMd result { get; set; } public Boolean? result_success { get; set; } } public class OnlineResultMd { public string error_desc { get; set; } public string intl_tracking_no { get; set; } public string out_order_id { get; set; } public string success { get; set; } public string trade_order_from { get; set; } public string trade_order_id { get; set; } public string warehouse_order_id { get; set; } } /// /// 线上获取跟踪码 /// public class OnlineTrackCodeResult { public OnlineTrackCodeResultList result { get; set; } } /// /// 线上获取跟踪码 /// public class OnlineTrackCodeResultList { public OnlineTrackCodeResultList2 result_list { get; set; } public Boolean? success { get; set; } } /// /// 线上获取跟踪码 /// public class OnlineTrackCodeResultList2 { public List aeop_logistics_order_detail_dto { get; set; } } /// /// 线上获取跟踪码 /// public class OnlineTrackCodeResultListModel { public string international_logistics_type { get; set; } public string international_logistics_num { get; set; } public string out_order_code { get; set; } public string logistics_order_id { get; set; } public string channel_code { get; set; } public string trade_order_id { get; set; } } /// /// 线上发货标签 /// public class AeopWarehouseOrderQueryPdfRequest { public List warehouse_order_query_d_t_os { get; set; } } public class warehouse_order_query_d_t_os { public string international_logistics_id { get; set; } } public class Result2 { public string result { get; set; } } public class pdflabel2 { public string body { get; set; } public string StatusCode { get; set; } } public class OrderXXInfoResult { public AeopTpOrderDetailDto target { get; set; } } public class AeopTpOrderDetailDto { public buyer_info buyer_info { get; set; } public string buyer_signer_fullname { get; set; } public receipt_address receipt_address { get; set; } public string gmt_pay_success { get; set; } public money order_amount { get; set; } public string memo { get; set; } public order_msg_dtomd order_msg_list { get; set; } public child_order_list child_order_list { get; set; } } public class child_order_list { public List aeop_tp_child_order_dto { get; set; } } public class AeopTpChildOrderDto { public string child_order_id { get; set; } public string product_id { get; set; } public string product_name { get; set; } public string product_attributes { get; set; } public money product_price { get; set; } public string sku_code { get; set; } public Int32? product_count { get; set; } } public class product_info_dto { public List tp_open_order_product_info_dto { get; set; } } public class product_info_dtosku { public string sku { get; set; } public string quantity { get; set; } public string unit_price { get; set; } public string product_name { get; set; } public string product_id { get; set; } } public class buyer_info { public string login_id { get; set; } public string last_name { get; set; } public string first_name { get; set; } public string country { get; set; } } public class receipt_address { public string fax_area { get; set; } public string zip { get; set; } public string fax_country { get; set; } public string address2 { get; set; } public string country { get; set; } public string city { get; set; } public string detail_address { get; set; } public string fax_number { get; set; } public string phone_number { get; set; } public string address { get; set; } public string province { get; set; } public string phone_area { get; set; } public string phone_country { get; set; } public string contact_person { get; set; } public string mobile_no { get; set; } } public class order_msg_dtomd { public List tp_open_order_msg_dto { get; set; } } public class order_msg_dto { public string status { get; set; } public string content { get; set; } public string id { get; set; } public string gmt_create { get; set; } } }