Example #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Qijia.PCI.MethodPCI pci = new Qijia.PCI.MethodPCI();
            string data             = "method=UpdateGoods&goodsId=11&tempType=1&datatype=json";

            Qijia.PCI.PasswordParam pp = new Qijia.PCI.PasswordParam();
            string sign = pp.Encrypt3DES(data);

            string realdata = pp.Encrypt3DES(data + "&sign=" + sign);
            //data = data.Replace("+", "[jia]");

            string s = pci.GetYouWant(realdata).ToString();
            //Response.ContentType = "text/xml";
            Response.Write(s);
            Response.End();
        }
    }
Example #2
0
        /// <summary>
        ///  对外发布的服务方法
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public object GetYouWant(string str)
        {
            Type type = mg.GetType();

            PasswordParam pp        = new PasswordParam();
            string        decrptStr = pp.Decrypt3DES(str);

            //最后会多出一个\0
            decrptStr = decrptStr.Replace("\0", "");

            //判断合法
            if (!decrptStr.Contains("sign="))
            {
                return("未传入sign");
            }

            string sign = decrptStr.Substring(decrptStr.IndexOf("sign=") + 5, decrptStr.Length - (decrptStr.IndexOf("sign=") + 5));

            if (pp.Encrypt3DES(decrptStr.Substring(0, decrptStr.IndexOf("sign=") - 1)) != sign)
            {
                return("不合法");
            }

            decrptStr = decrptStr.Replace("&sign=" + sign, "");

            string[] paramsNameValue = decrptStr.Split('&');
            if (paramsNameValue.Length == 0 || paramsNameValue[0] == "")
            {
                return("");
            }

            Dictionary <string, string> paramDic = new Dictionary <string, string>();

            string method = "";

            string datatype = "";

            foreach (string p in paramsNameValue)
            {
                string[] pnamevalue = p.Split('=');
                if (pnamevalue.Length != 2)
                {
                    return("");
                }

                if (pnamevalue[0].ToLower() == "method")
                {
                    method = pnamevalue[1].ToLower();
                    continue;
                }

                if (pnamevalue[0].ToLower() == "datatype")
                {
                    datatype = pnamevalue[1];
                }

                paramDic.Add(pnamevalue[0], pnamevalue[1]);
            }

            if (method == "")
            {
                return("未传入方法名");
            }

            MethodInfo methodinfo = type.GetMethod(method);

            ParameterInfo[] pinfos = methodinfo.GetParameters();

            List <string> paramsList = new List <string>();

            foreach (ParameterInfo pinfo in pinfos)
            {
                foreach (KeyValuePair <string, string> kvp in paramDic)
                {
                    if (pinfo.Name.ToLower() == kvp.Key.ToLower())
                    {
                        paramsList.Add(kvp.Value);
                        break;
                    }
                }
            }
            bool   isdoit  = false;
            string errinfo = "";

            try
            {
                object obj = methodinfo.Invoke(mg, paramsList.ToArray());
                isdoit = true;
                return(obj);
            }
            catch (Exception ex)
            {
                errinfo = ex.Message;
                if (datatype.ToLower() == "json")
                {
                    return(GetJsonErr(ex.Message));
                }

                return(GetXmlErr(ex.Message));
            }

            finally
            {
                if (isdoit)
                {
                    Jia_ApiSucLog slog = new Jia_ApiSucLog {
                        ActDate = DateTime.Now, ApiName = method, Data = str, Guid = Guid.NewGuid().ToString()
                    };
                    slogDal.AddJia_ApiSucLog(slog);
                }
                else
                {
                    Jia_ApiFailLog flog = new Jia_ApiFailLog {
                        ActDate = DateTime.Now, ApiName = method, Data = str, Guid = Guid.NewGuid().ToString(), ErrInfo = errinfo
                    };
                    flogDal.AddJia_ApiFailLog(flog);
                }
            }
        }