using CallCenter.Utility;
using CallCenterApi.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CallCenterApi.Interface.App_Start
{
    public class OutOutActionFilter : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var sign = filterContext.HttpContext.Request["signcode"];
            bool bl = true;
            if (sign != null)
            {
                string insigncode = sign.ToString();
                string outsigncode = Configs.GetValue("OutSignCode");
                string controllercode = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName.ToLower();
                string actioncode = filterContext.ActionDescriptor.ActionName.ToLower();
                string signcode = EncryptHelper.MD5Encrypt(controllercode + "/" + actioncode + "+" + EncryptHelper.SHA1Encrypt(outsigncode + "+" + DateTime.Now.ToString("yyyyMMdd")));
                if (insigncode == signcode)
                {
                    bl = false;
                }
            }
            if (bl)
            {
                filterContext.Result = new ContentResult() { Content = new AjaxResult { state = ResultTypes.error.ToString(), message = "签名错误" }.ToJson() };
                return;
            }

            base.OnActionExecuting(filterContext);
        }
    }
}