.net核心webhook发布动态json绑定

时间:2019-02-21 16:27:05

标签: c# json .net-core

我正在集成ESignGenie WebHook,在同一路径上得到了不同类型的json。 如何在同一条路线上处理不同类型的json请求。 Json请求根据根对象eventName进行更改。

{
    "event_name": "folder_signed"
}

有6个不同的事件。

using System;
using Microsoft.AspNetCore.Mvc;
using WebApp.Enum;
using WebApp.Models;

namespace WebApp.Controllers
{
    [ApiController]
    [Route("ESignGenie")]
    public class ESignGenieController : Controller
    {
        /// <summary>
        /// Callback for ESignGenie
        /// </summary>
        /// <param name="model"></param>
        /// <returns>A newly created TodoItem</returns>
        /// <response code="299"></response>
        /// <response code="400"></response>            
        [HttpPost("webHook/Callback")]
        [ProducesResponseType(299)]
        [ProducesResponseType(400)]
        public IActionResult Callback([FromBody] ESignGenieWebhookResponseModel model)
        {
            switch (model.EventName)
            {
                case nameof(ESignGenieStatus.folder_cancelled):
                    break;
                case nameof(ESignGenieStatus.folder_deleted):
                    break;
                case nameof(ESignGenieStatus.folder_executed):
                    break;
                case nameof(ESignGenieStatus.folder_sent):
                    break;
                case nameof(ESignGenieStatus.folder_signed):
                    // Handle Signed
                    break;
                case nameof(ESignGenieStatus.folder_viewed):
                    break;
            }
            return Ok();
        }
    }
}

目前,我只对folder_signed事件进行了映射

0 个答案:

没有答案