} //H5调起JS API参数 // // GET: /WxPay/ public ActionResult Index() { //JSAPI支付预处理 try { string openid = Utility.ChangeText.GetOpenId(); string total_fee = Request["PayTotal"].ToString(); decimal Paytotal_fee = Convert.ToDecimal(total_fee) * 100; string OrdersId = Request["OrdersId"]; ViewData["OrdersId"] = OrdersId; //检测是否给当前页面传递了相关参数 //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数 JsApiPay jsApiPay = new JsApiPay(); jsApiPay.openid = openid; jsApiPay.total_fee = Convert.ToInt32(Paytotal_fee); WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(OrdersId); wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数 ViewData["WxPayInfo"] = wxJsApiParam; ERP.WxPay.Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam); } catch (Exception ex) { Utility.Log.WriteTextLog("微信支付", "", "", "", ex.ToString()); } return(View()); }
protected void Page_Load(object sender, EventArgs e) { Log.Info(this.GetType().ToString(), "page load"); if (!IsPostBack) { //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数 JsApiPay jsApiPay = new JsApiPay(this); //调用【网页授权获取用户信息】接口获取用户的openid和access_token jsApiPay.GetOpenidAndAccessToken(); //jsApiPay.openid = openid; //JSAPI支付预处理 try { int orderID = RequestHelper.GetQueryString <int>("OrderID"); OrderInfo order = OrderBLL.ReadOrder(orderID, Cookies.User.GetUserID(true)); jsApiPay.out_trade_no = order.OrderNumber; jsApiPay.body = "订单号:" + order.OrderNumber; jsApiPay.total_fee = (int)(order.ProductMoney * 100); //(order.ProductMoney - order.FavorableMoney + order.ShippingMoney + order.OtherMoney - order.Balance - order.CouponMoney).ToString(); WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数 Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam); //在页面上显示订单信息 Response.Write("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td colspan=\"2\" align=\"center\">订单详情</td></tr><tr><td width=\"40%\" align=\"right\">订单号:</td><td width=\"60%\" align=\"left\">" + order.OrderNumber + "</td></tr><tr><td align=\"right\">总金额:</td><td align=\"left\">" + order.ProductMoney + "元</td></tr><tr><td colspan=\"2\" align=\"center\"><div onclick=\"callpay()\" style=\"width:210px; height:50px; text-align:center; line-height:50px; border-radius: 15px;background-color:#00CD00; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px; cursor:pointer;\" >立即支付</div></td></tr></table>"); } catch (Exception ex) { Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>"); //submit.Visible = false; } } }
public void UnifiedOrder(string deviceid, string tariffid, string tradetype) { int tariff_id = int.Parse(tariffid); SQLServerOperating s = new SQLServerOperating(); DataTable dt = s.Selects(" select ID, TariffName, Price, OldPrice, BuyCount, Type from TariffPackages where ID=@tariff_id", new SqlParameter[] { new SqlParameter("tariff_id", tariff_id) }); if (dt.Rows.Count <= 0) { return; } s.ExecuteSql("update TariffPackages set BuyCount=BuyCount+cast( ceiling(rand()*100) as int) where ID=@ID", new SqlParameter[] { new SqlParameter("ID", tariff_id) }); s.Selects(" select ID, TariffName, Price, OldPrice, BuyCount, Type from TariffPackages where ID=@tariff_id", new SqlParameter[] { new SqlParameter("tariff_id", tariff_id) }); string total_fee = dt.Rows[0]["Price"].toStringEmpty(); string tariff_name = dt.Rows[0]["TariffName"].toStringEmpty(); string device_name = s.Select("select case when DeviceName='' then SerialNumber else DeviceName end from Devices where deviceid=@deviceid", new SqlParameter[] { new SqlParameter("deviceid", deviceid) }); if (string.IsNullOrEmpty(device_name)) { return; } tariff_name = "GPS移动流量-" + device_name + " 充值" + tariff_name; JsApiPay jsApiPay = new JsApiPay(); jsApiPay.user_id = int.Parse(myHeader.UserID); jsApiPay.openid = ""; jsApiPay.total_fee = jsApiPay.user_id == 6 || jsApiPay.user_id == 7 ? new Random().Next(1, 10) : int.Parse(total_fee); jsApiPay.device_id = int.Parse(deviceid); jsApiPay.tariff_id = tariff_id; jsApiPay.product_body = tariff_name; WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); jsApiPay.InsertMgooOrder(); // AddOrder(myHeader.UserID,deviceid,"",); }
public ActionResult <string> GetJsApiPay(string openid, string total_fee) { //检测是否给当前页面传递了相关参数 if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee)) { return("页面传参出错,请返回重试"); } //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数 JsApiPay jsApiPay = new JsApiPay(_httpContext) { Openid = openid, Total_Fee = int.Parse(total_fee) }; //JSAPI支付预处理 try { WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); //获取H5调起JS API参数 string wxJsApiParam = jsApiPay.GetJsApiParameters(); Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam); //在页面上显示订单信息 return(unifiedOrderResult.ToPrintStr()); } catch (Exception ex) { return("下单失败,请返回重试" + ex.Message); } }
/// <summary> /// 返回前端js 支付需要的支付参数 /// </summary> public void GetWxJsApiParam(string total_fee) { string wxJsApiParam = string.Empty; string openid = GetOpenId(); //检测是否给当前页面传递了相关参数 if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee)) { Log.Error(this.GetType().ToString(), "This page have not get params, cannot be inited, exit..."); Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面传参出错,请返回重试" + "</span>"); } //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数 JsApiPay jsApiPay = new JsApiPay(this); jsApiPay.openid = openid; jsApiPay.total_fee = int.Parse(total_fee); //JSAPI支付预处理 try { WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数 Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam); //在页面上显示订单信息 //Response.Write("<span style='color:#00CD00;font-size:20px'>订单详情:</span><br/>"); //Response.Write("<span style='color:#00CD00;font-size:20px'>" + unifiedOrderResult.ToPrintStr() + "</span>"); } catch (Exception ex) { Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>"); } Response.Write(wxJsApiParam); }
/// <summary> /// 调用JSAPI /// </summary> /// <param name="openid">用户对于公众号唯一标识</param> /// <param name="total_fee"></param> /// <returns></returns> public static JSApi_model JsPay(string openid, string total_fee, string oName) { JSApi_model model = new JSApi_model(); string wxJsApiParam = ""; double money = double.Parse(total_fee); int truemoney = (int)(money * 100); //检测是否给当前页面传递了相关参数 if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee)) { return(null); } //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数 JsApiPay jsApiPay = new JsApiPay(); //JSAPI支付预处理 try { //进行统一支付认证 WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(oName, openid, truemoney); //获取H5调起JS API参数 wxJsApiParam = jsApiPay.GetJsApiParameters(); model = wxJsApiParam.toJsonObject <JSApi_model>(); } catch (Exception ex) { //Response.Write("<span style='color:#FF0000;font-size:20px'>" + ex + "下单失败,请返回重试" + "</span>"); //submit.Visible = false; } return(model); }
public BaseApiResponse WxPay(WxPaymentRequest request) { request.CheckNotNull(nameof(request)); JsApiPay jsApiPay = new JsApiPay(); jsApiPay.openid = request.OpenId; jsApiPay.total_fee = request.Amount; //JSAPI支付预处理 try { WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); //统一下单 var wxJsApiParam = jsApiPay.GetJsApiParameters(); //获取H5调起JS API参数 这个要返回给客户端 Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam); //在页面上显示订单信息 //unifiedOrderResult.ToPrintStr(); return(new BaseApiResponse { Message = wxJsApiParam }); } catch (Exception ex) { return(new BaseApiResponse { Code = 400, Message = ex.Message }); } }
public IActionResult ShowWeiXInPay(string openid, string orderNo = "asdfsdgbadfgsdf", string employeeid = null, decimal fAmt = 0) { orderNo = commercialRepository.ProduceID(4); var userAgent = (HttpContext.Request.Headers as Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameRequestHeaders).HeaderUserAgent.ToString().ToLower(); //检测是否给当前页面传递了相关参数 if (string.IsNullOrEmpty(openid)) { ViewData["error"] = "页面传参出错,请返回重试"; Log.Error(this.GetType().ToString(), "This page have not get params, cannot be inited, exit..."); return(View()); } //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数 var jsApiPay = new JsApiPay(); jsApiPay.openid = openid; jsApiPay.total_fee = Convert.ToInt32(fAmt * 100); jsApiPay.notice_url = $"{_setting.DomainName}/registerresult"; jsApiPay.out_trade_no = orderNo; jsApiPay.body = "奖励金"; jsApiPay.attach = employeeid; //JSAPI支付预处理 try { WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); var wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数 Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam); ViewData["wxJsApiParam"] = wxJsApiParam; } catch (Exception ex) { ViewData["error"] = $"下单失败,请返回重试,{ex.Message}"; } return(View()); }
/// <summary> /// 充值 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <string> ChargePay(InsertOrderInput input) { var order = new StoreOrder() { OpenId = input.OpenId, PayType = PayType.PayCharge, OrderNum = Guid.NewGuid().ToString("N"), OrderState = null, PayState = null, Price = input.Price, ProductId = input.ProductId }; var type = await _chargeTypeRepository.FirstOrDefaultAsync(input.ProductId); if (type == null) { throw new UserFriendlyException("充值类型不存在"); } await _storeRepository.InsertAsync(order); JsApiPay jsApiPay = new JsApiPay { Openid = input.OpenId, TotalFee = type.Cost }; jsApiPay.GetUnifiedOrderResult(order.OrderNum, "用户充值", "用户充值"); var param = jsApiPay.GetJsApiParameters(); return(param); }
/// <summary> /// 生成js调用相关数据 /// </summary> public WxPayData JsApiPayPage() { //检测是否给当前页面传递了相关参数 if (total_fee <= 0) { Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面传参出错,请返回重试" + "</span>"); WxPayAPI.Log.Error(this.GetType().ToString(), "交易资金小于等于0"); return(null); } //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数 JsApiPay jsApiPay = new JsApiPay(this); //jsApiPay.openid = ""; jsApiPay.total_fee = total_fee; //JSAPI支付预处理 try { //付款方信息 string buyer = string.Empty; if (acc != null) { buyer = string.IsNullOrWhiteSpace(acc.Ac_MobiTel1) ? acc.Ac_AccName : acc.Ac_MobiTel1; } Song.Entities.Organization org = Business.Do <IOrganization>().OrganSingle(orgid); //统一下单 return(jsApiPay.GetUnifiedOrderResult("MWEB", org.Org_PlatformName, serial, appid, mchid, paykey, notify_url, buyer)); } catch (Exception ex) { WxPayAPI.Log.Error(this.GetType().ToString(), "支付下单失败 : " + ex.Message); WxPayAPI.Log.Error(this.GetType().ToString(), "支付下单失败 : " + ex.StackTrace); return(null); } }
/// <summary> /// 卡券支付 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <string> CardPay(InsertOrderInput input) { var p = await _productRepository.FirstOrDefaultAsync(c => c.Id == input.ProductId); if (p == null) { throw new UserFriendlyException("该商品不存在"); } var order = new StoreOrder() { OpenId = input.OpenId, PayType = PayType.ActivityPay, OrderNum = Guid.NewGuid().ToString("N"), OrderState = null, PayState = null, Price = p.Price, ProductId = p.ProductId }; await _storeRepository.InsertAsync(order); JsApiPay jsApiPay = new JsApiPay { Openid = input.OpenId, TotalFee = p.Price }; jsApiPay.GetUnifiedOrderResult(order.OrderNum, p.ProductName, p.Description); var param = jsApiPay.GetJsApiParameters(); return(param); }
/// <summary> /// wx支付提交请求 /// </summary> /// <param name="clientOpenId"></param> /// <param name="totalfell">注意这里单位是 分</param> /// <returns></returns> public string WXNAVITE_SubRequest(string orderNumber, string totalfell) { if (!orderNumber.OrderNumberVerify()) { return("-1");//提交失败 参数异常 } JsApiPay jsApiPay = new JsApiPay(); jsApiPay.total_fee = AlipayConfig.MoneyFormatEco(totalfell).ParseInt(); jsApiPay.orderNumber = orderNumber; try { string url; WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(true, out url); string wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数 Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam); return(url); } catch (Exception ex) { return("-2");//提交异常 } }
public string Pays(int fee) { this.HttpContext.Session.SetInt32("fee", fee); var openid = HttpContext.Session.GetString("openid"); if (openid != null) { //string url = "http://paysdk.weixin.qq.com/example/JsApiPayPage.aspx?openid=" + openid + "&total_fee=" + total_fee; //Response.Redirect(url); JsApiPay jsApiPay = new JsApiPay(this); jsApiPay.openid = openid; jsApiPay.total_fee = fee;// int.Parse(total_fee); //JSAPI支付预处理 try { WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); var wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数 Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam); //在页面上显示订单信息 var info = unifiedOrderResult.ToPrintStr(); return(wxJsApiParam); } catch (Exception ex) { return("下单失败"); } } return("-1"); }
public static Wxprepay wxPayOrderSomething(string openid, string total_fee, string couponType, Store store) { //var url = ConfigurationManager.AppSettings["wxpay"].ToString() + "?" + "grant_type=client_credential&appid=" + Appid + "&secret=" + Secret; Wxprepay wxprepay = new Wxprepay(); //检测是否给当前页面传递了相关参数 if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee)) { return(null); } else { ////若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数 JsApiPay jsApiPay = new JsApiPay(); //jsApiPay.openid = openid; //jsApiPay.total_fee = int.Parse(total_fee); //JSAPI支付预处理 var prepayid = WxPayApi.GenerateOutTradeNo(); WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(store.appid.Trim(), store.mchid.Trim(), total_fee, store.StoreName, couponType, openid, prepayid); var wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数 LogHelper.WriteLog("wxJsApiParam:" + wxJsApiParam.ToString()); //在页面上显示订单信息 wxprepay.wxJsApiParam = wxJsApiParam; wxprepay.prepayid = prepayid; return(wxprepay); } }
/// <summary> /// 在线支付 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <string> LinePay(InsertOrderInput input) { var p = await _productRepository.FirstOrDefaultAsync(c => c.Id == input.ProductId); if (p == null) { throw new UserFriendlyException("该商品不存在"); } var order = await _storeRepository.FirstOrDefaultAsync(c => c.OrderNum.Equals(input.Order)); if (order == null) { order = new StoreOrder() { FastCode = input.FastCode, OpenId = input.OpenId, PayType = PayType.LinePay, OrderType = input.OrderType, OrderState = null, OrderNum = input.Order, DeviceNum = input.Device, PayState = null, Price = p.Price, ProductId = p.ProductId }; } else { if (order.PayState.HasValue && order.PayState.Value) { throw new UserFriendlyException("该订单已支付,不可重复付款"); } order.OpenId = input.OpenId; order.Price = p.Price; order.FastCode = input.FastCode; order.OrderType = input.OrderType; order.PayType = PayType.LinePay; } JsApiPay jsApiPay = new JsApiPay { Openid = input.OpenId, TotalFee = p.Price }; var card = await _cardRepository.FirstOrDefaultAsync(c => c.Key == input.Key.Value); //使用优惠券 if (card != null) { order.UseCard = input.Key; var t = p.Price - card.Cost; jsApiPay.TotalFee = t <= 0 ? 0 : t; } await _storeRepository.InsertOrUpdateAsync(order); jsApiPay.GetUnifiedOrderResult(order.OrderNum, p.ProductName, p.Description); var param = jsApiPay.GetJsApiParameters(); return(param); }
protected void Page_Load(object sender, EventArgs e) { Log.Info(this.GetType().ToString(), "page load"); if (!IsPostBack) { Cms.Model.C_user userModel = adminUser.GetuserLoginState(); int otid = Convert.ToInt32(Request["orderid"].ToString()); Cms.BLL.C_order otBll = new Cms.BLL.C_order(); Cms.Model.C_order orderEntity = otBll.GetModel(otid); order_num.Text = orderEntity.order_num; litMoney.Text = Convert.ToDecimal(orderEntity.price_sum).ToString("0.00"); litDate.Text = orderEntity.updateTime.ToString(); string openid = userModel.openid.ToString(); string total_fee = ((int)(Convert.ToDecimal(orderEntity.price_sum) * 100)).ToString(); //检测是否给当前页面传递了相关参数 if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee)) { Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面传参出错,请返回重试" + "</span>"); Log.Error(this.GetType().ToString(), "This page have not get params, cannot be inited, exit..."); submit.Visible = false; return; } //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数 JsApiPay jsApiPay = new JsApiPay(this); jsApiPay.openid = openid; jsApiPay.orderid = orderEntity.order_num; DataTable dt = new Cms.BLL.C_ordersub().GetList("order_id=" + orderEntity.id).Tables[0]; if (dt != null && dt.Rows.Count > 0) { jsApiPay.productName = dt.Rows[0]["title"].ToString(); } else { jsApiPay.productName = "泓源鼎盛酒业商品"; } try { jsApiPay.total_fee = int.Parse(total_fee); //JSAPI支付预处理 WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数 orderNum = Request["orderid"].ToString(); Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam); //在页面上显示订单信息 //Response.Write("<span style='color:#00CD00;font-size:20px'>订单详情:</span><br/>"); //Response.Write("<span style='color:#00CD00;font-size:20px'>" + unifiedOrderResult.ToPrintStr() + "</span>"); } catch (Exception ex) { Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>" + ex.Message.ToString() + Convert.ToDecimal(orderEntity.price_sum).ToString()); submit.Visible = false; } } }
// /WeChat/WeChatPay/JsApiPayPage?uid=123&total_fee=0.01return_url=oksMlwPF5Y1KQvoi8AklF-lUwnYQ& public ActionResult JsApiPayPage(double total_fee, string return_url) { string openid = DataContext.UserId; if (!openid.HasValue() || !return_url.HasValue()) { return(Content("参数错误")); } var money = (int)(total_fee * 100); var wxJsApiParam = ""; //检测是否给当前页面传递了相关参数 if (string.IsNullOrEmpty(openid)) { return(Content("<span style='color:#FF0000;font-size:20px'>" + "页面传参出错,请返回重试" + "</span>"));; } //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数 var jsApiPay = new JsApiPay <Qx.Account.Configs.Setting.WxPayConfig.Sports>(HttpContext); jsApiPay.openid = openid; jsApiPay.total_fee = money; var poid = ""; //JSAPI支付预处理 try { //1.创建支付订单 var chargePayOrder = _accountPayService.CreatePayOrder(Qx.Account.Configs.Setting.PLATE_WECHAT_ACCOUNT, openid, total_fee, PayOrderTypeEnum.WeChatPay, PaymentTypeEnum.Rmb); poid = chargePayOrder.PayOrder.PO_ID; var trade_no = chargePayOrder.PayOrder.PO_ID; //2.同步支付订单 _accountPayService.SyncPayOrder(chargePayOrder); //3.通知微信服务器 var unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(trade_no, "充值" + (total_fee) + "元"); wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数 if (!wxJsApiParam.HasValue()) { throw new Exception("下单失败"); } //在页面上显示订单信息 return(View("JsApiPayPage", JsApiPayPage_M.Init(wxJsApiParam, "<span style='color:#00CD00;font-size:20px'>充值" + total_fee + "元</span><br/><span style='color:#00CD00;font-size:20px'>" + "</span>", //"<span style='color:#00CD00;font-size:20px'>订单详情:</span><br/><span style='color:#00CD00;font-size:20px'>" + unifiedOrderResult.ToPrintStr() + "</span>", total_fee + "", poid, DataContext.UserId, return_url ))); } catch (Exception ex) { return(View("JsApiPayPage", JsApiPayPage_M.Init(wxJsApiParam, "<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "<hr/>" + ex.Data + "<hr/>" + ex.InnerException + "<hr/>" + ex.Message + "<hr/>" + ex.StackTrace + "</span>", "", poid, DataContext.UserId, return_url))); } }
public string CreateWxJsApiParam() { JsApiPay jsApiPay = new JsApiPay(); WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(this); Prepay_id = (string)unifiedOrderResult.GetValue("prepay_id"); string wxJsApiParam = jsApiPay.GetJsApiParameters(); return(wxJsApiParam); }
public string CreateWxJsApiParam(PayOrder payOrder) { JsApiPay jsApiPay = new JsApiPay(); WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(payOrder); payOrder.Prepay_id = (string)unifiedOrderResult.GetValue("prepay_id"); _storeHouse.SaveChanges(); string wxJsApiParam = jsApiPay.GetJsApiParameters(); return(wxJsApiParam); }
/// <summary> /// 获取微信支付JS订单参数(微信公众号环境支付) /// </summary> /// <param name="orderCode">订单号</param> /// <param name="userId">付款用户</param> /// <param name="money">交易金额</param> /// <param name="clientIp">客户端ip</param> /// <param name="timeOut">支付超时时间</param> /// <returns></returns> private ApiResultModel <string> GetWeChatPayJavaScriptApiParam(string orderCode, string userId, decimal money, string clientIp, int?timeOut) { ApiResultModel <string> result = new ApiResultModel <string> { Code = ApiResultCode.Fail }; string total_fee = (money * 100).ToString("f0"); int.TryParse(total_fee, out int _total_fee); JsApiPay jsApiPay = new JsApiPay(); string openid = userId; WxPayData data = new WxPayData(); data.SetValue("body", Subject); data.SetValue("attach", "BUYGOODS"); data.SetValue("out_trade_no", orderCode); data.SetValue("total_fee", total_fee); data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss")); // data.SetValue("time_expire", DateTime.Now.AddMinutes(30).ToString("yyyyMMddHHmmss")); data.SetValue("time_expire", DateTime.Now.AddMinutes(timeOut ?? PayTimeOut).ToString("yyyyMMddHHmmss")); data.SetValue("goods_tag", ""); data.SetValue("trade_type", "JSAPI"); data.SetValue("openid", openid); data.SetValue("appid", AppId); data.SetValue("mch_id", MchId);//商户号 //prepay_id if (!string.IsNullOrEmpty(clientIp)) { data.SetValue("spbill_create_ip", clientIp);//终端ip } //LogHelper.LogError("GetWeChatPayJavaScriptApiParam", "data=" + data.ToXml()); //JSAPI支付预处理 try { WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(data, NotifyUrl, Key); //WritePostThirdApi(ThirdPlatformBusinessType.Payment, orderCode, ThirdPlatformType.WechatPay, "JsApiPay", data.ToXml(), DateTime.Now, unifiedOrderResult.ToXml(), DateTime.Now, true); result.Message = jsApiPay.GetJsApiParameters(Key);//获取H5调起JS API参数 result.Code = ApiResultCode.Success; return(result); } catch (WxPayFallException ex) { //LogHelper.LogError("GetWeChatPayJavaScriptApiParam", "checkout_ex=" + ex.Message); result.Message = ex.Message; return(result); } catch (Exception ex) { //LogHelper.LogError("GetWeChatPayJavaScriptApiParam", "checkout_ex=" + ex.ToString()); result.Message = "微信统一下单失败(" + ex.Message + ")"; return(result); } }
public ActionResult PlaceOrder(string orderNo) { if (_account == null) { return(Json(new ResultMessage() { Code = -1, Msg = "您还没有登录" })); } var order = _orderService.GetOrderNo(orderNo); if (order == null) { return(Json(new ResultMessage() { Code = -1, Msg = "订单不存在" })); } if (order.payState != PayStates.non_payment) { return(Json(new ResultMessage() { Code = -1, Msg = "订单状态不正确" })); } JsApiPay jsApiPay = new JsApiPay(); jsApiPay.openid = _account.openID; jsApiPay.total_fee = (int)(order.payAmount * 100); try { WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(order.orderNo); string wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数 WxPayAPI.Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam); return(Json(new ResultMessage() { Code = 0, Msg = wxJsApiParam })); //在页面上显示订单信息 //Response.Write("<span style='color:#00CD00;font-size:20px'>订单详情:</span><br/>"); //Response.Write("<span style='color:#00CD00;font-size:20px'>" + unifiedOrderResult.ToPrintStr() + "</span>"); } catch (Exception ex) { WxPayAPI.Log.Error(this.GetType().ToString(), ex.Message.ToString()); return(Json(new ResultMessage() { Code = -1, Msg = ex.Message.ToString() })); //Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>"); //submit.Visible = false; } }
} //H5调起JS API参数 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //string openid = Request.QueryString["openid"]; string orderno = HYRequest.GetQueryString("orderno"); OrderModel orderinfo = OrderFactory.Get(orderno); int total_fee = HYRequest.GetQueryInt("total_fee", 0); //单位为分 //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数 JsApiPay jsApiPay = new JsApiPay(this); if (orderinfo != null && orderinfo.productlist.Count > 0) { jsApiPay.body_desc = orderinfo.productlist[0].productinfo.productname + "等"; } else { jsApiPay.body_desc = shopconfig.ShopName + "购物"; } //单独测试,先微信登陆一下,整合后,有openid了,就无需重复获取授权了。 //jsApiPay.GetOpenidAndAccessToken(); jsApiPay.openid = this.LoginUser.openid; jsApiPay.total_fee = total_fee; jsApiPay.out_trade_no = orderno; //WxPayApi.GenerateOutTradeNo(321); //此处订单号,整合到系统后,从订单产生开始就确立,无需在支付页面生成 //JSAPI支付预处理 try { WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数 //在页面上显示订单信息 //Response.Write("<span style='color:#00CD00;font-size:20px'>订单详情:</span><br/>"); //Response.Write("<span style='color:#00CD00;font-size:20px'>" + unifiedOrderResult.ToPrintStr() + "</span>"); //Response.Write(string.Format("<span style='color:#00CD00;font-size:20px'>订单号:{0}</span><br/>", orderinfo.orderno)); //Response.Write(string.Format("<span style='color:#00CD00;font-size:20px'>支付额:{0}</span><br/>", orderinfo.totalyfprice)); System.Text.StringBuilder sbtips = new System.Text.StringBuilder(); sbtips.Append("<span style='color:#00CD00;font-size:20px'>订单详情:</span><br/>"); sbtips.Append(string.Format("<span style='color:#00CD00;font-size:16px'>订单编号:{0}</span><br/>", orderinfo.orderno)); sbtips.Append(string.Format("<span style='color:#00CD00;font-size:16px'>支付总额:{0}</span><br/>", orderinfo.totalyfprice)); this.ltlTips.Text = sbtips.ToString(); } catch { this.ltlTips.Text = "<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>"; } } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string openid = HttpContext.Current.Request.QueryString["openid"]; string total_fee = HttpContext.Current.Request.QueryString["total_fee"]; JsApiPay jsApiPay = new JsApiPay(context); jsApiPay.openid = openid; jsApiPay.total_fee = int.Parse(total_fee); WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); context.Response.Write(jsApiPay.GetJsApiParameters());//获取H5调起JS API参数 }
public async Task <WePayDto> Pay([FromBody] TestDto testDto) { var jsApiPay = new JsApiPay(); var outTradeNo = DateTime.Now.ToString("yyyyMMddHHmmss"); await jsApiPay.GetUnifiedOrderResult(testDto.body, outTradeNo, testDto.totalFee, testDto.openId); JsonData jd = JsonMapper.ToObject(jsApiPay.GetJsApiParameters()); WePayDto wePayDto = new WePayDto(); wePayDto.timeStamp = (string)jd["timeStamp"]; wePayDto.package = (string)jd["package"]; wePayDto.paySign = (string)jd["paySign"]; wePayDto.nonceStr = (string)jd["nonceStr"]; return(wePayDto); }
} //H5调起JS API参数 protected void Page_Load(object sender, EventArgs e) { Log.Info(this.GetType().ToString(), "page load"); if (!IsPostBack) { try { JsApiPay jsApiPay = new JsApiPay(this); //调用【网页授权获取用户信息】接口获取用户的openid和access_token jsApiPay.GetOpenidAndAccessToken(); //获取收货地址js函数入口参数 //wxEditAddrParam = jsApiPay.GetEditAddressParameters(); ViewState["openid"] = jsApiPay.openid; string openid = jsApiPay.openid; string total_fee = "0.01";// //检测是否给当前页面传递了相关参数 if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee)) { Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面传参出错,请返回重试" + "</span>"); Log.Error(this.GetType().ToString(), "This page have not get params, cannot be inited, exit..."); submit.Visible = false; return; } //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数 //JsApiPay jsApiPay = new JsApiPay(this); jsApiPay.openid = openid; jsApiPay.total_fee = int.Parse(total_fee); //JSAPI支付预处理 WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数 Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam); //在页面上显示订单信息 Response.Write("<span style='color:#00CD00;font-size:20px'>订单详情:</span><br/>"); Response.Write("<span style='color:#00CD00;font-size:20px'>" + unifiedOrderResult.ToPrintStr() + "</span>"); } catch (Exception ex) { Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>"); submit.Visible = false; } } }
// GET: WXPay /// <summary> /// 微信小程序统一下单 /// </summary> /// <returns></returns> public ActionResult WxUnifiedOrder(string openID, int total_fee, string out_trade_no, string body) { JsApiPay jsApiPay = new JsApiPay(); jsApiPay.openid = openID; jsApiPay.total_fee = total_fee; jsApiPay.out_trade_no = out_trade_no; jsApiPay.body = body; WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); var parameters = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数 ResponseMessage msg = new ResponseMessage(); msg.Status = true; msg.Data = parameters; return(Json(msg, JsonRequestBehavior.AllowGet)); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string content = Request.QueryString["c"]; if (string.IsNullOrEmpty(content)) { Response.Write("Ex-" + "页面传参出错,请返回重试11"); return; } try { content = System.Web.HttpUtility.UrlDecode(content); WXOrderInfo lvWXOrderInfo = JsonHelper.JsonDeserialize <WXOrderInfo>(content); if (lvWXOrderInfo == null || string.IsNullOrEmpty(lvWXOrderInfo.OpenID) || string.IsNullOrEmpty(lvWXOrderInfo.PayMoney)) { Response.Write("Ex-" + "页面传参出错,请返回重试22"); return; } //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数 JsApiPay jsApiPay = new JsApiPay(this); jsApiPay.openid = lvWXOrderInfo.OpenID; jsApiPay.total_fee = (int)(double.Parse(lvWXOrderInfo.PayMoney) * 100); content = "999"; //JSAPI支付预处理 WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(content, lvWXOrderInfo.Title); string lvWxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数 //在页面上显示订单信息 Response.Write(lvWxJsApiParam + "÷" + content); return; } catch (Exception ex) { Response.Write("Ex1-" + ex.Message); return; } } }
public async Task <Tuple <bool, string> > JsApiPay(string body, string outTradeNo, int totalFee, string openId) { try { var jsApiPay = new JsApiPay(); await jsApiPay.GetUnifiedOrderResult(body, outTradeNo, totalFee, openId); var wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数 return(wxJsApiParam == null ? new Tuple <bool, string>(false, "返回数据为空!") : new Tuple <bool, string>(true, wxJsApiParam)); } catch (Exception e) { return(new Tuple <bool, string>(false, e.Message)); } }
protected override ActionResult SetPostRequest(Enroll enroll) { try { Member member = SessionHelper.Mob.GetSession <Member>(); JsApiPay jsApiPay = new JsApiPay(); jsApiPay.openid = member.OpenId; jsApiPay.GetUnifiedOrderResult(enroll, _helper.GetCourse(enroll.CourseId)); WxPayData wxPayData = jsApiPay.GetJsApiParameters(); return(Success(wxPayData.GetValues()));//获取H5调起JS API参数 } catch (Exception ex) { LogHelper.Error(ex); return(Faild("支付失败,请重试。")); } }
} //H5调起JS API参数 protected void Page_Load(object sender, EventArgs e) { Log.Info(this.GetType().ToString(), "page load"); if (!IsPostBack) { try { string openid = Request.QueryString["openid"]; string total_fee = Request.QueryString["total_fee"]; string inner_order = Request.QueryString["order"]; //检测是否给当前页面传递了相关参数 if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee)) { Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面传参出错,请返回重试" + "</span>"); Log.Error(this.GetType().ToString(), "This page have not get params, cannot be inited, exit..."); submit.Visible = false; return; } //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数 JsApiPay jsApiPay = new JsApiPay(this); jsApiPay.openid = openid; decimal money = Convert.ToDecimal(total_fee) * 100; jsApiPay.total_fee = Convert.ToInt32(money); //JSAPI支付预处理 WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(inner_order); wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数 Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam); //在页面上显示订单信息 //Response.Write("<span style='color:#00CD00;font-size:20px'>订单详情:</span><br/>"); //Response.Write("<span style='color:#00CD00;font-size:20px'>支付金额:" + total_fee + "元</span><br/>"); //Response.Write("<span style='color:#00CD00;font-size:20px'>" + unifiedOrderResult.ToPrintStr() + "</span>"); lblInfo.Text = "支付金额:" + total_fee + "元"; } catch (Exception ex) { Log.Error(this.GetType().ToString(), "---" + ex.StackTrace.ToString() + "---" + ex.ToString()); Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>"); //Response.Write("<span style='color:#FF0000;font-size:20px'>" + mm.ToString() + "</span>"); submit.Visible = false; } } }