Beispiel #1
0
        public object GetMeituanGetUrl()
        {
            //1.校验请求参数
            var errMsg = string.Empty;
            var parms  = new SortedDictionary <string, object>();

            parms.Add("appAuthToken", "5eb0b7509b2148e2a5ba4a4c671e9750208bb59ef8e3c7f4349cb88aa8d63384224cc76585b83f9f112b3480b715fd52");
            parms.Add("charset", "utf-8");
            parms.Add("timestamp", TimeUtil.SecondTicks_1970);
            //parms.Add("ePoiId", "10004");
            var sign = SignUtil.GetMeituanSign(parms, ConfigUtil.MeiSignKey);

            var parmStr = new StringBuilder();
            var url     = "http://api.open.cater.meituan.com/waimai/dish/queryCatList";//"http://api.open.cater.meituan.com/waimai/dish/queryBaseListByEPoiId";

            foreach (var parm in parms)
            {
                parmStr.AppendFormat("{0}={1}&", parm.Key, parm.Value);
            }
            var pars = string.Format("{0}sign={1}", parmStr.ToString(), sign);

            try
            {
                var result = HttpRequestUtil.HttpGet(url, pars);
                LogUtil.Info(string.Format("调用接口,返回:{0}", result));

                errMsg = result;
            }
            catch (Exception ex)
            {
                errMsg = ex.InnerException.ToString();
            }
            return(errMsg);
        }
        /// <summary>
        /// 发送普通心跳
        /// </summary>
        public void SendCommonHeartbeat()
        {
            try
            {
                var deviceList = spServ.GetList(PlatformType.Meituan);
                var devices    = (from d in deviceList
                                  select new
                {
                    ePoiId = d.ShopId.ToString(),
                    posId = d.PrinterCode
                }).ToList();

                var parms = new SortedDictionary <string, object>();
                parms.Add("developerId", ConfigUtil.MeiDeveloperId);
                parms.Add("time", TimeUtil.SecondTicks_1970);
                parms.Add("list", devices);

                var datastr = JsonUtil.ToJson(parms);
                var data    = new SortedDictionary <string, object>();
                data.Add("data", datastr);

                var sign   = SignUtil.GetMeituanSign(data, ConfigUtil.MeiSignKey);
                var url    = MeituanConsts.COMMON_HEARBEAT_API;
                var pars   = string.Format("data={0}&sign={1}", datastr, sign);
                var result = HttpRequestUtil.HttpPost(url, pars);

                LogUtil.Info(string.Format("发送普通心跳,返回:{0}", result));
            }
            catch (Exception ex)
            {
                LogUtil.Error(string.Format("发送普通心跳失败,参考信息:{0}", ex.Message));
            }
        }
        /// <summary>
        /// 查询美团门店信息
        /// </summary>
        /// <returns></returns>
        public MeituanShopModel GetMeituanShop(string appAuthToken, string ePoiIds)
        {
            MeituanShopModel model = null;
            var parms = new SortedDictionary <string, object>();

            parms.Add("appAuthToken", appAuthToken);
            parms.Add("charset", "utf-8");
            parms.Add("timestamp", TimeUtil.SecondTicks_1970);
            parms.Add("ePoiIds", ePoiIds);
            var sign = SignUtil.GetMeituanSign(parms, ConfigUtil.MeiSignKey);

            var parmStr = new StringBuilder();
            var url     = MeituanConsts.QUERY_SHOP_INFO_API;

            foreach (var parm in parms)
            {
                parmStr.AppendFormat("{0}={1}&", parm.Key, parm.Value);
            }
            var pars = string.Format("{0}sign={1}", parmStr.ToString(), sign);

            try
            {
                var result = HttpRequestUtil.HttpGet(url, pars);
                LogUtil.Info(string.Format("调用查询美团门店接口,返回:{0}", result));
                var list = JsonUtil.ToObject <List <MeituanShopModel> >(result.Replace("{\"data\":", string.Empty).TrimEnd('}'));
                model = (list != null && list.Count > 0) ? list.FirstOrDefault() : null;
            }
            catch (Exception ex)
            {
                LogUtil.Error(string.Format("调用查询美团门店接口失败,参考信息:{0}", ex.InnerException.ToString()));
            }
            return(model);
        }
        /// <summary>
        /// 查询订单
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="appAuthToken"></param>
        /// <returns></returns>
        public MeituanOrderModel QueryOrder(string orderId, string appAuthToken)
        {
            MeituanOrderModel orderModel = null;

            try
            {
                var parms = new SortedDictionary <string, object>();
                parms.Add("orderId", orderId);
                parms.Add("appAuthToken", appAuthToken);
                parms.Add("charset", "utf-8");
                parms.Add("timestamp", TimeUtil.SecondTicks_1970);
                var sign = SignUtil.GetMeituanSign(parms, ConfigUtil.MeiSignKey);

                var parmStr = new StringBuilder();
                var url     = MeituanConsts.QUERY_ORDER_BYID_API;
                foreach (var parm in parms)
                {
                    parmStr.AppendFormat("{0}={1}&", parm.Key, parm.Value);
                }
                var pars   = string.Format("{0}sign={1}", parmStr.ToString(), sign);
                var result = HttpRequestUtil.HttpPost(url, pars);
                LogUtil.Info(string.Format("调用查询订单接口,返回:{0}", result));
                var retValue = JsonUtil.ToObject <ApiDataQueryModel>(result);
                orderModel = JsonUtil.ToObject <MeituanOrderModel>(retValue.data.ToString());
            }
            catch (Exception ex)
            {
                var msg = string.Format("查询美团订单失败,订单Id:{0},访问令牌:{1},参考信息:{2}", orderId, appAuthToken, ex.InnerException);
                LogUtil.Error(msg);
            }
            return(orderModel);
        }
        /// <summary>
        /// 确认订单
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="appAuthToken"></param>
        /// <returns></returns>
        public string ConfirmOrder(long orderId, string appAuthToken)
        {
            var errMsg = string.Empty;
            var parms  = new SortedDictionary <string, object>();

            parms.Add("orderId", orderId);
            parms.Add("appAuthToken", appAuthToken);
            parms.Add("charset", "utf-8");
            parms.Add("timestamp", TimeUtil.SecondTicks_1970);
            var sign = SignUtil.GetMeituanSign(parms, ConfigUtil.MeiSignKey);

            var parmStr = new StringBuilder();
            var url     = MeituanConsts.CONFIRM_ORDER_API;

            foreach (var parm in parms)
            {
                parmStr.AppendFormat("{0}={1}&", parm.Key, parm.Value);
            }
            var pars = string.Format("{0}sign={1}", parmStr.ToString(), sign);

            try
            {
                var result = HttpRequestUtil.HttpPost(url, pars);
                LogUtil.Info(string.Format("调用确认订单接口,返回:{0}", result));
                if (result.ToUpper().IndexOf("\"" + MeituanConsts.API_RETURN_OK + "\"") <= -1)
                {
                    errMsg = result;
                }
            }
            catch (Exception ex)
            {
                errMsg = ex.InnerException.ToString();
            }
            return(errMsg);
        }
        /// <summary>
        /// 发送补充数据【待完善】
        /// </summary>
        /// <returns></returns>
        public void SendUploadData()
        {
            try
            {
                var parms   = new SortedDictionary <string, object>();
                var datastr = JsonUtil.ToJson(parms);
                var data    = new SortedDictionary <string, object>();
                data.Add("data", datastr);

                var sign   = SignUtil.GetMeituanSign(data, ConfigUtil.MeiSignKey);
                var url    = MeituanConsts.COMMON_HEARBEAT_API;
                var pars   = string.Format("data={0}&sign={1}", datastr, sign);
                var result = HttpRequestUtil.HttpPost(url, pars);

                LogUtil.Info(string.Format("发送补充数据,返回:{0}", result));
            }
            catch (Exception ex)
            {
                LogUtil.Error(string.Format("发送补充数据失败,参考信息:{0}", ex.Message));
            }
        }