protected override void AttachRequest(PayRequestModel model, IMap <RequestMapField> requestMapper)
 {
     requestMapper.Add(new NameValueCollection
     {
         { "timestamp", Extensions.UnixTimeSpan().ToString() },
         { "orderId", "" },
         { "merchantId", "" },
         { "amount", "" },
         { "type", "" },
         { "notifyUrl", "" },
         { "frontUrl", "" },
         { "merchantKey", Settings.Mkey },
         { "productName", "" }
     })
     .Add(new Dictionary <RequestMapField, string>()
     {
         { RequestMapField.Mid, "merchantId" },
         { RequestMapField.Amount, "amount" },
         { RequestMapField.OrderId, "orderId" },
         { RequestMapField.ProductName, "productName" },
         { RequestMapField.ClientNotifyUrl, "frontUrl" },
         { RequestMapField.ServerNotifyUrl, "notifyUrl" },
         { RequestMapField.BankCo, "type" }
     });
 }
        protected virtual RequestContext CreateRequest(PayRequestModel requestModel, IRequestMap <RequestMapField> requestMapper)
        {
            //设置订单号
            if (string.IsNullOrWhiteSpace(requestModel.OrderId))
            {
                requestModel[RequestMapField.OrderId] = GenerateOrderId();
            }

            //var evt = WorkContext.Resolve<IPaymentEventHandler>();

            // evt.Posting(requestModel);

            //兼容Money格式
            requestModel.Amount = ConvertAmount(requestModel.Amount);
            requestModel[RequestMapField.Amount] = requestModel.Amount.ToString(CultureInfo.InvariantCulture);
            requestModel[RequestMapField.Mid]    = Settings.Mid;

            AttachRequest(requestModel, requestMapper);
            //合并映射到参数
            requestMapper.Combine(requestModel.MapValues);
            var request = requestMapper.GetMapResult();

            request[SignFieldName] = Sign(request);

            return(CreateRequestContext(request, requestModel, GateWay));
        }
示例#3
0
        /// <summary>
        /// 新增订单
        /// </summary>
        /// <param name="requestModel"></param>
        /// <param name="aoid"></param>
        /// <param name="qr"></param>
        /// <param name="jsapi_info"></param>
        /// <returns></returns>
        public static bool Add(PayRequestModel requestModel, string aoid = "", string qr = "", string jsapi_info = "")
        {
            string sql = "insert into orders(order_no,buyer,price,pay_type,name,more,add_time,aoid,qr,jsapi_info)";

            sql += " values(@order_no,@buyer,@price,@pay_type,@name,@more,@add_time,@aoid,@qr,@jsapi_info)";
            SQLiteParameter[] parameters = new SQLiteParameter[]
            {
                new SQLiteParameter("@order_no", requestModel.order_id),
                new SQLiteParameter("@buyer", requestModel.order_uid),
                new SQLiteParameter("@price", requestModel.price),
                new SQLiteParameter("@pay_type", requestModel.pay_type),
                new SQLiteParameter("@name", requestModel.name),
                new SQLiteParameter("@more", requestModel.more),
                new SQLiteParameter("@add_time", DateTime.Now),
                new SQLiteParameter("@aoid", aoid),
                new SQLiteParameter("@qr", qr),
                new SQLiteParameter("@jsapi_info", jsapi_info)
            };
            return(SqlHelper.ExecuteNonQuery(sql, parameters) > 0);
        }
示例#4
0
        public async Task <PayResult <PayResponseModel> > AuthorizeAsync(PayRequestModel model)
        {
            var errors = new List <PayError>();

            model.Api = _configuration.Api;

            model.ValidateModel(errors);
            if (errors.Any())
            {
                return(PayResult <PayResponseModel> .Failed(errors.ToArray()));
            }

            var t = await PostRequestBase <PayResponseModel, PayRequestModel>(model, _requestUrl);

            if (t.Succeeded)
            {
                return(PayResult <PayResponseModel> .Invoke(t.Result));
            }

            errors.AddRange(t.Errors);
            return(PayResult <PayResponseModel> .Failed(errors.ToArray()));
        }
示例#5
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
            }));
        }
示例#6
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
            }));
        }
示例#7
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);
            }
        }
示例#8
0
 internal RequestContext(NameValueCollection requestParameters, PaymentServicesProviderBase provider, PayRequestModel model)
 {
     ProviderInstance  = provider;
     Model             = model;
     RequestParameters = requestParameters;
 }
 protected abstract void AttachRequest(PayRequestModel model, IMap <RequestMapField> requestMapper);
 protected virtual RequestContext CreateRequestContext(NameValueCollection request, PayRequestModel requestModel, string gateway)
 {
     return(new RequestContext(request, this, requestModel)
     {
         GateWay = gateway
     });
 }
 public RequestContext Request(PayRequestModel mode)
 {
     return(CreateRequest(mode, new RequestMapper()));
 }