Exemplo n.º 1
0
        public string BindBankCard(int userId, int merchantId)
        {
            BindBankCardModel model = new BindBankCardModel();

            model.UserId           = userId;
            model.MerchantId       = merchantId;
            model.BankId           = 1;
            model.BankAccountPhone = "15989287032";
            model.BankAccountName  = "邱庆文";
            model.BankAccountNo    = "545553232321";
            string a1 = JsonConvert.SerializeObject(model);

            string signStr = Signature.Compute(key, secret, timespan, a1);


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

            headers.Add("key", key);
            headers.Add("timestamp", timespan.ToString());
            headers.Add("sign", signStr);
            HttpUtil http   = new HttpUtil();
            string   result = http.HttpPostJson("http://localhost:1664/api/BankCard/Bind", a1, headers);

            return(result);
        }
Exemplo n.º 2
0
        public string GetBankList()
        {
            string signStr = Signature.Compute(key, secret, timespan, null);

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

            headers.Add("key", key);
            headers.Add("timestamp", timespan.ToString());
            headers.Add("sign", signStr);
            HttpUtil http   = new HttpUtil();
            string   result = http.HttpGet("http://localhost:1664/api/Bank/GetList", headers);

            return(result);
        }
Exemplo n.º 3
0
        public static ulong GetDataTypeSignature(string normalizedLayout, IEnumerable <DsdlField> fields)
        {
            var layoutSignature = Signature.Compute(normalizedLayout);
            var sig             = new Signature(layoutSignature);

            foreach (var f in fields)
            {
                var fieldSig = f.Type.GetDataTypeSignature();
                if (fieldSig != null)
                {
                    var sigValue = sig.Value;
                    sig.Add(Signature.bytes_from_crc64(fieldSig.Value));
                    sig.Add(Signature.bytes_from_crc64(sigValue));
                }
            }
            return(sig.Value);
        }
Exemplo n.º 4
0
        public string GetBankCardList(int userId, int merchantId)
        {
            Dictionary <string, string> parames = new Dictionary <string, string>();

            parames.Add("userId", userId.ToString());
            parames.Add("merchantId", merchantId.ToString());
            string signStr = Signature.Compute(key, secret, timespan, Signature.GetQueryData(parames));

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

            headers.Add("key", key);
            headers.Add("timestamp", timespan.ToString());
            headers.Add("sign", signStr);
            HttpUtil http   = new HttpUtil();
            string   result = http.HttpGet("http://localhost:1664/api/BankCard/GetList?userId=" + userId.ToString() + "&merchantId=" + merchantId, headers);

            return(result);
        }
Exemplo n.º 5
0
        public string GetBannerDetails(string id)
        {
            Dictionary <string, string> parames = new Dictionary <string, string>();

            parames.Add("id", id);

            string signStr = Signature.Compute(key, secret, timespan, Signature.GetQueryData(parames));

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

            headers.Add("key", key);
            headers.Add("timestamp", timespan.ToString());
            headers.Add("sign", signStr);
            HttpUtil http   = new HttpUtil();
            string   result = http.HttpGet("http://localhost:1664/api/Banner/GetDetails?id=" + id, headers);

            return(result);
        }
Exemplo n.º 6
0
        public string GetBannerList(Enumeration.BannerType type)
        {
            Dictionary <string, string> parames = new Dictionary <string, string>();

            parames.Add("type", ((int)type).ToString());

            string signStr = Signature.Compute(key, secret, timespan, Signature.GetQueryData(parames));

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

            headers.Add("key", key);
            headers.Add("timestamp", timespan.ToString());
            headers.Add("sign", signStr);
            HttpUtil http   = new HttpUtil();
            string   result = http.HttpGet("http://localhost:1664/api/Banner/GetList?type=" + ((int)type).ToString(), headers);

            return(result);
        }
Exemplo n.º 7
0
        public string GetExtendedAppList(ExtendedAppType type)
        {
            Dictionary <string, string> parames = new Dictionary <string, string>();

            parames.Add("type", ((int)type).ToString());
            parames.Add("userId", ((int)type).ToString());
            parames.Add("fuselageNumber", "sfsdffsffsf");
            string signStr = Signature.Compute(key, secret, timespan, Signature.GetQueryData(parames));

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

            headers.Add("key", key);
            headers.Add("timestamp", timespan.ToString());
            headers.Add("sign", signStr);
            HttpUtil http   = new HttpUtil();
            string   result = http.HttpGet("http://localhost:1664/api/ExtendedApp/GetList?type=" + ((int)type).ToString() + "&userId=" + ((int)type).ToString() + "&fuselageNumber=sfsdffsffsf", headers);

            return(result);
        }
Exemplo n.º 8
0
        public string GetOrderList(int userId, int merchantId, int pageIndex, int status)
        {
            Dictionary <string, string> parames = new Dictionary <string, string>();

            parames.Add("userId", userId.ToString());
            parames.Add("merchantId", merchantId.ToString());
            parames.Add("pageIndex", pageIndex.ToString());
            parames.Add("status", status.ToString());
            string signStr = Signature.Compute(key, secret, timespan, Signature.GetQueryData(parames));

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

            headers.Add("key", key);
            headers.Add("timestamp", timespan.ToString());
            headers.Add("sign", signStr);
            HttpUtil http   = new HttpUtil();
            string   result = http.HttpGet("" + host + "/api/Order/GetList?userId=" + userId.ToString() + "&merchantId=" + merchantId + "&pageIndex=" + pageIndex + "&status=" + status, headers);

            return(result);
        }
Exemplo n.º 9
0
        public string RemoveBankCard(int id, int userId, int merchantId)
        {
            RemoveBankCardModel model = new RemoveBankCardModel();

            model.UserId     = userId;
            model.MerchantId = merchantId;
            model.Id         = 1;
            string a1 = JsonConvert.SerializeObject(model);

            string signStr = Signature.Compute(key, secret, timespan, a1);


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

            headers.Add("key", key);
            headers.Add("timestamp", timespan.ToString());
            headers.Add("sign", signStr);
            HttpUtil http   = new HttpUtil();
            string   result = http.HttpPostJson("http://localhost:1664/api/BankCard/Remove", a1, headers);

            return(result);
        }
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            try
            {
                DateTime requestTime   = DateTime.Now;
                var      request       = ((HttpContextWrapper)actionContext.Request.Properties["MS_HttpContext"]).Request;
                var      requestMethod = request.HttpMethod;

                request.Headers.Add("CurrentUserId", "");

                MonitorLog.OnActionExecuting(actionContext);

                bool skipAuthorization = actionContext.ActionDescriptor.GetCustomAttributes <AllowAnonymousAttribute>().Any();
                if (skipAuthorization)
                {
                    return;
                }



                string app_key         = request.Headers["key"];
                string app_sign        = request.Headers["sign"];
                string app_version     = request.Headers["version"];
                string app_timestamp_s = request.Headers["timestamp"];


                string app_data = null;

                if (requestMethod == "POST")
                {
                    Stream stream = HttpContext.Current.Request.InputStream;
                    stream.Seek(0, SeekOrigin.Begin);
                    app_data = new StreamReader(stream).ReadToEnd();

                    #region 过滤图片
                    if (app_data.LastIndexOf(",\"ImgData\":{") > -1)
                    {
                        //Log.Info("去掉图片之前的数据:" + app_data);
                        int x = app_data.LastIndexOf(",\"ImgData\":{");
                        app_data  = app_data.Substring(0, x);
                        app_data += "}";
                        //Log.Info("去掉图片之后的数据:" + app_data);
                    }
                    else if (app_data.LastIndexOf(",\"imgData\":{") > -1)
                    {
                        // Log.Info("去掉图片之前的数据:" + app_data);
                        int x = app_data.LastIndexOf(",\"imgData\":{");
                        app_data  = app_data.Substring(0, x);
                        app_data += "}";
                        //Log.Info("去掉图片之后的数据:" + app_data);
                    }

                    #endregion
                }
                else
                {
                    NameValueCollection         queryForm = HttpContext.Current.Request.QueryString;
                    Dictionary <string, string> queryData = new Dictionary <string, string>();
                    for (int f = 0; f < queryForm.Count; f++)
                    {
                        string querykey = queryForm.Keys[f];
                        queryData.Add(querykey, queryForm[querykey]);
                    }
                    app_data = GetQueryData(queryData);
                }

                //检查必要的参数
                if (app_key == null || app_sign == null || app_timestamp_s == null)
                {
                    OwnApiHttpResult result = new OwnApiHttpResult(ResultType.Failure, ResultCode.Failure2Sign, "缺少必要参数");
                    actionContext.Response = new OwnApiHttpResponse(result);
                    return;
                }

                //检查key是否在数据库中存在
                string app_secret = BizFactory.Merch.GetTermApiSecret(app_key);

                if (app_secret == null)
                {
                    OwnApiHttpResult result = new OwnApiHttpResult(ResultType.Failure, ResultCode.Failure2Sign, "应用程序Key,存在错误");
                    actionContext.Response = new OwnApiHttpResponse(result);
                    return;
                }

                long app_timestamp = long.Parse(app_timestamp_s);

                string signStr = Signature.Compute(app_key, app_secret, app_timestamp, app_data);

                if (Signature.IsRequestTimeout(app_timestamp))
                {
                    OwnApiHttpResult result = new OwnApiHttpResult(ResultType.Failure, ResultCode.Failure2Sign, "请求已超时");
                    actionContext.Response = new OwnApiHttpResponse(result);
                    return;
                }

                if (signStr != app_sign)
                {
                    LogUtil.Warn("API签名错误");
                    OwnApiHttpResult result = new OwnApiHttpResult(ResultType.Failure, ResultCode.Failure2Sign, "签名错误");
                    actionContext.Response = new OwnApiHttpResponse(result);
                    return;
                }

                base.OnActionExecuting(actionContext);
            }
            catch (Exception ex)
            {
                LogUtil.Error(string.Format("API错误:{0}", ex.Message), ex);
                OwnApiHttpResult result = new OwnApiHttpResult(ResultType.Exception, ResultCode.Exception, "内部错误");
                actionContext.Response = new OwnApiHttpResponse(result);
                return;
            }
        }