public async Task <Tuple <bool, string> > PagePay(string body, string outTradeNo, int totalFee, string productId) { try { var nativePay = new NativePay(); //生成扫码支付模式二url var url2 = await nativePay.GetPayUrl(body, outTradeNo, totalFee, productId); //将url生成二维码图片 var writerSvg = new BarcodeWriterSvg { Format = BarcodeFormat.QR_CODE, Options = new QrCodeEncodingOptions { ErrorCorrection = ErrorCorrectionLevel.H } }; var svgImageData = writerSvg.Write(url2); return(svgImageData == null ? new Tuple <bool, string>(false, "返回数据为空!") : new Tuple <bool, string>(true, svgImageData.ToString())); } catch (Exception e) { return(new Tuple <bool, string>(false, e.Message)); } }
//跳转至微信支付页面 public ActionResult wechat(int id) { OrderResponse response = _orderService.OrderDetail(id); var userContext = UserContext.WebUserContext; ViewBag.UserContext = userContext; if (response == null || response.MemberId != userContext.Id) { return(RedirectToAction("index", "player", new { area = "player" })); } else if (response.OrderStatus == OrderStatusEm.支付成功) { return(RedirectToAction("paysuccess", "playerpay", new { area = "player", orderId = id })); } else if (response.OrderStatus != OrderStatusEm.等待支付 && response.OrderStatus != OrderStatusEm.支付失败) { return(RedirectToAction("index", "player", new { area = "player" })); } else { _orderService.PayLog(id, response.Money, PayTypeEm.微信, userContext.Id);//插入支付流水信息 NativePay nativePay = new NativePay(); string url = nativePay.GetPayUrl(response); ViewBag.QRCode = "/commondata/makeqrcode?data=" + HttpUtility.UrlEncode(url); ViewBag.Order = response; return(View()); } }
//扫码支付 public ActionResult Payment(int orederId) { var order = _payMeentDbService.GetOrderById(orederId); if (string.IsNullOrEmpty(order.TradeNumber)) { order.TradeNumber = WxPayApi.GenerateOutTradeNo(); } if (order.OrderState == OrderState.Success) { //Success("已经支付"); return(RedirectToAction("PaidSuccess", new { tradeno = order.TradeNumber })); } var user = new User() { UserGuid = Guid.NewGuid(), Username = "******" }; NativePay nativePay = new NativePay(); string url2 = nativePay.GetPayUrl(order, user.LastIpAddress); ViewBag.QRCode = "/Checkout/MakeQRCode?data=" + HttpUtility.UrlEncode(url2); ViewBag.Order = order; return(View()); }
// GET: test public ActionResult Index(int s) { NativePay nativePay = new NativePay(); //string url = nativePay.GetPayUrl("1", "套餐一", "02180323000000001949", 1); string url = "sdsssssssssssssssssssssssssssssssssssssssss"; QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M; qrCodeEncoder.QRCodeVersion = 0; qrCodeEncoder.QRCodeScale = s; //将字符串生成二维码图片 Bitmap image = qrCodeEncoder.Encode(url, Encoding.Default); //string _root = Server.MapPath($"~/wxpaycode/{166191}/"); //if (!System.IO.Directory.Exists(_root)) //{ // System.IO.Directory.CreateDirectory(_root); //} //string _filename = Guid.NewGuid().ToString().Replace("-", "") + ".jpg"; //image.Save(_root + _filename, System.Drawing.Imaging.ImageFormat.Jpeg); MemoryStream ms = new MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); return(File(ms.ToArray(), "image/jpeg")); }
/// <summary> /// 获取微信支付二维码 /// </summary> private void get_WX_QRCode(System.Web.HttpContext context) { string result = "{\"success\":false,\"msg\":\"获取微信支付二维码,请稍后再试!\"}"; context.Response.ContentType = "application/json"; context.Response.AddHeader("Access-Control-Allow-Origin", "*"); //这行代码就告诉浏览器,只有来自www.XXX.com源下的脚本才可以进行访问。 string str_productId = context.Request["productId"]; string str_productDescribe = context.Request["productDescribe"]; string str_total_fee = context.Request["total_fee"]; string str_orderid = context.Request["orderid"]; Uri prevUri = HttpContext.Current.Request.UrlReferrer; string strDomainName = (prevUri != null) ? prevUri.Host : Globals.DomainName; if (!string.IsNullOrEmpty(str_productId) && !string.IsNullOrEmpty(str_productDescribe) && !string.IsNullOrEmpty(str_total_fee)) { NativePay nativePay = new NativePay(); //支付url,有效期为10小时 string strQRCodeUrl = nativePay.GetPayUrl(str_productId, str_productDescribe, int.Parse(str_total_fee) , string.Format(WxPayConfig.NOTIFY_URL_Custom, strDomainName), str_orderid); if (!string.IsNullOrEmpty(strQRCodeUrl)) { string t = "支付成功回调地址:" + string.Format(WxPayConfig.NOTIFY_URL_Custom, strDomainName); strQRCodeUrl = "http://" + Globals.DomainName + "/API/MakeQRCode.aspx?data=" + HttpUtility.UrlEncode(strQRCodeUrl); result = "{\"success\":true,\"msg\":\"" + strQRCodeUrl + "\",\"remark\":\"" + t + "\"}"; } } context.Response.Write(result); context.Response.End(); }
public static byte[] qrcode(string orderId, string body, string total_fee) { NativePay nativePay = new NativePay(); //生成扫码支付模式二url string url = nativePay.GetPayUrl(orderId, body, total_fee); //string str = HttpUtility.UrlEncode(url); string str = url; //初始化二维码生成工具 QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M; qrCodeEncoder.QRCodeVersion = 0; qrCodeEncoder.QRCodeScale = 4; //将字符串生成二维码图片 Bitmap image = qrCodeEncoder.Encode(str, Encoding.Default); //保存为PNG到内存流 MemoryStream ms = new MemoryStream(); image.Save(ms, ImageFormat.Png); //输出二维码图片 //Response.BinaryWrite(ms.GetBuffer()); //Response.End(); return(ms.GetBuffer()); //return ms; }
public ActionResult WeiXin() { if (Globals.IsWeiXinDevice()) { //是微信客户端走这边 string wechatcode = QueryString.SafeQ("wechatcode"); if (string.IsNullOrEmpty(wechatcode)) { string url = Request.Url.ToString(); string redirecturl = string.Format(WeiXinConfig.URL_WeiXin_Redirect, WeiXinConfig.GetAppId(), System.Web.HttpContext.Current.Server.UrlEncode(url), "0"); return(Redirect(redirecturl)); } else { MemWeChatMsgEntity msg = WeiXinJsSdk.Instance.GetWeChatShortInfo(wechatcode); string _paycode = QueryString.SafeQ("paycode"); VWPayOrderEntity _payen = PayOrderBLL.Instance.GetVWPayOrderByPayCode(_paycode); string redirecturl = string.Format(WeiXinConfig.URL_Pay_InWeiXin, msg.OpenId, _payen.NeedPayPrice); Response.Redirect(redirecturl); } } else { //网站类调出微信端支付通道 string _paycode = QueryString.SafeQ("paycode"); VWPayOrderEntity _payen = PayOrderBLL.Instance.GetVWPayOrderByPayCode(_paycode); DateTime dtnow = DateTime.Now; NativePay nativePay = new NativePay(); WxPayData data = nativePay.GetPayUrl(_payen, "MWEB");//得到调用微信接口的路径 string url = data.GetValue("mweb_url").ToString(); return(Redirect(url)); } return(View()); }
/// <summary> /// 实名验证(1分钱) /// </summary> /// <param name="openid"></param> /// <param name="realname"></param> /// <param name="cardid"></param> /// <returns></returns> public JsonResult CheckRealName(string openid, string nickname, string realname, string cardid, string city) { city = "杭州市"; var bus = new Bus(this.DataSource); var isSign = bus.isSign(openid, WxPayConfig.APPID(city), city); var user = bus.GetUserInfo(openid, WxPayConfig.APPID(city)); nickname = (string.IsNullOrEmpty(nickname)) ? "" : nickname; var exdata = bus.Sign(openid, nickname, Request.UserHostAddress, city); var pay = new NativePay(); var paydata = pay.GetPay(openid, realname, cardid, city); if (user != null) { user.DataDriver = this.DataSource; user.Realname = realname; user.Creid = cardid; user.RNameChecked = 0; user.out_trade_no = paydata.GetValue("out_trade_no").ToString(); user.RCheckTime = DateTime.Now; user.Store(); } string timeStamp = paydata.IsSet("timeStamp")? paydata.GetValue("timeStamp").ToString():""; string nonceStr = paydata.IsSet("nonceStr") ? paydata.GetValue("nonceStr").ToString() : ""; string package = paydata.IsSet("package") ? paydata.GetValue("package").ToString() : ""; string signType = paydata.IsSet("signType") ? paydata.GetValue("signType").ToString() : ""; string paySign = paydata.IsSet("paySign") ? paydata.GetValue("paySign").ToString() : ""; return(Json(new { exdata = exdata, isSign = isSign, timeStamp = timeStamp, nonceStr = nonceStr, package = package, signType = signType, paySign = paySign, realname = realname }, JsonRequestBehavior.AllowGet)); }
public JsonResult getRecordDebt(string openid, string city) { int state = 0, itotal_fee = 0; var bus = new Bus(this.DataSource); var items = bus.getRecord(openid, city, state); string trade_nos = ""; foreach (var r in items) { trade_nos += r.OutTradeNo + ","; itotal_fee += r.TotalFee; } trade_nos = trade_nos.Substring(0, trade_nos.Length - 1); //int itotal_fee//bus.GetTotalFee(trade_nos, city); var pay = new NativePay(); var paydata = pay.GetUPay(openid, itotal_fee, city, trade_nos); string timeStamp = paydata.IsSet("timeStamp") ? paydata.GetValue("timeStamp").ToString() : ""; string nonceStr = paydata.IsSet("nonceStr") ? paydata.GetValue("nonceStr").ToString() : ""; string package = paydata.IsSet("package") ? paydata.GetValue("package").ToString() : ""; string signType = paydata.IsSet("signType") ? paydata.GetValue("signType").ToString() : ""; string paySign = paydata.IsSet("paySign") ? paydata.GetValue("paySign").ToString() : ""; return(Json(new { items = items, totalFee = itotal_fee, paydata = new { timeStamp = timeStamp, nonceStr = nonceStr, package = package, signType = signType, paySign = paySign } }, JsonRequestBehavior.AllowGet)); }
//二维码支付 public ActionResult NativePay(string OrderId) { Log.Info(this.GetType().ToString(), "page load"); int totalPrice = 0; string OrderNum = OrderId; if (string.IsNullOrEmpty(OrderNum)) { if (Session["orderId"] != null) { OrderNum = Session["orderId"].ToString(); } else { return(Content("暂无订单!")); } } var models = OSer.GetOrderDetail(OrderNum);//正常订单 if (models.TotalPrice != null && models.TotalPrice > 0) { totalPrice = Convert.ToInt32(models.TotalPrice * 100); } if (models.SubtractPrice != null && models.SubtractPrice > 0) { totalPrice = Convert.ToInt32((models.TotalPrice - models.SubtractPrice) * 100); } NativePay nativePay = new NativePay(); //生成扫码支付模式一url //string url1 = nativePay.GetPrePayUrl("123456789"); //生成扫码支付模式二url string url2 = nativePay.GetPayUrl(OrderNum, totalPrice); //初始化二维码生成工具 QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M; qrCodeEncoder.QRCodeVersion = 0; qrCodeEncoder.QRCodeScale = 4; //将字符串生成二维码图片 Bitmap image = qrCodeEncoder.Encode(url2, Encoding.Default); //保存为PNG到内存流 MemoryStream ms = new MemoryStream(); image.Save(ms, ImageFormat.Png); return(File(ms.GetBuffer(), @"image/Png")); //输出二维码图片 //Response.BinaryWrite(ms.GetBuffer()); }
public ActionResult Pay(string productCode, string productName, string productDesc, float price, int num, int paytype /*1-支付宝,2-微信,3-银联*/) { string orderno = wxPayService.generate_orderno(1, 1); #region 保存订单记录,以便接收支付成功消息时更新订单的状态 /// insert 到order表 //orders o = new orders(); //o.orderno = generate_orderno(1, 1); //o.product_code = cpcode; //o.product_name = cpname; //o.product_desc = cpdesc; //o.price = price; //o.num = num; //switch (paytype) //{ // case 1: // o.paytype = "支付宝"; // break; // case 2: // o.paytype = "微信支付"; // break; // case 3: // o.paytype = "银联支付"; // break; //} //o.sumittime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //o.Insert(); #endregion float f = price * 100.0F * num; int total_fee = (int)f; ////LogService.LOG_LEVENL = 3; ////LogService.Debug(this.GetType().ToString(), "total_fee=" + f); switch (paytype) { case 1: //支付宝 //Response.Redirect(Url.Action("Index", "aliPay") + "?productCode=" + cpcode + "&productName=" + cpname + "&productDesc=" + cpdesc + "&orderno=" + o.orderno + "&total_fee=" + total_fee); break; case 2: // 微信支付 // Response.Redirect(Url.Action("Index", "Weixin") + "?productCode=" + cpcode + "&productName=" + cpname + "&productDesc=" + cpdesc + "&orderno=" + orderno + "&total_fee=" + total_fee); NativePay nativePay = new NativePay(); //生成扫码支付模式二url string url = StringService.ToHexString(nativePay.GetPayUrl(productCode, productName, productDesc, orderno, total_fee)); Response.Redirect(Url.Action("ScanQRCodeImage", "Home") + "?url=" + HttpUtility.UrlEncode(url) + "&orderno=" + orderno); break; case 3: // 银联 //Response.Redirect(Url.Action("Index", "Bank") + "?productCode=" + cpcode + "&productName=" + cpname + "&productDesc=" + cpdesc + "&orderno=" + o.orderno + "&total_fee=" + total_fee); break; } return(Content("")); }
public async Task <IActionResult> NativePay() { Log.Info(GetType().ToString(), "page load"); var nativePay = new NativePay(); var url = await nativePay.GetPayUrl("123456789"); var imageUrl = "MakeQrCode?data=" + UrlEncoder.Default.Encode(url); return(View("NativePay", imageUrl)); }
protected void Page_Load(object sender, EventArgs e) { NativePay nativePay = new NativePay(); //生成扫码支付模式二url string url2 = nativePay.GetPayUrl("123456789"); Image2.ImageUrl = "MakeQRCode.aspx?data=" + HttpUtility.UrlEncode(url2); }
public BusinessPayCode() { InitializeComponent(); TextBox.Text = Properties.Resources.Note_text.ToString(); //初始化支付页面说明 NativePay nativePay = new NativePay(); string url2 = nativePay.GetPayUrl("Test"); //生成扫码支付模式二url //将url生成二维码图片 WxPayCode.ImageLocation = "MakeQRCode.aspx?data=" + HttpUtility.UrlEncode(url2); }
public string PrintColor; //彩色黑白 protected void Page_Load(object sender, EventArgs e) { //接收从WebUi.aspx传过来的pages参数 int pages = int.Parse(Request.QueryString["pages"]); Label3.Text = pages.ToString(); //本地文件的路径 path = Request.QueryString["path"]; //获取传递过来的单/双 PrintType = Request.QueryString["PrintType"]; //获取黑白/彩色 PrintColor = Request.QueryString["PrintColor"]; NativePay nativePay = new NativePay(); //生成扫码支付模式二url //传递到微信后台的参数 int price = 1; //显示价格的参数 double showprice = 0; if (PrintColor.Equals("0")) { price = pages * 15; showprice = pages * 0.15; } else { price = pages * 100; showprice = pages * 1; } //显示页数 lb_page.Text = pages.ToString(); //显示价格 lb_Money.Text = showprice.ToString(); //price 为了测试改成1 WxPayData wx = nativePay.GetPayUrl(1, "123456789", "商品名称", "商品标记", "商品描述"); WxPayData result = new WxPayData(); result.SetValue("appid", wx.GetValue("appid")); result.SetValue("mch_id", wx.GetValue("mch_id")); result.SetValue("nonce_str", WxPayApi.GenerateNonceStr()); result.SetValue("out_trade_no", wx.GetValue("out_trade_no")); result.SetValue("sign", wx.MakeSign()); //为了测试,把下单后的信息输出到控制台 System.Diagnostics.Debug.Write(result.ToXml()); //把下单后WxPayData的对象result存到Session Session["result"] = result; //获得统一下单接口返回的二维码链接 string url2 = wx.GetValue("code_url").ToString(); //生成二维码 CreateQRImg(url2); }
// GET: Weixin public ActionResult Index(string productCode, string productName, string productDesc, string orderno, int total_fee) { LogService.LOG_LEVENL = 2; NativePay nativePay = new NativePay(); //生成扫码支付模式二url string url = StringService.StringToHexString(nativePay.GetPayUrl(productCode, productName, productDesc, orderno, total_fee)); Response.Redirect(Url.Action("ScanQRCodeImage", "weixin") + "?url=" + HttpUtility.UrlEncode(url) + "&orderno=" + orderno); return(View()); }
public ActionResult WeiXin() { string _paycode = QueryString.SafeQ("paycode"); VWPayOrderEntity _payen = PayOrderBLL.Instance.GetVWPayOrderByPayCode(_paycode); DateTime dtnow = DateTime.Now; NativePay nativePay = new NativePay(); WxPayData data = nativePay.GetPayUrl(_payen); string url = data.GetValue("code_url").ToString();//获得统一下单接口返回的二维码链接 ViewBag.Url = url; return(View()); }
public async Task <IActionResult> GetImg() { var pay = new NativePay(); var str = pay.GetPrePayUrl(Guid.NewGuid().ToString()); var stream = (MemoryStream)await Task.Run(() => { return(WeAppPayApi.MakeQRCode(str)); }); //var bytes = new byte[stream.Length]; //await stream.WriteAsync(bytes, 0, bytes.Length); //System.IO.File.WriteAllBytes(AppDomain.CurrentDomain.BaseDirectory + "testqrcode2.jpg", bytes); var resStream = new MemoryStream(stream.GetBuffer()); return(new FileStreamResult(resStream, "image/jpeg")); //return File(stream, "image/jpeg"); }
protected void Page_Load(object sender, EventArgs e) { Log.Info(this.GetType().ToString(), "page load"); NativePay nativePay = new NativePay(); //生成扫码支付模式一url string url1 = nativePay.GetPrePayUrl("123456789"); //生成扫码支付模式二url string url2 = nativePay.GetPayUrl("123456789", 100); //将url生成二维码图片 Image1.ImageUrl = "MakeQRCode.aspx?data=" + HttpUtility.UrlEncode(url1); Image2.ImageUrl = "MakeQRCode.aspx?data=" + HttpUtility.UrlEncode(url2); }
/// <summary> /// 结清欠款发起 /// </summary> /// <param name="openid"></param> /// <param name="city"></param> /// <param name="trade_nos"></param> /// <param name="total_fee"></param> /// <returns></returns> public JsonResult ClearTheDebt(string openid, string city) { var bus = new Bus(this.DataSource); string trade_nos = ""; int itotal_fee = bus.GetTotalFee(trade_nos, city); var pay = new NativePay(); var paydata = pay.GetUPay(openid, itotal_fee, city, trade_nos); string timeStamp = paydata.IsSet("timeStamp") ? paydata.GetValue("timeStamp").ToString() : ""; string nonceStr = paydata.IsSet("nonceStr") ? paydata.GetValue("nonceStr").ToString() : ""; string package = paydata.IsSet("package") ? paydata.GetValue("package").ToString() : ""; string signType = paydata.IsSet("signType") ? paydata.GetValue("signType").ToString() : ""; string paySign = paydata.IsSet("paySign") ? paydata.GetValue("paySign").ToString() : ""; return(Json(new { timeStamp = timeStamp, nonceStr = nonceStr, package = package, signType = signType, paySign = paySign }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 微信支付 /// </summary> /// <returns></returns> public ViewResultBase WeiXinPcPay() { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; var nativePay = new NativePay(); //订单号 var code = "XXXX"; //提示内容 var body = "支付"; //价格 var realPrice = (Convert.ToDecimal(0.1 * 100).ToString("#.##")); var url2 = nativePay.GetPayUrl(code, realPrice, body); //将url生成二维码图片 ViewData["imgUrl"] = "/Demo/Pay/MakeQrCode?data=" + HttpUtility.UrlEncode(url2); return(View()); }
//转到支付页面 public ActionResult Payment(string orderId) { if (string.IsNullOrEmpty(orderId)) { throw new ArgumentException("guide"); } NativePay nativePay = new NativePay(); string outTradeNo; string url2 = nativePay.GetPayUrl(orderId, out outTradeNo); ViewBag.QRCode = "/Home/MakeQrCode?data=" + HttpUtility.UrlEncode(url2); //ViewBag.Order = order; ViewBag.outTradeNo = outTradeNo; return(View()); }
public JsonResult WXPayUrl(PaperInfo paperInfo) { if (Session["user"] == null) { return(Json(new { success = false, data = "请您先登录,才能购买商品哦!" }, JsonRequestBehavior.AllowGet)); } else { string userId = string.Empty; List <UserRecord> list = (List <UserRecord>)Session["user"]; userId = list[0].UserId; NativePay nativePay = new NativePay(); PaperBLL paperBLL = new PaperBLL(); PaperDetailViewModel paperDetailViewModel = paperBLL.PaperDetailById(paperInfo.Id.ToString(), userId); string _outTradeNo = string.Empty; string url = nativePay.GetPayUrl(paperDetailViewModel.detail[0], out _outTradeNo); if (string.IsNullOrEmpty(url)) { return(Json(new { success = false, data = "微信生成订单时出现错误,请您重新支付!" }, JsonRequestBehavior.AllowGet)); } else { Business business = new Business(); List <UserRecord> rows = (List <UserRecord>)Session["user"]; business.UserId = rows[0].UserId; business.Name = rows[0].Name; business.CreateTime = DateTime.Now; business.OutTradeNo = _outTradeNo; business.PaperCode = paperDetailViewModel.detail[0].Code; business.PaperId = paperDetailViewModel.detail[0].Id; business.Title = paperDetailViewModel.detail[0].Title; business.Version = paperDetailViewModel.detail[0].Version; business.Price = paperDetailViewModel.detail[0].Price; business.PayState = 0; bool result = paperBLL.CreateBusiness(business); if (result == true) { return(Json(new { success = true, data = url, orderNumber = _outTradeNo }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, data = "微信生成订单时出现错误,请您重新支付!" }, JsonRequestBehavior.AllowGet)); } } } }
protected void Page_Load(object sender, EventArgs e) { LogHelper.Info(this.GetType().ToString(), "page load"); NativePay nativePay = new NativePay(); //生成扫码支付模式一url string url1 = nativePay.GetPrePayUrl("123456789"); //生成扫码支付模式二url //TODO 根据productId获取产品信息 //string url2 = nativePay.GetPayUrl("123456789", "牛肉干", "", "1000", "meet"); //将url生成二维码图片 Image1.ImageUrl = "MakeQRCode.aspx?data=" + HttpUtility.UrlEncode(url1); //Image2.ImageUrl = "MakeQRCode.aspx?data=" + HttpUtility.UrlEncode(url2); }
//查询订单 private bool QueryOrder(string transaction_id) { WxPayData req = new WxPayData(); req.SetValue("transaction_id", transaction_id); WxPayData res = NativePay.OrderQuery(site_payment_id, req); if (res.GetValue("return_code").ToString() == "SUCCESS" && res.GetValue("result_code").ToString() == "SUCCESS") { return(true); } else { return(false); } }
public ActionResult <string> GetMakeQRCode(string productId, int type) { NativePay nativePay = new NativePay(); string url = string.Empty; if (type == 1) { //生成扫码支付模式一url url = nativePay.GetPrePayUrl(productId); } else if (type == 2) { //生成扫码支付模式二url url = nativePay.GetPayUrl(productId); } //将url生成二维码图片 return(MakeQRCode.GetMakeQRCodeBase64String(HttpUtility.UrlEncode(url))); }
public (Stream, string) NativeCreateOrder(string openId, IOrderBase order, string notifyUrl) { NativePay nativePay = new NativePay(); var outTradeNo = WxPayApi.GenerateOutTradeNo(); var orderDict = new Dictionary <string, string>(); orderDict.Add("fee", order.Fee.ToString()); orderDict.Add("name", order.Name); orderDict.Add("notify_url", notifyUrl); orderDict.Add("tag", order.Tag ?? String.Empty); orderDict.Add("desc", order.Desc ?? String.Empty); orderDict.Add("out_trade_no", outTradeNo); orderDict.Add("productId", order.Id.ToString()); var payUrl = nativePay.GetPayUrl(orderDict); return(MakeQRCode(payUrl), outTradeNo); }
private void Pay_Click(object sender, RoutedEventArgs e) { NativePay nativePay = new NativePay(); //生成扫码支付模式二url //string tmp = priceTB.Text.Trim(); //double price = 0.01; //double.TryParse(tmp, out price); int totalFee = 1; string out_trade_no = WxPayApi.GenerateOutTradeNo(); WxPayData data = new WxPayData(); data.SetValue("body", "张裕DIY流程演示用"); //商品描述 data.SetValue("attach", "张裕DIY流程演示用"); //附加数据 data.SetValue("out_trade_no", out_trade_no); //随机字符串 data.SetValue("total_fee", totalFee); //总金额 data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss")); //交易起始时间 data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss")); //交易结束时间 data.SetValue("goods_tag", "jjj"); //商品标记 data.SetValue("trade_type", "NATIVE"); //交易类型 data.SetValue("product_id", "123456789"); //商品ID WxPayData result = WxPayApi.UnifiedOrder(data); //调用统一下单接口 string url = result.GetValue("code_url").ToString(); //获得统一下单接口返回的二维码链接 //string url2 = nativePay.GetPayUrl("123456789", totalFee); //string ss = HttpUtility.UrlEncode(url2); //CreateQrCode(url2); QrCodeDisplay dis = new WeChatDemo.QrCodeDisplay(out_trade_no); dis.Owner = this; dis.SetQR(url); dis.Show(); }
public ActionResult WeiXin() { string _paycode = QueryString.SafeQ("paycode"); VWPayOrderEntity _payen = PayOrderBLL.Instance.GetVWPayOrderByPayCode(_paycode); DateTime dtnow = DateTime.Now; NativePay nativePay = new NativePay(); WxPayData data = nativePay.GetPayUrl(_payen); if (data.GetValue("result_code").ToString().ToLower() == "success") { string url = data.GetValue("code_url").ToString();//获得统一下单接口返回的二维码链接 ViewBag.Url = url; } else { string error = data.GetValue("err_code_des").ToString(); ViewBag.ErrorMsg = error; } ViewBag.PayEntity = _payen; return(View()); }
/// <summary> /// 创建订单 /// </summary> /// <param name="setid"></param> /// <param name="paytype"></param> /// <returns></returns> public string createOrder(int setid, int paytype) { if (paytype > 2) { return(JsonConvert.SerializeObject(new repmsg { state = 0, msg = "支付方式不正确" })); } int userid = User.userid; //创建订单 using (shhouseEntities ent = new shhouseEntities()) { ObjectParameter ordernum = new ObjectParameter("ordernum", typeof(string)); ObjectParameter setname = new ObjectParameter("setname", typeof(string)); ObjectParameter state = new ObjectParameter("state", typeof(int)); ObjectParameter totals = new ObjectParameter("totals", typeof(int)); ObjectParameter msg = new ObjectParameter("msg", typeof(string)); ent.order_create_jjr2018(userid, DateTime.Now, DateTime.Now.AddHours(2), setid, 1, paytype, ordernum, setname, totals, state, msg); int _state = (int)state.Value; if (_state == 1) { if (paytype == 1) { IAopClient client = new DefaultAopClient( "https://openapi.alipay.com/gateway.do", "APPID", "APP_PRIVATE_KEY", "json", "1.0", "RSA2", "ALIPAY_PUBLIC_KEY", "UTF-8", false ); //支付宝支付 AlipayTradePagePayModel model = new AlipayTradePagePayModel { Body = (string)setname.Value, Subject = (string)setname.Value, TotalAmount = Math.Round((decimal)totals.Value / 100m, 2).ToString(), OutTradeNo = (string)ordernum.Value, ProductCode = "FAST_INSTANT_TRADE_PAY" }; AlipayTradePagePayRequest request = new AlipayTradePagePayRequest(); // 设置同步回调地址 request.SetReturnUrl(""); // 设置异步通知接收地址 request.SetNotifyUrl(""); // 将业务model载入到request request.SetBizModel(model); try { AlipayTradePagePayResponse response = client.SdkExecute(request); //支付宝支付地址 string url = "https://openapi.alipay.com/gateway.do?" + response.Body; //Response.Write(response.Body); return(JsonConvert.SerializeObject(new repmsg { state = 1, msg = "", data = new { tradeno = (string)ordernum.Value, total = (int)totals.Value, paytype = paytype, url = url } })); } catch (Exception exp) { return(JsonConvert.SerializeObject(new repmsg { state = 0, msg = exp.Message })); } } else if (paytype == 2) { try { //微信支付 NativePay nativePay = new NativePay(); string url = nativePay.GetPayUrl(setid.ToString(), (string)setname.Value, (string)ordernum.Value, (int)totals.Value); if (string.IsNullOrEmpty(url)) { return(JsonConvert.SerializeObject(new repmsg { state = 0, msg = "订单创建失败" })); } QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M; qrCodeEncoder.QRCodeVersion = 0; qrCodeEncoder.QRCodeScale = 8; //将字符串生成二维码图片 Bitmap image = qrCodeEncoder.Encode(url, Encoding.Default); string _root = Server.MapPath($"~/wxpaycode/{userid}/"); if (!System.IO.Directory.Exists(_root)) { System.IO.Directory.CreateDirectory(_root); } string _filename = Guid.NewGuid().ToString().Replace("-", "") + ".jpg"; image.Save(_root + _filename, System.Drawing.Imaging.ImageFormat.Jpeg); return(JsonConvert.SerializeObject(new repmsg { state = 1, msg = "", data = new { tradeno = (string)ordernum.Value, setname = (string)setname.Value, total = (int)totals.Value, paytype = paytype, qrimg = $"/wxpaycode/{userid}/{_filename}" } })); } catch (Exception e) { return(JsonConvert.SerializeObject(new repmsg { state = 0, msg = e.Message })); } } else { return(""); } } else { return(JsonConvert.SerializeObject(new repmsg { state = 0, msg = "提交失败,请稍后再试" })); } } }