public IHttpActionResult Pay() { var request = Context.AuthenticatedRequest; var repository = new RecordRepository(); 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, IsPayed = false, UserName = request.UserName, AddDate = DateTime.Now }; repository.Insert(recordInfo); var redirectUrl = string.Empty; var wxPayQrCodeUrl = string.Empty; var wxPayOrderNo = string.Empty; if (channel == "AliPay") { redirectUrl = paymentApi.ChargeByAliPay(productName, fee, orderNo, successUrl); } if (channel == "WxPay") { var apiUrl = Context.Environment.ApiUrl; wxPayOrderNo = orderNo; var notifyUrl = UrlUtils.GetWxPayNotifyUrl(apiUrl, wxPayOrderNo, siteId); var url = HttpUtility.UrlEncode(paymentApi.ChargeByWxPay(productName, fee, orderNo, notifyUrl)); wxPayQrCodeUrl = UrlUtils.GetWxPayQrCodeUrl(apiUrl, url); } return(Ok(new { Value = redirectUrl, WxPayQrCodeUrl = wxPayQrCodeUrl, WxPayOrderNo = wxPayOrderNo })); }
public IHttpActionResult GetConfig() { var request = Context.AuthenticatedRequest; var siteId = request.GetQueryInt("siteId"); var type = request.GetQueryString("type"); var apiUrl = Context.Environment.ApiUrl; if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(siteId, Main.PluginId)) { return(Unauthorized()); } var paymentApi = new PaymentApi(siteId); var redirectUrl = string.Empty; var wxPayQrCodeUrl = string.Empty; var wxPayOrderNo = string.Empty; if (Utils.EqualsIgnoreCase(type, "AliPay")) { redirectUrl = paymentApi.ChargeByAliPay("测试", 0.01M, Utils.GetShortGuid(), "https://www.alipay.com"); } else if (Utils.EqualsIgnoreCase(type, "WxPay")) { wxPayOrderNo = Utils.GetShortGuid(); var notifyUrl = UrlUtils.GetWxPayNotifyUrl(apiUrl, wxPayOrderNo, siteId); var url = HttpUtility.UrlEncode(paymentApi.ChargeByWxPay("测试", 0.01M, wxPayOrderNo, notifyUrl)); wxPayQrCodeUrl = UrlUtils.GetWxPayQrCodeUrl(apiUrl, url); } return(Ok(new { Value = redirectUrl, WxPayQrCodeUrl = wxPayQrCodeUrl, WxPayOrderNo = wxPayOrderNo })); }