示例#1
0
        public async Task <IActionResult> GetMeituanProducts([FromQuery] int offset, [FromQuery] int limit)
        {
            var url          = "https://waimaiopen.meituan.com/api/v1/food/list";
            var timestamp    = DateTime.Now.ToTimestamp();
            var app_id       = Business.MT_AppId;
            var key          = Business.MT_AppKey;
            var app_poi_code = Business.MT_Poi_Id;

            limit = limit == 0 ? 50 : limit;
            var mt = new MTInputData(key, url);

            mt.SetValue(nameof(timestamp), timestamp);
            mt.SetValue(nameof(app_id), app_id);
            mt.SetValue(nameof(app_poi_code), app_poi_code);
            mt.SetValue(nameof(limit), limit);
            mt.SetValue(nameof(offset), offset);
            var sig = mt.MakeSign();
            var api = $"{url}?{mt.ToUrl()}&sig={sig}";
            var res = await UtilHelper.RequestAsync(api, method : "get");

            var json  = JObject.Parse(res);
            var items = json["data"].Select(item => new { name = item["name"].Value <string>(), pic = item["picture"].Value <string>() });

            return(Json(json));
        }
示例#2
0
        /// <summary>
        /// 美团订单已完成
        /// </summary>
        /// <returns></returns>
        private async Task MT_FinishOrderAsync(string id, Business business)
        {
            var url = "https://waimaiopen.meituan.com/api/v1/order/arrived";
            var mt  = new MTInputData(business.MT_AppKey, url);

            mt.SetValue("timestamp", DateTime.Now.ToTimestamp());
            mt.SetValue("app_id", business.MT_AppId);
            mt.SetValue("order_id", id);
            var sig = mt.MakeSign();

            mt.SetValue("sig", sig);
            url = $"{url}?{mt.ToUrl()}";
            await UtilHelper.RequestAsync(url, method : "get");
        }
示例#3
0
        /// <summary>
        /// 拉取用户真实手机号
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> GetUserPhones()
        {
            var url = "https://waimaiopen.meituan.com/api/v1/order/batchPullPhoneNumber";
            var mt  = new MTInputData(Business.MT_AppKey, url);

            mt.SetValue("timestamp", DateTime.Now.ToTimestamp());
            mt.SetValue("app_id", Business.MT_AppId);
            mt.SetValue("app_poi_code", Business.MT_Poi_Id);
            mt.SetValue("offset", 0);
            mt.SetValue("limit", 100);
            var sig = mt.MakeSign();

            mt.SetValue("sig", sig);
            url = $"{url}?{mt.ToUrl()}";
            var content = await UtilHelper.RequestAsync(url, method : "post");

            return(Content(content));
        }
示例#4
0
        /// <summary>
        /// 商家确认订单
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> ConfirmOrder([FromQuery] string orderId)
        {
            if (string.IsNullOrEmpty(orderId))
            {
                return(Content("请添加参数:orderId"));
            }
            var url = "https://waimaiopen.meituan.com/api/v1/order/confirm";
            var mt  = new MTInputData(Business.MT_AppKey, url);

            mt.SetValue("timestamp", DateTime.Now.ToTimestamp());
            mt.SetValue("app_id", Business.MT_AppId);
            mt.SetValue("order_id", orderId);
            var sig = mt.MakeSign();

            mt.SetValue("sig", sig);
            url = $"{url}?{mt.ToUrl()}";
            var content = await UtilHelper.RequestAsync(url, method : "get");

            return(Content(content));
        }
示例#5
0
        /// <summary>
        /// 验证签名
        /// </summary>
        /// <returns></returns>
        private bool ValidateSign()
        {
            var appId = formDic["app_id"];

            if (!_appDic.Keys.Contains(appId))
            {
                var service = HttpContext.RequestServices.GetService <IThirdOrderRepository>();
                var keyTask = service.GetMTAppKeyAsync(appId);
                keyTask.Wait();
                var key = keyTask.Result;
                if (string.IsNullOrEmpty(key))
                {
                    return(false);
                }
                _appDic.Add(appId, key);
            }
            var appKey = _appDic[appId];
            var host   = $"{Request.Scheme}://{Request.Host.Value}{Request.Path.Value}";
            var mt     = new MTInputData(appKey, host);

            foreach (var item in formDic)
            {
                if (item.Key == "sig")
                {
                    continue;
                }
                mt.SetValue(item.Key, item.Value);
            }
            var sign = mt.MakeSign();
            //Log.Debug($"{host},sig={formDic["sig"]},sign={sign},{formDic["sig"] == sign}");
            var result = sign == formDic["sig"];

            if (!result)
            {
                Log.Debug($"本地sign:{sign},美团sign:{formDic["sig"]}");
                Log.Debug($"接收的参数:{mt.ToUrl()}");
            }
            //return result;
            return(true);
        }
示例#6
0
        /// <summary>
        /// 新订单
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> Order([FromServices] IThirdOrderRepository service)
        {
            var business = await service.GetBusinessByMtPoi(formDic["app_poi_code"]);

            if (business == null || !business.MT_AutoRecieved)
            {
                return(Json(new { data = "ok" }));
            }
            //Log.Debug($"美团[新]订单:{business.Name}-{formDic["app_poi_code"]}-{formDic["day_seq"]}");
            // 如果设置了美团自动接单,则调用商户确认接口
            var url = "https://waimaiopen.meituan.com/api/v1/order/confirm";
            var mt  = new MTInputData(business.MT_AppKey, url);

            mt.SetValue("timestamp", DateTime.Now.ToTimestamp());
            mt.SetValue("app_id", business.MT_AppId);
            mt.SetValue("order_id", formDic["order_id"]);
            var sig = mt.MakeSign();

            mt.SetValue("sig", sig);
            url = $"{url}?{mt.ToUrl()}";
            await UtilHelper.RequestAsync(url, method : "get");

            return(Json(new { data = "ok" }));
        }