Example #1
0
        public static OrderResponse OrderSearch(string orderNo)
        {
            if (string.IsNullOrEmpty(orderNo))
            {
                throw new Exception("顺丰订单号不能为空");
            }
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append("<Request service='OrderSearchService' lang='zh-CN'>");
            strBuilder.Append("<Head>" + ClientCode + "</Head>");
            strBuilder.Append("<Body>");
            strBuilder.Append("<OrderSearch").Append(" ");
            strBuilder.Append("orderid='" + orderNo + "" + "'").Append(" > ");
            strBuilder.Append("</OrderSearch>");
            strBuilder.Append("</Body>");
            strBuilder.Append("</Request>");
            string            xml        = strBuilder.ToString();
            string            verifyCode = MD5ToBase64String(xml + Checkword);
            string            result     = DoPost(requestUrl, xml, verifyCode);
            SFExpressResponse response   = XMLSerializer.DeserializeXML <SFExpressResponse>(result);

            if (response.Head == "OK")
            {
                return(response.Body.OrderResponse);
            }
            else
            {
                throw new Exception(response.ERROR.text);
            }
        }
Example #2
0
        /// <summary>
        /// 下单 返回订单号
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static OrderResponse OrderSubmit(SFDataEntity entity)
        {
            string            xml        = GetOrderServiceRequestXml(entity);
            string            verifyCode = MD5ToBase64String(xml + Checkword);
            string            result     = DoPost(requestUrl, xml, verifyCode);//这就得到了返回结果
            SFExpressResponse response   = XMLSerializer.DeserializeXML <SFExpressResponse>(result);

            if (response.Head == "OK")
            {
                return(response.Body.OrderResponse);
            }
            else
            {
                throw new Exception(response.ERROR.text ?? response.ERROR.code);
            }
        }
Example #3
0
        /// <summary>
        /// 路由查询接口(RouteService):支持两类查询方式:①根据顺丰运单号查询 ②根据客户订单号查询
        /// </summary>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public static RouteResponse RouteSearch(string orderIdOrMailNo, bool isOrderId = true)
        {
            if (string.IsNullOrEmpty(orderIdOrMailNo))
            {
                throw new Exception("查询单号不能为空");
            }
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append("<Request service='RouteService' lang='zh-CN'>");
            strBuilder.Append("<Head>" + ClientCode + "</Head>");
            strBuilder.Append("<Body>");
            strBuilder.Append("<RouteRequest").Append(" ");
            if (isOrderId)
            {
                strBuilder.Append("tracking_type='2'").Append(" ");//1为运单号 2为订单号
            }
            else
            {
                strBuilder.Append("tracking_type='1'").Append(" ");
            }
            strBuilder.Append("method_type='1'").Append(" ");//标准路由
            strBuilder.Append("tracking_number='" + orderIdOrMailNo + "'").Append(" >");
            strBuilder.Append("</RouteRequest>");
            strBuilder.Append("</Body>");
            strBuilder.Append("</Request>");
            string            xml        = strBuilder.ToString();
            string            verifyCode = MD5ToBase64String(xml + Checkword);
            string            result     = DoPost(requestUrl, xml, verifyCode);
            SFExpressResponse response   = XMLSerializer.DeserializeXML <SFExpressResponse>(result);

            if (response == null)
            {
                throw new Exception("序列化解析XML出错:" + result);
            }
            if (response.Head == "OK")
            {
                if (response.Body == null || response.Body.RouteResponse == null)
                {
                    throw new Exception("未查询到路由信息");
                }
                return(response.Body.RouteResponse);
            }
            else
            {
                throw new Exception(response.ERROR.text);
            }
        }
Example #4
0
        /// <summary>
        /// 订单确认或者取消 isConfirm=true 确认 需要传入orderNo 和mailNo
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="mailNo"></param>
        /// <param name="isConfirm"></param>
        /// <returns></returns>
        public static bool OrderConfirm(string orderId, string mailNo, bool isConfirm = true)
        {
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append("<Request service='OrderConfirmService' lang='zh-CN'>");
            strBuilder.Append("<Head>" + ClientCode + "</Head>");
            strBuilder.Append("<Body>");
            strBuilder.Append("<OrderConfirm").Append(" ");
            strBuilder.Append("orderid='" + orderId + "" + "'").Append(" ");

            if (isConfirm)//默认是确认 否则取消订单
            {
                strBuilder.Append("mailno='" + mailNo + "" + "'").Append(" ");
                strBuilder.Append("dealtype='1'").Append(" > ");
            }
            else
            {
                strBuilder.Append("dealtype='2'").Append(" > ");
            }
            strBuilder.Append("</OrderConfirm>");

            strBuilder.Append("</Body>");
            strBuilder.Append("</Request>");
            string            xml        = strBuilder.ToString();
            string            verifyCode = MD5ToBase64String(xml + Checkword);
            string            result     = DoPost(requestUrl, xml, verifyCode);
            SFExpressResponse response   = XMLSerializer.DeserializeXML <SFExpressResponse>(result);

            if (response.Head == "OK")
            {
                return(true);
            }
            else
            {
                throw new Exception(response.ERROR.text);
            }
        }