/// <summary> /// 获取Web支付参数(一个from表单) /// </summary> public string GetWebPayParameter(decimal amount, string orderNo, string subject, string body, string passbackParams = null) { string parameter = string.Empty; //组装业务参数 var model = new AlipayTradeWapPayModel() { Body = body, Subject = subject, TotalAmount = amount.ToString(), OutTradeNo = orderNo, ProductCode = ProductCode, QuitUrl = QuitUrl, PassbackParams = HttpUtility.UrlEncode(passbackParams) }; var request = new AlipayTradeWapPayRequest(); request.SetBizModel(model); request.SetReturnUrl(ReturnUrl); // 支付中途退出返回商户网站地址 request.SetNotifyUrl(NotifyUrl); // 设置支付完成异步通知接收地址 AlipayTradeWapPayResponse response = aopClient.pageExecute(request, null, "post"); if (response != null && response.Code == "10000") { parameter = response.Body; } //记日志response.ToJson(); return(parameter); }
public string AlipayTradeWapPay(Order order) { DefaultAopClient client = new DefaultAopClient(_aliPayPaymentSettings.GatewayUrl, _aliPayPaymentSettings.AppID, _aliPayPaymentSettings.PrivateKey, "json", "1.0", _aliPayPaymentSettings.SignType, _aliPayPaymentSettings.AlipayPublicKey, "UTF-8", false); // 外部订单号,商户网站订单系统中唯一的订单号 string out_trade_no = order.Id.ToString(); string subject = _storeContext.CurrentStore.Name; string total_amout = order.OrderTotal.ToString("0.00", CultureInfo.InvariantCulture); string body = "Order from " + _storeContext.CurrentStore.Name; //手机访问 AlipayTradeWapPayResponse response = null; AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); request.SetReturnUrl(_webHelper.GetStoreLocation(false) + "Plugins/PaymentAliPay/Return"); request.SetNotifyUrl(_webHelper.GetStoreLocation(false) + "Plugins/PaymentAliPay/Notify"); request.SetBizModel(new AlipayTradeWapPayModel() { Body = body, Subject = subject, TotalAmount = total_amout, OutTradeNo = out_trade_no, ProductCode = "FAST_INSTANT_TRADE_PAY" }); try { response = client.pageExecute(request, null, "post"); return(response.Body); } catch (Exception exp) { _logger.Information($"{DateTime.Now.ToLocalTime().ToString()}AliWapPay:{exp.Message}"); return("<script>alert('AlipayTradeWapPay Failed!');</script>"); } }
public void TestPayWithOptional() { Dictionary <string, object> optionalArgs = new Dictionary <string, object> { { "timeout_express", "10m" }, { "body", "iPhone6 16G" } }; AlipayTradeWapPayResponse response = Factory.Payment.Wap() .Agent("ca34ea491e7146cc87d25fca24c4cD11").BatchOptional(optionalArgs) .Pay("iPhone6 16G", "b7f4bc7d-ea4b-4efd-9072-d8ea913c8946", "0.10", "https://www.taobao.com", "https://www.taobao.com"); Assert.IsTrue(ResponseChecker.Success(response)); Assert.IsTrue(response.Body.Contains("<form name=\"punchout_form\" method=\"post\" " + "action=\"https://openapi.alipay.com/gateway.do?")); Assert.IsTrue(response.Body.Contains("notify_url")); Assert.IsTrue(response.Body.Contains("return_url")); Assert.IsTrue(response.Body.Contains("app_auth_token")); Assert.IsTrue(response.Body.Contains("timeout_express")); Assert.IsTrue(response.Body.Contains("body")); Assert.IsTrue(response.Body.Contains("<input type=\"hidden\" name=\"biz_content\" value=\"{"subject":"iPhone6 16G","out_trade_no":"" + "b7f4bc7d-ea4b-4efd-9072-d8ea913c8946","total_amount":"0.10","quit_url":"" + "https://www.taobao.com","product_code":"QUICK_WAP_WAY","timeout_express":"" + "10m","body":"iPhone6 16G"}\">")); Assert.IsTrue(response.Body.Contains("<input type=\"submit\" value=\"立即支付\" style=\"display:none\" >")); Assert.IsTrue(response.Body.Contains("<script>document.forms[0].submit();</script>")); }
/// <summary> /// 手机支付 /// </summary> /// <param name="info"></param> /// <returns></returns> protected virtual bool CreateByWap(PaylineEntity info) { var builder = new StringBuilder("{"); builder.AppendFormat("\"body\":\"{0}\",", info.TypeName); builder.AppendFormat("\"subject\":\"{0}\",", info.TypeName); builder.AppendFormat("\"out_trade_no\":\"{0}\",", info.Number); builder.AppendFormat("\"total_amount\":\"{0}\",", info.Amount != 0 || info.PaylineItems == null ? info.Amount : info.PaylineItems.Sum(it => it.Amount)); builder.AppendFormat("\"product_code\":\"{0}\",", "QUICK_WAP_PAY");//FAST_INSTANT_TRADE_PAY builder.Append("}"); AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); request.BizContent = builder.ToString(); var processUrl = string.Format("{0}/AliPay/Process", ConfigurationManager.GetSetting <string>("DistributedOutsidePayUrl")); var returnUrl = string.Format("{0}?returnurl={1}&returntitle={2}&autoreturnurl={3}&autoreturntitle={4}" , processUrl, HttpContext.Current.Request["returnurl"] , HttpContext.Current.Request["returntitle"] , HttpContext.Current.Request["autoreturnurl"] , HttpContext.Current.Request["autoreturntitle"]); request.SetReturnUrl(returnUrl); request.SetNotifyUrl(processUrl); AlipayTradeWapPayResponse response = AopClient.pageExecute(request); info.Request = response.Body; return(true); }
public static string ProcessRequest(OrderListModel orderList, long orderId, string wapSpId) { DefaultAopClient client = new DefaultAopClient(wapConfig.gatewayUrl, wapConfig.app_id, wapConfig.private_key, "json", "1.0", wapConfig.sign_type, wapConfig.alipay_public_key, wapConfig.charset, false); AlipayTradeWapPayModel model = ConvertToModel(orderList, orderId); AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); // 设置同步回调地址 string retunUrl = string.Format(wapConfig.RETURN_URL, wapSpId, orderId); request.SetReturnUrl(retunUrl); // 设置异步通知接收地址 request.SetNotifyUrl(wapConfig.NOTIFY_URL); // 将业务model载入到request request.SetBizModel(model); AlipayTradeWapPayResponse response = null; try { //因为是页面跳转类服务,使用pageExecute方法得到form表单后输出给前端跳转 response = client.pageExecute(request, null, "post"); if (response != null && !response.IsError) { return(response.Body); } } catch (Exception exp) { LogUtil.Error(exp.Message); } return(string.Empty); }
/// <summary> /// 阿里手机网页支付 /// </summary> /// <param name="totalAmount">支付金额</param> /// <param name="outTradeNo">系统订单号码</param> /// <param name="notifyUrl">订单成功返回路径</param> /// <param name="body">内容</param> /// <param name="subject">订单名称</param> /// <returns></returns> public string CreateAlipayWapOrder(string totalAmount, string outTradeNo, string notifyUrl, string body, string subject) { DefaultAopClient client = new DefaultAopClient(gatewayUrl, app_id, private_key, "json", "1.0", sign_type, alipay_public_key, charset, false); //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称如:alipay.trade.app.pay AlipayTradeWapPayModel model = new AlipayTradeWapPayModel(); model.Body = body; model.Subject = subject; model.TotalAmount = totalAmount; model.OutTradeNo = outTradeNo; model.ProductCode = "QUICK_WAP_WAY"; //订单号 model.TimeoutExpress = "30m"; AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); request.SetBizModel(model); request.SetNotifyUrl(notifyUrl); // 设置同步回调地址 request.SetReturnUrl(notifyUrl); //这里和普通的接口调用不同,使用的是sdkExecute AlipayTradeWapPayResponse response = null; try { response = client.pageExecute(request, null, "post"); return(response.Body); } catch (Exception exp) { throw exp; } }
private static string GetOrderInfo(string amount) { //EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX); IAopClient client = new DefaultAopClient("https://openapi.alipaydev.com/gateway.do", APPID, APP_PRIVATE_KEY, "json", "1.0", "RSA2", ALIPAY_PUBLIC_KEY, CHARSET, false); AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); AlipayTradeWapPayModel model = new AlipayTradeWapPayModel { Body = HttpUtility.UrlEncode("门诊挂号"), //"我是测试数据", Subject = HttpUtility.UrlEncode("门诊挂号缴费"), // "App支付测试DoNet", TotalAmount = amount, //"0.01", ProductCode = "QUICK_WAP_WAY", OutTradeNo = "2020060111510", //TimeoutExpress = "120m", TimeExpire = DateTime.Now.AddMinutes(60).ToString("yyyy-MM-dd HH:mm"), QuitUrl = "http://www.taobao.com/product/113714.html", }; request.SetBizModel(model); //request.SetNotifyUrl("外网商户可以访问的异步地址"); request.SetReturnUrl("https://wwww.baidu.com"); AlipayTradeWapPayResponse response = client.pageExecute(request); return(response.Body); //HttpUtility.HtmlEncode是为了输出到页面时防止被浏览器将关键参数html转义,实际打印到日志以及http传输不会有这个问题 //Response.Write(HttpUtility.HtmlEncode(response.Body)); }
public ActionResult MobilePay() { //appid ,private key ,public key, //测试 url https://openapi.alipaydev.com/gateway.do //正式 url https://openapi.alipay.com/gateway.do string out_trade_no = DateTime.Now.ToString("yyyyMMddHHmmssfff"); IAopClient client = new DefaultAopClient(AliPayConfig.serverUrl, AliPayConfig.app_id, AliPayConfig.merchant_private_key, AliPayConfig.format, AliPayConfig.version, AliPayConfig.sginType, AliPayConfig.alipay_public_key, AliPayConfig.charset, AliPayConfig.keyFromsFile); AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); //支付异步回调地址 request.SetNotifyUrl("http://1x687f9296.iok.la/AliPay/Receive_notify"); request.SetReturnUrl("http://www.baidu.com"); request.BizContent = "{" + " \"body\":\"这是一个大可乐,有2.5L,大不大\"," + " \"subject\":\"大可乐\"," + " \"out_trade_no\":\"" + out_trade_no + "\"," + " \"timeout_express\":\"90m\"," + " \"total_amount\":0.01," + " \"product_code\":\"QUICK_WAP_WAY\"" + " }"; AlipayTradeWapPayResponse response = client.pageExecute(request); string form = response.Body; return(Content(form)); }
protected void BtnAlipay_Click(object sender, EventArgs e) { // 外部订单号,商户网站订单系统中唯一的订单号 string out_trade_no = WIDout_trade_no.Text.Trim(); // 订单名称 string subject = WIDsubject.Text.Trim(); // 付款金额 string total_amout = WIDtotal_amount.Text.Trim(); // 商品描述 string body = WIDbody.Text.Trim(); // 支付中途退出返回商户网站地址 string quit_url = WIDquit_url.Text.Trim(); try { var msg = AddNewOrder(out_trade_no, total_amout, subject, body, "950F76CC-B4E8-4733-A336-E3E2C6118579"); if (string.IsNullOrEmpty(msg)) { var aliAccount = Config.WapAccounts[0]; var alipayPublicKey = string.Format(Config.alipay_public_key, aliAccount.AppName); var alipayPrivateKey = string.Format(Config.merchant_private_key, aliAccount.AppName); DefaultAopClient client = new DefaultAopClient(Config.gatewayUrl, aliAccount.AppId, alipayPrivateKey, "json", "1.0", Config.sign_type, alipayPublicKey, Config.charset, true); // 组装业务参数model AlipayTradeWapPayModel model = new AlipayTradeWapPayModel(); model.Body = body; model.Subject = subject; model.TotalAmount = total_amout; model.OutTradeNo = out_trade_no; model.ProductCode = "QUICK_WAP_WAY"; model.QuitUrl = quit_url; AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); // 设置支付完成同步回调地址 // request.SetReturnUrl(""); // 设置支付完成异步通知接收地址 request.SetNotifyUrl("http://139.196.211.10/payapi/Notify_url.aspx"); // 将业务model载入到request request.SetBizModel(model); AlipayTradeWapPayResponse response = client.pageExecute(request, null, "post"); Response.Write(response.Body); } else { Response.Write(msg); } } catch (Exception ex) { Logger.Log("Exception:" + ex.ToString()); } }
/// <summary> /// 订单编号 /// </summary> /// <param name="oidStr"></param> /// <returns></returns> public void AliPay() { #region 统一下单 try { DefaultAopClient client = new DefaultAopClient(WeixinConfig.serviceUrl, WeixinConfig.aliAppId, WeixinConfig.privateKey, "json", "1.0", WeixinConfig.signType, WeixinConfig.publicKey, WeixinConfig.charset, false); // 外部订单号,商户网站订单系统中唯一的订单号 string out_trade_no = DateTime.Now.ToString("yyyyMMddHHmmss"); // 订单名称 string subject = "App支付测试DoNet"; // 付款金额 string total_amout = "0.01"; // 商品描述 string body = "我是测试数据"; // 支付中途退出返回商户网站地址 string quit_url = "/webapp/jntt/index"; // 组装业务参数model AlipayTradeWapPayModel model = new AlipayTradeWapPayModel(); model.Body = body; model.Subject = subject; model.TotalAmount = total_amout; model.OutTradeNo = out_trade_no; model.ProductCode = "QUICK_WAP_WAY"; model.QuitUrl = quit_url; AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); // 设置支付完成同步回调地址 // request.SetReturnUrl(""); // 设置支付完成异步通知接收地址 // request.SetNotifyUrl(""); // 将业务model载入到request request.SetBizModel(model); AlipayTradeWapPayResponse response = null; try { response = client.pageExecute(request, null, "post"); Response.Write(response.Body); } catch (Exception exp) { throw exp; } } catch (Exception ex) { //return Json(new { Result = false, msg = "缺少参数" }); } #endregion }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; try { Log.WriteLog("Alipay", "进入支付宝", "-----"); //subject = "商品描述"; string orderNo = context.Request["orderNo"].ObjToStr(); Log.WriteLog("Alipay", "orderNo", orderNo); decimal amount = context.Request["amount"].ObjToDecimal(0); string subject = "幸事多"; //context.Request["subject"].ObjToStr(); string app_id = Config.AppId; //Config.Partner;//合作伙伴id string merchant_private_key = Config.Private_key; string alipay_public_key = Config.Public_key; string timeout_express = "30m"; //订单有效时间(分钟) string postUrl = Config.GateWayUrl; string sign_type = Config.Sign_type; //加签方式 有两种RSA和RSA2 我这里使用的RSA2(支付宝推荐的) string version = "1.0"; //固定值 不用改 string format = "json"; //固定值 string Amount = amount.ObjToStr(); //订单金额 string method = "alipay.trade.wap.pay"; //调用接口 固定值 不用改 IAopClient client = new DefaultAopClient(postUrl, app_id, merchant_private_key, format, version, sign_type, alipay_public_key, Config.Input_charset, false); AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); string notify_url = Config.Notify_url; string return_url = Config.Return_url; Log.WriteLog("Alipay", "notify_url", notify_url); Log.WriteLog("Alipay", "return_url", return_url); request.SetNotifyUrl(notify_url); request.SetReturnUrl(return_url); var bizcontent = "{" + " \"body\":\"" + subject + "\"," + " \"subject\":\"" + subject + "\"," + " \"out_trade_no\":\"" + orderNo + "\"," + " \"timeout_express\":\"" + timeout_express + "\"," + " \"total_amount\":\"" + Amount + "\"," + " \"product_code\":\"" + method + "\"" + " }"; Log.WriteLog("Alipay", "bizcontent", bizcontent); request.BizContent = bizcontent; AlipayTradeWapPayResponse response = client.pageExecute(request); string form = response.Body; context.Response.Write(form); } catch (Exception ex) { context.Response.Write(ex.Message); } }
protected void BtnAlipay_Click(object sender, EventArgs e) { DefaultAopClient client = new DefaultAopClient(config.gatewayUrl, config.app_id, config.private_key, "json", "1.0", config.sign_type, config.alipay_public_key, config.charset, false); // 外部订单号,商户网站订单系统中唯一的订单号 //WIDout_trade_no.Text = DateTime.Now.ToLongTimeString(); string out_trade_no = WIDout_trade_no.Text.Trim(); // 订单名称 string subject = WIDsubject.Text.Trim(); // 付款金额 string total_amout = WIDtotal_amount.Text.Trim(); // 商品描述 string body = WIDbody.Text.Trim(); // 支付中途退出返回商户网站地址 string quit_url = WIDquit_url.Text.Trim(); // 组装业务参数model AlipayTradeWapPayModel model = new AlipayTradeWapPayModel(); model.Body = body; model.Subject = subject; model.TotalAmount = total_amout; model.OutTradeNo = out_trade_no; model.ProductCode = "QUICK_WAP_WAY"; model.QuitUrl = quit_url; AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); // 设置支付完成同步回调地址 // request.SetReturnUrl(""); // 设置支付完成异步通知接收地址 request.SetNotifyUrl("http://" + Request.Url.Authority + "/GameWebApplication/AliNotify_url.aspx"); Debug.Log("request.SetNotifyUrl", "http://" + Request.Url.Authority + "/GameWebApplication/AliNotify_url.aspx"); Debug.Log("UserId", UserId.ToString()); // 将业务model载入到request request.SetBizModel(model); AlipayTradeWapPayResponse response = null; try { response = client.pageExecute(request, null, "post"); Response.Write(response.Body); } catch (Exception exp) { throw exp; } }
protected void BtnAlipay_Click(object sender, EventArgs e) { DefaultAopClient client = new DefaultAopClient(AlipayConfig.mobile_gatewayUrl, AlipayConfig.mobile_app_id, AlipayConfig.mobile_private_key_value, "json", "1.0", AlipayConfig.sign_type, AlipayConfig.mobile_public_key_value, AlipayConfig.charset, false); // 外部订单号,商户网站订单系统中唯一的订单号 string out_trade_no = WIDout_trade_no.Text.Trim(); // 订单名称 string subject = WIDsubject.Text.Trim(); // 付款金额 string total_amout = WIDtotal_amount.Text.Trim(); // 商品描述 string body = WIDbody.Text.Trim(); // 支付中途退出返回商户网站地址 string quit_url = WIDquit_url.Text.Trim(); // 组装业务参数model AlipayTradeWapPayModel model = new AlipayTradeWapPayModel(); model.Body = body; model.Subject = subject; model.TotalAmount = total_amout; model.OutTradeNo = out_trade_no; model.ProductCode = "QUICK_WAP_PAY"; model.QuitUrl = quit_url; AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); // 设置支付完成同步回调地址 // request.SetReturnUrl(""); // 设置支付完成异步通知接收地址 // request.SetNotifyUrl(""); // 将业务model载入到request request.SetBizModel(model); request.SetNotifyUrl(""); AlipayTradeWapPayResponse response = null; try { response = client.pageExecute(request, null, "post"); Response.Write(response.Body); } catch (Exception exp) { throw exp; } }
/// <summary> /// 支付宝支付 /// </summary> /// <param name="out_trade_no">外部订单号,商户网站订单系统中唯一的订单号</param> /// <param name="subject">订单名称</param> /// <param name="total_amout">会员帐号</param> /// <param name="type">对账类型[1=链商城 2=商城]</param> public ActionResult Alipay(string out_trade_no, string subject, string total_amout, int type, string ReturnType = "0") { // 商品描述 string body = "链商支付"; // 支付中途退出返回商户网站地址 string quit_url = Help.quit_url; // 组装业务参数model AlipayTradeWapPayModel model = new AlipayTradeWapPayModel(); model.Body = body; model.Subject = subject; model.TotalAmount = total_amout; model.OutTradeNo = out_trade_no; model.ProductCode = "QUICK_WAP_PAY"; model.QuitUrl = quit_url; AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); // 设置支付完成同步回调地址 request.SetReturnUrl(Help.Url + "/Pay/PayOK?type=" + type.ToString() + "&OrderNo=" + out_trade_no + "&ReturnType=" + ReturnType); // 设置支付完成异步通知接收地址 if (type == 1) { request.SetNotifyUrl(Help.notify_url); } else if (type == 2) { request.SetNotifyUrl(Help.shopnotify_url); } // 将业务model载入到request request.SetBizModel(model); AlipayTradeWapPayResponse response = null; try { DefaultAopClient client = new DefaultAopClient(Help.gatewayUrl, Help.app_id, Help.private_key, "json", "1.0", Help.sign_type, Help.alipay_public_key, Help.charset, false); response = client.pageExecute(request, null, "post"); return(Content(response.Body)); } catch (Exception exp) { return(Helper.Redirect("支付失败", "history.go(-1);", "订单异常=" + exp.Message)); } }
public void TestPay() { AlipayTradeWapPayResponse response = Factory.Payment.Wap().Pay("iPhone6 16G", "b7f4bc7d-ea4b-4efd-9072-d8ea913c8946", "0.10", "https://www.taobao.com", "https://www.taobao.com"); Assert.IsTrue(ResponseChecker.Success(response)); Assert.IsTrue(response.Body.Contains("<form name=\"punchout_form\" method=\"post\" action=\"https://openapi.alipay.com/gateway.do?")); Assert.IsTrue(response.Body.Contains("notify_url")); Assert.IsTrue(response.Body.Contains("return_url")); Assert.IsTrue(response.Body.Contains("<input type=\"hidden\" name=\"biz_content\" value=\"{"subject":"iPhone6 16G","" + "out_trade_no":"b7f4bc7d-ea4b-4efd-9072-d8ea913c8946","" + "total_amount":"0.10","quit_url":"https://www.taobao.com","" + "product_code":"QUICK_WAP_WAY"}\">")); Assert.IsTrue(response.Body.Contains("<input type=\"submit\" value=\"立即支付\" style=\"display:none\" >")); Assert.IsTrue(response.Body.Contains("<script>document.forms[0].submit();</script>")); }
/// <summary> /// 获取wap支付宝支付订单参数 /// </summary> /// <param name="orderCode"></param> /// <param name="money"></param> /// <param name="timeOut">订单支付超时时间</param> /// <returns></returns> private ApiResultModel <string> GetWapAlipayPram(string orderCode, decimal money, int?timeOut) { IAopClient client = new DefaultAopClient(AliPayConfig.gatewayUrl, AliPayConfig.AppId, AliPayConfig.privatekey, "json", "1.0", AliPayConfig.sign_type, AliPayConfig.alipublickey, AliPayConfig.charset, false); //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称如:alipay.trade.app.pay AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); //SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。 AlipayTradeWapPayModel alipayModel = new AlipayTradeWapPayModel { //Body = "buygoods", Subject = Subject, TotalAmount = decimal.Round(money, 2).ToString("f2"), ProductCode = "QUICK_WAP_PAY", OutTradeNo = orderCode, // TimeoutExpress = "30m", TimeoutExpress = (timeOut ?? PayTimeOut).ToString() + "m", }; request.SetReturnUrl(AppSettingsHelper.Configuration[ConfigConstants.AliPaymentResultUrl]); request.SetNotifyUrl(NotifyUrl); request.SetBizModel(alipayModel); //这里和普通的接口调用不同,使用的是pageExecute var reqTime = DateTime.Now; AlipayTradeWapPayResponse response = null; try { response = client.pageExecute(request, null, "post"); //记录支付宝调用的日志 //WritePostThirdApi(ThirdPlatformBusinessType.Payment, orderCode, ThirdPlatformType.Alipay, AliPayConfig.gatewayUrl, request.ToJsonString(), reqTime, response.Body, DateTime.Now, true); } catch (Exception ex) { //LogHelper.LogError("提交支付宝预付款订单 SubmitPay", ex.ToString()); ////记录支付宝调用的日志 //WritePostThirdApi(ThirdPlatformBusinessType.Payment, orderCode, ThirdPlatformType.Alipay, AliPayConfig.gatewayUrl, request.ToJsonString(), reqTime, // response.IsNull() ? ex.ToString() : response.Body, DateTime.Now, true); } var res = new ApiResultModel <string>() { Code = ApiResultCode.Success, Message = response.Body }; return(res); }
/// <summary> /// 提交支付 - 新版本手机网站支付 /// </summary> public void SubmitPayment(string orderNo, string orderName, string amount, string describe) { log.Info("start-提交支付"); DefaultAopClient client = new DefaultAopClient(config.gatewayUrl, config.app_id, config.private_key, "json", "1.0", config.sign_type, config.alipay_public_key, config.charset, false); // 外部订单号,商户网站订单系统中唯一的订单号 string out_trade_no = orderNo; // 订单名称 string subject = orderName; // 付款金额 string total_amout = amount; // 商品描述 string body = describe; // 支付中途退出返回商户网站地址 string quit_url = "http://www.jiaodai.online/Pay/PayBreakOff"; // 组装业务参数model AlipayTradeWapPayModel model = new AlipayTradeWapPayModel(); model.Body = body; model.Subject = subject; model.TotalAmount = total_amout; model.OutTradeNo = out_trade_no; model.ProductCode = "QUICK_WAP_WAY"; model.QuitUrl = quit_url; log.Info("请求阿里,业务model:" + JsonConvert.SerializeObject(model)); AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); // 设置支付完成同步回调地址 request.SetReturnUrl("http://www.jiaodai.online/Pay/SyncNotify"); // 设置支付完成异步通知接收地址 request.SetNotifyUrl("http://www.jiaodai.online/Pay/AsyncNotify"); // 将业务model载入到request request.SetBizModel(model); AlipayTradeWapPayResponse response = null; try { response = client.pageExecute(request, null, "post"); log.Info("阿里响应信息:" + response.Body); Response.Write(response.Body); } catch (Exception e) { log.Info("支付异常,异常信息为:" + e.Message); } }
public void should_return_query_string_contains_root_cert_sn_and_app_cert() { IAopClient client = new DefaultAopClient(TestAccount.ProdCert.Gateway, TestAccount.ProdCert.AppId, TestAccount.ProdCert.AppPrivateKey, "json", "1.0", "RSA2", "utf-8", false, TestAccount.ProdCert.CertParams); AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); request.BizContent = "{" + " \"body\":\"对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body。\"," + " \"subject\":\"大乐透\"," + " \"out_trade_no\":\"70501111111S001111119\"," + " \"timeout_express\":\"90m\"," + " \"total_amount\":9.00," + " \"product_code\":\"QUICK_WAP_WAY\"" + " }"; AlipayTradeWapPayResponse response = client.pageExecute(request, "123", "123", "GET"); String orderString = response.Body; Assert.AreEqual(orderString.Contains("app_cert_sn="), true); Assert.AreEqual(orderString.Contains("alipay_root_cert_sn="), true); }
/// <summary> /// 支付 /// </summary> /// <param name="parameter"></param> /// <returns></returns> public string Pay(H5PaymentParameter parameter) { DefaultAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", PublicKey, "utf-8", false); // 组装业务参数model AlipayTradeWapPayModel model = new AlipayTradeWapPayModel { Body = parameter.Body, Subject = parameter.Subject, TotalAmount = parameter.Amount.ToString(), OutTradeNo = parameter.TradeNo, ProductCode = "QUICK_WAP_WAY", QuitUrl = parameter.QuitUrl, PassbackParams = parameter.PassbackParams }; // 请求 AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); // 设置支付完成同步回调地址 request.SetReturnUrl(parameter.QuitUrl); // 设置支付完成异步通知接收地址 request.SetNotifyUrl(parameter.NotifyUrl); // 将业务model载入到request request.SetBizModel(model); // 响应 AlipayTradeWapPayResponse response = client.pageExecute(request, null, "post"); return(response.Body); }
public static string MakeWapPayOrder(string companyId, PreAliPayOrderModel model, string returnUrl, string notifyUrl) { try { AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); request.BizContent = JsonHelper.GetJsonString(model); request.SetNotifyUrl(notifyUrl); request.SetReturnUrl(returnUrl); AlipayTradeWapPayResponse response = GetDefaultAopClient(companyId).pageExecute(request); if (response.IsError) { TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("wap网站支付失败:{0}", response.Body)); return(""); } return(response.Body); } catch (Exception ex) { TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("网站支付失败:{0}", ex.Message)); } return(""); }
public void should_return_correct_signed_order_form() { IAopClient client = new DefaultAopClient(TestAccount.Sandbox.Gateway, TestAccount.Sandbox.AppId, TestAccount.Sandbox.AppPrivateKey, "json", "1.0", "RSA2", TestAccount.Sandbox.AlipayPublicKey, "utf-8", false); AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); request.BizContent = "{" + " \"body\":\"对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body。\"," + " \"subject\":\"大乐透\"," + " \"out_trade_no\":\"70501111111S001111119\"," + " \"timeout_express\":\"90m\"," + " \"total_amount\":9.00," + " \"product_code\":\"QUICK_WAP_WAY\"" + " }"; AlipayTradeWapPayResponse response = client.pageExecute(request); String orderString = response.Body; // 必须拥有正确的签名串 Assert.AreEqual(orderString.Contains("name='sign'"), true); }
public void should_return_order_form_with_access_token() { IAopClient client = new DefaultAopClient(TestAccount.Sandbox.Gateway, TestAccount.Sandbox.AppId, TestAccount.Sandbox.AppPrivateKey, "json", "1.0", "RSA2", TestAccount.Sandbox.AlipayPublicKey, "utf-8", false); AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); request.BizContent = "{" + " \"body\":\"对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body。\"," + " \"subject\":\"大乐透\"," + " \"out_trade_no\":\"70501111111S001111119\"," + " \"timeout_express\":\"90m\"," + " \"total_amount\":9.00," + " \"product_code\":\"QUICK_WAP_WAY\"" + " }"; AlipayTradeWapPayResponse response = client.pageExecute(request, "123", null, "POST"); String orderString = response.Body; //必须含有auth_tokne参数,不包含app_auth_token参数 Assert.AreEqual(orderString.Contains("app_auth_token"), false); Assert.AreEqual(orderString.Contains("name='auth_token' value='123'"), true); }
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; } }
protected void Page_Load(object sender, EventArgs e) { var orderNo = Request.QueryString["orderNo"]; var userAddressId = Request.QueryString["userAddressId"]; if (string.IsNullOrWhiteSpace(orderNo)) { Response.Write("请求错误"); Response.End(); return; } if (string.IsNullOrWhiteSpace(userAddressId)) { Response.Write("请选择收货地址"); Response.End(); return; } _database = new Database("ecard"); using (_databaseInstance = new DatabaseInstance(_database)) { var address = _databaseInstance.Query <Order>("select * from fz_UserAddress where userAddressId=@userAddressId", new { userAddressId = userAddressId }).FirstOrDefault(); if (address == null) { Response.Write("收货地址不存在,请重新付款"); Response.End(); return; } var order = _databaseInstance.Query <Order>("select * from fz_Orders where orderNo=@orderNo", new { orderNo = orderNo }).FirstOrDefault(); if (order == null) { Response.Write("订单不存在"); Response.End(); return; } if (order.orderState != OrderStates.awaitPay) { Response.Write("订单不是待付款状态"); Response.End(); return; } order.payAmount = order.amount + order.freight; order.detailedAddress = address.detailedAddress; order.moblie = address.moblie; order.recipients = address.recipients; order.UserAddressId = address.UserAddressId; if (_databaseInstance.Update(order, "fz_Orders") <= 0) { Response.Write("付款失败"); Response.End(); return; } IAopClient client = new DefaultAopClient(AlipayConfig.URL, AlipayConfig.APPID, AlipayConfig.APP_PRIVATE_KEY, "json", "1.0", "RSA", AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.CHARSET, false); AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); request.SetReturnUrl("http://wx.fislive.com/WeChatViews/i.html"); request.SetNotifyUrl("http://wx.fislive.com/NotifyUrl/AlipayNotifyUrl.aspx"); request.BizContent = "{" + " \"body\":\"菲爱仕商城\"," + " \"subject\":\"菲爱仕商城\"," + " \"out_trade_no\":\"" + orderNo + "\"," + " \"timeout_express\":\"90m\"," + " \"total_amount\":" + order.payAmount + "," + " \"product_code\":\"QUICK_WAP_WAY\"" + " }"; AlipayTradeWapPayResponse response = client.pageExecute(request); string form = response.Body; WxPayAPI.Log.Info("支付宝请求参数:", form); Response.Write(form); } //IAopClient client = new DefaultAopClient(AlipayConfig.URL, AlipayConfig.APPID, AlipayConfig.APP_PRIVATE_KEY, "json", "1.0", "RSA", AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.CHARSET, false); //////实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称如:alipay.trade.app.pay //AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest(); ////SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。 //AlipayTradeAppPayModel model = new AlipayTradeAppPayModel(); ////model.m //model.Body = "我是测试数据"; //model.Subject = "App支付测试DoNet"; //model.TotalAmount = "0.01"; //model.ProductCode = "QUICK_WAP_PAY"; //model.OutTradeNo = "sadfa" + DateTime.Now.ToString("yyyyMMddHHmmssfff"); //// model.TimeoutExpress = "30m"; //request.SetBizModel(model); //request.SetNotifyUrl(AlipayConfig.NOTIFY_URL); ////这里和普通的接口调用不同,使用的是sdkExecute //string from = client.pageExecute(request).Body; ////AlipayTradeAppPayResponse response = client.SdkExecute(request); //Response.AddHeader("content-type", "text/html"); //Response.AddHeader("charset","UTF-8"); //Response.Write(from); }
//对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 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; } }
protected new void Page_Load(object sender, EventArgs e) { //orderOID--订单ID,不重复的订单编号 //orderName--订单名称 //payMoney--支付金额 //note--说明 //WIDquitUrl--支付中途退出返回商户网站地址 //ReturnUrl--支付完成同步回掉的页面 //NotifyUrl--支付宝异步回掉接口--必须保证外网能访问 //支付宝支付回掉域名(只要域名,不带http) string _AliPayNotifyHostPoint = "wefamily.me"; HKModel hkModel = HKModel; decimal basemoney = 0; decimal minmoney = 0; decimal czbase = 0; if (hkModel.HKType == 1)// { basemoney = 100; minmoney = 100; czbase = 1; //basemoney =Convert.ToDecimal( 0.1); //minmoney = Convert.ToDecimal(0.1); //czbase = Convert.ToDecimal(0.1); } else if (hkModel.HKType == 2) { basemoney = 200; minmoney = 200; czbase = 200; } else { Response.Write("支付类型不存在"); Response.End(); } if (hkModel.RealMoney % basemoney != 0) { Response.Write("汇款倍数有误"); Response.End(); } if (hkModel.RealMoney < minmoney) { Response.Write("汇款金额不能低于" + minmoney); Response.End(); } hkModel.ValidMoney = hkModel.RealMoney / czbase; BLL.HKModel.Insert(hkModel); try { DefaultAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", config.app_id, config.private_key, "json", "1.0", "RSA2", _AliPayNotifyHostPoint, "UTF-8", false); // 外部订单号,商户网站订单系统中唯一的订单号 string out_trade_no = hkModel.HKCode; // 订单名称 string subject = "WE支付"; // 付款金额 string total_amout = hkModel.RealMoney.ToString(); // 商品描述 string body = "商品描述"; // 支付中途退出返回商户网站地址 string quit_url = "https://wefamily.me/"; // 组装业务参数model AlipayTradeWapPayModel model = new AlipayTradeWapPayModel(); model.Body = body; model.Subject = subject; model.TotalAmount = total_amout; model.OutTradeNo = out_trade_no; model.ProductCode = "QUICK_WAP_WAY"; model.QuitUrl = quit_url; AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); // 设置支付完成同步回调地址 string url = "https://" + HttpContext.Current.Request.Url.Authority.ToString(); string Merchanturl = url + "/Payment/AliPay/TBReturn.aspx"; request.SetReturnUrl(Merchanturl); // 设置支付完成异步通知接收地址 string Merchanturl2 = url + "/Payment/AliPay/YBReturn.aspx"; request.SetNotifyUrl(Merchanturl2); // 将业务model载入到request request.SetBizModel(model); AlipayTradeWapPayResponse response = null; try { response = client.pageExecute(request, null, "post"); //return response.Body; //拼接好的form标签,页面直接submit这个标签就可以了 Response.Write(response.Body); } catch (Exception exp) { throw exp; } } catch (Exception ex) { throw ex; } //Response.Write(postForm); }
protected void Page_Load(object sender, EventArgs e) { var type = Request.RequestType.ToUpper(); var result = new AliPayResult() { Status = "FAILED", Msg = "", Body = "" }; if (type.Equals("POST")) { try { var requestStr = ReadStream(Request.InputStream); var logMsg = bool.Parse(ConfigurationManager.AppSettings["LogMsg"].ToString()); if (logMsg) { Logger.Log(requestStr); } var turnOn = bool.Parse(ConfigurationManager.AppSettings["AllowPay"].ToString()); if (turnOn) { if (Config.WapAccounts.Count > 0) { // 外部订单号,商户网站订单系统中唯一的订单号 string out_trade_no = Request.Form["out_trade_no"]; // 订单名称 string subject = Request.Form["subject"]; // 付款金额 string total_amout = Request.Form["total_amout"]; // 商品描述 string body = Request.Form["body"]; // 支付中途退出返回商户网站地址 string quit_url = Request.Form["quit_url"]; // 支付成功回调商户地址 string notify_url = Request.Form["notify_url"]; string key = Request.Form["key"]; var msg = AddNewOrder(out_trade_no, total_amout, subject, body, key); if (string.IsNullOrEmpty(msg)) { var aliAccount = Config.WapAccounts[0]; var alipayPublicKey = string.Format(Config.alipay_public_key, aliAccount.AppName); var alipayPrivateKey = string.Format(Config.merchant_private_key, aliAccount.AppName); DefaultAopClient client = new DefaultAopClient(Config.gatewayUrl, aliAccount.AppId, alipayPrivateKey, "json", "1.0", Config.sign_type, alipayPublicKey, Config.charset, true); // 组装业务参数model AlipayTradeWapPayModel model = new AlipayTradeWapPayModel(); model.Body = body; model.Subject = subject; model.TotalAmount = total_amout; model.OutTradeNo = out_trade_no; model.ProductCode = "QUICK_WAP_WAY"; model.QuitUrl = quit_url; AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); // 设置支付完成同步回调地址 // request.SetReturnUrl(""); // 设置支付完成异步通知接收地址 request.SetNotifyUrl("http://139.196.211.10/payapi/Notify_url.aspx"); // 将业务model载入到request request.SetBizModel(model); AlipayTradeWapPayResponse response = client.pageExecute(request, null, "post"); result.Body = response.Body; result.Status = "SUCCESS"; } else { result.Msg = msg; } } else { result.Msg = "无可用通道..."; } } else { result.Msg = "通道维护中..."; } } catch (Exception ex) { Logger.Log("Exception:" + ex.ToString()); result.Msg = "请求支付宝服务遇到异常,请联系客服!"; } } else { result.Msg = "请发送POST请求"; } Response.ContentType = "application/json; charset=utf-8"; Response.Write(JsonConvert.SerializeObject(result)); }
public ActionResult RemitPay(string RemitId) { var orderModel = DB.Fin_Remit.FindEntity(Convert.ToInt32(RemitId)); DefaultAopClient client = new DefaultAopClient(Common.Alipay.Config.gatewayUrl, Common.Alipay.Config.app_id, Common.Alipay.Config.private_key, "json", "1.0", Common.Alipay.Config.sign_type, Common.Alipay.Config.alipay_public_key, Common.Alipay.Config.charset, false); ////////////////////支付宝支付////////////////////////请求参数//////////////////////////////////////////// //商户订单号,+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++,必填 string out_trade_no = orderModel.RemitId.ToString(); //订单名称,必填 string subject = "汇款申请"; //付款金额,必填 string total_fee = orderModel.Amount.ToString(); //商品描述,可空 string body = "123"; if (Convert.ToDecimal(total_fee) > 0) { //// 组装业务参数model AlipayTradeWapPayModel alipaymodel = new AlipayTradeWapPayModel(); alipaymodel.Body = body; alipaymodel.Subject = subject; alipaymodel.TotalAmount = total_fee; alipaymodel.OutTradeNo = out_trade_no; alipaymodel.ProductCode = "QUICK_WAP_WAY"; alipaymodel.QuitUrl = "/Mall/usercenter/Order"; AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); //设置支付完成同步回调地址 request.SetReturnUrl("http://www.jst1314.cn/member_finance/remit/index"); //设置支付完成异步通知接收地址 request.SetNotifyUrl("http://www.jst1314.cn/Member_Mall/Pay/RemitRecevie"); // 将业务model载入到request request.SetBizModel(alipaymodel); AlipayTradeWapPayResponse response = null; try { response = client.pageExecute(request, null, "post"); //return response.Body; //return Success("生成订单成功", new //{ // ordercode = orderModel.BillCode, // addressid = orderModel.PostAddress, // amount = orderModel.TotalPrice, // ordertype = orderModel.PaymentType, // body = response.Body //}); ViewBag.body = response.Body; return(View()); } catch (Exception exp) { LogHelper.Error("支付接口错误:" + exp.Message); throw exp; } } return(View()); }