public static object ApiPay(IRequest request) { var siteId = request.GetPostInt("siteId"); var productId = request.GetPostString("productId"); var productName = request.GetPostString("productName"); var fee = request.GetPostDecimal("fee"); var channel = request.GetPostString("channel"); var message = request.GetPostString("message"); var isMobile = request.GetPostBool("isMobile"); var successUrl = request.GetPostString("successUrl"); var orderNo = Regex.Replace(Convert.ToBase64String(Guid.NewGuid().ToByteArray()), "[/+=]", ""); successUrl += "&orderNo=" + orderNo; var paymentApi = new PaymentApi(siteId); var recordInfo = new RecordInfo { SiteId = siteId, Message = message, ProductId = productId, ProductName = productName, Fee = fee, OrderNo = orderNo, Channel = channel, IsPaied = false, UserName = request.UserName, AddDate = DateTime.Now }; RecordDao.Insert(recordInfo); if (channel == "alipay") { return(isMobile ? paymentApi.ChargeByAlipayMobi(productName, fee, orderNo, successUrl) : paymentApi.ChargeByAlipayPc(productName, fee, orderNo, successUrl)); } if (channel == "weixin") { var apiUrl = Context.PluginApi.GetPluginApiUrl(Main.PluginId); var notifyUrl = $"{apiUrl}/{nameof(ApiWeixinNotify)}/{orderNo}?siteId={siteId}"; var url = HttpUtility.UrlEncode(paymentApi.ChargeByWeixin(productName, fee, orderNo, notifyUrl)); var qrCodeUrl = $"{apiUrl}/{nameof(ApiQrCode)}?qrcode={url}"; return(new { qrCodeUrl, orderNo }); } if (channel == "jdpay") { return(paymentApi.ChargeByJdpay(productName, fee, orderNo, successUrl)); } return(null); }
public static object ApiOrdersPay(IRequest context) { if (!context.IsUserLoggin) { return(null); } var siteId = context.GetPostInt("siteId"); var orderId = context.GetPostInt("orderId"); var channel = context.GetPostString("channel"); var isMobile = context.GetPostBool("isMobile"); var successUrl = context.GetPostString("successUrl"); if (string.IsNullOrEmpty(successUrl)) { successUrl = Context.SiteApi.GetSiteUrl(siteId); } var siteInfo = Context.SiteApi.GetSiteInfo(siteId); var orderInfo = OrderDao.GetOrderInfo(orderId); orderInfo.Channel = channel; var paymentApi = new PaymentApi(siteId); var amount = orderInfo.TotalFee; var orderNo = orderInfo.Guid; successUrl = $"{successUrl}?guid={orderNo}"; if (channel == "alipay") { return(isMobile ? paymentApi.ChargeByAlipayMobi(siteInfo.SiteName, amount, orderNo, successUrl) : paymentApi.ChargeByAlipayPc(siteInfo.SiteName, amount, orderNo, successUrl)); } if (channel == "weixin") { var apiUrl = Context.PluginApi.GetPluginApiUrl(Main.PluginId); var notifyUrl = $"{apiUrl}/{nameof(StlShoppingPay.ApiPayWeixinNotify)}/{orderNo}"; var url = HttpUtility.UrlEncode(paymentApi.ChargeByWeixin(siteInfo.SiteName, amount, orderNo, notifyUrl)); var qrCodeUrl = $"{apiUrl}/{nameof(StlShoppingPay.ApiPayQrCode)}?qrcode={url}"; return(new { qrCodeUrl, orderNo }); } if (channel == "jdpay") { return(paymentApi.ChargeByJdpay(siteInfo.SiteName, amount, orderNo, successUrl)); } return(null); }
public static object ApiPay(IRequest request) { var siteId = request.GetPostInt("siteId"); var channelId = request.GetPostInt("channelId"); var contentId = request.GetPostInt("contentId"); var amount = request.GetPostDecimal("amount"); var channel = request.GetPostString("channel"); var message = request.GetPostString("message"); var isMobile = request.GetPostBool("isMobile"); var successUrl = request.GetPostString("successUrl"); var orderNo = Regex.Replace(Convert.ToBase64String(Guid.NewGuid().ToByteArray()), "[/+=]", ""); successUrl += "&orderNo=" + orderNo; var paymentApi = new PaymentApi(siteId); var recordInfo = new RecordInfo { PublishmentSystemId = siteId, ChannelId = channelId, ContentId = contentId, Message = message, Amount = amount, OrderNo = orderNo, IsPaied = false, AddDate = DateTime.Now }; Main.RecordDao.Insert(recordInfo); if (channel == "alipay") { return(isMobile ? paymentApi.ChargeByAlipayMobi("文章打赏", amount, orderNo, successUrl) : paymentApi.ChargeByAlipayPc("文章打赏", amount, orderNo, successUrl)); } if (channel == "weixin") { var notifyUrl = Main.FilesApi.GetApiHttpUrl(nameof(ApiWeixinNotify), orderNo); var url = HttpUtility.UrlEncode(paymentApi.ChargeByWeixin("文章打赏", amount, orderNo, notifyUrl)); var qrCodeUrl = $"{Main.FilesApi.GetApiHttpUrl(nameof(ApiQrCode))}?qrcode={url}"; return(new { qrCodeUrl, orderNo }); } if (channel == "jdpay") { return(paymentApi.ChargeByJdpay("文章打赏", amount, orderNo, successUrl)); } return(null); }
public void Page_Load(object sender, EventArgs e) { _siteId = Convert.ToInt32(Request.QueryString["siteId"]); if (!Main.Instance.AdminApi.IsSiteAuthorized(_siteId)) { Response.Write("<h1>未授权访问</h1>"); Response.End(); return; } if (IsPostBack) { return; } var paymentApi = new PaymentApi(_siteId); if (!string.IsNullOrEmpty(Request.QueryString["alipayPc"])) { LtlScript.Text = paymentApi.ChargeByAlipayPc("测试", 0.01M, Utils.GetShortGuid(), "https://www.alipay.com"); } else if (!string.IsNullOrEmpty(Request.QueryString["alipayMobi"])) { LtlScript.Text = paymentApi.ChargeByAlipayMobi("测试", 0.01M, Utils.GetShortGuid(), "https://www.alipay.com"); } else if (!string.IsNullOrEmpty(Request.QueryString["weixin"])) { try { var url = HttpUtility.UrlEncode(paymentApi.ChargeByWeixin("测试", 0.01M, Utils.GetShortGuid(), "https://pay.weixin.qq.com")); LtlScript.Text = $@"<div style=""display: none""><img id=""weixin_test"" src=""{GetRedirectUrl(_siteId)}&qrcode={url}"" width=""200"" height=""200"" /></div><script>{Utils.SwalDom(Page, "微信支付测试", "weixin_test")}</script>"; } catch (Exception ex) { LtlScript.Text = $"<script>{Utils.SwalError(Page, "测试报错", ex.Message)}</script>"; } } else if (!string.IsNullOrEmpty(Request.QueryString["qrcode"])) { Response.BinaryWrite(QrCodeUtils.GetBuffer(Request.QueryString["qrcode"])); Response.End(); } else if (!string.IsNullOrEmpty(Request.QueryString["jdpay"])) { LtlScript.Text = paymentApi.ChargeByJdpay("测试", 0.01M, Utils.GetShortGuid(), "https://www.jdpay.com"); } var configInfo = Main.Instance.GetConfigInfo(_siteId); LtlAlipayPc.Text = configInfo.IsAlipayPc ? $@" <span class=""label label-primary"">已开通</span> <a class=""m-l-10"" href=""{GetRedirectUrl(_siteId)}&alipayPc=true"">测试</a>" : "未开通"; LtlAlipayMobi.Text = configInfo.IsAlipayMobi ? $@" <span class=""label label-primary"">已开通</span> <a class=""m-l-10"" href=""{GetRedirectUrl(_siteId)}&alipayMobi=true"">测试</a>" : "未开通"; LtlWeixin.Text = configInfo.IsWeixin ? $@" <span class=""label label-primary"">已开通</span> <a class=""m-l-10"" href=""{GetRedirectUrl(_siteId)}&weixin=true"">测试</a>" : "未开通"; LtlJdpay.Text = configInfo.IsJdpay ? $@" <span class=""label label-primary"">已开通</span> <a class=""m-l-10"" href=""{GetRedirectUrl(_siteId)}&jdpay=true"">测试</a>" : "未开通"; }
public static object ApiPay(IRequest context) { var siteId = context.GetPostInt("siteId"); var sessionId = context.GetPostString("sessionId"); var addressId = context.GetPostInt("addressId"); var channel = context.GetPostString("channel"); var totalFee = context.GetPostDecimal("totalFee"); var deliveryFee = context.GetPostDecimal("deliveryFee"); var totalCount = context.GetPostInt("totalCount"); var message = context.GetPostString("message"); var cartIdList = context.GetPostObject <List <string> >("cartIdList").Select(cartId => Utils.ParseInt(cartId)).ToList(); var isMobile = context.GetPostBool("isMobile"); var successUrl = context.GetPostString("successUrl"); if (string.IsNullOrEmpty(successUrl)) { successUrl = Context.SiteApi.GetSiteUrl(siteId); } var guid = Regex.Replace(Convert.ToBase64String(Guid.NewGuid().ToByteArray()), "[/+=]", ""); var paymentApi = new PaymentApi(siteId); var siteInfo = Context.SiteApi.GetSiteInfo(siteId); var addressInfo = AddressDao.GetAddressInfo(addressId); var orderInfo = new OrderInfo { SiteId = siteId, Guid = guid, AddDate = DateTime.Now, Address = addressInfo.Address, ZipCode = addressInfo.ZipCode, Location = addressInfo.Location, Message = message, Mobile = addressInfo.Mobile, Channel = channel, TotalFee = totalFee, ExpressCost = deliveryFee, RealName = addressInfo.RealName, UserName = context.UserName, SessionId = sessionId, IsPaied = false, State = string.Empty, Tel = addressInfo.Tel, TotalCount = totalCount }; orderInfo.Id = OrderDao.Insert(orderInfo); var cartInfoList = CartDao.GetCartInfoList(siteId, context.UserName, sessionId); var newCardIdList = new List <int>(); foreach (var newCardInfo in cartInfoList) { newCardIdList.Add(newCardInfo.Id); } //CartDao.UpdateOrderId(cartIdList, orderInfo.Id); CartDao.UpdateOrderId(newCardIdList, orderInfo.Id); var amount = totalFee + deliveryFee; var orderNo = guid; successUrl = $"{successUrl}?guid={guid}"; if (channel == "alipay") { return(isMobile ? paymentApi.ChargeByAlipayMobi(siteInfo.SiteName, amount, orderNo, successUrl) : paymentApi.ChargeByAlipayPc(siteInfo.SiteName, amount, orderNo, successUrl)); } if (channel == "weixin") { var apiUrl = Context.PluginApi.GetPluginApiUrl(Main.PluginId); var notifyUrl = $"{apiUrl}/{nameof(ApiPayWeixinNotify)}/{orderNo}"; var url = HttpUtility.UrlEncode(paymentApi.ChargeByWeixin(siteInfo.SiteName, amount, orderNo, notifyUrl)); var qrCodeUrl = $"{apiUrl}/{nameof(ApiPayQrCode)}?qrcode={url}"; return(new { qrCodeUrl, orderNo }); } if (channel == "jdpay") { return(paymentApi.ChargeByJdpay(siteInfo.SiteName, amount, orderNo, successUrl)); } return(new { guid, amount }); }