Example #1
0
        /// <summary>
        /// 外部调用接口
        /// </summary>
        /// <param name="code">接口编码</param>
        /// <param name="inputParameters">可传入参数</param>
        /// <returns></returns>
        public object DynamicFetch(IDictionary <string, object> config, string code, IDictionary <string, object> inputParameters = null)
        {
            string dataBaseKey        = config.GetValue <string>("DataBaseKey");
            string pluginAssemblyPath = config.GetValue <string>("PluginAssemblyPath");
            string pluginClassName    = config.GetValue <string>("PluginClassName");

            threadLocalDataBaseKey.Value = dataBaseKey;
            ConfigApiPlugin dynamicApiPlugin = ReflectorHelper.GetPluginInstance <ConfigApiPlugin>(pluginAssemblyPath, pluginClassName);
            IDictionary <string, object>             parameters = RequestDataHelper.GetMixParams();
            IDictionary <string, IList <IFormFile> > files      = RequestDataHelper.GetAllFiles();
            IDictionary <string, object>             headers    = RequestDataHelper.GetHeaders();
            IDictionary <string, object>             cookies    = RequestDataHelper.GetCookies();
            object bodyJson = RequestDataHelper.GetBodyJsonParameters();

            if (inputParameters != null && inputParameters.Count > 0)
            {
                parameters = RequestDataHelper.MergeDictionary(parameters, inputParameters);
            }
            return(this.AopDynamicApi <object>((apiConfig, paramsData, formFiles, reqHeaders, reqCookies, json) =>
            {
                if (dynamicApiPlugin != null)
                {
                    IDbHelper dbHelper = this._dbContext.Use(dataBaseKey);
                    //调用接口前扩展处理
                    dynamicApiPlugin.Before(dbHelper, apiConfig, paramsData, formFiles, json);
                }
            }, (apiConfig, paramsData, json) =>
            {
                string scriptCode = apiConfig.GetValue <string>("ScriptCode");

                /*
                 * 1=单一结果(单个值,或者一条sql语句执行结果)
                 * 2=分页
                 * 3=列表结果集(多个值以List<object>返回
                 * 4=字典结果集(多个值以Dictionary<string,object>返回
                 * 5=主从结果集 (会查询嵌套子查询,多个值以Dictionary<string,object>返回
                 * 6=返回脚本执行结果(直接返回脚本执行结果)
                 */
                int codeKind = apiConfig.GetValue <int>("CodeKind");
                int apiKind = apiConfig.GetValue <int>("ApiKind"); //0=公共接口;1=对内接口
                int status = apiConfig.GetValue <int>("Status");   //0=禁用;1=启用
                return this.ExecuteScript(scriptCode, codeKind, paramsData, bodyJson);
            }, (apiConfig, paramsData, json, result) =>
            {
                if (dynamicApiPlugin != null)
                {
                    IDbHelper dbHelper = this._dbContext.Use(dataBaseKey);
                    //调用接口后扩展处理
                    return dynamicApiPlugin.After(dbHelper, apiConfig, paramsData, json, result);
                }
                return result;
            }, config, parameters, files, headers, cookies, bodyJson));
        }
Example #2
0
        private string GetToken()
        {
            var headers = RequestDataHelper.GetHeaders();

            return(headers.ContainsKey("Authorization") ? headers["Authorization"].ToString() : "");
        }