Beispiel #1
0
        public async Task <BbExpressResponse> AddExpress(BbExpressRequest request)
        {
            try
            {
                using (HttpClient hc = new HttpClient())
                {
                    Dictionary <string, string> dict = new Dictionary <string, string>();
                    dict.Add("method", "beibei.outer.trade.logistics.ship");
                    dict.Add("app_id", appId);
                    dict.Add("session", session);
                    dict.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    dict.Add("oid", request.Oid);
                    dict.Add("company", request.Company);
                    dict.Add("out_sid", request.Out_sid);
                    if (request.Order_items != null)
                    {
                        dict.Add("order_items", request.Order_items);
                    }
                    string sing = CommonHelper.BbOpera(dict, secret);
                    dict.Add("sign", sing);
                    FormUrlEncodedContent content = new FormUrlEncodedContent(dict);
                    HttpResponseMessage   msg     = await hc.PostAsync(gateway, content);

                    string res = await msg.Content.ReadAsStringAsync();

                    return(CommonHelper.DeJson <BbExpressResponse>(res));
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #2
0
        public async void AddExp()
        {
            try
            {
                List <string> sourceIds   = new List <string>();
                var           models      = orderService.QueryOrder("ZHGS23", "ZY0113", ref sourceIds);
                var           bbSourceIds = await shopService.GetWaitSendOid();

                var jjSourceIds = sourceIds.Intersect(bbSourceIds).ToList();
                var selModels   = models.Where(m => jjSourceIds.Contains(m.SourceOrderID)).ToList();
                if (selModels.Count > 0)
                {
                    var listExpress = await shopService.GetExpress();

                    foreach (var model in selModels)
                    {
                        if (model.ExpressName.Contains("中通"))
                        {
                            model.ExpressName = "中通";
                        }
                        if (model.ExpressName.Contains("圆通"))
                        {
                            model.ExpressName = "圆通";
                        }
                        if (model.ExpressName.Contains("韵达"))
                        {
                            model.ExpressName = "韵达";
                        }
                        if (model.ExpressName.Contains("申通"))
                        {
                            model.ExpressName = "申通";
                        }
                        if (model.ExpressName.Contains("EMS"))
                        {
                            model.ExpressName = "邮政国内";
                        }
                        var expItem = listExpress.ToList().Where(e => e.Name == model.ExpressName).ToList();
                        if (expItem.Count > 0)
                        {
                            model.ExpressCode = expItem[0].Code;
                        }
                    }

                    foreach (var sourceId in jjSourceIds)
                    {
                        var model = selModels.Where(m => m.SourceOrderID == sourceId).ToList();
                        if (model.Count > 0)
                        {
                            foreach (var mod in model)
                            {
                                if (!string.IsNullOrEmpty(mod.WAYBILLID))
                                {
                                    BbExpressRequest request = new BbExpressRequest
                                    {
                                        Oid         = sourceId,
                                        Company     = mod.ExpressCode,
                                        Out_sid     = mod.WAYBILLID,
                                        Order_items = mod.OrderDTList
                                    };
                                    var msg = await shopService.AddExpress(request);

                                    if (msg.Success)
                                    {
                                        successUploadOrders += mod.BillID + ",";
                                    }
                                    else
                                    {
                                        failUploadOrders += mod.BillID + "," + msg.Message;
                                    }
                                }
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(successUploadOrders))
                    {
                        log.Debug("=========已将以下订单同步至贝贝==========" + successUploadOrders);
                    }

                    if (!string.IsNullOrEmpty(failUploadOrders))
                    {
                        log.Error("===========以下订单同步失败 请检查==========" + failUploadOrders);
                    }
                }
            }
            catch (Exception e)
            {
                log.Error("执行AddExp出错", e);
            }
        }