using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Reflection;
using JuSNS.ApiInterface;

namespace JuSNS.Web.appserver
{
    public partial class SSecretUser : System.Web.UI.Page
    {
        /// <summary>
        /// appkey
        /// </summary>
        protected string appkey = string.Empty;
        /// <summary>
        /// 请求类型
        /// </summary>
        protected string action = string.Empty;
        /// <summary>
        /// 参数
        /// </summary>
        protected string param = string.Empty;
        /// <summary>
        /// 应用程序ID
        /// </summary>
        protected int AppID = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            this.init();
            MethodInfo methodInfo;

            methodInfo = this.GetType().GetMethod(action, BindingFlags.NonPublic | BindingFlags.IgnoreCase | BindingFlags.Instance);

            if (methodInfo == null)
            {
                Response.Write((int)EnumErr.ErrRequestType);
                Response.End();
            }
            methodInfo.Invoke(this, null);
        }
        /// <summary>
        /// 初始化
        /// </summary>
        protected void init()
        {
            appkey = Request.Form["appkey"];
            action = Request.Form["action"];
            param = Request.Form["param"];
            bool valid = App.VerifyKey(appkey, out AppID);
            if (!valid)
            {
                Response.Write((int)EnumErr.ErrKey);
                Response.End();
            }
            if (string.IsNullOrEmpty(action))
            {
                Response.Write((int)EnumErr.ErrRequestType);
                Response.End();
            }
        }
        protected void DecryptUserID()
        {
            if (string.IsNullOrEmpty(param))
            {
                Response.Write((int)EnumErr.ErrParams);
                return;
            }
            string str=SecretUser.DecryptUserID(param);
            Response.Write(str);
        }
    }
}
