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(); }
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); }