コード例 #1
0
ファイル: AlipaySubmit.cs プロジェクト: Bobom/kuanmai
 public Submit(AlipayConfig config)
 {
     if (config == null)
     {
         throw new KMBitException("Alipay config is missing");
     }
     _config = config;
     _key = config.Key.Trim();
     _input_charset = config.Input_charset.Trim().ToLower();
     _sign_type = config.Sign_Type.Trim().ToUpper();
     GATEWAY_NEW = config.Gate_Url;
 }
コード例 #2
0
ファイル: AlipayNotify.cs プロジェクト: Bobom/kuanmai
        private string _sign_type = ""; //签名方式

        #endregion Fields

        #region Constructors

        /// <summary>
        /// 构造函数
        /// 从配置文件中初始化变量
        /// </summary>
        /// <param name="inputPara">通知返回参数数组</param>
        /// <param name="notify_id">通知验证ID</param>
        //public Notify()
        //{
        //    //初始化基础配置信息
        //    _partner = Config.Partner.Trim();
        //    _key = Config.Key.Trim();
        //    _input_charset = Config.Input_charset.Trim().ToLower();
        //    _sign_type = Config.Sign_type.Trim().ToUpper();
        //}
        public Notify(AlipayConfig config)
        {
            if(config==null)
            {
                throw new KMBitException("Alipay config is missing");
            }
            //初始化基础配置信息
            _partner = config.Partner.Trim();
            _key = config.Key.Trim();
            _input_charset = config.Input_charset.Trim().ToLower();
            _sign_type = config.Sign_Type.Trim().ToUpper();
            Https_veryfy_url = config.Verify_Url;
        }
コード例 #3
0
ファイル: PaymentController.cs プロジェクト: Bobom/kuanmai
        // GET: PayBack此方法仅供直冲用户支付宝支付完成回调以及支付宝充值账户回调
        public ActionResult AlipayBack()
        {
            SortedDictionary<string, string> sPara = GetRequestGet();
            ChargeResult result = new ChargeResult() { Status= ChargeStatus.FAILED };
            if (sPara.Count > 0)//判断是否有带返回参数
            {
                AlipayConfig config = new AlipayConfig(System.IO.Path.Combine(Request.PhysicalApplicationPath, "Config\\AliPayConfig.xml"));
                Notify aliNotify = new Notify(config);
                bool verifyResult = aliNotify.Verify(sPara, Request.QueryString["notify_id"], Request.QueryString["sign"]);

                if (verifyResult)//验证成功
                {
                    //本地系统支付号
                    string out_trade_no = Request.QueryString["out_trade_no"];
                    int paymentId = 0;
                    int.TryParse(out_trade_no, out paymentId);

                    //支付宝交易号
                    string trade_no = Request.QueryString["trade_no"];

                    //买家支付宝账户
                    string buyerAccount = Request.QueryString["buyer_email"];
                    //交易状态
                    string trade_status = Request.QueryString["trade_status"];
                    if (Request.QueryString["trade_status"] == "TRADE_FINISHED" || Request.QueryString["trade_status"] == "TRADE_SUCCESS")
                    {
                        //判断该笔订单是否在商户网站中已经做过处理
                        //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                        //如果有做过处理,不执行商户的业务程序
                        OrderManagement orderMgr = new OrderManagement(0);
                        PaymentManagement payMgr = new PaymentManagement(0);
                        if(paymentId>0)
                        {
                            try
                            {
                                BPaymentHistory payment = null;
                                int total = 0;
                                List<BPaymentHistory> payments = payMgr.FindPayments(paymentId,0, 0,out total);
                                if(payments!=null && payments.Count==1)
                                {
                                    payment = payments[0];
                                    if(payment.PayType==0)//直冲用户支付
                                    {
                                        result = orderMgr.ProcessOrderAfterPaid(paymentId, trade_no, buyerAccount);
                                        result.Status = ChargeStatus.SUCCEED;
                                        result.Message = "支付成功,已经提交到充值系统,请耐心等待...";
                                        return Redirect("/Product/Charge?message=" + result.Message);
                                    }
                                    else if(payment.PayType==1)//代理商用户充值账户
                                    {
                                        payMgr.UpdateAccountMoneyAfterPayment(payment);
                                        return Redirect("/Agent/ChargeAccount?message=" + result.Message);
                                    }

                                }else
                                {
                                    result.Status = ChargeStatus.FAILED;
                                    result.Message = string.Format("支付号{0}在本系统中不存在",paymentId);
                                }

                            }
                            catch(KMBitException e)
                            {
                                result.Message = e.Message;
                                result.Status = ChargeStatus.FAILED;
                            }
                            catch(Exception ex)
                            {
                                result.Message = ex.Message;
                                result.Status = ChargeStatus.FAILED;
                            }
                        }
                    }
                    else
                    {
                        result.Message = string.Format("支付宝支付失败:{0}",Request.QueryString["trade_status"]);
                        result.Status = ChargeStatus.FAILED;

                        //需要删除本地系统内的支付记录或者充值订单记录TBD
                    }
                }
                else//验证失败
                {
                    result.Message = "支付宝返回数据验证失败,请不要串改支付宝返回的数据";
                    result.Status = ChargeStatus.FAILED;
                    //需要删除本地系统内的支付记录或者充值订单记录TBD
                }
            }
            else
            {
                result.Message = "支付宝没有返回任何数据,充值失败";
                result.Status = ChargeStatus.FAILED;
            }
            return Redirect("/Product/Charge?message=" + result.Message);
        }
コード例 #4
0
ファイル: ProductController.cs プロジェクト: Bobom/kuanmai
        public ActionResult Charge(ChargeModel model)
        {
            if (ModelState.IsValid)
            {
                //ChargeBridge cb = new ChargeBridge();
                ChargeOrder order = new ChargeOrder()
                { ChargeType = 0, AgencyId = 0, Id = 0, Province = model.Province, City = model.City, MobileSP = model.SPName, MobileNumber = model.Mobile, OutOrderId = "", ResourceId = 0, ResourceTaocanId = model.ResourceTaocanId, RouteId = 0, CreatedTime = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now) };
                //
                OrderManagement orderMgt = new OrderManagement();
                ResourceManagement resourceMgr = new ResourceManagement(0);
                try
                {
                    order = orderMgt.GenerateOrder(order);
                }
                catch(KMBitException kex)
                {
                    ViewBag.Message = kex.Message;
                    return View();
                }
                catch(Exception ex)
                {
                    ViewBag.Message = "未知错误请联系系统管理员";
                    return View();
                }

                int total = 0;
                List<BResourceTaocan> taocans = resourceMgr.FindResourceTaocans(order.ResourceTaocanId, 0, 0, out total);
                if (taocans == null || taocans.Count == 0)
                {
                    ViewBag.Message = "当前套餐不可用";
                    return View();
                }
                BResourceTaocan taocan = taocans[0];
                //Redirct to the payment page.
                //TBD
                //After the payment is done then process below steps
                AlipayConfig config = new AlipayConfig(System.IO.Path.Combine(Request.PhysicalApplicationPath, "Config\\AliPayConfig.xml"));
                Submit submit = new Submit(config);

                SortedDictionary<string, string> sParaTemp = new SortedDictionary<string, string>();
                sParaTemp.Add("partner", config.Partner);
                sParaTemp.Add("seller_email", "*****@*****.**");
                sParaTemp.Add("_input_charset", config.Input_charset.ToLower());
                sParaTemp.Add("service", "create_direct_pay_by_user");
                sParaTemp.Add("payment_type", "1");
                sParaTemp.Add("notify_url", config.Notify_Url);
                sParaTemp.Add("return_url", config.Return_Url);
                sParaTemp.Add("out_trade_no", order.PaymentId.ToString());
                sParaTemp.Add("subject", string.Format("{0}M", taocan.Taocan.Quantity));
                sParaTemp.Add("total_fee", taocan.Taocan.Sale_price.ToString("0.00"));
                sParaTemp.Add("body", string.Format("{0}M", taocan.Taocan.Quantity));
                sParaTemp.Add("show_url", "");
                sParaTemp.Add("seller_id",config.Partner);
                //sParaTemp.Add("anti_phishing_key", "");
                //sParaTemp.Add("exter_invoke_ip", "");

                //建立请求
                string sHtmlText = submit.BuildRequest(sParaTemp, "get", "确认");
                //Response.Write("ok");
                Response.Clear();
                Response.Charset = "utf-8";
                Response.Write(sHtmlText);

                //ChargeResult result = cb.Charge(order);
                //ViewBag.Message = result.Message;
            }

            return View();
        }
コード例 #5
0
ファイル: AgentController.cs プロジェクト: Bobom/kuanmai
        public ActionResult ChargeAccount(ChargeAccountModel model)
        {
            PaymentManagement payMgr = new PaymentManagement(User.Identity.GetUserId<int>());
            if(model.TransferType==1)
            {
                AlipayConfig config = new AlipayConfig(System.IO.Path.Combine(Request.PhysicalApplicationPath, "Config\\AliPayConfig.xml"));
                Submit submit = new Submit(config);
                BPaymentHistory payment = null;
                try
                {
                    payment = payMgr.CreateChargeAccountPayment(User.Identity.GetUserId<int>(), model.Amount, model.TransferType);
                    if (payment == null)
                    {
                        ViewBag.Message = "充值失败";
                        return View(model);
                    }

                }catch(Exception ex)
                {
                    ViewBag.Message = "充值失败";
                    return View(model);
                }
                
                SortedDictionary<string, string> sParaTemp = new SortedDictionary<string, string>();
                sParaTemp.Add("partner", config.Partner);
                sParaTemp.Add("seller_email", config.Email);
                sParaTemp.Add("_input_charset", config.Input_charset.ToLower());
                sParaTemp.Add("service", "create_direct_pay_by_user");
                sParaTemp.Add("payment_type", "1");
                sParaTemp.Add("notify_url", config.Notify_Url);
                sParaTemp.Add("return_url", config.Return_Url);
                sParaTemp.Add("out_trade_no", payment.Id.ToString());
                sParaTemp.Add("subject", string.Format("宽迈网络账户充值 {0} 元", model.Amount));
                sParaTemp.Add("total_fee", model.Amount.ToString("0.00"));
                sParaTemp.Add("body", string.Format("宽迈网络账户充值 {0} 元", model.Amount));
                sParaTemp.Add("show_url", "");
                sParaTemp.Add("seller_id", config.Partner);
                //sParaTemp.Add("anti_phishing_key", "");
                //sParaTemp.Add("exter_invoke_ip", "");

                //建立请求
                string sHtmlText = submit.BuildRequest(sParaTemp, "get", "确认");
                //Response.Write("ok");
                Response.Clear();
                Response.Charset = "utf-8";
                Response.Write(sHtmlText);
            }
            return View(model);
        }