public ActionResult ajaxorder(string orderno) { try { ReturnJson root = null; var ordersEntity = ordersbll.GetEntityByOrderSn(orderno); if (ordersEntity != null) { var sp_billno = ordersEntity.OrderSn; var nonceStr = TenPayV3Util.GetNoncestr(); //商品Id,用户自行定义 string productId = ordersEntity.TelphoneID.ToString(); decimal?Amount = ordersEntity.Price;//0.01M 测试 if (Amount < 0) { root = new ReturnJson { code = 200, msg = "付款金额小于0" }; } else { if (ordersEntity.PayType == "支付宝") { try { DefaultAopClient client = new DefaultAopClient(WeixinConfig.serviceUrl, WeixinConfig.aliAppId, WeixinConfig.privateKey, "json", "1.0", WeixinConfig.signType, WeixinConfig.payKey, WeixinConfig.charset, false); // 组装业务参数model AlipayTradeWapPayModel model = new AlipayTradeWapPayModel(); model.Body = "支付宝购买靓号"; // 商品描述 model.Subject = productId; // 订单名称 model.TotalAmount = Amount.ToString(); // 付款金额"0.01"ordersEntity.Price.ToString() model.OutTradeNo = sp_billno; // 外部订单号,商户网站订单系统中唯一的订单号 model.ProductCode = "QUICK_WAP_WAY"; model.QuitUrl = "http://www.1650539.com/webapp/agentshop/index"; // 支付中途退出返回商户网站地址 model.TimeoutExpress = "90m"; AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); //设置支付完成同步回调地址 request.SetReturnUrl(WeixinConfig.return_url); //设置支付完成异步通知接收地址 request.SetNotifyUrl(WeixinConfig.notify_url); // 将业务model载入到request request.SetBizModel(model); AlipayTradeWapPayResponse response = null; try { response = client.pageExecute(request, null, "post"); //Response.Write(response.Body); H5PayData h5PayData = new H5PayData(); h5PayData.form = response.Body; root = new ReturnJson { code = 200, msg = "\u652f\u4ed8\u5b9d\u63d0\u4ea4\u6210\u529f\uff01", data = h5PayData }; } catch (Exception exp) { throw exp; } } catch (Exception ex) { //return Json(new { Result = false, msg = "缺少参数" }); } } else { //0 手机(H5支付) 1 电脑(扫码Native支付),2微信浏览器(JSAPI) //pc端返回二维码,否则H5 if (ordersEntity.PayType == "微信扫码") { //创建请求统一订单接口参数 var xmlDataInfo = new TenPayV3UnifiedorderRequestData(WeixinConfig.AppID, tenPayV3Info.MchId, "扫码支付靓号", sp_billno, Convert.ToInt32(Amount * 100), //1, Request.UserHostAddress, tenPayV3Info.TenPayV3Notify, TenPayV3Type.NATIVE, null, tenPayV3Info.Key, nonceStr, productId: productId); //调用统一订单接口 var result = TenPayV3.Unifiedorder(xmlDataInfo); if (result.return_code == "SUCCESS") { H5PayData h5PayData = new H5PayData() { appid = WeixinConfig.AppID, code_url = result.code_url,//weixin://wxpay/bizpayurl?pr=lixpXgt-----------扫码支付 mch_id = WeixinConfig.MchId, nonce_str = result.nonce_str, prepay_id = result.prepay_id, result_code = result.result_code, return_code = result.return_code, return_msg = result.return_msg, sign = result.sign, trade_type = "NATIVE", trade_no = sp_billno, payid = ordersEntity.Id.ToString(), wx_query_href = "http://www.1650539.com/webapp/agentshop/queryWx/" + ordersEntity.Id, wx_query_over = "http://www.1650539.com/webapp/agentshop/paymentFinish/" + ordersEntity.Id }; root = new ReturnJson { code = 200, msg = "\u5fae\u4fe1\u626b\u7801\u63d0\u4ea4\u6210\u529f\uff01", data = h5PayData }; } else { root = new ReturnJson { code = 400, msg = result.return_msg }; } } else { var xmlDataInfoH5 = new TenPayV3UnifiedorderRequestData(WeixinConfig.AppID, tenPayV3Info.MchId, "H5购买靓号", sp_billno, // 1, Convert.ToInt32(Amount * 100), Request.UserHostAddress, tenPayV3Info.TenPayV3Notify, TenPayV3Type.MWEB /*此处无论传什么,方法内部都会强制变为MWEB*/, null, tenPayV3Info.Key, nonceStr); var resultH5 = TenPayV3.Html5Order(xmlDataInfoH5); //调用统一订单接口 LogHelper.AddLog(resultH5.ResultXml); //记录日志 if (resultH5.return_code == "SUCCESS") { H5PayData h5PayData = new H5PayData() { appid = WeixinConfig.AppID, mweb_url = resultH5.mweb_url,//H5访问链接 mch_id = WeixinConfig.MchId, nonce_str = resultH5.nonce_str, prepay_id = resultH5.prepay_id, result_code = resultH5.result_code, return_code = resultH5.return_code, return_msg = resultH5.return_msg, sign = resultH5.sign, trade_type = "H5", trade_no = sp_billno, payid = ordersEntity.Id.ToString(), wx_query_href = "http://www.1650539.com/webapp/agentshop/queryWx/" + ordersEntity.Id, wx_query_over = "http://www.1650539.com/webapp/agentshop/paymentFinish/" + ordersEntity.Id }; root = new ReturnJson { code = 200, msg = "\u5fae\u4fe1\u0048\u0035\u63d0\u4ea4\u6210\u529f\uff01", data = h5PayData }; } else { root = new ReturnJson { code = 400, msg = resultH5.return_msg }; } } } } } else { root = new ReturnJson { code = 400, msg = "订单号不存在!" }; } LogHelper.AddLog(JsonConvert.SerializeObject(root));//记录日志 return(Json(root)); } catch (Exception ex) { LogHelper.AddLog(ex.Message);//记录日志 throw; } }
public ActionResult paymentProcess(int?id) { //return Content("{\"code\":true,\"status\":true,\"msg\":\"提交成功!\",\"data\":{\"appid\":\"wx288f944166a4bdc6\",\"code_url\":\"weixin://wxpay/bizpayurl?pr=K9tQFgw\",\"mch_id\":\"1582948931\",\"nonce_str\":\"gelx5Eej34TWkYjL\",\"prepay_id\":\"wx18152655644502b82539bf421260374600\",\"result_code\":\"SUCCESS\",\"return_code\":\"SUCCESS\",\"return_msg\":null,\"sign\":\"4D19F96F050056C904DBD7371D974905\",\"trade_type\":\"NATIVE\",\"trade_no\":\"LX-20200418151928103008\",\"payid\":\"11\",\"wx_query_href\":\"http://localhost:4066/WeChatManage/user_order/queryWx/11\",\"wx_query_over\":\"http://localhost:4066/WeChatManage/user_order/paymentFinish/11\"}}"); try { OrdersEntity ordersEntity = ordersbll.GetEntity(id); var sp_billno = ordersEntity.OrderSn; var nonceStr = TenPayV3Util.GetNoncestr(); //商品Id,用户自行定义 string productId = ordersEntity.TelphoneID.ToString(); //创建请求统一订单接口参数 var xmlDataInfo = new TenPayV3UnifiedorderRequestData(WeixinConfig.AppID2, tenPayV3Info.MchId, "支付靓号", sp_billno, Convert.ToInt32(ordersEntity.Price * 100), Request.UserHostAddress, tenPayV3Info.TenPayV3Notify, TenPayV3Type.NATIVE, null, tenPayV3Info.Key, nonceStr, productId: productId); //调用统一订单接口 var result = TenPayV3.Unifiedorder(xmlDataInfo); LogHelper.AddLog(result.ResultXml);//记录日志 H5Response root = null; if (result.return_code == "SUCCESS") { H5PayData h5PayData = new H5PayData() { appid = WeixinConfig.AppID2, code_url = result.code_url,//weixin://wxpay/bizpayurl?pr=lixpXgt mch_id = WeixinConfig.MchId, nonce_str = result.nonce_str, prepay_id = result.prepay_id, result_code = result.result_code, return_code = result.return_code, return_msg = result.return_msg, sign = result.sign, trade_type = "NATIVE", trade_no = sp_billno, payid = id.ToString(), wx_query_href = Config.GetValue("Domain2") + "/WeChatManage/user_order/queryWx/" + id, wx_query_over = Config.GetValue("Domain2") + "/WeChatManage/user_order/paymentFinish/" + id }; root = new H5Response { code = true, status = true, msg = "\u63d0\u4ea4\u6210\u529f\uff01", data = h5PayData }; } else { root = new H5Response { code = false, status = false, msg = result.return_msg }; } LogHelper.AddLog(JsonConvert.SerializeObject(root));//记录日志 return(Content(JsonConvert.SerializeObject(root))); } catch (Exception ex) { LogHelper.AddLog(ex.Message);//记录日志 throw; } }
public ActionResult ajaxorder(OrdersEntity ordersEntity) { try { string city = ordersEntity.City; if (city.Contains("-")) { string[] area = ordersEntity.City.Split('-'); if (area.Length > 0) { ordersEntity.Province = area[0]; //省 ordersEntity.City = area[1]; //市 ordersEntity.Country = area[2]; //市 } } else { string[] area = ordersEntity.City.Split(' '); if (area.Length > 0) { ordersEntity.Province = area[0]; //省 ordersEntity.City = area[1]; //市 } } string payType = ordersEntity.PayType; if (payType == "alipay") { payType = "支付宝"; } else { if (ordersEntity.PC == 1) { payType = "微信扫码"; } else { payType = "微信H5"; } } ordersEntity.PayType = payType; ordersEntity = ordersbll.SaveForm(ordersEntity); var sp_billno = ordersEntity.OrderSn; var nonceStr = TenPayV3Util.GetNoncestr(); //商品Id,用户自行定义 string productId = ordersEntity.TelphoneID.ToString(); H5Response root = null; if (payType == "支付宝") { try { DefaultAopClient client = new DefaultAopClient(WeixinConfig.serviceUrl, WeixinConfig.aliAppId, WeixinConfig.privateKey, "json", "1.0", WeixinConfig.signType, WeixinConfig.payKey, WeixinConfig.charset, false); // 组装业务参数model AlipayTradeWapPayModel model = new AlipayTradeWapPayModel(); model.Body = "支付宝购买靓号"; // 商品描述 model.Subject = productId; // 订单名称 model.TotalAmount = ordersEntity.Price.ToString(); // 付款金额"0.01" model.OutTradeNo = sp_billno; // 外部订单号,商户网站订单系统中唯一的订单号 model.ProductCode = "QUICK_WAP_WAY"; model.QuitUrl = "https://ghdh.digitdance.cn:8069/webapp/jntt/Index"; // 支付中途退出返回商户网站地址 model.TimeoutExpress = "90m"; AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); //设置支付完成同步回调地址 request.SetReturnUrl(WeixinConfig.return_url); //设置支付完成异步通知接收地址 request.SetNotifyUrl(WeixinConfig.notify_url); // 将业务model载入到request request.SetBizModel(model); AlipayTradeWapPayResponse response = null; try { response = client.pageExecute(request, null, "post"); //Response.Write(response.Body); H5PayData h5PayData = new H5PayData(); h5PayData.form = response.Body; root = new H5Response { code = true, status = true, msg = "\u652f\u4ed8\u5b9d\u63d0\u4ea4\u6210\u529f\uff01", data = h5PayData }; } catch (Exception exp) { throw exp; } } catch (Exception ex) { //return Json(new { Result = false, msg = "缺少参数" }); } } else { //pc端返回二维码,否则H5 if (payType == "微信扫码") { //创建请求统一订单接口参数 var xmlDataInfo = new TenPayV3UnifiedorderRequestData(WeixinConfig.AppID2, tenPayV3Info.MchId, "扫码支付靓号", sp_billno, Convert.ToInt32(ordersEntity.Price * 100), //1, Request.UserHostAddress, tenPayV3Info.TenPayV3Notify, TenPayV3Type.NATIVE, null, tenPayV3Info.Key, nonceStr, productId: productId); //调用统一订单接口 var result = TenPayV3.Unifiedorder(xmlDataInfo); if (result.return_code == "SUCCESS") { H5PayData h5PayData = new H5PayData() { appid = WeixinConfig.AppID2, code_url = result.code_url,//weixin://wxpay/bizpayurl?pr=lixpXgt-----------扫码支付 mch_id = WeixinConfig.MchId, nonce_str = result.nonce_str, prepay_id = result.prepay_id, result_code = result.result_code, return_code = result.return_code, return_msg = result.return_msg, sign = result.sign, trade_type = "NATIVE", trade_no = sp_billno, payid = ordersEntity.Id.ToString(), wx_query_href = "https://shop.jnlxsm.net/webapp/jntt/queryWx/" + ordersEntity.Id, wx_query_over = "https://shop.jnlxsm.net/webapp/jntt/paymentFinish/" + ordersEntity.Id }; root = new H5Response { code = true, status = true, msg = "\u5fae\u4fe1\u626b\u7801\u63d0\u4ea4\u6210\u529f\uff01", data = h5PayData }; } else { root = new H5Response { code = false, status = false, msg = result.return_msg }; } } else { var xmlDataInfoH5 = new TenPayV3UnifiedorderRequestData(WeixinConfig.AppID2, tenPayV3Info.MchId, "H5购买靓号", sp_billno, // 1, Convert.ToInt32(ordersEntity.Price * 100), Request.UserHostAddress, tenPayV3Info.TenPayV3Notify, TenPayV3Type.MWEB /*此处无论传什么,方法内部都会强制变为MWEB*/, null, tenPayV3Info.Key, nonceStr); var resultH5 = TenPayV3.Html5Order(xmlDataInfoH5); //调用统一订单接口 LogHelper.AddLog(resultH5.ResultXml); //记录日志 if (resultH5.return_code == "SUCCESS") { H5PayData h5PayData = new H5PayData() { appid = WeixinConfig.AppID2, mweb_url = resultH5.mweb_url,//H5访问链接 mch_id = WeixinConfig.MchId, nonce_str = resultH5.nonce_str, prepay_id = resultH5.prepay_id, result_code = resultH5.result_code, return_code = resultH5.return_code, return_msg = resultH5.return_msg, sign = resultH5.sign, trade_type = "H5", trade_no = sp_billno, payid = ordersEntity.Id.ToString(), wx_query_href = "https://shop.jnlxsm.net/webapp/jntt/queryWx/" + ordersEntity.Id, wx_query_over = "https://shop.jnlxsm.net/webapp/jntt/paymentFinish/" + ordersEntity.Id }; root = new H5Response { code = true, status = true, msg = "\u5fae\u4fe1\u0048\u0035\u63d0\u4ea4\u6210\u529f\uff01", data = h5PayData }; } else { root = new H5Response { code = false, status = false, msg = resultH5.return_msg }; } } } LogHelper.AddLog(JsonConvert.SerializeObject(root));//记录日志 return(Content(JsonConvert.SerializeObject(root))); } catch (Exception ex) { LogHelper.AddLog(ex.Message);//记录日志 throw; } }