Example #1
0
        public void QuickPay(object obj)
        {
            if (string.IsNullOrWhiteSpace(Barcode))
            {
                ShowMessage("Scanning the QC code prior to submit");
            }

            if (_totalPay == 0.0)
            {
                ShowMessage("no payment");
            }

            if (string.IsNullOrWhiteSpace(ProductDescription))
            {
                ShowMessage("please input the production description");
            }
            try
            {
                string result = MicroPay.Run(ProductDescription, (_totalPay * 100).ToString(), Barcode);
            }
            catch (WxPayException ex)
            {
                ShowMessage(ex.ToString());
            }
            catch (Exception ex)
            {
                ShowMessage(ex.ToString());
            }
        }
Example #2
0
 protected void submit_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(auth_code.Text))
     {
         Response.Write("<script LANGUAGE='javascript'>alert('请输入授权码!');</script>");
         return;
     }
     if (string.IsNullOrEmpty(body.Text))
     {
         Response.Write("<script LANGUAGE='javascript'>alert('请输入商品描述!');</script>");
         return;
     }
     if (string.IsNullOrEmpty(fee.Text))
     {
         Response.Write("<script LANGUAGE='javascript'>alert('请输入商品总金额!');</script>");
         return;
     }
     //调用刷卡支付,如果内部出现异常则在页面上显示异常原因
     try
     {
         string result = MicroPay.Run(body.Text, fee.Text, auth_code.Text);
         Response.Write("<span style='color:#00CD00;font-size:20px'>" + result + "</span>");
     }
     catch (WxPayException ex)
     {
         Response.Write("<span style='color:#FF0000;font-size:20px'>" + ex.ToString() + "</span>");
     }
     catch (Exception ex)
     {
         Response.Write("<span style='color:#FF0000;font-size:20px'>" + ex.ToString() + "</span>");
     }
 }
Example #3
0
        /// <summary>
        /// 执行条码支付
        /// </summary>
        /// <param name="orderInfo">支付订单</param>
        /// <param name="resultInfo">支付结果记录</param>
        /// <returns></returns>
        public override ExecuteResult <PayNotifyInfo> ExecuteBarcodePay(PayOrderInfo orderInfo, PayResultInfo resultInfo)
        {
            var result = new ExecuteResult <PayNotifyInfo>();

            try
            {
                int       paymentAmt = (int)(Convert.ToDecimal(orderInfo.PaymentAmt) * 100);//微信支付金额的单位为“分”,所以要乘以100
                WxPayData runData    = MicroPay.Run(orderInfo.OrderId, paymentAmt, orderInfo.Barcode);
                if (runData.GetValue("return_code").ToString() != "SUCCESS")
                {
                    resultInfo.ExecuteResult = (int)ResultStatus.Failure;
                    resultInfo.ResultDesc    = "微信条码支付请求失败:" + runData.GetValue("return_msg").ToString();
                    PayResultDAL.Update(resultInfo);

                    result.Status  = ResultStatus.Failure;
                    result.Message = resultInfo.ResultDesc;
                    return(result);
                }
                else if (runData.GetValue("result_code").ToString() != "SUCCESS")
                {
                    resultInfo.ExecuteResult = (int)ResultStatus.Failure;
                    resultInfo.ResultDesc    = "微信条码支付失败:" + runData.GetValue("err_code_des").ToString();
                    PayResultDAL.Update(resultInfo);

                    result.Status  = ResultStatus.Failure;
                    result.Message = resultInfo.ResultDesc;
                    return(result);
                }

                //支付成功,更新支付结果记录
                resultInfo.OrderId       = orderInfo.OrderId;
                resultInfo.TradeNo       = runData.GetValue("transaction_id").ToString();
                resultInfo.PaymentAmt    = Convert.ToDecimal(runData.GetValue("total_fee")) / 100; //微信支付金额的单位为“分”,所以要除以100
                resultInfo.ExecuteResult = (int)ResultStatus.Success;

                result.Data   = this.GetPayNotifyInfo(resultInfo);
                result.Status = ResultStatus.Success;
            }
            catch (WxPayException wex)
            {
                resultInfo.ExecuteResult = (int)ResultStatus.Error;
                resultInfo.ResultDesc    = wex.Message;
                PayResultDAL.Update(resultInfo);

                result.Status  = ResultStatus.Error;
                result.Message = resultInfo.ResultDesc;
            }
            catch (Exception ex)
            {
                resultInfo.ExecuteResult = (int)ResultStatus.Error;
                resultInfo.ResultDesc    = ex.ToString();
                PayResultDAL.Update(resultInfo);

                result.Status  = ResultStatus.Error;
                result.Message = ex.Message;
            }
            return(result);
        }
Example #4
0
 public ActionResult <string> GetMicroPay(string auth_code, string body, string fee)
 {
     //调用刷卡支付,如果内部出现异常则在页面上显示异常原因
     try
     {
         string result = MicroPay.Run(body, fee, auth_code);
         return(result);
     }
     catch (WxPayException ex)
     {
         return(ex.ToString());
     }
     catch (Exception ex)
     {
         return(ex.ToString());
     }
 }
 public override bool Pay(decimal money, string QRCode)
 {
     if (money > 0)
     {
         string result = MicroPay.Run("微信支付出场", "1", QRCode);
         Dictionary <string, string> dicResult = new Dictionary <string, string>();
         SplitResult(result, ref dicResult);
         if (dicResult.ContainsKey("RESULT_CODE"))
         {
             if (dicResult["RESULT_CODE"] == "SUCCESS")
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Example #6
0
        public string Pay()
        {
            string sTag = Request["paytype"];
            //string sBody = Request["body"];
            string sAmount      = Request["fee"];
            string sPayAccount  = Request["auth_code"];
            string sPlateNumber = Request["PlateNumber"];
            string sPKID        = Request["PKID"];

            if (sTag.IsEmpty() || (sTag != "0" && sTag != "1" && sTag != "2"))
            {
                return("2");
            }

            //if (string.IsNullOrEmpty(sBody))
            //{
            //    return "2sBody";
            //}
            if (string.IsNullOrEmpty(sAmount))
            {
                return("2");
            }

            if (sTag != "2")
            {
                if (string.IsNullOrEmpty(sPayAccount))
                {
                    return("2");
                }
            }
            if (string.IsNullOrEmpty(sPlateNumber))
            {
                return("2");
            }
            if (string.IsNullOrEmpty(sPKID))
            {
                return("2");
            }

            OnlineOrder model = new OnlineOrder();

            model.OrderTime = DateTime.Now;

            TempParkingFeeResult result = RechargeService.WXTempParkingFee(sPlateNumber, sPKID, sPayAccount, model.OrderTime);

            if (result.Result == APPResult.NoNeedPay)
            {
                return("3"); //不需要交费
            }
            if (result.Result == APPResult.RepeatPay)
            {
                return("4"); //重复交费
            }

            decimal dAmount = decimal.Parse(sAmount) / 100;

            //if (result.Pkorder.Amount != dAmount)
            //{
            //    return "6"; //金额不一致
            //}
            try
            {
                RechargeService.CheckCalculatingTempCost(result.Result);
            }
            catch (Exception ex)
            {
                return(((int)result.Result).ToString());
            }

            if (result.OrderSource == PayOrderSource.Platform)
            {
                bool testResult = CarService.WXTestClientProxyConnectionByPKID(result.ParkingID);
                if (!testResult)
                {
                    throw new MyException("车场网络异常,暂无法缴停车费!");
                }
                //int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(result.Pkorder.OrderNo);

                int interfaceOrderState = InterfaceOrderServices.OrderWhetherEffective(result.Pkorder.OrderNo, result.ParkingID, result.Pkorder.TagID);
                if (interfaceOrderState != 1)
                {
                    if (interfaceOrderState == 2)
                    {
                        return("4"); //重复交费
                    }
                    else
                    {
                        return("5"); //订单已失效
                    }
                }
            }

            model.ParkCardNo   = result.CardNo;
            model.PKID         = result.ParkingID;
            model.PKName       = result.ParkName;
            model.InOutID      = result.Pkorder.TagID;
            model.PlateNo      = result.PlateNumber;
            model.EntranceTime = result.EntranceDate;
            model.ExitTime     = model.OrderTime.AddMinutes(result.OutTime);
            //model.Amount = result.Pkorder.Amount;
            model.Amount         = dAmount;
            model.PayDetailID    = result.Pkorder.OrderNo;
            model.DiscountAmount = result.Pkorder.DiscountAmount;
            // model.OrderSource = PayOrderSource.HAND;
            model.ExternalPKID = result.ExternalPKID;

            model.OrderID   = IdGenerator.Instance.GetId();
            model.Status    = OnlineOrderStatus.WaitPay;
            model.OrderType = OnlineOrderType.ParkFee;

            BaseCompany company = CompanyServices.QueryByParkingId(model.PKID);

            if (company == null)
            {
                throw new MyException("获取单位信息失败");
            }

            if (sTag == "0")
            {
                WX_ApiConfig config = WXApiConfigServices.QueryWXApiConfig(company.CPID);
                if (config == null)
                {
                    ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "获取微信配置信息失败", "单位编号:" + company.CPID, LogFrom.WeiXin);
                    return("-1");
                }
                if (!config.Status)
                {
                    ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "该车场暂停使用微信支付", "单位编号:" + company.CPID, LogFrom.WeiXin);
                    return("-1");
                }

                model.PayeeUser      = config.SystemName;
                model.PayeeAccount   = config.PartnerId;
                model.PayAccount     = sPayAccount;
                model.Payer          = sPayAccount;
                model.AccountID      = model.AccountID;
                model.CardId         = model.AccountID;
                model.PayeeChannel   = PaymentChannel.WeiXinPay;
                model.PaymentChannel = PaymentChannel.WeiXinPay;
                model.CompanyID      = config.CompanyID;

                bool isSuc = OnlineOrderServices.Create(model);
                if (!isSuc)
                {
                    throw new MyException("生成待缴费订单失败");
                }
            }
            else if (sTag == "1")
            {
                //支付宝
                AliPayApiConfig config = AliPayApiConfigServices.QueryAliPayConfig(company.CPID);
                if (config == null)
                {
                    ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "获取支付宝配置信息失败[0001]", "单位编号:" + company.CPID, LogFrom.WeiXin);
                    return("-1");
                }
                if (!config.Status)
                {
                    ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "该支付宝暂停使用", "单位编号:" + config.CompanyID, LogFrom.WeiXin);
                    return("-1");
                }

                model.AccountID      = string.Empty;
                model.CardId         = string.Empty;
                model.PayeeChannel   = PaymentChannel.AliPay;
                model.PaymentChannel = PaymentChannel.AliPay;
                model.PayeeUser      = config.SystemName;
                model.PayeeAccount   = config.PayeeAccount;
                model.Payer          = sPayAccount;
                model.PayAccount     = sPayAccount;
                model.CompanyID      = config.CompanyID;

                bool isSuc = OnlineOrderServices.Create(model);
                if (!isSuc)
                {
                    throw new MyException("生成待缴费订单失败");
                }
            }
            else if (sTag == "2")
            {
                //现金支付的
                model.AccountID  = string.Empty;
                model.CardId     = string.Empty;
                model.Payer      = sPayAccount;
                model.PayAccount = sPayAccount;
                model.CompanyID  = company.CPID;
            }

            //调用刷卡支付,如果内部出现异常则在页面上显示异常原因
            try
            {
                //int status=1;

                string tradeNo   = "";
                string sDataInfo = "";
                if (sTag == "0")    //微信
                {
                    if (!MicroPay.Run(model, out sDataInfo))
                    {
                        return("-2");
                    }
                    else
                    {
                        tradeNo = sDataInfo;
                        //发送通知开闸
                        bool isPayState = OnlineOrderServices.PaySuccess(model.OrderID, tradeNo, DateTime.Now, sPayAccount);
                        if (!isPayState)
                        {
                            throw new Exception("修改微信订单状态失败");
                        }

                        TxtLogServices.WriteTxtLogEx("WXPayReturn", string.Format("WXPayResult:{0}支付完成", tradeNo));
                    }
                }
                else if (sTag == "1")   //支付宝
                {
                    if (AliPayPay.Run(model, out sDataInfo) == false)
                    {
                        return("-3");
                    }
                    else
                    {
                        tradeNo = sDataInfo;

                        bool isPayState = OnlineOrderServices.PaySuccess(model.OrderID, tradeNo, DateTime.Now, sPayAccount);
                        if (!isPayState)
                        {
                            throw new Exception("修改支付宝订单状态失败");
                        }

                        TxtLogServices.WriteTxtLogEx("AliPayReturn", string.Format("AliPayShowResult:{0}支付完成", tradeNo));
                    }
                }
                else if (sTag == "2") //现金支付的
                {
                    TempStopPaymentResult payResult = RechargeService.WXTempStopPayment(result.Pkorder.OrderNo, (int)OrderPayWay.Cash, dAmount, sPKID, "", model.OrderID.ToString(), DateTime.Now);
                    TxtLogServices.WriteTxtLogEx("CashReturn", string.Format("CashShowResult:{1}:{0} 支付完成", payResult.ToXml(System.Text.Encoding.UTF8), dAmount));
                    if (payResult.Result != APPResult.Normal)
                    {
                        return("5");
                    }
                }

                //不是预支付的订单 就暂时不修改了
                //bool results = OnlineOrderServices.UpdatePrepayIdById(tradeNo, model.OrderID);
                //Response.Write("<span style='color:#00CD00;font-size:20px'>" + result + "</span>");
                ParkingFeeService.DeleteParkingFee(model.PlateNo + model.PKID);
                return("0");
            }
            //catch (WxPayException ex)
            //{
            //    return "1";
            //    //Response.Write("<span style='color:#FF0000;font-size:20px'>" + ex.ToString() + "</span>");
            //}
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("PayError", "该支付失败", "单位编号:" + model.CompanyID + "<br/>" + ex.StackTrace, LogFrom.UnKnown);
                return("-4");
                //Response.Write("<span style='color:#FF0000;font-size:20px'>" + ex.ToString() + "</span>");
            }
        }
Example #7
0
        private void WxPay()
        {
            string amount = actualTextbox.Text.Trim();

            if (string.IsNullOrEmpty(amount))
            {
                return;
            }
            else if (float.Parse(amount) == 0)
            {
                return;
            }
            else
            {
                amount = float.Parse(amount).ToString("0.00").Replace(".", "");
            }
            ///商品描述, 总金额 , 二维码, 订单号
            WxPayData result = MicroPay.Run(GoodsDetails, amount, codeTextbox.Text.Trim(), this.OrderNumber + "4");

            if ("SUCCESS".Equals(result.GetValue("result_code")) && "SUCCESS".Equals(result.GetValue("return_code")))
            {
                MessageBox.Show("微信支付成功!");
                PayInfo obj = new PayInfo();
                obj.Id         = Guid.NewGuid().ToString();
                obj.CreateTime = DateTime.Now;
                obj.UpdateTime = DateTime.Now;
                obj.PayAmount  = actualTextbox.Text.Trim();
                obj.orderId    = this.OrderNumber;
                obj.salesmanId = LoginUserInfo.id;
                obj.payDate    = DateTime.Now;
                obj.PayMode    = BranchPay.WxPay;
                //obj.MemberId = memberCardId;
                obj.BranchId = LoginUserInfo.branchId;

                //BranchPayInfoService service = new BranchPayInfoService();
                //service.AddPayInfo(obj);
                ////上传支付信息
                //PayInfoService masterPayInfoService = new PayInfoService();
                //masterPayInfoService.AddPayInfo(obj);

                this.payForm.AddPayInfo(obj);

                payForm.AddPaidAmount(obj.PayAmount);

                clFlag = true;

                this.Close();
            }
            else if ("SUCCESS".Equals(result.GetValue("return_code")))
            {
                if (result.IsSet("err_code_des"))
                {
                    MessageBox.Show(result.GetValue("err_code_des").ToString());
                    return;
                }
                else
                {
                    MessageBox.Show("微信支付发生未知错误!");
                    return;
                }
            }
            else
            {
                MessageBox.Show("微信支付通信失败,请检查网络!");
                return;
            }
        }