Ejemplo n.º 1
0
        void pay_status()
        {
            string orderno = Request.QueryString["orderno"] ?? string.Empty;

            if (string.IsNullOrEmpty(orderno))
            {
                return;
            }

            var service = new Services.OrderService();
            var status  = service.QueryOrderStatus(orderno);

            CallbackData(new { code = 0, status = status, orderno = orderno });
        }
Ejemplo n.º 2
0
        void callbackUrlDo(string orderno)
        {
            var service = new Services.OrderService();

            var info = service.GetOrderInfo(orderno);

            if (info == null)
            {
                return;
            }

            var status = service.QueryOrderStatus(orderno);

            var config = Config.GetProjectConfig(info.Project);

            if (config == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(config.CallbackURL))
            {
                Uri calluri = null;

                if (Uri.TryCreate(config.CallbackURL, UriKind.Absolute, out calluri))
                {
                    var nvc = new NameValueCollection();
                    nvc["orderno"] = orderno;
                    nvc["amount"]  = info.Amount.ToString();
                    nvc["status"]  = status == Services.OrderStatus.Succ ? "succ" : "unkonwn";
                    nvc["sign"]    = GetCallbackUrlDoSign(config, nvc);


                    using (var wc = new System.Net.WebClient())
                    {
                        byte[] data = wc.UploadValues(config.CallbackURL, "POST", nvc);

                        string result = null;

                        if (data != null)
                        {
                            result = System.Text.Encoding.GetEncoding("utf-8").GetString(data);
                        }

                        service.UpdateCallbackData(orderno, result ?? string.Empty);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        void pay_callback_do(string payConfigKey)
        {
            if (string.IsNullOrEmpty(payConfigKey))
            {
                return;
            }

            var    query    = Request.QueryString;
            var    form     = Request.Form;
            string bodydata = ReadBodyData();


            var payclient = Pay.PayFactory.Create(payConfigKey);

            Action <Pay.CallbackInfo> action = new Action <Pay.CallbackInfo>((info) =>
            {
                string orderno = info.OrderNo;
                if (!string.IsNullOrEmpty(orderno))
                {
                    var service = new Services.OrderService();

                    var status = Services.OrderStatus.Fail;

                    if (info.Status == Pay.ResultStatus.Succ)
                    {
                        status = Services.OrderStatus.Succ;
                    }

                    service.UpdateOrderStatus(orderno, status);


                    callbackUrlDo(orderno);
                }
            });

            if (payclient.DoCallback(query, form, bodydata, action))
            {
                payclient.EchoStatus(Pay.ResultStatus.Succ);
            }
            else
            {
                payclient.EchoStatus(Pay.ResultStatus.Fail);
            }
        }
Ejemplo n.º 4
0
        void pay_do()
        {
            string datatype = Request.QueryString["dt"] ?? string.Empty;
            string project  = Request.QueryString["project"] ?? string.Empty;
            string paytype  = Request.QueryString["paytype"] ?? string.Empty;
            string name     = Request.QueryString["name"] ?? string.Empty;

            string rurl   = Request.QueryString["rurl"];
            string rurlOK = null;

            if (!string.IsNullOrEmpty(rurl))
            {
                Uri rurlUri = null;

                if (Uri.TryCreate(rurl, UriKind.Absolute, out rurlUri))
                {
                    rurlOK = rurl;
                }
            }


            int amount = int.Parse(Request.QueryString["amt"] ?? "0");

            if (string.IsNullOrEmpty(project))
            {
                EchoFailJson("project is null or empty");
                return;
            }

            if (amount <= 0)
            {
                EchoFailJson("amt<=0");
                return;
            }

            var payconfig = Config.GetPayConfig(project, paytype);

            if (payconfig == null)
            {
                EchoFailJson("payconfig is null");
                return;
            }


            var orderService = new Services.OrderService();


            string orderno = Request.QueryString["orderno"] ?? string.Empty;

            if (string.IsNullOrEmpty(orderno))
            {
                orderno = orderService.genNotExistOrerNo(project);
            }

            string cip = Common.HttpUtil.GetClientIP();

            bool succ = orderService.InitOrder(new Services.OrderInfo
            {
                Amount  = amount,
                OrderNo = orderno,
                PayCH   = payconfig.Key,
                PayType = paytype,
                Project = project
            });


            if (!succ)
            {
                EchoFailJson("InitOrder fail");
                return;
            }


            var payclient = Pay.PayFactory.Create(payconfig);

            var result = payclient.Pay(new Pay.PayInfo
            {
                Amount    = amount,
                Attach    = "project=" + project + "&paytype=" + paytype,
                IP        = cip,
                Name      = name,
                OrderNo   = orderno,
                ReturnUrl = rurlOK
            });

            if (result.Status != Pay.ResultStatus.Succ)
            {
                EchoFailJson("pay fail");
                return;
            }



            if (result.ResultType == Pay.PayResultType.Url)
            {
                var data = new
                {
                    url     = result.ResultData,
                    data    = result.Data,
                    type    = "url",
                    orderno = orderno
                };

                if (datatype.Equals("html"))
                {
                    string url = data.url as string;
                    if (!string.IsNullOrEmpty(url))
                    {
                        Response.Redirect(url);
                    }
                    else
                    {
                        EchoFailJson("pay fail");
                        return;
                    }
                }
                else
                {
                    EchoSuccJson(data);
                }
            }
            else if (result.ResultType == Pay.PayResultType.Html)
            {
                Response.ContentType = "text/html;charset=utf-8";
                Response.Write(result.ResultData.ToString());
            }
        }