public ApiMessage GetAgencyResourceTaocans() { this.IniRequest(); ApiMessage message = new ApiMessage(); AgentAdminMenagement agentMgtMgr = new AgentAdminMenagement(User.Identity.Name); int agencyId = 0; int resourceId = 0; int.TryParse(request["agencyId"], out agencyId); int.TryParse(request["resourceId"], out resourceId); if (agencyId == 0 && resourceId == 0) { message.Status = "ERROR"; message.Item = null; message.Message = "代理商编号和资源编号都不能为空"; return(message); } List <BResourceTaocan> taocans = new List <BResourceTaocan>(); if (resourceId > 0 && agencyId > 0) { taocans = agentMgtMgr.FindAgencyResourceTaocans(agencyId, resourceId); } else if (resourceId > 0 && agencyId <= 0) { ResourceManagement resourceMgr = new ResourceManagement(agentMgtMgr.CurrentLoginUser); taocans = resourceMgr.FindResourceTaocans(resourceId, 0, false); } message.Status = "OK"; message.Item = taocans; return(message); }
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, OutId = "", ResourceId = 0, ResourceTaocanId = model.ResourceTaocanId, RouteId = 0, CreatedTime = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now) }; // OrderManagement orderMgt = new OrderManagement(); ResourceManagement resourceMgr = new ResourceManagement(0); order = orderMgt.GenerateOrder(order); 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 JsonResult PreCharge(WeChatChargeModel model) { logger.Info("WeChatController.PreCharge......................................................"); ApiMessage message = new ApiMessage(); ChargeOrder order = null; if (ModelState.IsValid) { try { if (string.IsNullOrEmpty(model.OpenId)) { message.Status = "ERROR"; message.Message = "请从公众号菜单打开此页面"; return(Json(message, JsonRequestBehavior.AllowGet)); } //ChargeBridge cb = new ChargeBridge(); 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), Payed = false, OpenId = model.OpenId, OpenAccountType = 1 }; // OrderManagement orderMgt = new OrderManagement(); ResourceManagement resourceMgr = new ResourceManagement(0); string msg = string.Empty; if (orderMgt.IsThisMonthCharged(order.MobileNumber, order.ResourceTaocanId, out msg)) { message.Status = "ERROR"; message.Message = msg; return(Json(message, JsonRequestBehavior.AllowGet)); } order = orderMgt.GenerateOrder(order); int total = 0; List <BResourceTaocan> taocans = resourceMgr.FindResourceTaocans(order.ResourceTaocanId, 0, 0, out total); if (taocans == null || taocans.Count == 0) { message.Message = "当前套餐不可用"; message.Status = "ERROR"; return(Json(message, JsonRequestBehavior.AllowGet)); } logger.Info(string.Format("Order is generated, Id - {0}, mobile - {1}", order.Id, order.MobileNumber)); BResourceTaocan taocan = taocans[0]; message.Status = "OK"; message.Message = "预充值订单已经生成"; message.Item = null; // string ip = Request.ServerVariables["REMOTE_ADDR"]; if (ip != null && ip.IndexOf("::") > -1) { ip = "127.0.0.1"; } string prepayId = WeChatPaymentWrapper.GetPrepayId(PersistentValueManager.config, Session["wechat_openid"] != null ? Session["wechat_openid"].ToString() : "", order.PaymentId.ToString(), "TEST WECHATPAY", ip, (int)taocan.Taocan.Sale_price * 100, TradeType.JSAPI); logger.Info(string.Format("Prepay Id - {0}", prepayId)); WeChatOrder weOrder = new WeChatOrder(); weOrder.Order = new ChargeOrder { Id = order.Id, Payed = order.Payed, PaymentId = order.PaymentId, MobileNumber = order.MobileNumber, MobileSP = order.MobileSP, Province = order.Province }; weOrder.PrepayId = prepayId; weOrder.PaySign = ""; message.Item = weOrder; AccessToken token = PersistentValueManager.GetWeChatAccessToken(); JSAPITicket ticket = PersistentValueManager.GetWeChatJsApiTicket(); SortedDictionary <string, string> parameters = new SortedDictionary <string, string>(); parameters.Add("appId", PersistentValueManager.config.APPID); parameters.Add("timeStamp", model.timestamp); parameters.Add("nonceStr", model.nancestr); parameters.Add("package", "prepay_id=" + prepayId); parameters.Add("signType", "MD5"); logger.Info(string.Format("timeStamp:{0}", model.timestamp)); logger.Info(string.Format("nonceStr:{0}", model.nancestr)); logger.Info(string.Format("package:{0}", "prepay_id=" + prepayId)); string querystr = null; foreach (KeyValuePair <string, string> para in parameters) { if (querystr == null) { querystr = para.Key + "=" + para.Value; } else { querystr += "&" + para.Key + "=" + para.Value; } } querystr += "&key=" + PersistentValueManager.config.ShopSecret; logger.Info(querystr); string sign = UrlSignUtil.GetMD5(querystr); model.paySign = sign.ToUpper(); model.prepay_id = prepayId; logger.Info(string.Format("paySign:{0}", sign.ToUpper())); message.Item = model; } catch (KMBitException kex) { logger.Error(kex); message.Message = kex.Message; message.Status = "ERROR"; } catch (Exception ex) { message.Message = "未知错误,请联系我们"; message.Status = "ERROR"; logger.Fatal(ex); } finally { } } logger.Info("Done."); return(Json(message, JsonRequestBehavior.AllowGet)); }