Beispiel #1
0
        /// <summary>
        /// 获取标准商品类目属性
        /// </summary>
        /// <param name="itemprop"></param>
        /// <returns></returns>
        internal List <ItemProp> GetItemprops(ItempropsGet itemprop)
        {
            ITopClient          client = new DefaultTopClient(StaticSystemConfig.soft.ApiURL, StaticSystemConfig.soft.AppKey, StaticSystemConfig.soft.AppSecret, "json");
            ItempropsGetRequest req    = new ItempropsGetRequest();

            req.Fields      = "is_input_prop,type,modified_time,modified_type,cid,required,features,is_taosir,taosir_do,pid,parent_pid,parent_vid,name,is_key_prop,is_sale_prop,is_color_prop,is_enum_prop,is_item_prop,must,multi,prop_values,status,sort_order,child_template,is_allow_alias";
            req.Cid         = itemprop.Cid;
            req.Pid         = itemprop.Pid;
            req.ParentPid   = itemprop.ParentPid;
            req.IsKeyProp   = itemprop.IsKeyProp;
            req.IsSaleProp  = itemprop.IsSaleProp;
            req.IsColorProp = itemprop.IsColorProp;
            req.IsEnumProp  = itemprop.IsEnumProp;
            req.IsInputProp = itemprop.IsInputProp;
            req.IsItemProp  = itemprop.IsItemProp;
            req.ChildPath   = itemprop.ChildPath;
            req.Type        = itemprop.Type;
            req.AttrKeys    = itemprop.AttrKeys;
            ItempropsGetResponse response = client.Execute(req);

            TopJsonParser         topjson = new TopJsonParser();
            ItempropsGetResponse1 resp    = topjson.Parse <ItempropsGetResponse1>(response.Body);

            return(resp.ItemProps);
        }
Beispiel #2
0
        /// <summary>
        /// 获取标准类目属性值
        /// </summary>
        /// <param name="Cid">叶子类目ID </param>
        /// <param name="Pvs">属性和属性值 id串,格式例如(pid1;pid2)或(pid1:vid1;pid2:vid2)或(pid1;pid2:vid2)</param>
        /// <param name="Type">获取类目的类型:1代表集市、2代表天猫</param>
        /// <param name="AttrKeys">属性的Key,支持多条,以“,”分隔</param>
        /// <returns></returns>
        public List <PropValue> GetItemPropValues(string Cid, string Pvs, string Type, string AttrKeys)
        {
            ITopClient client            = new DefaultTopClient(StaticSystemConfig.soft.ApiURL, StaticSystemConfig.soft.AppKey, StaticSystemConfig.soft.AppSecret, "json");
            ItempropvaluesGetRequest req = new ItempropvaluesGetRequest();

            req.Fields = "cid,pid,prop_name,vid,name,name_alias,status,sort_order";
            if (Cid != null)
            {
                req.Cid = long.Parse(Cid);
            }
            else
            {
                return(null);
            }
            if (Pvs != null)
            {
                req.Pvs = Pvs;
            }
            if (Type != null)
            {
                req.Type = long.Parse(Type);
            }
            if (AttrKeys != null)
            {
                req.AttrKeys = AttrKeys;
            }
            ItempropvaluesGetResponse response = client.Execute(req);

            TopJsonParser topjson           = new TopJsonParser();
            ItempropvaluesGetResponse1 resp = topjson.Parse <ItempropvaluesGetResponse1>(response.Body);

            return(resp.PropValues);
        }
Beispiel #3
0
        /// <summary>
        /// 获取单笔交易的部分信息(性能高)
        /// </summary>
        /// <param name="sessionKey"></param>
        /// <param name="tid"></param>
        /// <param name="ErrorMsg"></param>
        /// <returns></returns>
        internal Trade GetTrade(string sessionKey, string tid, out string ErrorMsg)
        {
            ErrorMsg = null;
            List <Trade> ListTrades = new List <Trade>();

            try
            {
                ITopClient      client = new DefaultTopClient(StaticSystemConfig.soft.ApiURL, StaticSystemConfig.soft.AppKey, StaticSystemConfig.soft.AppSecret, "json");
                TradeGetRequest req    = new TradeGetRequest();
                req.Fields = "tid,created,pay_time,end_time,status,snapshot_url,buyer_message,price,buyer_nick ,seller_nick, buyer_nick, title, type, created, tid, seller_rate,seller_can_rate, buyer_rate,can_rate, status, payment, discount_fee, adjust_fee, post_fee, total_fee, pay_time, end_time, modified, consign_time, buyer_obtain_point_fee, point_fee, real_point_fee, received_payment, pic_path, num_iid, num, price, cod_fee, cod_status, shipping_type, receiver_name, receiver_state, receiver_city, receiver_district, receiver_address, receiver_zip, receiver_mobile, receiver_phone,seller_flag,alipay_id,alipay_no,is_lgtype,is_force_wlb,is_brand_sale,buyer_area,has_buyer_message, credit_card_fee, lg_aging_type, lg_aging, step_trade_status,step_paid_fee,mark_desc,has_yfx,yfx_fee,yfx_id,yfx_type,trade_source,send_time,is_daixiao,is_wt,is_part_consign,zero_purchase,orders";
                if (tid == null)
                {
                    ErrorMsg = "交易编号不能为空!";
                    return(null);
                }
                req.Tid = long.Parse(tid);
                TradeGetResponse response = client.Execute(req, sessionKey);
                if (response.IsError)
                {
                    ErrorMsg = response.SubErrMsg;
                    return(null);
                }
                else
                {
                    TopJsonParser         topjson = new TopJsonParser();
                    TradeMemoAddResponse1 resp    = topjson.Parse <TradeMemoAddResponse1>(response.Body);
                    return(resp.Trade);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #4
0
        public static object DecodeMsg(String msg)
        {
            IDictionary dict = TopUtils.ParseJson(msg);

            if (dict != null && dict.Count > 0)
            {
                IEnumerator em = dict.Keys.GetEnumerator();
                em.MoveNext();
                IDictionary data = dict[em.Current] as IDictionary;

                if (data != null)
                {
                    TopJsonParser tjp    = new TopJsonParser();
                    ITopReader    reader = new TopJsonReader(data);
                    //if (dict.Contains(NOTIFY_ITEM))
                    //{
                    //    return tjp.FromJson(reader, typeof(NotifyItem));
                    //}
                    if (dict.Contains(NOTIFY_TRADE))
                    {
                        return(tjp.FromJson(reader, typeof(NotifyTrade)));
                    }
                    //else if (dict.Contains(NOTIFY_REFUND))
                    //{
                    //    return tjp.FromJson(reader, typeof(NotifyRefund));
                    //}
                }
            }
            return(null);
        }
Beispiel #5
0
        /// <summary>
        /// 查询支持起始地到目的地范围的物流公司
        /// </summary>
        /// <param name="ServiceType">服务类型,</param>
        /// <param name="SourceId">物流公司揽货地地区码</param>
        /// <param name="TargetId">物流公司派送地地区码(</param>
        /// <param name="GoodsValue">货物价格</param>
        /// <param name="IsNeedCarriage">是否需要揽收资费信息</param>
        /// <returns></returns>
        public List <LogisticsPartner> GetLogisticsPartners(string ServiceType, bool?IsNeedCarriage, string SourceId = null, string TargetId = null, string GoodsValue = null)
        {
            ITopClient client = new DefaultTopClient(StaticSystemConfig.soft.ApiURL, StaticSystemConfig.soft.AppKey, StaticSystemConfig.soft.AppSecret, "json");
            LogisticsPartnersGetRequest req = new LogisticsPartnersGetRequest();

            req.ServiceType = ServiceType;
            if (SourceId != null)
            {
                req.SourceId = SourceId;
            }
            if (TargetId != null)
            {
                req.TargetId = TargetId;
            }
            req.IsNeedCarriage = false;
            LogisticsPartnersGetResponse response = client.Execute(req);

            if (!response.IsError)
            {
                TopJsonParser topjson = new TopJsonParser();
                LogisticsPartnersGetResponse1 resp = topjson.Parse <LogisticsPartnersGetResponse1>(response.Body);
                return(resp.LogisticsPartners);
            }
            else
            {
                return(null);
            }
        }
Beispiel #6
0
        /// <summary>
        /// 将淘宝类型转化为本地类型
        /// </summary>
        /// <param name="str">获得的商品列表JSon </param>
        /// <returns></returns>
        internal IList <Item> ChangeTypeForItem(string str)
        {
            TopJsonParser           topjson = new TopJsonParser();
            ItemsOnsaleGetResponse1 resp    = topjson.Parse <ItemsOnsaleGetResponse1>(str);

            return(resp.Items);

            //itemsresponse result = Utils.JsonStrToObject<itemsresponse>(str);
            #region    待验证的代码 (无用)
            //IList<Item> result = null;
            //foreach (Top.Api.Domain.Item item in Ilist)
            //{

            //Item proc = new Item();
            //proc.AfterSaleId = item.AfterSaleId;
            //proc.ApproveStatus = item.ApproveStatus;
            //proc.AuctionPoint = item.AuctionPoint;
            //proc.AutoFill = item.AutoFill;
            //proc.Barcode = item.Barcode;
            //proc.ChangeProp = item.ChangeProp;
            //proc.Cid = item.Cid;
            //proc.CodPostageId = item.CodPostageId;
            //proc.Created = item.Created;
            //proc.CustomMadeTypeId = item.CustomMadeTypeId;
            //proc.DelistTime = item.DelistTime;
            //proc.DeliveryTime = new DeliveryTime();
            //proc.DeliveryTime.DeliveryTime_ = item.DeliveryTime.DeliveryTime_;
            //proc.DeliveryTime.DeliveryTimeType = item.DeliveryTime.DeliveryTimeType;
            //proc.DeliveryTime.NeedDeliveryTime = item.DeliveryTime.NeedDeliveryTime;
            //proc.Desc = item.Desc;
            //proc.DescModuleInfo = new DescModuleInfo();
            //proc.DescModuleInfo.AnchorModuleIds = item.DescModuleInfo.AnchorModuleIds;
            //proc.DescModuleInfo.Type = item.DescModuleInfo.Type;
            //proc.DescModules = item.DescModules;
            //proc.DetailUrl = item.DetailUrl;
            //proc.EmsFee = item.EmsFee;
            //proc.ExpressFee = item.ExpressFee;
            //proc.Features = item.Features;
            //proc.FoodSecurity = new FoodSecurity();
            //proc.FoodSecurity.Contact = item.FoodSecurity.Contact;
            //proc.FoodSecurity.DesignCode = item.FoodSecurity.DesignCode;
            //proc.FoodSecurity.Factory = item.FoodSecurity.Factory;
            //proc.FoodSecurity.FactorySite = item.FoodSecurity.FactorySite;
            //proc.FoodSecurity.FoodAdditive = item.FoodSecurity.FoodAdditive;
            //proc.FoodSecurity.HealthProductNo = item.FoodSecurity.HealthProductNo;
            //proc.FoodSecurity.Mix = item.FoodSecurity.Mix;
            //proc.FoodSecurity.Period = item.FoodSecurity.Period;
            //proc.FoodSecurity.PlanStorage = item.FoodSecurity.PlanStorage;
            //proc.FoodSecurity.PrdLicenseNo = item.FoodSecurity.PrdLicenseNo;
            //proc.FoodSecurity.ProductDateEnd = item.FoodSecurity.ProductDateEnd;

            //  result.Add(proc);
            //}
            #endregion
            // return result.items_onsale_get_response.items.item;
        }
Beispiel #7
0
        /// <summary>
        /// 获取前台展示的店铺内卖家自定义商品类目
        /// </summary>
        /// <param name="NickName"></param>
        internal List <SellerCat> GetSPLM(string NickName)
        {
            ITopClient client            = new DefaultTopClient(StaticSystemConfig.soft.ApiURL, StaticSystemConfig.soft.AppKey, StaticSystemConfig.soft.AppSecret, "json");
            SellercatsListGetRequest req = new SellercatsListGetRequest();

            req.Nick = NickName;
            SellercatsListGetResponse  response = client.Execute(req);
            TopJsonParser              topjson  = new TopJsonParser();
            SellercatsListGetResponse1 resp     = topjson.Parse <SellercatsListGetResponse1>(response.Body);

            return(resp.SellerCats);
        }
Beispiel #8
0
        /// <summary>
        /// 查询商家被授权品牌列表和类目列表
        /// </summary>
        internal SellerAuthorize GetAuthorizeItemcats(string sessionKey)
        {
            ITopClient client = new DefaultTopClient(StaticSystemConfig.soft.ApiURL, StaticSystemConfig.soft.AppKey, StaticSystemConfig.soft.AppSecret, "json");
            ItemcatsAuthorizeGetRequest req = new ItemcatsAuthorizeGetRequest();

            req.Fields = "brand.vid, brand.name, item_cat.cid, item_cat.name, item_cat.status,item_cat.sort_order,item_cat.parent_cid,item_cat.is_parent, xinpin_item_cat.cid, xinpin_item_cat.name, xinpin_item_cat.status, xinpin_item_cat.sort_order, xinpin_item_cat.parent_cid, xinpin_item_cat.is_parent";
            ItemcatsAuthorizeGetResponse response = client.Execute(req, sessionKey);

            TopJsonParser topjson = new TopJsonParser();
            ItemcatsAuthorizeGetResponse1 resp = topjson.Parse <ItemcatsAuthorizeGetResponse1>(response.Body);

            return(resp.SellerAuthorize);
        }
Beispiel #9
0
        /// <summary>
        /// 更改交易的收货地址
        /// </summary>
        /// <param name="sessionKey"></param>
        /// <param name="TradeShipping"></param>
        /// <param name="ErrorMsg"></param>
        internal Trade UpdateTradeShippingAddress(string sessionKey, TradeShippingaddressUpdate TradeShipping, out string ErrorMsg)
        {
            ErrorMsg = null;
            Trade newtrade = new Trade();

            try
            {
                ITopClient client = new DefaultTopClient(StaticSystemConfig.soft.ApiURL, StaticSystemConfig.soft.AppKey, StaticSystemConfig.soft.AppSecret, "json");
                TradeShippingaddressUpdateRequest req = new TradeShippingaddressUpdateRequest();
                if (TradeShipping.Tid != null)
                {
                    req.Tid = 2755739791L;
                }
                else
                {
                    ErrorMsg = "交易编号不能为空!";
                    return(null);
                }
                req.ReceiverName     = TradeShipping.ReceiverName;
                req.ReceiverPhone    = TradeShipping.ReceiverPhone;
                req.ReceiverMobile   = TradeShipping.ReceiverMobile;
                req.ReceiverState    = TradeShipping.ReceiverState;
                req.ReceiverCity     = TradeShipping.ReceiverCity;
                req.ReceiverDistrict = TradeShipping.ReceiverDistrict;
                req.ReceiverAddress  = TradeShipping.ReceiverAddress;
                req.ReceiverZip      = TradeShipping.ReceiverZip;
                TradeShippingaddressUpdateResponse response = client.Execute(req, sessionKey);
                if (response.IsError)
                {
                    ErrorMsg = response.SubErrMsg;
                    return(null);
                }
                else
                {
                    TopJsonParser         topjson = new TopJsonParser();
                    TradeMemoAddResponse1 resp    = topjson.Parse <TradeMemoAddResponse1>(response.Body);
                    if (!response.IsError)
                    {
                        newtrade = resp.Trade;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(newtrade);
        }
        public T Execute <T>(ITopRequest <T> request, string session) where T : TopResponse
        {
            // 添加协议级请求参数
            TopDictionary txtParams = new TopDictionary(request.GetParameters());

            txtParams.Add(METHOD, request.GetApiName());
            txtParams.Add(VERSION, "2.0");
            txtParams.Add(APP_KEY, appKey);
            txtParams.Add(FORMAT, format);
            txtParams.Add(PARTNER_ID, "top-sdk-net-20110512");
            txtParams.Add(TIMESTAMP, DateTime.Now);
            txtParams.Add(SESSION, session);

            // 添加签名参数
            txtParams.Add(SIGN, TopUtils.SignTopRequest(txtParams, appSecret));

            // 是否需要上传文件
            string body;

            if (request is ITopUploadRequest <T> )
            {
                ITopUploadRequest <T>          uRequest   = (ITopUploadRequest <T>)request;
                IDictionary <string, FileItem> fileParams = TopUtils.CleanupDictionary(uRequest.GetFileParameters());
                body = webUtils.DoPost(this.serverUrl, txtParams, fileParams);
            }
            else
            {
                body = webUtils.DoPost(this.serverUrl, txtParams);
            }

            T rsp;

            if (FORMAT_XML.Equals(format))
            {
                ITopParser <T> tp = new TopXmlParser <T>();
                rsp = tp.Parse(body);
            }
            else
            {
                ITopParser <T> tp = new TopJsonParser <T>();
                rsp = tp.Parse(body);
            }

            return(rsp);
        }
Beispiel #11
0
        /// <summary>
        /// 添加一条备注
        /// </summary>
        /// <param name="sessionKey"></param>
        /// <param name="Tid">交易编号</param>
        /// <param name="Memo">交易备注。最大长度: 1000个字节</param>
        /// <param name="Flag">交易备注旗帜,可选值为:0(灰色), 1(红色), 2(黄色), 3(绿色), 4(蓝色), 5(粉红色),默认值为0</param>
        /// <param name="ErrorMsg">错误信息</param>
        /// <returns></returns>
        internal Trade AddTradeMemo(string sessionKey, string Tid, string Memo, int Flag, out string ErrorMsg)
        {
            ErrorMsg = null;
            Trade newtrade = new Trade();

            try
            {
                ITopClient          client = new DefaultTopClient(StaticSystemConfig.soft.ApiURL, StaticSystemConfig.soft.AppKey, StaticSystemConfig.soft.AppSecret, "json");
                TradeMemoAddRequest req    = new TradeMemoAddRequest();
                if (!string.IsNullOrEmpty(Tid))
                {
                    req.Tid = long.Parse(Tid);
                }
                else
                {
                    ErrorMsg = "订单编号不能为空!";
                    return(null);
                }
                req.Memo = Memo;
                req.Flag = Flag;
                TradeMemoAddResponse response = client.Execute(req, sessionKey);
                if (response.IsError)
                {
                    ErrorMsg = response.SubErrMsg;
                    return(null);
                }
                else
                {
                    TopJsonParser         topjson = new TopJsonParser();
                    TradeMemoAddResponse1 resp    = topjson.Parse <TradeMemoAddResponse1>(response.Body);
                    if (!response.IsError)
                    {
                        newtrade = resp.Trade;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(newtrade);
        }
Beispiel #12
0
        /// <summary>
        /// 把JSON解释为API响应对象。
        /// </summary>
        /// <typeparam name="T">API响应类型</typeparam>
        /// <param name="json">JSON字符串</param>
        /// <returns>API响应对象</returns>
        public static T ParseResponse <T>(string json) where T : TopResponse
        {
            TopJsonParser parser = new TopJsonParser();

            return(parser.Parse <T>(json));
        }
        private T DoExecute <T>(ITopRequest <T> request, string session, long timestamp) where T : YunResponse
        {
            // 提前检查业务参数
            try
            {
                request.Validate();
            }
            catch (YunException e)
            {
                return(CreateErrorResponse <T>(e.ErrorCode, e.ErrorMsg));
            }

            // 添加协议级请求参数
            var txtParams = new YunDictionary(request.GetParameters())
            {
                { METHOD, request.GetApiName() },
                { VERSION, "1.0" },
                { APP_KEY, appKey },
                { FORMAT, format },
                { TIMESTAMP, timestamp },
                { SESSION, session }
            };

            txtParams.AddAll(this.systemParameters);

            // 添加签名参数
            txtParams.Add(SIGN, TopUtils.SignTopRequest(txtParams, appSecret, "UTF-8"));

            var reqUrl = webUtils.BuildGetUrl(this.serverUrl, txtParams);

            try
            {
                string body;
                if (request is ITopUploadRequest <T> ) // 是否需要上传文件
                {
                    var uRequest   = (ITopUploadRequest <T>)request;
                    var fileParams = TopUtils.CleanupDictionary(uRequest.GetFileParameters());
                    body = webUtils.DoPost(this.serverUrl, txtParams, fileParams);
                }
                else
                {
                    body = webUtils.DoPost(this.serverUrl, txtParams);
                }

                // 解释响应结果
                T rsp;
                if (disableParser)
                {
                    rsp      = Activator.CreateInstance <T>();
                    rsp.Body = body;
                }
                else
                {
                    if (FORMAT_XML.Equals(format))
                    {
                        ITopParser tp = new TopXmlParser();
                        rsp = tp.Parse <T>(body);
                    }
                    else
                    {
                        ITopParser tp = new TopJsonParser();
                        rsp = tp.Parse <T>(body);
                        //rsp = Newtonsoft.Json.JsonConvert.DeserializeObject<T>(body);
                        //rsp = JsonDeserialize<T>(body);
                    }
                }

                rsp.ReqUrl = reqUrl;

                // 追踪错误的请求
                if (!disableTrace && rsp.IsError)
                {
                    var sb = new StringBuilder(reqUrl).Append(" response error!\r\n").Append(rsp.Body);
                    topLogger.Warn(sb.ToString());
                }
                return(rsp);
            }
            catch (Exception e)
            {
                if (!disableTrace)
                {
                    var sb = new StringBuilder(reqUrl).Append(" request error!\r\n").Append(e.StackTrace);
                    topLogger.Error(sb.ToString());
                }
                throw e;
            }
        }
Beispiel #14
0
        /// <summary>
        /// 查询卖家已卖出的增量交易数据(根据修改时间)
        /// </summary>
        /// <param name="sessionKey"></param>
        /// <param name="TradesSold"></param>
        /// <param name="ErrorMsg"></param>
        /// <returns></returns>
        internal List <Trade> GetTradesSoldIncrement(string sessionKey, TradesSoldGet TradesSold, out string ErrorMsg)
        {
            ErrorMsg = null;
            List <Trade> ListTrades = new List <Trade>();
            DateTime     starttime  = new DateTime();
            DateTime     endtime    = new DateTime();

            try
            {
                ITopClient client = new DefaultTopClient(StaticSystemConfig.soft.ApiURL, StaticSystemConfig.soft.AppKey, StaticSystemConfig.soft.AppSecret, "json");
                TradesSoldIncrementGetRequest req = new TradesSoldIncrementGetRequest();
                req.Fields = "tid,created,pay_time,end_time,status,snapshot_url,buyer_message,price,buyer_nick,seller_memo,seller_flag,orders";
                if (TradesSold.StartCreated != null)
                {
                    string startt = TradesSold.StartModified.Value.ToString("yyyy-MM-dd HH:mm:ss");
                    starttime         = DateTime.Parse(startt);
                    req.StartModified = starttime;
                }
                if (TradesSold.EndCreated != null)
                {
                    string startt = TradesSold.EndModified.Value.ToString("yyyy-MM-dd HH:mm:ss");
                    endtime         = DateTime.Parse(startt);
                    req.EndModified = endtime;
                }
                //这里修正结束时间与开始时间间隔超一天,自动修改时间为开始时间的后一天
                if (starttime != new DateTime() && endtime != new DateTime())
                {
                    if (endtime.Subtract(starttime).Days > 1)
                    {
                        req.EndModified = starttime.AddDays(1);
                    }
                }
                if (TradesSold.Status != null)
                {
                    req.Status = TradesSold.Status;
                }
                if (TradesSold.Type != null)
                {
                    req.Type = TradesSold.Type;
                }
                if (TradesSold.ExtType != null)
                {
                    req.ExtType = TradesSold.ExtType;
                }
                if (TradesSold.Tag != null)
                {
                    req.Tag = TradesSold.Tag;
                }
                if (TradesSold.PageNo != null)
                {
                    req.PageNo = TradesSold.PageNo;
                }
                if (TradesSold.PageSize != null)
                {
                    req.PageSize = TradesSold.PageSize;
                }
                if (TradesSold.UseHasNext != null)
                {
                    req.UseHasNext = TradesSold.UseHasNext;
                }
                TradesSoldIncrementGetResponse response = client.Execute(req, sessionKey);
                if (response.IsError)
                {
                    ErrorMsg = response.SubErrMsg;
                }
                else
                {
                    TopJsonParser          topjson = new TopJsonParser();
                    TradesSoldGetResponse1 resp    = topjson.Parse <TradesSoldGetResponse1>(response.Body);
                    ListTrades = resp.Trades;
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(ListTrades);
        }
        private T DoExecute <T>(ITopRequest <T> request, string session, DateTime timestamp) where T : TopResponse
        {
            // 提前检查业务参数
            try
            {
                request.Validate();
            }
            catch (TopException e)
            {
                return(CreateErrorResponse <T>(e.ErrorCode, e.ErrorMsg));
            }

            // 添加协议级请求参数
            TopDictionary txtParams = new TopDictionary(request.GetParameters());

            txtParams.Add(METHOD, request.GetApiName());
            txtParams.Add(VERSION, "2.0");
            txtParams.Add(SIGN_METHOD, Constants.SIGN_METHOD_MD5);
            txtParams.Add(APP_KEY, appKey);
            txtParams.Add(FORMAT, format);
            txtParams.Add(PARTNER_ID, GetSdkVersion());
            txtParams.Add(TIMESTAMP, timestamp);
            txtParams.Add(TARGET_APP_KEY, request.GetTargetAppKey());
            txtParams.Add(SESSION, session);
            txtParams.AddAll(this.systemParameters);

            if (this.useSimplifyJson)
            {
                txtParams.Add(SIMPLIFY, "true");
            }

            // 添加签名参数
            txtParams.Add(SIGN, TopUtils.SignTopRequest(txtParams, appSecret, true));

            // 添加头部参数
            if (this.useGzipEncoding)
            {
                request.GetHeaderParameters()[Constants.ACCEPT_ENCODING] = Constants.CONTENT_ENCODING_GZIP;
            }

            string realServerUrl = GetServerUrl(this.serverUrl, request.GetApiName(), session);
            string reqUrl        = webUtils.BuildGetUrl(realServerUrl, txtParams);

            try
            {
                string body;
                if (request is ITopUploadRequest <T> ) // 是否需要上传文件
                {
                    ITopUploadRequest <T>          uRequest   = (ITopUploadRequest <T>)request;
                    IDictionary <string, FileItem> fileParams = TopUtils.CleanupDictionary(uRequest.GetFileParameters());
                    body = webUtils.DoPost(realServerUrl, txtParams, fileParams, request.GetHeaderParameters());
                }
                else
                {
                    body = webUtils.DoPost(realServerUrl, txtParams, request.GetHeaderParameters());
                }

                // 解释响应结果
                T rsp;
                if (disableParser)
                {
                    rsp      = Activator.CreateInstance <T>();
                    rsp.Body = body;
                }
                else
                {
                    if (FORMAT_XML.Equals(format))
                    {
                        ITopParser tp = new TopXmlParser();
                        rsp = tp.Parse <T>(body);
                    }
                    else
                    {
                        ITopParser tp;
                        if (useSimplifyJson)
                        {
                            tp = new TopJsonSimplifyParser();
                        }
                        else
                        {
                            tp = new TopJsonParser();
                        }
                        rsp = tp.Parse <T>(body);
                    }
                }

                // 追踪错误的请求
                if (!disableTrace && rsp.IsError)
                {
                    StringBuilder sb = new StringBuilder(reqUrl).Append(" response error!\r\n").Append(rsp.Body);
                    topLogger.Warn(sb.ToString());
                }
                return(rsp);
            }
            catch (Exception e)
            {
                if (!disableTrace)
                {
                    StringBuilder sb = new StringBuilder(reqUrl).Append(" request error!\r\n").Append(e.StackTrace);
                    topLogger.Error(sb.ToString());
                }
                throw e;
            }
        }
Beispiel #16
0
        /// <summary>
        /// 查询卖家已卖出的交易数据(根据创建时间)
        /// </summary>
        /// <param name="sessionKey"></param>
        /// <param name="TradesSold"></param>
        /// <param name="ErrorMsg">错误信息</param>
        /// <param name="HasNext">是否存在下一页</param>
        /// <param name="TotalResults">总行数</param>
        /// <returns></returns>
        internal List <Trade> GetTradesSoldToTradeRate(string sessionKey, TradesSoldGet TradesSold, out string ErrorMsg, out bool HasNext, out long TotalResults)
        {
            ErrorMsg     = null;
            HasNext      = false;
            TotalResults = 0;
            List <Trade> ListTrades = new List <Trade>();

            try
            {
                ITopClient           client = new DefaultTopClient(StaticSystemConfig.soft.ApiURL, StaticSystemConfig.soft.AppKey, StaticSystemConfig.soft.AppSecret, "json");
                TradesSoldGetRequest req    = new TradesSoldGetRequest();
                req.Fields = "seller_nick, buyer_nick, title, type, created, tid, seller_rate,seller_can_rate, buyer_rate,can_rate, status, payment, discount_fee, adjust_fee, post_fee, total_fee, pay_time, end_time, modified, consign_time, buyer_obtain_point_fee, point_fee, real_point_fee, received_payment, pic_path, num_iid, num, price, cod_fee, cod_status, shipping_type, receiver_name, receiver_state, receiver_city, receiver_district, receiver_address, receiver_zip, receiver_mobile, receiver_phone,seller_flag,alipay_id,alipay_no,is_lgtype,is_force_wlb,is_brand_sale,buyer_area,has_buyer_message, credit_card_fee, lg_aging_type, lg_aging, step_trade_status,step_paid_fee,mark_desc,has_yfx,yfx_fee,yfx_id,yfx_type,trade_source,send_time,is_daixiao,is_wt,is_part_consign,zero_purchase,orders";

                if (TradesSold.StartCreated != null)
                {
                    string   startt   = TradesSold.StartCreated.Value.ToString("yyyy-MM-dd HH:mm:ss");
                    DateTime dateTime = DateTime.Parse(startt);
                    req.StartCreated = dateTime;
                }
                if (TradesSold.EndCreated != null)
                {
                    string   endt     = TradesSold.EndCreated.Value.ToString("yyyy-MM-dd HH:mm:ss");
                    DateTime dateTime = DateTime.Parse(endt);
                    req.EndCreated = dateTime;
                }
                if (TradesSold.Status != null)
                {
                    req.Status = TradesSold.Status;
                }
                if (TradesSold.BuyerNick != null)
                {
                    req.BuyerNick = TradesSold.BuyerNick;
                }

                /* fixed(一口价) auction(拍卖) guarantee_trade(一口价、拍卖) step(分阶段付款,万人团,阶梯团订单)
                 * independent_simple_trade(旺店入门版交易) independent_shop_trade(旺店标准版交易)
                 * auto_delivery(自动发货) ec(直冲) cod(货到付款) game_equipment(游戏装备) shopex_trade(ShopEX交易)
                 * netcn_trade(万网交易) external_trade(统一外部交易) instant_trade (即时到账) b2c_cod(大商家货到付款)
                 * hotel_trade(酒店类型交易) super_market_trade(商超交易) super_market_cod_trade(商超货到付款交易)
                 * taohua(淘花网交易类型) waimai(外卖交易类型) o2o_offlinetrade(O2O交易) nopaid(即时到帐/趣味猜交易类型)
                 * step (万人团) eticket(电子凭证) tmall_i18n(天猫国际);nopaid (无付款交易)insurance_plus(保险)
                 * finance(基金) 注:guarantee_trade是一个组合查询条件,并不是一种交易类型,获取批量或单个订单中不会返回此种类型的订单。
                 * pre_auth_type(预授权0元购)
                 */
                TradesSold.Type += "guarantee_trade, step," +
                                   " independent_simple_trade, independent_shop_trade, " +
                                   " auto_delivery, ec,cod, game_equipment, shopex_trade," +
                                   " netcn_trade, external_trade, instant_trade , b2c_cod," +
                                   " hotel_trade, super_market_trade, super_market_cod_trade," +
                                   " taohua,waimai, o2o_offlinetrade, nopaid,pre_auth_type," +
                                   " step, eticket, tmall_i18n,nopaid ,insurance_plus, finance";

                if (TradesSold.Type != null)
                {
                    req.Type = TradesSold.Type;
                }
                if (TradesSold.ExtType != null)
                {
                    req.ExtType = TradesSold.ExtType;
                }
                if (TradesSold.RateStatus != null)
                {
                    req.RateStatus = TradesSold.RateStatus;
                }
                if (TradesSold.Tag != null)
                {
                    req.Tag = TradesSold.Tag;
                }
                if (TradesSold.PageNo != null)
                {
                    req.PageNo = TradesSold.PageNo;
                }
                if (TradesSold.PageSize != null)
                {
                    req.PageSize = TradesSold.PageSize;
                }
                if (TradesSold.UseHasNext != null)
                {
                    req.UseHasNext = TradesSold.UseHasNext;
                }
                TradesSoldGetResponse response = client.Execute(req, sessionKey);
                if (response.IsError)
                {
                    ErrorMsg = response.SubErrMsg;
                }
                else
                {
                    TopJsonParser          topjson = new TopJsonParser();
                    TradesSoldGetResponse1 resp    = topjson.Parse <TradesSoldGetResponse1>(response.Body);
                    ListTrades = resp.Trades;
                    if (TradesSold.UseHasNext == true)
                    {
                        HasNext = resp.HasNext;
                    }
                    else
                    {
                        TotalResults = resp.TotalResults;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(ListTrades);
        }
Beispiel #17
0
        /// <summary>
        /// 查询卖家已卖出的交易数据(根据创建时间)
        /// </summary>
        /// <param name="sessionKey"></param>
        /// <param name="TradesSold"></param>
        /// <param name="ErrorMsg">错误信息</param>
        /// <param name="HasNext">是否存在下一页</param>
        /// <param name="TotalResults">总行数</param>
        /// <returns></returns>
        internal List <Trade> GetTradesSold(string sessionKey, TradesSoldGet TradesSold, out string ErrorMsg, out bool HasNext, out long TotalResults)
        {
            ErrorMsg     = null;
            HasNext      = false;
            TotalResults = 0;
            List <Trade> ListTrades = new List <Trade>();

            try
            {
                ITopClient           client = new DefaultTopClient(StaticSystemConfig.soft.ApiURL, StaticSystemConfig.soft.AppKey, StaticSystemConfig.soft.AppSecret, "json");
                TradesSoldGetRequest req    = new TradesSoldGetRequest();
                req.Fields = "tid,created,pay_time,end_time,status,price,buyer_nick";

                if (TradesSold.StartCreated != null)
                {
                    string   startt   = TradesSold.StartCreated.Value.ToString("yyyy-MM-dd HH:mm:ss");
                    DateTime dateTime = DateTime.Parse(startt);
                    req.StartCreated = dateTime;
                }
                if (TradesSold.EndCreated != null)
                {
                    string   endt     = TradesSold.EndCreated.Value.ToString("yyyy-MM-dd HH:mm:ss");
                    DateTime dateTime = DateTime.Parse(endt);
                    req.EndCreated = dateTime;
                }
                if (TradesSold.Status != null)
                {
                    req.Status = TradesSold.Status;
                }
                if (TradesSold.BuyerNick != null)
                {
                    req.BuyerNick = TradesSold.BuyerNick;
                }

                /* fixed(一口价) auction(拍卖) guarantee_trade(一口价、拍卖) step(分阶段付款,万人团,阶梯团订单)
                 * independent_simple_trade(旺店入门版交易) independent_shop_trade(旺店标准版交易)
                 * auto_delivery(自动发货) ec(直冲) cod(货到付款) game_equipment(游戏装备) shopex_trade(ShopEX交易)
                 * netcn_trade(万网交易) external_trade(统一外部交易) instant_trade (即时到账) b2c_cod(大商家货到付款)
                 * hotel_trade(酒店类型交易) super_market_trade(商超交易) super_market_cod_trade(商超货到付款交易)
                 * taohua(淘花网交易类型) waimai(外卖交易类型) o2o_offlinetrade(O2O交易) nopaid(即时到帐/趣味猜交易类型)
                 * step (万人团) eticket(电子凭证) tmall_i18n(天猫国际);nopaid (无付款交易)insurance_plus(保险)
                 * finance(基金) 注:guarantee_trade是一个组合查询条件,并不是一种交易类型,获取批量或单个订单中不会返回此种类型的订单。
                 * pre_auth_type(预授权0元购)
                 */
                TradesSold.Type += "guarantee_trade, step," +
                                   " independent_simple_trade, independent_shop_trade, " +
                                   " auto_delivery, ec,cod, game_equipment, shopex_trade," +
                                   " netcn_trade, external_trade, instant_trade , b2c_cod," +
                                   " hotel_trade, super_market_trade, super_market_cod_trade," +
                                   " taohua,waimai, o2o_offlinetrade, nopaid,pre_auth_type," +
                                   " step, eticket, tmall_i18n,nopaid ,insurance_plus, finance";

                if (TradesSold.Type != null)
                {
                    req.Type = TradesSold.Type;
                }
                if (TradesSold.ExtType != null)
                {
                    req.ExtType = TradesSold.ExtType;
                }
                if (TradesSold.RateStatus != null)
                {
                    req.RateStatus = TradesSold.RateStatus;
                }
                if (TradesSold.Tag != null)
                {
                    req.Tag = TradesSold.Tag;
                }
                if (TradesSold.PageNo != null)
                {
                    req.PageNo = TradesSold.PageNo;
                }
                if (TradesSold.PageSize != null)
                {
                    req.PageSize = TradesSold.PageSize;
                }
                if (TradesSold.UseHasNext != null)
                {
                    req.UseHasNext = TradesSold.UseHasNext;
                }
                TradesSoldGetResponse response = client.Execute(req, sessionKey);
                if (response.IsError)
                {
                    ErrorMsg = response.SubErrMsg;
                }
                else
                {
                    TopJsonParser          topjson = new TopJsonParser();
                    TradesSoldGetResponse1 resp    = topjson.Parse <TradesSoldGetResponse1>(response.Body);
                    ListTrades = resp.Trades;
                    if (TradesSold.UseHasNext == true)
                    {
                        HasNext = resp.HasNext;
                    }
                    else
                    {
                        TotalResults = resp.TotalResults;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(ListTrades);
        }
Beispiel #18
0
 /// <summary>
 /// 把JSON解释为API响应对象。
 /// </summary>
 /// <typeparam name="T">API响应类型</typeparam>
 /// <param name="json">JSON字符串</param>
 /// <returns>API响应对象</returns>
 public static T ParseResponse<T>(string json) where T : TopResponse
 {
     TopJsonParser<T> parser = new TopJsonParser<T>();
     return parser.Parse(json);
 }
Beispiel #19
0
        private T DoExecute <T>(ITopRequest <T> request, string session, DateTime timestamp) where T : TopResponse
        {
            // 提前检查业务参数

            try
            {
                request.Validate();
            }
            catch (TopException e)
            {
                return(createErrorResponse <T>(e.ErrorCode, e.ErrorMsg));
            }
            string sip_timestamp = timestamp.ToString("yyyy-MM-dd HH:mm:ss.000");
            // 添加协议级请求参数
            TopDictionary     txtParams         = new TopDictionary();
            PortalRestRequest portalRestRequest = request.GetParameters();

            //Jayrock.Json.JsonTextWriter writer = new Jayrock.Json.JsonTextWriter();
            //Jayrock.Json.Conversion.JsonConvert.Export(paramDict, writer);
            //txtParams.Add(PORTALTRANSACTION, "[" + Jayrock.Json.Conversion.JsonConvert.ExportToString(portalRestRequest) + "]");
            txtParams.Add(PORTALTRANSACTION, "[" + Newtonsoft.Json.JsonConvert.SerializeObject(portalRestRequest) + "]");
            txtParams.Add(APP_KEY, appKey);
            txtParams.Add(TIMESTAMP, sip_timestamp);
            txtParams.AddAll(this.systemParameters);

            // 添加签名参数
            txtParams.Add(SIGN, TopUtils.SignBurgeonPortalRequest(appKey, appSecret, sip_timestamp));

            // 是否需要上传文件
            string body;

            if (request is ITopUploadRequest <T> )
            {
                ITopUploadRequest <T>          uRequest   = (ITopUploadRequest <T>)request;
                IDictionary <string, FileItem> fileParams = TopUtils.CleanupDictionary(uRequest.GetFileParameters());
                body = webUtils.DoPost(this.serverUrl, txtParams, fileParams);
            }
            else
            {
                body = webUtils.DoPost(this.serverUrl, txtParams);
            }

            // 解释响应结果
            T rsp;

            if (disableParser)
            {
                rsp      = Activator.CreateInstance <T>();
                rsp.Body = body;
            }
            else
            {
                ITopParser tp = new TopJsonParser();
                //去掉body[]
                body = body.Substring(1, body.LastIndexOf(']') - 1);

                rsp = tp.Parse <T>(body);
            }

            // 追踪错误的请求
            if (!disableTrace)
            {
                rsp.Body   = body;
                rsp.ReqUrl = webUtils.BuildGetUrl(this.serverUrl, txtParams);
                if (rsp.IsError)
                {
                    topLogger.Warn(rsp.ReqUrl + "\r\n" + rsp.Body);
                }
            }

            return(rsp);
        }
Beispiel #20
0
        private T DoExecute <T>(ITopRequest <T> request, string session, DateTime timestamp) where T : TopResponse
        {
            // 提前检查业务参数
            try
            {
                request.Validate();
            }
            catch (TopException e)
            {
                return(createErrorResponse <T>(e.ErrorCode, e.ErrorMsg));
            }

            // 添加协议级请求参数
            TopDictionary txtParams = new TopDictionary(request.GetParameters());

            txtParams.Add(METHOD, request.GetApiName());
            txtParams.Add(VERSION, "2.0");
            txtParams.Add(APP_KEY, appKey);
            txtParams.Add(FORMAT, format);
            txtParams.Add(PARTNER_ID, "top-sdk-net-20130425");
            txtParams.Add(TIMESTAMP, timestamp);
            txtParams.Add(SESSION, session);
            txtParams.AddAll(this.systemParameters);

            // 添加签名参数
            txtParams.Add(SIGN, TopUtils.SignTopRequest(txtParams, appSecret));

            // 是否需要上传文件
            string body;

            if (request is ITopUploadRequest <T> )
            {
                ITopUploadRequest <T>          uRequest   = (ITopUploadRequest <T>)request;
                IDictionary <string, FileItem> fileParams = TopUtils.CleanupDictionary(uRequest.GetFileParameters());
                body = webUtils.DoPost(this.serverUrl, txtParams, fileParams);
            }
            else
            {
                body = webUtils.DoPost(this.serverUrl, txtParams);
            }

            // 解释响应结果
            T rsp;

            if (disableParser)
            {
                rsp      = Activator.CreateInstance <T>();
                rsp.Body = body;
            }
            else
            {
                if (FORMAT_XML.Equals(format))
                {
                    ITopParser tp = new TopXmlParser();
                    rsp = tp.Parse <T>(body);
                }
                else
                {
                    ITopParser tp = new TopJsonParser();
                    rsp = tp.Parse <T>(body);
                }
            }

            // 追踪错误的请求
            if (!disableTrace)
            {
                rsp.ReqUrl = webUtils.BuildGetUrl(this.serverUrl, txtParams);
                if (rsp.IsError)
                {
                    topLogger.Warn(rsp.ReqUrl + "\r\n" + rsp.Body);
                }
            }

            return(rsp);
        }
Beispiel #21
0
        private T DoExecute <T>(ITopRequest <T> request, string session, DateTime timestamp) where T : TopResponse
        {
            long start = DateTime.Now.Ticks;

            // 提前检查业务参数
            try
            {
                request.Validate();
            }
            catch (TopException e)
            {
                return(CreateErrorResponse <T>(e.ErrorCode, e.ErrorMsg));
            }

            // 添加协议级请求参数
            TopDictionary txtParams = new TopDictionary(request.GetParameters());

            txtParams.Add(Constants.METHOD, request.GetApiName());
            txtParams.Add(Constants.VERSION, "2.0");
            txtParams.Add(Constants.SIGN_METHOD, Constants.SIGN_METHOD_HMAC);
            txtParams.Add(Constants.APP_KEY, appKey);
            txtParams.Add(Constants.FORMAT, format);
            txtParams.Add(Constants.PARTNER_ID, GetSdkVersion());
            txtParams.Add(Constants.TIMESTAMP, timestamp);
            txtParams.Add(Constants.TARGET_APP_KEY, request.GetTargetAppKey());
            txtParams.Add(Constants.SESSION, session);
            txtParams.AddAll(this.systemParameters);

            if (this.useSimplifyJson)
            {
                txtParams.Add(Constants.SIMPLIFY, "true");
            }

            // 添加签名参数
            txtParams.Add(Constants.SIGN, TopUtils.SignTopRequest(txtParams, appSecret, Constants.SIGN_METHOD_HMAC));

            // 添加头部参数
            if (this.useGzipEncoding)
            {
                request.GetHeaderParameters()[Constants.ACCEPT_ENCODING] = Constants.CONTENT_ENCODING_GZIP;
            }

            string realServerUrl = GetServerUrl(this.serverUrl, request.GetApiName(), session);
            string reqUrl        = WebUtils.BuildRequestUrl(realServerUrl, txtParams);

            try
            {
                string body;
                if (request is ITopUploadRequest <T> ) // 是否需要上传文件
                {
                    ITopUploadRequest <T>          uRequest   = (ITopUploadRequest <T>)request;
                    IDictionary <string, FileItem> fileParams = TopUtils.CleanupDictionary(uRequest.GetFileParameters());
                    body = webUtils.DoPost(realServerUrl, txtParams, fileParams, request.GetHeaderParameters());
                }
                else
                {
                    body = webUtils.DoPost(realServerUrl, txtParams, request.GetHeaderParameters());
                }

                // 解释响应结果
                T rsp;
                if (disableParser)
                {
                    rsp      = Activator.CreateInstance <T>();
                    rsp.Body = body;
                }
                else
                {
                    if (Constants.FORMAT_XML.Equals(format))
                    {
                        ITopParser <T> tp = new TopXmlParser <T>();
                        rsp = tp.Parse(body);
                    }
                    else
                    {
                        ITopParser <T> tp;
                        if (useSimplifyJson)
                        {
                            tp = new TopSimplifyJsonParser <T>();
                        }
                        else
                        {
                            tp = new TopJsonParser <T>();
                        }
                        rsp = tp.Parse(body);
                    }
                }

                // 追踪错误的请求
                if (rsp.IsError)
                {
                    TimeSpan latency = new TimeSpan(DateTime.Now.Ticks - start);
                    TraceApiError(appKey, request.GetApiName(), serverUrl, txtParams, latency.TotalMilliseconds, rsp.Body);
                }
                return(rsp);
            }
            catch (Exception e)
            {
                TimeSpan latency = new TimeSpan(DateTime.Now.Ticks - start);
                TraceApiError(appKey, request.GetApiName(), serverUrl, txtParams, latency.TotalMilliseconds, e.GetType() + ": " + e.Message);
                throw e;
            }
        }
Beispiel #22
0
        private T DoExecute <T>(ITopRequest <T> request, string session, DateTime timestamp) where T : TopResponse
        {
            long start = DateTime.Now.Ticks;

            TopBatchRequest batchRequest = request as TopBatchRequest;
            List <ITopRequest <TopResponse> > requestList = batchRequest.RequestList;

            if (requestList == null || requestList.Count == 0)
            {
                throw new TopException("40", "client-error:api request list is empty");
            }

            // 本地校验请求参数
            if (batchRequest.PublicParams == null || batchRequest.PublicParams.Count == 0)
            {
                for (int i = 0; i < requestList.Count; i++)
                {
                    try
                    {
                        requestList[i].Validate();
                    }
                    catch (TopException e)
                    {
                        return(CreateErrorResponse <T>(e.ErrorCode, e.ErrorMsg));
                    }
                }
            }

            // 添加协议级请求参数
            TopDictionary parameters = new TopDictionary();

            parameters.Add(Constants.VERSION, "2.0");
            parameters.Add(Constants.APP_KEY, appKey);
            parameters.Add(Constants.TIMESTAMP, timestamp);
            parameters.Add(Constants.FORMAT, format);
            parameters.Add(Constants.SIGN_METHOD, Constants.SIGN_METHOD_HMAC);
            parameters.Add(Constants.PARTNER_ID, GetSdkVersion());
            parameters.Add(Constants.TARGET_APP_KEY, request.GetTargetAppKey());
            parameters.Add(Constants.SESSION, session);
            if (Constants.FORMAT_JSON.Equals(format) && this.useSimplifyJson)
            {
                parameters.Add(Constants.SIMPLIFY, "true");
            }

            // 添加自定义分隔符
            string separator = BATCH_API_DEFAULT_SPLIT;

            if (!string.IsNullOrEmpty(batchApiSeparator))
            {
                batchRequest.AddHeaderParameter(BATCH_API_HEADER_SPLIT, separator = batchApiSeparator);
            }

            // 是否需要压缩响应
            if (this.useGzipEncoding)
            {
                batchRequest.AddHeaderParameter(Constants.ACCEPT_ENCODING, Constants.CONTENT_ENCODING_GZIP);
            }

            try
            {
                // 添加公共请求头
                if (!string.IsNullOrEmpty(batchRequest.PublicMethod))
                {
                    batchRequest.AddPublicParam(Constants.METHOD, batchRequest.PublicMethod);
                }
                else
                {
                    if (IsSameRequest(requestList))
                    {
                        batchRequest.AddPublicParam(Constants.METHOD, requestList[0].GetApiName());
                    }
                }

                // 构建批量请求主体
                StringBuilder requestBody    = new StringBuilder();
                string        publicParamStr = WebUtils.BuildQuery(batchRequest.PublicParams);
                if (!string.IsNullOrEmpty(publicParamStr))
                {
                    requestBody.Append(BATCH_API_PUBLIC_PARAMETER).Append(publicParamStr).Append(separator);
                }

                // 组装每个API的请求参数
                for (int i = 0; i < requestList.Count; i++)
                {
                    ITopRequest <TopResponse> bRequest = requestList[i];
                    bRequest.SetBatchApiOrder(i);
                    IDictionary <string, string> apiParams = bRequest.GetParameters();
                    // 如果单个API的方法和批量API的公共方法不一致,那么需要设置单个API的方法名称
                    if (!string.IsNullOrEmpty(bRequest.GetApiName()) && !bRequest.GetApiName().Equals(batchRequest.PublicMethod))
                    {
                        apiParams.Add(Constants.METHOD, bRequest.GetApiName());
                    }
                    if (!string.IsNullOrEmpty(request.GetBatchApiSession()))
                    {
                        apiParams.Add(Constants.SESSION, bRequest.GetBatchApiSession());
                    }
                    if (!string.IsNullOrEmpty(request.GetTargetAppKey()))
                    {
                        apiParams.Add(Constants.TARGET_APP_KEY, bRequest.GetTargetAppKey());
                    }

                    string apiParamStr = WebUtils.BuildQuery(apiParams);
                    if (string.IsNullOrEmpty(apiParamStr))
                    {
                        apiParamStr = "N";
                    }
                    requestBody.Append(apiParamStr);
                    if (i != requestList.Count - 1)
                    {
                        requestBody.Append(separator);
                    }
                }

                string apiBody = requestBody.ToString();

                // 添加签名参数
                parameters.Add(Constants.SIGN, TopUtils.SignTopRequest(parameters, apiBody, appSecret, Constants.SIGN_METHOD_HMAC));

                // 发起批量请求
                string fullUrl = WebUtils.BuildRequestUrl(this.batchServerUrl, parameters);
                string rsp     = webUtils.DoPost(fullUrl, Encoding.UTF8.GetBytes(apiBody), BATCH_API_CONTENT_TYPE, batchRequest.GetHeaderParameters());

                // 构造响应解释器
                ITopParser <TopResponse> parser = null;
                if (Constants.FORMAT_XML.Equals(format))
                {
                    parser = new TopXmlParser <TopResponse>();
                }
                else
                {
                    if (this.useSimplifyJson)
                    {
                        parser = new TopSimplifyJsonParser <TopResponse>();
                    }
                    else
                    {
                        parser = new TopJsonParser <TopResponse>();
                    }
                }

                // 解释响应结果
                TopBatchResponse batchResponse = new TopBatchResponse();
                batchResponse.Body = rsp;

                string[] responseArray = batchResponse.Body.Split(new string[] { separator }, StringSplitOptions.None);
                // 批量API在走单通道验证时没通过,如前面验证,此时只有一个报错信息
                if (responseArray.Length > 0 && responseArray.Length != requestList.Count)
                {
                    TopResponse tRsp = parser.Parse(responseArray[0], requestList[0].GetType().BaseType.GetGenericArguments()[0]);
                    batchResponse.ErrCode    = tRsp.ErrCode;
                    batchResponse.ErrMsg     = tRsp.ErrMsg;
                    batchResponse.SubErrCode = tRsp.SubErrCode;
                    batchResponse.SubErrMsg  = tRsp.SubErrMsg;
                }
                else
                {
                    for (int i = 0; i < responseArray.Length; i++)
                    {
                        TopResponse tRsp = parser.Parse(responseArray[i], requestList[i].GetType().BaseType.GetGenericArguments()[0]);
                        tRsp.Body = responseArray[i];
                        batchResponse.AddResponse(tRsp);
                    }
                }

                if (batchResponse.IsError)
                {
                    TimeSpan latency = new TimeSpan(DateTime.Now.Ticks - start);
                    TraceApiError(appKey, "BatchApi", batchServerUrl, parameters, latency.TotalMilliseconds, batchResponse.Body);
                }

                return(batchResponse as T);
            }
            catch (Exception e)
            {
                TimeSpan latency = new TimeSpan(DateTime.Now.Ticks - start);
                TraceApiError(appKey, "BatchApi", batchServerUrl, parameters, latency.TotalMilliseconds, e.GetType() + ": " + e.Message);
                throw e;
            }
        }