Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="sinfo">加密验证参数{appid:"",apppwd:"",signname:"",time:"",code:""}</param>
        /// <param name="functionname">功能名</param>
        /// <param name="functionparameter">功能参数</param>
        /// <returns></returns>
        public Stream Entrance(string type, string sinfo, string info)//(string type, string name, string date, string code, string parameter)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            ResultData result = new ResultData();

            if (string.IsNullOrEmpty(sinfo) || string.IsNullOrEmpty(info))
            {
                result.returntext = "验证码错误";
                return(new MemoryStream(Encoding.UTF8.GetBytes(result.ToJSONjss())));
            }
            JObject sinfoObj     = JObject.Parse(sinfo);
            string  appid        = sinfoObj.Value <string>("appid");
            string  apppwd       = sinfoObj.Value <string>("apppwd");
            string  signname     = sinfoObj.Value <string>("signname");
            string  time         = sinfoObj.Value <string>("time");
            string  code         = sinfoObj.Value <string>("code");
            string  functionname = sinfoObj.Value <string>("functionname");
            string  appUrl       = "";
            JObject infoObj      = JObject.Parse(info);
            JObject appinfoObj   = infoObj["appinfo"] as JObject;
            JObject uinfoObj     = infoObj["uinfo"] as JObject;
            string  username     = uinfoObj.Value <string>("username");
            JObject funinfoObj   = new JObject();

            if (infoObj["funinfo"] != null)
            {
                funinfoObj = infoObj["funinfo"] as JObject;
            }
            log.Info(sinfo);
            log.Info(info);

            UserCheck uc           = null;
            int       verifyResult = ApiCheckManager.ApiAuthorizationVerify(sinfoObj, infoObj, functionname, out uc);

            if (verifyResult != 1)
            {
                result.returntext = "无权限访问此API";
                return(new MemoryStream(Encoding.UTF8.GetBytes(result.ToJSONjss())));
            }
            else
            {
                object     objClass = null;
                MethodInfo method   = apiCommon.EntranceHelper.GetMethodInfo(type, functionname, out objClass);
                if (method == null || objClass == null)
                {
                    result.returntext = "未找到方法!";
                    return(new MemoryStream(Encoding.UTF8.GetBytes(result.ToJSONjss())));
                }
                try
                {
                    Type         objClassType = objClass.GetType();
                    PropertyInfo UserName     = objClassType.GetProperty("UserName");
                    PropertyInfo SignName     = objClassType.GetProperty("SignName");
                    PropertyInfo FxtCompanyId = objClassType.GetProperty("FxtCompanyId");
                    UserName.SetValue(objClass, username, null);
                    SignName.SetValue(objClass, signname, null);
                    FxtCompanyId.SetValue(objClass, uc.companyid, null);
                    ParameterInfo[] parameterInfos = method.GetParameters();
                    object[]        objvalue       = null;
                    if (funinfoObj.Count != parameterInfos.Length)
                    {
                        result.returntext = "方法参数有误!";
                        return(new MemoryStream(Encoding.UTF8.GetBytes(result.ToJSONjss())));
                    }
                    objvalue = new object[parameterInfos.Length];
                    for (int i = 0; i < parameterInfos.Length; i++)
                    {
                        ParameterInfo parameterInfo = parameterInfos[i];
                        if (funinfoObj[parameterInfo.Name] == null)
                        {
                            result.returntext = "方法参数不存在!";
                            return(new MemoryStream(Encoding.UTF8.GetBytes(result.ToJSONjss())));
                        }
                        if (funinfoObj[parameterInfo.Name].Type == JTokenType.Null)
                        {
                            objvalue[i] = null;
                            continue;
                        }
                        objvalue[i] = CommonUtility.valueType(parameterInfo.ParameterType, funinfoObj.Value <JValue>(parameterInfo.Name).Value);
                    }
                    var o = method.Invoke(objClass, objvalue);

                    if (o is ResultData)
                    {
                        result = o as ResultData;
                    }
                    else
                    {
                        var to = o as Task <ResultData>;
                        result = to.Result;
                    }
                    log.Info("data:" + result.data);
                    log.Info("returntext:" + result.returntext);
                    log.Info("returntype:" + result.returntype);

                    sw.Stop();
                    TimeSpan ts2 = sw.Elapsed;
                    log.Info("functionname:" + functionname + ",操作总共花费" + ts2.TotalMilliseconds + "ms.");

                    return(new MemoryStream(Encoding.UTF8.GetBytes(result.ToJSONjss())));
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException exe)
                {
                    log.Error("实体验证失败:" + exe.Message);
                    result.returntext = "实体验证失败!";
                    return(new MemoryStream(Encoding.UTF8.GetBytes(result.ToJSONjss())));
                }
                catch (Exception exe)
                {
                    string errorMessage = string.Format("type:{0},\r\n sinfo:{1}, \r\n info:{2}  \r\n error:{3}",
                                                        type == null ? "null" : type, sinfo == null ? "null" : sinfo, info == null ? "null" : info, exe.Message == null ? "null" : exe.Message
                                                        );
                    //log.Error(errorMessage, exe);
                    log.Error(exe);
                    result.returntext = "系统异常!";
                    return(new MemoryStream(Encoding.UTF8.GetBytes(result.ToJSONjss())));
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="sinfo">加密验证参数{appid:"",apppwd:"",signname:"",time:"",code:""}</param>
        /// <param name="functionname">功能名</param>
        /// <param name="functionparameter">功能参数</param>
        /// <returns></returns>
        public ResultData Entrance(string type, string sinfo, string info)//(string type, string name, string date, string code, string parameter)
        {
            if (string.IsNullOrEmpty(sinfo) || string.IsNullOrEmpty(info))
            {
                return(new ResultData {
                    returntype = 0, returntext = "验证码错误"
                });
            }
            JObject sinfoObj     = JObject.Parse(sinfo);
            string  appid        = sinfoObj.Value <string>("appid");
            string  apppwd       = sinfoObj.Value <string>("apppwd");
            string  signname     = sinfoObj.Value <string>("signname");
            string  time         = sinfoObj.Value <string>("time");
            string  code         = sinfoObj.Value <string>("code");
            string  functionname = sinfoObj.Value <string>("functionname");
            string  appUrl       = "";
            JObject infoObj      = JObject.Parse(info);
            JObject appinfoObj   = infoObj["appinfo"] as JObject;
            JObject uinfoObj     = infoObj["uinfo"] as JObject;
            string  username     = uinfoObj.Value <string>("username");
            JObject funinfoObj   = new JObject();

            if (infoObj["funinfo"] != null)
            {
                funinfoObj = infoObj["funinfo"] as JObject;
            }
            log.Info(sinfo);
            log.Info(info);

            UserCheck uc           = null;
            int       verifyResult = ApiCheckManager.ApiAuthorizationVerify(sinfoObj, infoObj, functionname, out uc);

            if (verifyResult != 1)
            {
                return(new ResultData {
                    returntype = 0, returntext = "无权限访问此API"
                });
            }
            else
            {
                object     objClass = null;
                MethodInfo method   = apiCommon.EntranceHelper.GetMethodInfo(type, functionname, out objClass);
                if (method == null || objClass == null)
                {
                    return(new ResultData {
                        returntype = 0, returntext = "未找到对象!"
                    });
                }
                try
                {
                    Type         objClassType = objClass.GetType();
                    PropertyInfo UserName     = objClassType.GetProperty("UserName");
                    PropertyInfo SignName     = objClassType.GetProperty("SignName");
                    PropertyInfo FxtCompanyId = objClassType.GetProperty("FxtCompanyId");
                    UserName.SetValue(objClass, username, null);
                    SignName.SetValue(objClass, signname, null);
                    FxtCompanyId.SetValue(objClass, uc.companyid, null);
                    ParameterInfo[] parameterInfos = method.GetParameters();
                    object[]        objvalue       = null;
                    if (funinfoObj.Count != parameterInfos.Length)
                    {
                        return(new ResultData {
                            returntype = 0, returntext = "未找到对象!"
                        });
                    }
                    objvalue = new object[parameterInfos.Length];
                    for (int i = 0; i < parameterInfos.Length; i++)
                    {
                        ParameterInfo parameterInfo = parameterInfos[i];
                        if (funinfoObj[parameterInfo.Name] == null)
                        {
                            return(new ResultData {
                                returntype = 0, returntext = "未找到对象!"
                            });
                        }
                        if (funinfoObj[parameterInfo.Name].Type == JTokenType.Null)
                        {
                            objvalue[i] = null;
                            continue;
                        }
                        objvalue[i] = CommonUtility.valueType(parameterInfo.ParameterType, funinfoObj.Value <JValue>(parameterInfo.Name).Value);
                    }
                    var        o = method.Invoke(objClass, objvalue);
                    ResultData obj;
                    if (o is ResultData)
                    {
                        obj = o as ResultData;
                    }
                    else
                    {
                        var to = o as Task <ResultData>;
                        obj = to.Result;
                    }
                    log.Info(obj.data);
                    log.Info(obj.returntext);
                    log.Info(obj.returntype);
                    return(obj);
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException exe)
                {
                    log.Error("实体验证失败:" + exe.Message);
                    return(new ResultData {
                        returntype = 0, returntext = "系统异常", debug = exe.Message
                    });
                }
                catch (Exception exe)
                {
                    string errorMessage = string.Format("type:{0},\r\n sinfo:{1}, \r\n info:{2}  \r\n error:{3}",
                                                        type == null ? "null" : type, sinfo == null ? "null" : sinfo, info == null ? "null" : info, exe.Message == null ? "null" : exe.Message
                                                        );
                    //log.Error(errorMessage, exe);
                    log.Error(exe);
                    return(new ResultData {
                        returntype = 0, returntext = "系统异常", debug = exe.Message
                    });
                }
            }
        }
Exemplo n.º 3
0
        public Stream UpLoadFile(System.IO.Stream stream, string type, string sinfo, string info)
        {
            log.Info("sinfo:" + sinfo);
            log.Info("info:" + info);
            ResultData result = new ResultData();

            if (string.IsNullOrEmpty(sinfo) || string.IsNullOrEmpty(info))
            {
                result.returntext = "验证码错误!";
                return(new MemoryStream(Encoding.UTF8.GetBytes(result.ToJSONjss())));
            }
            JObject sinfoObj     = JObject.Parse(sinfo);
            string  appid        = sinfoObj.Value <string>("appid");
            string  apppwd       = sinfoObj.Value <string>("apppwd");
            string  signname     = sinfoObj.Value <string>("signname");
            string  time         = sinfoObj.Value <string>("time");
            string  code         = sinfoObj.Value <string>("code");
            string  functionname = sinfoObj.Value <string>("functionname");
            string  appUrl       = "";
            JObject infoObj      = JObject.Parse(info);
            JObject appinfoObj   = infoObj["appinfo"] as JObject;
            JObject uinfoObj     = infoObj["uinfo"] as JObject;
            string  username     = uinfoObj.Value <string>("username");
            JObject funinfoObj   = new JObject();

            if (infoObj["funinfo"] != null)
            {
                funinfoObj = infoObj["funinfo"] as JObject;
            }
            UserCheck uc           = null;
            int       verifyResult = ApiCheckManager.ApiAuthorizationVerify(sinfoObj, infoObj, functionname, out uc);

            if (verifyResult != 1)
            {
                result.returntext = "无权限访问此API";
                return(new MemoryStream(Encoding.UTF8.GetBytes(result.ToJSONjss())));
            }
            else
            {
                object     objClass = null;
                MethodInfo method   = apiCommon.EntranceHelper.GetMethodInfo(type, functionname, out objClass);
                if (method == null || objClass == null)
                {
                    result.returntext = "未找到对象!";
                    return(new MemoryStream(Encoding.UTF8.GetBytes(result.ToJSONjss())));
                }
                try
                {
                    Type         objClassType = objClass.GetType();
                    PropertyInfo UserName     = objClassType.GetProperty("UserName");
                    PropertyInfo SignName     = objClassType.GetProperty("SignName");
                    PropertyInfo FxtCompanyId = objClassType.GetProperty("FxtCompanyId");
                    UserName.SetValue(objClass, username, null);
                    SignName.SetValue(objClass, signname, null);
                    FxtCompanyId.SetValue(objClass, uc.companyid, null);
                    ParameterInfo[] parameterInfos = method.GetParameters();
                    object[]        objvalue       = null;
                    if (funinfoObj.Count + 1 != parameterInfos.Length)
                    {
                        result.returntext = "未找到对象!";
                        return(new MemoryStream(Encoding.UTF8.GetBytes(result.ToJSONjss())));
                    }
                    objvalue = new object[parameterInfos.Length];
                    for (int i = 0; i < parameterInfos.Length; i++)
                    {
                        if (i == 0)
                        {
                            objvalue[i] = stream;
                            continue;
                        }
                        ParameterInfo parameterInfo = parameterInfos[i];
                        if (funinfoObj[parameterInfo.Name] == null)
                        {
                            result.returntext = "未找到对象!";
                            return(new MemoryStream(Encoding.UTF8.GetBytes(result.ToJSONjss())));
                        }
                        if (funinfoObj[parameterInfo.Name].Type == JTokenType.Null)
                        {
                            objvalue[i] = null;
                            continue;
                        }
                        objvalue[i] = CommonUtility.valueType(parameterInfo.ParameterType, funinfoObj.Value <JValue>(parameterInfo.Name).Value);
                    }
                    var        o = method.Invoke(objClass, objvalue);
                    ResultData obj;
                    if (o is ResultData)
                    {
                        obj = o as ResultData;
                    }
                    else
                    {
                        var to = o as Task <ResultData>;
                        obj = to.Result;
                    }
                    return(new MemoryStream(Encoding.UTF8.GetBytes(result.ToJSONjss())));
                }
                catch (Exception exe)
                {
                    string errorMessage = string.Format("type:{0},\r\n sinfo:{1}, \r\n info:{2}  \r\n error:{3}",
                                                        type == null ? "null" : type, sinfo == null ? "null" : sinfo, info == null ? "null" : info, exe.Message == null ? "null" : exe.Message
                                                        );
                    log.Error(exe);
                    result.returntext = "系统异常!";
                    return(new MemoryStream(Encoding.UTF8.GetBytes(result.ToJSONjss())));
                }
            }
        }