Пример #1
0
        //public ActionResult YeepayPayment(string orderNo, string imsi)
        //{
        //    Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");

        //    var callBackUrl = ConfigKeys.YEEPAY_CALLBACK_URL.ConfigValue();
        //    var customerOrder = OrderService.GetCustomerOrder(orderNo);
        //    if (customerOrder == null)
        //    {
        //        return Content("订单号错误!");
        //    }
        //    if (customerOrder.Status == OrderStatus.Successed)
        //    {
        //        return Content("已完成支付订单!");
        //    }
        //    ViewData["BuyUrl"] = com.yeepay.icc.Buy.GetBuyUrl();
        //    ViewData["p1_MerId"] = com.yeepay.icc.Buy.GetMerId();
        //    ViewData["CallBackUrl"] = callBackUrl;
        //    var amount = customerOrder.Payed != null ? customerOrder.Amount - customerOrder.Payed : customerOrder.Amount;
        //    ViewData["Amount"] = amount.ToString();
        //    ViewData["hmac"] = com.yeepay.icc.Buy.CreateBuyHmac(customerOrder.OrderNo, amount.ToString(), customerOrder.Currency, customerOrder.ProductName, customerOrder.ProductType, customerOrder.ProductDescription, callBackUrl, "0", customerOrder.MerchantExtentionalDescription, "", "1");

        //    return View(customerOrder);
        //}

        public ActionResult YeepayPayments(float?Amount, string productName = "", string productType = "", string productDescription = "", string MerchantExtentionalDescription = "", string userId = "", string userName = "")
        {
            var urlSig = new UrlSignature(this.RequestRepository, Encoding.UTF8);

            if (!urlSig.IsValid())
            {
                return(Content("签名错误"));
            }
            var callBackUrl = "callBackUrl".UrlDecodeFromRawQuery(this.RequestRepository);

            BlackMamba.Billing.Models.Payments.Order order = new BlackMamba.Billing.Models.Payments.Order();

            ViewData["BuyUrl"]   = com.yeepay.icc.Buy.GetBuyUrl();
            ViewData["p1_MerId"] = com.yeepay.icc.Buy.GetMerId();

            if (!callBackUrl.IsNullOrEmpty() && Amount != 0.00f && !userId.IsNullOrEmpty() && !userName.IsNullOrEmpty())
            {
                order = PaymentsService.RequestBankCardPayment(Amount.GetValueOrDefault(), productName, productType, productDescription, MerchantExtentionalDescription, callBackUrl, userId, userName);
                if (order.OrderNo.IsNullOrEmpty())
                {
                    return(Content("服务器错误"));
                }
                ViewData["CallBackUrl"] = callBackUrl;
                ViewData["Amount"]      = order.Amount.ToString();
                ViewData["hmac"]        = com.yeepay.icc.Buy.CreateBuyHmac(order.OrderNo, order.Amount.ToString(), order.Currency, order.ProductName, order.ProductType, order.ProductDescription, callBackUrl, "0", order.MerchantExtentionalDescription, "", "1");
            }
            else
            {
                return(Content("参数错误"));
            }

            return(View(order));
        }
        public Stream GetSignedDocuments(string envelopeId)
        {
            var uriTemplate = SignatureApiUriTemplates.BuildUriTemplate(SignatureApiUriTemplates.GetSignedEnvelopeDocuments);
            var parameters  = new NameValueCollection
            {
                { "userId", UserId },
                { "envelopeId", envelopeId }
            };

            var template = new UriTemplate(uriTemplate);

            Uri    url       = template.BindByName(new Uri(BaseAddress), parameters);
            string signedUrl = UrlSignature.Sign(url.AbsoluteUri, PrivateKey);

            var request = new HttpRequestMessage {
                Method = "GET", Uri = new Uri(signedUrl)
            };

            HttpContent content = request.Content;

            _client.DefaultHeaders.ContentLength = (content != null && content.HasLength() ? new long?(content.GetLength()) : null);

            OnSendingRequest(request);

            return(_client.Send(request).Content.ReadAsStream());
        }
Пример #3
0
        public void should_return_false_if_secret_is_empty()
        {
            this.RequestRepositoryMock.SetupGet <string>(s => s.RawUrl).Returns(DEFAULT_URL);
            var urlSignature = new UrlSignature(this.RequestRepositoryMock.Object, Encoding.UTF8);

            urlSignature.Context.Secret = string.Empty;

            var isValid = urlSignature.IsValid();

            Assert.False(isValid);
        }
Пример #4
0
        public void should_return_true_if_sig_same_with_client()
        {
            this.RequestRepositoryMock.SetupGet <string>(s => s.RawUrl).Returns(DEFAULT_URL);
            this.SignatureMock.Setup(s => s.Sign(It.IsAny <SignatureContext>())).Returns("dsfafjoai34343dsfa");
            var urlSignature = new UrlSignature(this.RequestRepositoryMock.Object, Encoding.UTF8);

            urlSignature.Signature = SignatureMock.Object;

            var isValid = urlSignature.IsValid();

            Assert.True(isValid);
        }
Пример #5
0
        public void should_return_false_if_sig_diff_from_client()
        {
            this.RequestRepositoryMock.SetupGet <string>(s => s.RawUrl).Returns(DEFAULT_URL);
            this.SignatureMock.Setup(s => s.Sign(It.IsAny <SignatureContext>())).Returns("232323");
            var urlSignature = new UrlSignature(this.RequestRepositoryMock.Object, Encoding.UTF8);

            urlSignature.Signature = SignatureMock.Object;

            var isValid = urlSignature.IsValid();

            Assert.False(isValid);
        }
Пример #6
0
        public void should_return_false_if_the_url_has_no_sign_information()
        {
            const string url = "http://inet.kk570.com/appstores/updatelist?imsi=9460009830450729&imei=860742000116331&smsc=+8613010305500&batch=MTK_6252_11b&dh=DH000005&pf=F000001&mpm=MD00001&mod=X9.N8.H8.T8.S8.0112.V5.02&lbyver=1008&tm=2012/3/9%2008:30:49&lcd=240X320&no=&ver=&mcode=3&SIM=1&tcard=1&touch=1&kb=1&gs=1&cap=1&java=0&c=1-1000-24M&lua=0&lbs=460:00:14145:26494&istest=1";

            this.RequestRepositoryMock.SetupGet <string>(s => s.RawUrl).Returns(url);
            this.SignatureMock.Setup(s => s.Sign(It.IsAny <SignatureContext>())).Returns("dsfafjoai34343dsfa");
            var urlSignature = new UrlSignature(this.RequestRepositoryMock.Object, Encoding.UTF8);

            urlSignature.Signature = SignatureMock.Object;

            var isValid = urlSignature.IsValid();

            Assert.False(isValid);
        }
Пример #7
0
        protected virtual ActionResult BuildRedirectResult(Func <bool> checkParameterAction, Func <string> getRedirectUrlAction, bool isCheckSign = false)
        {
            string redirectUrl = string.Empty;

            try
            {
                if (isCheckSign)
                {
                    var urlSig = new UrlSignature(this.RequestRepository, Encoding.UTF8);
                    if (!urlSig.IsValid())
                    {
                        var defaultViewModels = new List <IViewModel>();
                        var actionResult      = new CommonActionResult(this.RequestRepository, defaultViewModels);
                        actionResult.CommonResult        = new CommonResult();
                        actionResult.CommonResult.Result = ResultCode.ENCRYPTION_SIGN_INVALID;
                        return(Content(actionResult.ToString()));
                    }
                }

                if (checkParameterAction())
                {
                    redirectUrl = getRedirectUrlAction();
                }
            }
            catch (Exception ex)
            {
                Logger.Error("BuildRedirectResult" + ex.Message);
                Logger.Info("BuildRedirectResult" + ex.StackTrace);
            }

            if (!string.IsNullOrWhiteSpace(redirectUrl))
            {
                return(Redirect(redirectUrl));
            }
            else
            {
                return(null);
            }
        }
Пример #8
0
        public virtual CommonActionResult BuildResult <T>(Func <bool> checkParameterAction, Func <IList <T> > getViewModelsActions, bool?checkSignature = null)
            where T : IViewModel
        {
            var defaultViewModels = new List <IViewModel>();
            var actionResult      = new CommonActionResult(this.RequestRepository, defaultViewModels);

            actionResult.CommonResult = new CommonResult();

            try
            {
                var shouldCheckSignature = checkSignature ?? this.ShouldCheckSignature;

                if (shouldCheckSignature)
                {
                    var urlSig = new UrlSignature(this.RequestRepository, Encoding.UTF8);
                    if (urlSig.IsValid())
                    {
                        CheckParamAndGetResult <T>(checkParameterAction, getViewModelsActions, actionResult);
                    }
                    else
                    {
                        actionResult.CommonResult.Result = ResultCode.ENCRYPTION_SIGN_INVALID;
                    }
                }
                else
                {
                    CheckParamAndGetResult <T>(checkParameterAction, getViewModelsActions, actionResult);
                }
            }
            catch (Exception ex)
            {
                actionResult.CommonResult.Result = ResultCode.System_Error;
                Logger.Error(string.Format("BuildResult Error:{1}{0}URL:{2}{0}Stacktrace{3}", Environment.NewLine, ex.Message, this.RequestRepository.RawUrl, ex.StackTrace));
            }

            return(actionResult);
        }