public ActionResult TestPay() { #region 统一下单 LogManager.GetCurrentClassLogger().Debug("开始下单"); var model = new UnifiedorderRequest { OpenId = WeiChatApplicationContext.Current.WeiChatUser.OpenId }; LogManager.GetCurrentClassLogger().Debug(JsonConvert.SerializeObject(model.OpenId)); model.SpbillCreateIp = "8.8.8.8"; model.OutTradeNo = PayUtil.GenerateOutTradeNo(); model.TotalFee = "1"; model.NonceStr = PayUtil.GetNoncestr(); model.TradeType = "JSAPI"; model.Body = "购买商品"; model.DeviceInfo = "WEB"; var result = WeChatApisContext.Current.TenPayV3Api.Unifiedorder(model); var _dict = new Dictionary <string, string> { { "appId", result.AppId }, { "timeStamp", PayUtil.GetTimestamp() }, { "nonceStr", result.NonceStr }, { "package", "prepay_id=" + result.PrepayId }, { "signType", "MD5" } }; _dict.Add("paySign", PayUtil.CreateMd5Sign(_dict, WeChatConfigManager.Current.GetPayConfig().TenPayKey)); #endregion ViewBag.PayPam = JsonConvert.SerializeObject(_dict); return(View()); }
private void Transfers(string OpenId, int Amount) { var model = new EnterpriseRequest { Amount = Convert.ToInt32(Amount * 100).ToString(), CheckName = "NO_CHECK", Desc = "退货退款", DeviceInfo = "", NonceStr = PayUtil.GetNoncestr(), OpenId = OpenId, PartnerTradeNo = PayUtil.GenerateOutTradeNo() }; var relust = WeChatApisContext.Current.EnterprisePayApi.EnterprisePayment(model); }
public IHttpActionResult SendNormalRed() { var model = new NormalRedPackRequest(); model.ReOpenId = "ojyLxw31E_RvvrAw_m8HM-f6NpNA"; model.ActName = "测试红包"; model.MchBillno = PayUtil.GenerateOutTradeNo(); model.NonceStr = PayUtil.GetNoncestr(); model.SendName = "新来科技"; model.TotalAmount = "100"; model.TotalNum = "1"; model.Wishing = "测试测试测试测试测试测试测试测试测试测试"; LogManager.GetCurrentClassLogger().Debug(JsonConvert.SerializeObject(model)); var relust = WeChatApisContext.Current.RedPackApi.SendNormalRedPack(model); LogManager.GetCurrentClassLogger().Debug(JsonConvert.SerializeObject(relust)); return(Ok(relust)); }
public IHttpActionResult Enternpire() { var model = new EnterpriseRequest(); model.Amount = "100"; model.CheckName = "NO_CHECK"; model.Desc = "测试付款"; model.DeviceInfo = ""; model.NonceStr = PayUtil.GetNoncestr(); model.OpenId = "ojyLxw31E_RvvrAw_m8HM-f6NpNA"; model.SpbillCreateIp = "127.0.0.1"; model.PartnerTradeNo = PayUtil.GenerateOutTradeNo(); LogManager.GetCurrentClassLogger().Debug(JsonConvert.SerializeObject(model)); var relust = WeChatApisContext.Current.EnterprisePayApi.EnterprisePayment(model); LogManager.GetCurrentClassLogger().Debug(JsonConvert.SerializeObject(relust)); return(Ok(relust)); }
public IHttpActionResult PayMoney([FromBody] Log_Recharge model) { log.Log(LoggerLevels.Debug, "进入API[PayMoney]"); if (model.Amount <= 0) { return(BadRequest("充值金额必须大于0!")); } #region 统一下单 var paymodel = new UnifiedorderRequest { OpenId = WeiChatApplicationContext.Current.WeiChatUser.OpenId, SpbillCreateIp = "8.8.8.8", OutTradeNo = PayUtil.GenerateOutTradeNo(), TotalFee = Convert.ToInt32(model.Amount * 100).ToString(), NonceStr = PayUtil.GetNoncestr(), TradeType = "JSAPI", Body = "购买商品", DeviceInfo = "WEB" }; var result = WeChatApisContext.Current.TenPayV3Api.Unifiedorder(paymodel); var _dict = new Dictionary <string, string> { { "appId", result.AppId }, { "timeStamp", PayUtil.GetTimestamp() }, { "nonceStr", result.NonceStr }, { "package", string.Format("prepay_id={0}", result.PrepayId) }, { "signType", "MD5" } }; _dict.Add("paySign", PayUtil.CreateMd5Sign(_dict, WeChatConfigManager.Current.GetPayConfig().TenPayKey)); #endregion return(Ok(_dict)); }
public IHttpActionResult AddRefundOrder([FromBody] string[] inparamters) { var ids = string.Empty; if ((null == inparamters) || (inparamters.Length < 1)) { return(Ok(new { StatusCode = 0, message = "订单信息不存在" })); } try { var id = inparamters[0].ToGuid(); var openId = WeiChatApplicationContext.Current.WeiChatUser.OpenId; var order = db.Order_Infos.SingleOrDefault(o => (o.Id == id) && (o.OpenId == openId)); if (null == order) { return(Ok(new { StatusCode = 0, message = "订单信息不存在" })); } var price = inparamters[1].ToDecimal(0m); var type = inparamters[2].ToInt(1); var reason = inparamters[3].FilterHtml().FilterSqlKey(); var remark = inparamters[4].FilterHtml().FilterSqlKey(); var details = (JArray)JsonConvert.DeserializeObject(inparamters[5]); #region 退换货订单 var refundOrder = new Order_Refund { Id = Guid.NewGuid(), OrderID = order.Id, OrderCode = order.Code, Code = PayUtil.GenerateOutTradeNo(), Type = (EnumOrderRefundType)type, Amount = price, Quantity = 0, Reason = reason, Logistics = string.Empty, ShippingCode = string.Empty, Consignee = string.Empty, Mobile = string.Empty, Address = string.Empty, State = (EnumOrderRefundType)type == EnumOrderRefundType.Return ? EnumOrderRefundState.Replace : EnumOrderRefundState.WaitSellerAgree, Remark = remark, OpenId = openId, CreateTime = DateTime.Now, TenantId = TenantId }; #endregion #region 订单产品 var by = false; var shipping = new List <decimal>(); foreach (var detail in details) { var detailID = detail.ToString().ToGuid(); var product = db.Order_Details.FirstOrDefault(o => o.Id == detailID); if (null != product) { var refundDetail = new Order_RefundDetail { Id = Guid.NewGuid(), OrderRefund = refundOrder.Id, OrderDetail = product.Id, OpenId = openId, CreateTime = DateTime.Now, TenantId = TenantId }; db.Order_RefundDetails.Add(refundDetail); //增加退换货数据 refundOrder.Quantity += product.Quantity; } } #endregion //订单变更状态 order.State = EnumOrderStatus.ReturnedGoods; db.Entry(order).State = EntityState.Modified; if (db.Order_Refunds.Any(o => o.Code == refundOrder.Code)) { refundOrder.Code = PayUtil.GenerateOutTradeNo(); } db.Order_Refunds.Add(refundOrder); db.SaveChanges(); return(Ok(new { StatusCode = 1, message = refundOrder.Id })); } catch (Exception ex) { log.Log(LoggerLevels.Debug, "Order/Add:" + ex.Message); return(Ok(new { StatusCode = 0, message = "生成失败" })); } }
public IHttpActionResult ApplyRefund([FromBody] string[] inparamters) { var ids = string.Empty; if ((null == inparamters) || (inparamters.Length < 1)) { return(Ok(new { StatusCode = 0, message = "订单信息不存在" })); } try { var OrderId = inparamters[0].ToGuid(); var openId = WeiChatApplicationContext.Current.WeiChatUser.OpenId; var order = db.Order_Infos.SingleOrDefault(o => o.Id == OrderId); if (null == order) { return(Ok(new { StatusCode = 0, message = "订单信息不存在" })); } var reason = inparamters[1]; #region 退换货订单 var refundOrder = new Order_Refund { Id = Guid.NewGuid(), OrderID = order.Id, OrderCode = order.Code, Code = PayUtil.GenerateOutTradeNo(), Type = EnumOrderRefundType.ReturnGoods, Amount = order.TotalPrice, Quantity = 0, Reason = "", Logistics = string.Empty, ShippingCode = string.Empty, Consignee = string.Empty, Mobile = string.Empty, Address = string.Empty, State = EnumOrderRefundState.WaitSellerAgree, Remark = "", OpenId = openId, CreateTime = DateTime.Now, TenantId = TenantId }; #endregion #region 订单产品 var details = db.Order_Details.Where(p => p.OrderID == order.Id).ToList(); foreach (var detail in details) { var detailID = detail.ToString().ToGuid(); var product = db.Order_Details.FirstOrDefault(o => o.Id == detailID); if (null != product) { var refundDetail = new Order_RefundDetail { Id = Guid.NewGuid(), OrderRefund = refundOrder.Id, OrderDetail = product.Id, OpenId = openId, CreateTime = DateTime.Now, TenantId = TenantId }; db.Order_RefundDetails.Add(refundDetail); //增加退换货数据 refundOrder.Quantity += product.Quantity; } } #endregion //订单变更状态 order.State = EnumOrderStatus.ReturnedGoods; if (db.Order_Refunds.Any(o => o.Code == refundOrder.Code)) { refundOrder.Code = PayUtil.GenerateOutTradeNo(); } db.Order_Refunds.Add(refundOrder); db.SaveChanges(); return(Ok(new { StatusCode = 1, message = refundOrder.Id })); } catch (Exception ex) { return(Ok(new { StatusCode = 0, message = "生成失败" })); } #endregion }
public IHttpActionResult Add([FromBody] dynamic Json) { var ids = string.Empty; if (null == Json) { return(Ok(new { success = false, message = "产品信息不存在" })); } try { Guid AddressId = Guid.Parse(Convert.ToString(Json.AddressId)); string leave = Convert.ToString(Json.Remark); Guid FreiId = Guid.Parse(Convert.ToString(Json.YunFei)); var carts = (JArray)JsonConvert.DeserializeObject(Convert.ToString(Json.Products)); var FreiPrice = db.Logistics_FreightTemplates.Find(FreiId).Price; HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context #region 订单信息 var order = new Order_Info { Id = Guid.NewGuid(), Code = PayUtil.GenerateOutTradeNo(), OpenId = WeiChatApplicationContext.Current.WeiChatUser.OpenId, TotalPrice = 0, Remark = "", //User = WeiChatApplicationContext.Current.WeiChatUser, ThirdPayType = EnumThirdPayType.WX, DealOn = DateTime.Now, PaymentOn = (DateTime)SqlDateTime.MinValue, ShippingOn = (DateTime)SqlDateTime.MinValue, ReceiptOn = (DateTime)SqlDateTime.MinValue, Shipping = FreiPrice, Leave = leave, RejectReason = string.Empty, State = EnumOrderStatus.Obligation, CreateTime = DateTime.Now, UpdateTime = DateTime.Now, TenantId = TenantId, ClientIpAddress = context != null?context.GetClientIpAddress() : null }; #endregion #region 订单产品 var by = false; var shipping = new List <decimal>(); foreach (var cart in carts) { var cartID = Guid.Parse(cart.ToString()); var cartTemp = db.Cart_Infos.FirstOrDefault(o => o.Id == cartID); var product = (from pro in db.Product_Infos join photo in db.Site_Photos on pro.Id equals photo.GalleryId where pro.Id == cartTemp.ProductID select new { pro.Name, photo.Url, pro.Id }).FirstOrDefault(); //db.Product_Infos.FirstOrDefault(o => o.Id == cartTemp.ProductID); log.Log(LoggerLevels.Debug, "product:" + JsonConvert.SerializeObject(product)); var package = db.Product_ProductAttributes.FirstOrDefault(o => o.AttributeId == cartTemp.PackageID); log.Log(LoggerLevels.Debug, "package:" + JsonConvert.SerializeObject(package)); log.Log(LoggerLevels.Debug, "cartTemp:" + JsonConvert.SerializeObject(cartTemp)); if (null != cartTemp) { var orderDetail = new Order_Detail { Id = Guid.NewGuid(), OrderID = order.Id, ProductName = product.Name, ProductImage = product.Url, ProductID = product.Id, PackageID = package.Id, Price = package.AttributePrice, Quantity = cartTemp.Quantity, OpenId = order.OpenId, CreateTime = DateTime.Now, TenantId = TenantId }; db.Order_Details.Add(orderDetail); //清除购物车 db.Cart_Infos.Remove(cartTemp); //计算费用 order.TotalPrice += orderDetail.Price * orderDetail.Quantity; } } #endregion #region 收货 var address = db.User_Addresses.FirstOrDefault(o => o.Id == AddressId); log.Log(LoggerLevels.Debug, "address:" + JsonConvert.SerializeObject(address)); var orderLogistics = new Order_Logistics { Id = Guid.NewGuid(), OrderID = order.Id, Consignee = address.Name, Province = address.Province, City = address.City, Area = address.District, Address = address.Street, Mobile = address.PhoneNumber, Logistics = string.Empty, ShippingCode = string.Empty, OpenId = order.OpenId, CreateTime = DateTime.Now, TenantId = TenantId }; db.Order_Logistics.Add(orderLogistics); #endregion if (db.Order_Infos.Any(o => o.Code == order.Code)) { order.Code = PayUtil.GenerateOutTradeNo(); } db.Order_Infos.Add(order); db.SaveChanges(); return(Ok(order.Id)); } catch (Exception ex) { log.Log(LoggerLevels.Error, "Order/Add:" + ex.Message); return(BadRequest("系统异常,请联系管理员!")); } }