示例#1
0
        public async Task <IActionResult> GetElemeProducts([FromQuery] int offset, [FromQuery] int limit)
        {
            limit = limit == 0 ? 50 : limit;
            var url      = AppData.ElemeApi;
            var tokenUrl = AppData.ElemeToken;
            var token    = await Service.GetElemeTokenAsync(tokenUrl, Business.Eleme_AppKey, Business.Eleme_AppSecret);

            var json = new JObject
            {
                ["nop"]   = "1.0.0",
                ["id"]    = Guid.NewGuid().ToString(),
                ["metas"] = new JObject {
                    ["app_key"] = Business.Eleme_AppKey, ["timestamp"] = DateTime.Now.ToTimestamp()
                },
                ["action"] = "eleme.product.item.queryItemByPage",
                ["token"]  = token,
                //["params"] = new JObject { ["shopId"] = Business.Eleme_Poi_Id, ["offset"] = offset, ["limit"] = limit }
                ["params"] = new JObject {
                    ["queryPage"] = new JObject {
                        ["shopId"] = Business.Eleme_Poi_Id, ["offset"] = offset, ["limit"] = limit
                    }
                }
            };
            var eleme = new ElemeInputData(json, Business.Eleme_AppSecret);

            json["signature"] = eleme.MakeSignApi();
            using (var client = new HttpClient())
            {
                var body = new StringContent(json.ToJson());
                body.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                var res = await client.PostAsync(url, body);

                return(Content(await res.Content.ReadAsStringAsync()));
            }
        }
示例#2
0
        public async Task <IActionResult> Notify([FromBody] JObject message, [FromServices] IThirdOrderRepository service)
        {
            Service = service;
            var appId  = message["appId"].Value <long>();
            var secret = await service.GetElemeAppSecretAsync(appId);

            if (secret == null)
            {
                return(Json(new { message = "ok" }));
            }
            var eleme = new ElemeInputData(message, secret);

            if (!eleme.CheckSign())
            {
                // 签名验证不通过,不再继续处理
                return(Json(new { message = "ok" }));
            }
            var type = message["type"].Value <int>();

            switch (type)
            {
            case 10: await OrderAsync(message); break;                 // 订单生效

            case 12: await ReceviedAsync(message); break;              // 商户接单

            case 14: await CancelAsync(message); break;                // 订单被取消

            case 18: await FinishAsync(message); break;                // 订单已完成

            case 20: await ApplyCancelAsync(message); break;           // 用户申请取消订单

            case 23: await CancelAsync(message); break;                // 门店同意取消订单

            case 30: await ApplyCancelAsync(message); break;           // 用户申请退单

            case 33: await CancelAsync(message); break;                // 门店同意退单

            default:
                break;
            }

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