Пример #1
0
        /// <summary>
        /// 订单退款
        /// </summary>
        /// <param name="context"></param>
        private void refund(HttpContext context)
        {
            string aoid     = PayRequest.GetFormString("aoid");
            string errorMsg = "";

            if (string.IsNullOrWhiteSpace(aoid))
            {
                errorMsg = "XorPay平台订单号不能为空";
            }
            float price = PayRequest.GetFormFloat("price", 0f);

            if (price <= 0f)
            {
                errorMsg = "退款金额必须大于0";
            }
            if (!string.IsNullOrWhiteSpace(errorMsg))
            {
                context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string>
                {
                    status = 0,
                    msg    = errorMsg
                }));
                return;
            }
            string data_info = "";

            try
            {
                string strInfo = PayCore.Refund(aoid, price);
                if (!string.IsNullOrWhiteSpace(strInfo))
                {
                    statusInfo info = JsonHelper.JSONToObject <statusInfo>(strInfo);
                    if (info != null)
                    {
                        data_info = PayCore.GetDictValue(PayModel.refundStatusDict, info.status);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string>
                {
                    status = 0,
                    msg    = ex.Message
                }));
                return;
            }
            context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string>
            {
                status = 1,
                msg    = "请求成功",
                data   = data_info
            }));
        }
Пример #2
0
        /// <summary>
        /// 订单查询
        /// </summary>
        /// <param name="context"></param>
        private void query(HttpContext context)
        {
            string aoid = PayRequest.GetFormString("aoid");

            if (string.IsNullOrWhiteSpace(aoid))
            {
                context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string>
                {
                    status = 0,
                    msg    = "XorPay平台订单号不能为空"
                }));
                return;
            }
            string data_info = "";

            try
            {
                string strInfo = PayRequest.SendRequest($"https://xorpay.com/api/query/{aoid}", "", "GET", "UTF-8");
                if (!string.IsNullOrWhiteSpace(strInfo))
                {
                    statusInfo info = JsonHelper.JSONToObject <statusInfo>(strInfo);
                    if (info != null)
                    {
                        data_info = PayCore.GetDictValue(PayModel.queryStatusDict, info.status);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string>
                {
                    status = 0,
                    msg    = ex.Message
                }));
                return;
            }
            context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string>
            {
                status = 1,
                msg    = "请求成功",
                data   = data_info
            }));
        }
Пример #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string aoid      = PayRequest.GetFormString("aoid");
            string detail    = PayRequest.GetFormString("detail");
            string more      = PayRequest.GetFormString("more");
            string order_id  = PayRequest.GetFormString("order_id");
            string pay_price = PayRequest.GetFormString("pay_price");
            string pay_time  = PayRequest.GetFormString("pay_time");
            string sign      = PayRequest.GetFormString("sign");

            LogHelper.Info("----------订单回调通知接收参数----------");
            LogHelper.Info($"aoid:{aoid},detail:{detail},more:{more},order_id:{order_id},pay_price:{pay_price},pay_time:{pay_time},sign:{sign}");

            //验证签名
            if (!string.IsNullOrWhiteSpace(sign))
            {
                string parameters = $"{aoid}{order_id}{pay_price}{pay_time}{PayConfig.app_secret}";

                //签名验证通过
                if ((PayCore.Md5Hash(parameters, false) ?? "").ToLower() == sign.ToLower())
                {
                    //是否存在该订单
                    if (!Orders.Exists(order_id))
                    {
                        base.Response.Write("oid_not_exist");
                        return;
                    }

                    /*判断订单是否已支付,避免业务重复处理,以及订单金额与支付金额是否一致等
                     * ---------根据自身业务进行操作校验----------------*/

                    //更新订单状态
                    if (Orders.Update($"aoid='{aoid}',pay_price='{pay_price}',pay_time='{pay_time}'", $"order_no='{order_id}'"))
                    {
                        //业务处理成功后输出 ok/success ,XorPay停止通知
                        Response.Write("success");
                        return;
                    }
                }
            }
            Response.Write("failed");
        }
Пример #4
0
        /// <summary>
        /// 获取jsapi支付参数
        /// </summary>
        /// <param name="context"></param>
        private void payjsGetInfo(HttpContext context)
        {
            string name       = PayRequest.GetFormString("name");
            string pay_type   = PayRequest.GetFormString("pay_type");
            float  price      = PayRequest.GetFormFloat("price", 0f);
            string order_id   = PayRequest.GetFormString("order_id");
            string notify_url = PayRequest.GetFormString("notify_url");
            string order_uid  = PayRequest.GetFormString("order_uid");
            string more       = PayRequest.GetFormString("more");
            string open_id    = PayRequest.GetFormString("openid");

            if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(pay_type) || price <= 0f || string.IsNullOrWhiteSpace(order_id) || string.IsNullOrWhiteSpace(notify_url) || string.IsNullOrWhiteSpace(open_id))
            {
                context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string>
                {
                    status = 0,
                    msg    = "参数信息获取失败"
                }));
                return;
            }

            if (Orders.Exists(order_id))
            {
                string jsApiInfo = Orders.GetJsApiInfo(order_id);
                if (!string.IsNullOrWhiteSpace(jsApiInfo))
                {
                    context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string>
                    {
                        status = 1,
                        msg    = "订单已存在",
                        data   = order_id
                    }));
                    return;
                }
            }

            string errormsg = "请求失败";

            try
            {
                PayRequestModel payRequest = new PayRequestModel
                {
                    name       = name,
                    pay_type   = pay_type,
                    price      = price,
                    order_id   = order_id,
                    notify_url = notify_url,
                    order_uid  = order_uid,
                    more       = more,
                    openid     = open_id
                };

                string jsonStr = PayCore.GetPayInfo(payRequest);
                if (!string.IsNullOrWhiteSpace(jsonStr))
                {
                    JsPayResponse model = JsonHelper.JSONToObject <JsPayResponse>(jsonStr);
                    if (model != null)
                    {
                        if (model.status == "ok")
                        {
                            if (model.info != null)
                            {
                                var jsapiInfo = JsonHelper.ObjectToJSON(model.info);
                                if (Orders.Add(payRequest, model.aoid, "", jsapiInfo))
                                {
                                    context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string>
                                    {
                                        status = 1,
                                        msg    = "请求成功",
                                        data   = order_id
                                    }));
                                    return;
                                }
                            }
                        }
                        else
                        {
                            errormsg = PayCore.GetDictValue(PayModel.payStatusDict, model.status);
                        }
                    }
                }
                else
                {
                    errormsg = "请求失败,请检查aid与app_secret是否正确配置,以及XorPay后台是否正常";
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string>
                {
                    status = 0,
                    msg    = ex.Message
                }));
                return;
            }
            context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string>
            {
                status = 0,
                msg    = errormsg
            }));
        }
Пример #5
0
        /// <summary>
        /// 获取微信收银台跳转链接
        /// </summary>
        /// <param name="context"></param>
        private void paywapGetInfo(HttpContext context)
        {
            string name       = PayRequest.GetFormString("name");
            string pay_type   = PayRequest.GetFormString("pay_type");
            float  price      = PayRequest.GetFormFloat("price", 0f);
            string order_id   = PayRequest.GetFormString("order_id");
            string notify_url = PayRequest.GetFormString("notify_url");
            string cancel_url = PayRequest.GetFormString("cancel_url");
            string return_url = PayRequest.GetFormString("return_url");
            string order_uid  = PayRequest.GetFormString("order_uid");
            string more       = PayRequest.GetFormString("more");

            if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(pay_type) || price <= 0f || string.IsNullOrWhiteSpace(order_id) || string.IsNullOrWhiteSpace(notify_url))
            {
                context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string>
                {
                    status = 0,
                    msg    = "参数信息获取失败"
                }));
                return;
            }
            string qr;

            if (Orders.Exists(order_id))
            {
                qr = Orders.GetQR(order_id);
                if (!string.IsNullOrWhiteSpace(qr))
                {
                    context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string>
                    {
                        status = 1,
                        msg    = "订单已存在",
                        data   = qr
                    }));
                    return;
                }
            }
            PayRequestModel requestModel = new PayRequestModel
            {
                cancel_url = cancel_url,
                more       = more,
                name       = name,
                notify_url = notify_url,
                order_id   = order_id,
                order_uid  = order_uid,
                pay_type   = pay_type,
                price      = price,
                return_url = return_url
            };

            qr = PayCore.GetWXPayUrl(requestModel);
            if (!Orders.Add(requestModel, "", qr))
            {
                context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string>
                {
                    status = 0,
                    msg    = "添加失败"
                }));
                return;
            }
            context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string>
            {
                status = 1,
                msg    = "请求成功",
                data   = qr
            }));
        }
Пример #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string userAgent = Request.UserAgent;

            string order_no = "B" + DateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(10, 99);

            float amount = PayRequest.GetQueryFloat("amount", 1f);

            PayConfig payConfig = new PayConfig();

            string jsapi_callback = $"https://xorpay.com/api/openid/{PayConfig.aid}?callback={HttpUtility.UrlEncode(payConfig.protocol + "/unionurl.aspx?pay_type=jsapi&amount=" + amount)}";

            string open_id = PayRequest.GetQueryString("openid");

            if (Orders.Exists(order_no))
            {
                qr = Orders.GetQR(order_no);
                if (!string.IsNullOrWhiteSpace(qr))
                {
                    return;
                }
            }

            string pay_type = "alipay";

            if (userAgent.ToLower().Contains("alipayclient"))
            {
                pay_type = "alipay";
            }
            else
            {
                pay_type = "native";
                if (string.IsNullOrWhiteSpace(open_id))
                {
                    Response.Redirect(jsapi_callback);
                    return;
                }
            }

            PayRequestModel payRequest = new PayRequestModel
            {
                name       = "统一支付",
                pay_type   = pay_type,
                price      = 1f,
                order_id   = order_no,
                notify_url = payConfig.notify_url,
                order_uid  = "union_test",
                more       = "统一支付test",
                openid     = open_id
            };

            try
            {
                if (pay_type == "native")//微信支付
                {
                    string wxUrl = PayCore.GetWXPayUrl(payRequest);
                    if (!string.IsNullOrWhiteSpace(wxUrl))
                    {
                        qr = wxUrl;
                    }
                }
                else//默认支付宝
                {
                    string          jsonStr = PayCore.GetPayInfo(payRequest);
                    CodePayResponse model   = JsonHelper.JSONToObject <CodePayResponse>(jsonStr);
                    if (model != null)
                    {
                        if (model.status == "ok")
                        {
                            qr = ((model.info != null) ? model.info.qr : "");
                            Orders.Add(payRequest, model.aoid, qr);
                        }
                        else
                        {
                            errormsg = PayCore.GetDictValue(PayModel.payStatusDict, model.status);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                errormsg = "系统繁忙...";
                LogHelper.Error(ex.Message);
            }

            if (!string.IsNullOrWhiteSpace(errormsg))
            {
                Response.Write(errormsg);
            }
        }