Beispiel #1
0
        public static bool HasPaid(string order_no)
        {
            string        requestUrl = "http://www.bz-pospay.cn/apiorderquery";
            var           request    = (HttpWebRequest)WebRequest.Create(requestUrl);
            StringBuilder builder    = new StringBuilder();

            builder.Append(StringHelper.CreateField("mch_id", mch_id));
            builder.Append(StringHelper.CreateField("sdorderno", order_no));
            string postData = builder.ToString().Substring(1);
            var    data     = Encoding.UTF8.GetBytes(postData);

            try
            {
                request.Method        = "POST";
                request.ContentType   = "application/x-www-form-urlencoded";
                request.ContentLength = data.Length;
                using (var stream = request.GetRequestStream())
                {
                    stream.Write(data, 0, data.Length);
                }
                var    response       = (HttpWebResponse)request.GetResponse();
                string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
                if (!String.IsNullOrWhiteSpace(responseString))
                {
                    YSWL.Json.JsonObject jsonObject = JsonConvert.Import <JsonObject>(responseString);
                    if (jsonObject["status"] == null || YSWL.Common.Globals.SafeInt(jsonObject["status"].ToString(), 0) != 200)
                    {
                        return(false);
                    }
                    if (jsonObject["pay_state"] != null && YSWL.Common.Globals.SafeInt(jsonObject["ay_state"].ToString(), 0) == 1)//支付成功了
                    {
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                ColoPay.BLL.SysManage.LogHelp.AddErrorLog(String.Format("查询订单【{0}】支付状态失败:{1}", order_no, ex.Message), ex.StackTrace);
            }

            return(false);
        }
Beispiel #2
0
        public HttpResponseMessage PayBankOrder([FromBody] PayInfo payinfo)
        {
            //YSWL.Common.DEncrypt.DEncrypt.GetMD5FromStr
            //验证是否数据安全性
            if (payinfo.amount < 0)
            {
                return(new HttpResponseMessage {
                    Content = new StringContent("amount is illegal", Encoding.GetEncoding("UTF-8"), "text/plain")
                });
            }
            if (String.IsNullOrWhiteSpace(payinfo.order_no))
            {
                return(new HttpResponseMessage {
                    Content = new StringContent("ordercode is illegal", Encoding.GetEncoding("UTF-8"), "text/plain")
                });
            }


            ColoPay.Model.Pay.Enterprise CurrEnterprise = bll.GetEnterpriseInfo(payinfo.appid, payinfo.secrit);
            if (CurrEnterprise == null)
            {
                return(new HttpResponseMessage {
                    Content = new StringContent("appid or secrit is illegal", Encoding.GetEncoding("UTF-8"), "text/plain")
                });
            }
            //判断订单是否存在
            ColoPay.Model.Pay.Order orderInfo = orderBll.GetModelEx(payinfo.order_no, CurrEnterprise.EnterpriseID);

            if (orderInfo == null)
            {
                //创建订单
                orderInfo              = new Model.Pay.Order();
                orderInfo.Agentd       = CurrEnterprise.AgentId;
                orderInfo.Amount       = payinfo.amount;
                orderInfo.AppId        = CurrEnterprise.AppId;
                orderInfo.AppReturnUrl = String.IsNullOrWhiteSpace(payinfo.return_url) ? CurrEnterprise.AppReturnUrl : payinfo.return_url;
                orderInfo.AppSecrit    = CurrEnterprise.AppSecrit;
                orderInfo.AppUrl       = HttpContext.Current.Request.Url.ToString();
                orderInfo.CreatedTime  = DateTime.Now;
                orderInfo.EnterOrder   = payinfo.order_no;
                orderInfo.EnterpriseID = CurrEnterprise.EnterpriseID;
                orderInfo.OrderCode    = "P" + CurrEnterprise.EnterpriseID + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff");
                //获取支付方式
                ColoPay.Model.Pay.PaymentTypes typeInfo = typeBll.GetPaymentInfo(payinfo.paytype);
                if (typeInfo == null)
                {
                    return(new HttpResponseMessage {
                        Content = new StringContent("paytype is illegal", Encoding.GetEncoding("UTF-8"), "text/plain")
                    });
                }
                //获取支付费率

                ColoPay.Model.Pay.EnterprisePayFee feeInfo = feeBll.GetModel(CurrEnterprise.EnterpriseID, typeInfo.ModeId);
                if (feeInfo == null)
                {
                    return(new HttpResponseMessage {
                        Content = new StringContent("paytype is illegal", Encoding.GetEncoding("UTF-8"), "text/plain")
                    });
                }
                orderInfo.FeeRate         = feeInfo.FeeRate;
                orderInfo.PaymentFee      = payinfo.amount * (feeInfo.FeeRate / 100);
                orderInfo.OrderAmount     = payinfo.amount - orderInfo.PaymentFee;
                orderInfo.PaymentGateway  = typeInfo.Gateway;
                orderInfo.PaymentStatus   = 0;
                orderInfo.AppNotifyUrl    = CurrEnterprise.AppReturnUrl;
                orderInfo.PaymentTypeName = typeInfo.Name;
                orderInfo.PayModeId       = typeInfo.ModeId;
                orderInfo.OrderInfo       = String.IsNullOrWhiteSpace(payinfo.remark) ? "" : payinfo.remark;
                orderInfo.OrderId         = orderBll.Add(orderInfo);
                if (orderInfo.OrderId == 0)//创建订单失败
                {
                    return(new HttpResponseMessage {
                        Content = new StringContent("payorder is error", Encoding.GetEncoding("UTF-8"), "text/plain")
                    });
                }
            }
            else //订单已经存在了
            {
                if (orderInfo.Amount != payinfo.amount)//金额不一样,说明订单不一样
                {
                    return(new HttpResponseMessage {
                        Content = new StringContent("order_no has exist", Encoding.GetEncoding("UTF-8"), "text/plain")
                    });
                }
                if (orderInfo.PaymentStatus == 2)
                {
                    return(new HttpResponseMessage {
                        Content = new StringContent("order has paid", Encoding.GetEncoding("UTF-8"), "text/plain")
                    });
                }
            }

            string resullt = ColoPay.WebApi.PayApi.DaDaBank.PayRequest(orderInfo.OrderCode, payinfo.amount, payinfo.bankcode, orderInfo.OrderInfo);

            YSWL.Json.JsonObject jsonObject = JsonConvert.Import <JsonObject>(resullt);
            if (jsonObject["bxstatus"].ToString() == "SUCCESS")
            {
                string pay_url           = jsonObject["pay_url"].ToString();
                HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.Moved);
                resp.Headers.Location = new Uri(pay_url);
                return(resp);
            }
            else
            {
                return(new HttpResponseMessage {
                    Content = new StringContent(jsonObject["bxmsg"].ToString(), Encoding.GetEncoding("UTF-8"), "text/plain")
                });
            }
        }