//对k进行解码 k格式:{"m":"ABC123456789","t":[{"tid":"1-2","n":3},{"tid":"1-3","n":2}]} //支付宝支付 public ResultObj <PayStateModel> GetDataA(string k, bool isPayByTunnel = true) { PayStateModel payStateModel = new PayStateModel(); ////////////////////////////////////////////请求参数//////////////////////////////////////////// //解析k值 KeyJsonModel keyJsonInfo = new PayHelper().AnalizeKey(k); if (string.IsNullOrEmpty(keyJsonInfo.m) || keyJsonInfo.t.Count == 0) { payStateModel.RequestState = "2"; payStateModel.ProductJson = ""; payStateModel.RequestData = ""; return(Content(payStateModel)); } RedisHelper redisHelper = new RedisHelper(0); if (!redisHelper.KeyExists(keyJsonInfo.m)) { return(Content(payStateModel, ResultCode.Success, "机器不在线", new Pagination { })); } IPay _ipay = new PayService(); //移动支付赋值 Config config = _ipay.GenerateConfigModelA(keyJsonInfo.m); //生成交易号 string out_trade_no = new PayHelper().GeneraterTradeNo(); //取商品信息 decimal totalFee = 0; string productNames = string.Empty; List <ProductModel> lstProduct = new List <ProductModel>(); //按货道付款 if (isPayByTunnel) { lstProduct = _ipay.GetProducInfo(keyJsonInfo.m, keyJsonInfo.t); //遍历商品 foreach (ProductModel productInfo in lstProduct) { var tunnelInfo = (from m in keyJsonInfo.t where m.tid == productInfo.TunnelId select m).ToList <KeyTunnelModel>(); if (tunnelInfo.Count > 0) { productInfo.Num = string.IsNullOrEmpty(tunnelInfo[0].n) ? "1" : tunnelInfo[0].n; totalFee = totalFee + Convert.ToInt32(productInfo.Num) * Convert.ToDecimal(productInfo.UnitA); productNames = productNames + productInfo.WaresName + ","; productInfo.TradeNo = out_trade_no; tunnelInfo[0].p = productInfo.UnitA; tunnelInfo[0].wid = productInfo.WaresId; } } } else { lstProduct = _ipay.GetProducInfoByWaresId(keyJsonInfo.m, keyJsonInfo.t); //遍历商品 foreach (ProductModel productInfo in lstProduct) { var tunnelInfo = (from m in keyJsonInfo.t where m.tid == productInfo.WaresId select m).ToList <KeyTunnelModel>(); if (tunnelInfo.Count > 0) { productInfo.Num = string.IsNullOrEmpty(tunnelInfo[0].n) ? "1" : tunnelInfo[0].n; totalFee = totalFee + Convert.ToInt32(productInfo.Num) * Convert.ToDecimal(productInfo.UnitA); productNames = productNames + productInfo.WaresName + ","; productInfo.TradeNo = out_trade_no; tunnelInfo[0].p = productInfo.UnitA; tunnelInfo[0].wid = productInfo.WaresId; tunnelInfo[0].tid = productInfo.TunnelId; } } } //订单名称,必填 string subject = productNames.Length > 25 ? productNames.Substring(0, 25) : productNames; //付款金额,必填 string total_fee = totalFee.ToString(); //收银台页面上,商品展示的超链接,必填 string show_url = ""; //商品描述,可空 string body = JsonHandler.GetJsonStrFromObject(keyJsonInfo, false); //写入交易中转 //RedisHelper helper = new RedisHelper(0); var log = LogManager.GetLogger("FycnApi", "tradeNo"); //helper.StringSet(out_trade_no.Trim(), body,new TimeSpan(0,10,30)); // FileHandler.WriteFile("data/", out_trade_no + ".wa", body); //////////////////////////////////////////////////////////////////////////////////////////////// //把请求参数打包成数组 /*********************老接口注释 2017年11月16日********************/ /* * SortedDictionary<string, string> sParaTemp = new SortedDictionary<string, string>(); * sParaTemp.Add("partner", Config.partner); * sParaTemp.Add("seller_id", Config.seller_id); * sParaTemp.Add("_input_charset", Config.input_charset.ToLower()); * sParaTemp.Add("service", Config.service); * sParaTemp.Add("payment_type", Config.payment_type); * sParaTemp.Add("notify_url", Config.notify_url); * sParaTemp.Add("return_url", Config.return_url); * sParaTemp.Add("out_trade_no", out_trade_no); * sParaTemp.Add("subject", subject); * sParaTemp.Add("total_fee", total_fee); * sParaTemp.Add("show_url", show_url); * sParaTemp.Add("app_pay","Y");//启用此参数可唤起钱包APP支付。 * sParaTemp.Add("body", subject); * //其他业务参数根据在线开发文档,添加参数.文档地址:https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.2Z6TSk&treeId=60&articleId=103693&docType=1 * //如sParaTemp.Add("参数名","参数值"); * * //建立请求 * string sHtmlText = Config.GateWay+Submit.BuildRequestParaToString(sParaTemp, Encoding.UTF8); * * payStateModel.ProductJson = JsonHandler.GetJsonStrFromObject(lstProduct, false); * payStateModel.RequestData = sHtmlText; * payStateModel.RequestState = "1"; * * return Content(payStateModel); */ /**********************支付宝新接口添加**************************/ DefaultAopClient client = new DefaultAopClient(config.new_gatewayUrl, config.new_app_id, config.private_key, "json", "1.0", config.new_sign_type, config.alipay_public_key, config.new_charset, false); AlipayTradeWapPayModel model = new AlipayTradeWapPayModel(); model.Body = subject; model.Subject = subject; model.TotalAmount = total_fee; model.OutTradeNo = out_trade_no; model.PassbackParams = body; log.Info("99999-" + body); model.TimeoutExpress = "1m"; model.ProductCode = ""; model.QuitUrl = ""; AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); // 设置支付完成同步回调地址 request.SetReturnUrl(config.return_url); // 设置支付完成异步通知接收地址 request.SetNotifyUrl(config.notify_url); // 将业务model载入到request request.SetBizModel(model); AlipayTradeWapPayResponse response = null; try { response = client.pageExecute(request, null, "post"); response.OutTradeNo = out_trade_no; payStateModel.ProductJson = JsonHandler.GetJsonStrFromObject(lstProduct, false); payStateModel.RequestData = response.Body; payStateModel.RequestState = "1"; return(Content(payStateModel)); } catch (Exception exp) { throw exp; } //return Content(new PayStateModel()); }
public string ChargeByAlipayMobi(string productName, decimal amount, string orderNo, string returnUrl) { var config = ConfigInfo; if (!config.IsAlipayMobi) { return(null); } if (config.AlipayMobiIsMApi) { // 合作身份者ID,签约账号,以2088开头由16位纯数字组成的字符串,查看地址:https://b.alipay.com/order/pidAndKey.htm Third.Alipay.MApi.Mobi.Config.partner = config.AlipayMobiPid; // 收款支付宝账号,以2088开头由16位纯数字组成的字符串,一般情况下收款账号就是签约账号 Third.Alipay.MApi.Mobi.Config.seller_id = Third.Alipay.MApi.Mobi.Config.partner; // MD5密钥,安全检验码,由数字和字母组成的32位字符串,查看地址:https://b.alipay.com/order/pidAndKey.htm Third.Alipay.MApi.Mobi.Config.key = config.AlipayMobiMd5; // 服务器异步通知页面路径,需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问 Third.Alipay.MApi.Mobi.Config.notify_url = string.Empty; // 页面跳转同步通知页面路径,需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问 Third.Alipay.MApi.Mobi.Config.return_url = returnUrl; //把请求参数打包成数组 var sParaTemp = new SortedDictionary <string, string> { { "partner", Third.Alipay.MApi.Mobi.Config.partner }, { "seller_id", Third.Alipay.MApi.Mobi.Config.seller_id }, { "_input_charset", Third.Alipay.MApi.Mobi.Config.input_charset.ToLower() }, { "service", Third.Alipay.MApi.Mobi.Config.service }, { "payment_type", Third.Alipay.MApi.Mobi.Config.payment_type }, { "notify_url", Third.Alipay.MApi.Mobi.Config.notify_url }, { "return_url", Third.Alipay.MApi.Mobi.Config.return_url }, { "out_trade_no", orderNo }, { "subject", productName }, { "total_fee", amount.ToString("N2") }, { "show_url", returnUrl }, { "body", string.Empty } }; //商户订单号,商户网站订单系统中唯一订单号,必填 //收银台页面上,商品展示的超链接,必填 //sParaTemp.Add("app_pay","Y");//启用此参数可唤起钱包APP支付。 //其他业务参数根据在线开发文档,添加参数.文档地址:https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.2Z6TSk&treeId=60&articleId=103693&docType=1 //如sParaTemp.Add("参数名","参数值"); //建立请求 return(Third.Alipay.MApi.Mobi.Submit.BuildRequest(sParaTemp, "get", "确认")); } var client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", config.AlipayMobiAppId, config.AlipayMobiPrivateKey, "JSON", "1.0", "RSA2", config.AlipayMobiPublicKey, "utf-8", false); // 组装业务参数model var model = new AlipayTradePagePayModel { Body = string.Empty, Subject = productName, TotalAmount = amount.ToString("N2"), OutTradeNo = orderNo, TimeoutExpress = "90m", ProductCode = "QUICK_WAP_PAY" }; // 付款金额 // 外部订单号,商户网站订单系统中唯一的订单号 AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); // 设置同步回调地址 request.SetReturnUrl(returnUrl); // 设置异步通知接收地址 request.SetNotifyUrl(string.Empty); // 将业务model载入到request request.SetBizModel(model); var response = client.pageExecute(request); return(response.Body); }
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]; //市 } } ordersEntity.TouUrl = Request.Url.ToString(); 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://www.jnlxsm.net:447/webapp/Shop/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/shop/queryWx/" + ordersEntity.Id, wx_query_over = "https://shop.jnlxsm.net/webapp/shop/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/shop/queryWx/" + ordersEntity.Id, wx_query_over = "https://shop.jnlxsm.net/webapp/shop/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; } }
/// <summary> /// Post process payment (used by payment gateways that require redirecting to a third-party URL) /// </summary> /// <param name="postProcessPaymentRequest">Payment info required for an order processing</param> public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest) { //RemotePost DefaultAopClient client = new DefaultAopClient(_aliPayPaymentSettings.GatewayUrl, _aliPayPaymentSettings.AppID, _aliPayPaymentSettings.PrivateKey, "json", "1.0", _aliPayPaymentSettings.SignType, _aliPayPaymentSettings.AlipayPublicKey, "UTF-8", false); // 外部订单号,商户网站订单系统中唯一的订单号 string out_trade_no = postProcessPaymentRequest.Order.Id.ToString(); // 订单名称 string subject = _storeContext.CurrentStore.Name; //订单原始价格按主货币, var CNY = _currencyService.GetCurrencyByCode("CNY"); var primaryExchangeCurrency = _currencyService.GetCurrencyById(_currencySettings.PrimaryExchangeRateCurrencyId); if (primaryExchangeCurrency == null) { throw new NopException("Primary exchange rate currency is not set"); } // 付款金额 ,换算成 人民币 decimal cur_total = postProcessPaymentRequest.Order.OrderTotal; cur_total = cur_total / primaryExchangeCurrency.Rate * CNY.Rate; string total_amout = cur_total.ToString("0.00", CultureInfo.InvariantCulture); // 商品描述 string body = "Order from " + _storeContext.CurrentStore.Name; AopResponse response = null; string s = _httpContext.Request.UserAgent; Regex b = new Regex(@"android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino", RegexOptions.IgnoreCase | RegexOptions.Multiline); Regex v = new Regex(@"1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-", RegexOptions.IgnoreCase | RegexOptions.Multiline); if (!(b.IsMatch(s) || v.IsMatch(s.Substring(0, 4)))) { AlipayTradePagePayRequest request = new AlipayTradePagePayRequest(); // 设置同步回调地址 request.SetReturnUrl(_webHelper.GetStoreLocation(false) + "Plugins/PaymentAliPay/Return"); // 设置异步通知接收地址 request.SetNotifyUrl(_webHelper.GetStoreLocation(false) + "Plugins/PaymentAliPay/Notify"); // 将业务model载入到request request.SetBizModel(new AlipayTradePagePayModel() { Body = body, Subject = subject, TotalAmount = total_amout, OutTradeNo = out_trade_no, GoodsType = "0", TimeoutExpress = "15m", ProductCode = "FAST_INSTANT_TRADE_PAY" }); try { response = client.pageExecute(request, null, "post"); } catch (Exception exp) { _logger.Warning($"{DateTime.Now.ToString()}Ali Page PayError:{exp.Message}"); } } else { AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); // 设置同步回调地址 request.SetReturnUrl(_webHelper.GetStoreLocation(false) + "Plugins/PaymentAliPay/Return"); // 设置异步通知接收地址 request.SetNotifyUrl(_webHelper.GetStoreLocation(false) + "Plugins/PaymentAliPay/Notify"); // 将业务model载入到request request.SetBizModel(new AlipayTradeWapPayModel() { Body = body, Subject = subject, TotalAmount = total_amout, OutTradeNo = out_trade_no, GoodsType = "0", TimeoutExpress = "15m", ProductCode = "FAST_INSTANT_TRADE_PAY" }); try { response = client.pageExecute(request, null, "post"); } catch (Exception exp) { _logger.Warning($"{DateTime.Now.ToString()}Ali Wap PayError:{exp.Message}"); } } _httpContext.Response.Clear(); _httpContext.Response.Write("<html><head><meta http-equiv=\"Content - Type\" content=\"text / html; charset = utf - 8\"/></head><body style=\"display:none\">"); _httpContext.Response.Write(response.Body); _httpContext.Response.Write("</body></html>"); _httpContext.Response.End(); }