Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        public List <BResourceTaocan> SearchResourceTaocans(string spName, string province)
        {
            List <BResourceTaocan> taocans = new List <BResourceTaocan>();

            using (chargebitEntities db = new chargebitEntities())
            {
                int spId = 0;
                if (!string.IsNullOrEmpty(spName))
                {
                    spId = (from s in db.Sp where s.Name == spName select s.Id).FirstOrDefault <int>();
                }
                int provinceId = 0;
                if (!string.IsNullOrEmpty(province))
                {
                    provinceId = (from p in db.Area where p.Name.Contains(province) select p.Id).FirstOrDefault <int>();
                }

                var tmp = from rta in db.Resource_taocan
                          join r in db.Resource on rta.Resource_id equals r.Id
                          join cu in db.Users on rta.CreatedBy equals cu.Id into lcu
                          from llcu in lcu.DefaultIfEmpty()
                          join uu in db.Users on rta.UpdatedBy equals uu.Id into luu
                          from lluu in luu.DefaultIfEmpty()
                          join city in db.Area on rta.Area_id equals city.Id into lcity
                          from llcity in lcity.DefaultIfEmpty()
                          join sp in db.Sp on rta.Sp_id equals sp.Id into lsp
                          from llsp in lsp.DefaultIfEmpty()
                          join tt in db.Taocan on rta.Taocan_id equals tt.Id
                          where rta.Enabled == true && rta.Sale_price > 0 && r.Enabled == true
                          select new BResourceTaocan
                {
                    Taocan    = rta,
                    Taocan2   = tt,
                    CreatedBy = llcu,
                    UpdatedBy = lluu,
                    Province  = llcity,
                    SP        = llsp,
                    Resource  = new BResource()
                    {
                        Resource = r
                    }
                };

                if (spId > 0)
                {
                    tmp = tmp.Where(t => t.Taocan.Sp_id == spId || t.Taocan.Sp_id == 0);
                }
                else
                {
                    tmp = tmp.Where(t => t.Taocan.Sp_id == 0);
                }

                if (provinceId > 0)
                {
                    tmp = tmp.Where(t => t.Taocan.Area_id == provinceId);
                }
                else
                {
                    tmp = tmp.Where(t => t.Taocan.Area_id == 0);
                }

                List <BResourceTaocan> tmpTaocans    = tmp.OrderBy(t => t.Taocan.Quantity).ToList <BResourceTaocan>();
                List <int>             ts            = (from t in tmpTaocans select t.Taocan.Quantity).Distinct <int>().ToList <int>();
                List <BResourceTaocan> globalTaocans = (from t in tmpTaocans where t.Taocan.Area_id == 0 select t).ToList <BResourceTaocan>();
                List <BResourceTaocan> localTaocans  = (from t in tmpTaocans where t.Taocan.Area_id > 0 select t).ToList <BResourceTaocan>();
                foreach (int t in ts)
                {
                    BResourceTaocan st  = (from tc in globalTaocans where tc.Taocan.Quantity == t orderby tc.Taocan.Resource_Discount ascending select tc).FirstOrDefault <BResourceTaocan>();
                    BResourceTaocan st2 = (from tc in localTaocans where tc.Taocan.Quantity == t orderby tc.Taocan.Resource_Discount ascending select tc).FirstOrDefault <BResourceTaocan>();
                    if (st != null)
                    {
                        taocans.Add(st);
                    }
                    if (st2 != null)
                    {
                        taocans.Add(st2);
                    }
                }
            }
            return(taocans);
        }
Esempio n. 3
0
        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));
        }