Example #1
0
		public AlipayOrderCreationResult GenerateAlipayPaymentUrl(AlipayOrderModel payment) {
			var payModel = new AlipayTradePayModel {
				Subject = payment.Subject,
				Body = payment.Body,
				OutTradeNo = payment.OrderNo,
				TotalAmount = payment.Amount.ToString("f2"),
				DisablePayChannels = payment.AllowCreditCard ? null : "credit_group",
				ProductCode = "FAST_INSTANT_TRADE_PAY"
			};

			var wapPayRequest = new AlipayTradeWapPayRequest();
			wapPayRequest.SetNotifyUrl(payment.NotifyUrl ?? _options.DefaultNotifyUrl);
			wapPayRequest.SetReturnUrl(payment.ReturnUrl);
			wapPayRequest.SetBizModel(payModel);
			var wapPayResponse = _alipay.SdkExecute(wapPayRequest);

			var pagePayRequest = new AlipayTradePagePayRequest();
			pagePayRequest.SetNotifyUrl(payment.NotifyUrl ?? _options.DefaultNotifyUrl);
			pagePayRequest.SetReturnUrl(payment.ReturnUrl);
			pagePayRequest.SetBizModel(payModel);
			var pagePayResponse = _alipay.SdkExecute(pagePayRequest);

			return new AlipayOrderCreationResult {
				MobileWebPaymentUrl = _options.GatewayUrl + "?" + wapPayResponse.Body,
				DesktopPagePaymentUrl = _options.GatewayUrl + "?" + pagePayResponse.Body
			};
		}
Example #2
0
        public async Task <WapPayOutput> WapPay(WapPayInput input, AlipayOptions options = null)
        {
            await Task.Yield();

            // 设置产品代码
            if (input.Data.ProductCode.IsNullOrWhiteSpace())
            {
                input.Data.ProductCode = YoYoAlipayConsts.ProductCode_QUICK_WAP_WAY;
            }
            // 设置支付中途退出返回商户网站地址
            if (input.Data.QuitUrl.IsNullOrWhiteSpace())
            {
                input.Data.QuitUrl = input.QuitUrl;
            }

            var request = new AlipayTradeWapPayRequest();

            // 设置同步回调地址
            request.SetReturnUrl(input.SynchronizationCallbackUrl);
            // 设置异步通知接收地址
            request.SetNotifyUrl(input.AsyncNotifyUrl);
            // 将业务model载入到request
            request.SetBizModel(input.Data);

            // 发起支付
            var response = await this._alipayService.PageExecuteAsync(request);

            return(new WapPayOutput()
            {
                Response = response,
                Body = response.Body
            });
        }
Example #3
0
        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>");
            }
        }
        /// <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);
        }
Example #5
0
        /// <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);
        }
Example #6
0
        /// <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;
            }
        }
Example #7
0
        public ActionResult PayRequest(string tradeno, string subject, string totalAmout, string itemBody)
        {
            // 组装业务参数model
            AlipayTradeWapPayModel model = new AlipayTradeWapPayModel
            {
                Body        = itemBody,
                Subject     = subject,
                TotalAmount = totalAmout,
                OutTradeNo  = tradeno,
                ProductCode = "QUICK_WAP_WAY",
                QuitUrl     = ""
            };

            AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();

            // 设置同步回调地址
            request.SetReturnUrl($"http://{Request.Host}/Pay/Callback");
            // 设置异步通知接收地址
            request.SetNotifyUrl($"http://{"此处填写域名信息!!!"}/H5Pay/Notify");
            // 将业务model载入到request
            request.SetBizModel(model);

            var response = _alipayService.PageExecute(request, null, "post");

            Console.WriteLine($"订单支付发起成功,订单号:{tradeno}");
            //跳转支付宝支付
            //Response.Redirect(_alipayService.Options.Gatewayurl + "?" + response.Body);
            return(PartialView("SubmitForm", response.Body));
        }
Example #8
0
        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);
        }
Example #9
0
        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));
        }
Example #10
0
        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));
        }
Example #11
0
    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());
        }
    }
Example #12
0
        /// <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
        }
Example #13
0
        /// <summary>
        /// Wap统一下单
        /// </summary>
        /// <param name="request">提交给统一下单API的参数</param>
        /// <param name="config"></param>
        /// <param name="accessToken">用户授权码</param>
        /// <param name="method">请求方式,两个值可选:POST、GET;</param>
        /// <param name="timeOut">超时时间</param>
        /// <returns>成功时返回,其他抛异常</returns>
        public static async Task <AlipayTradeWapPayResponse> CreateOrderAsync(AlipayTradeWapPayModel request, AlipayConfig config, string accessToken = null, string method = "GET", int timeOut = 6)
        {
            IAopClient client      = new AopClient(AlipayConstants.GATEWAYURL, config.AppId, config.PrivateKey, config.Format, config.Version, config.SignType, config.AliPublicKey, config.Charset, config.KeyFromFile);
            var        requestData = new AlipayTradeWapPayRequest();

            requestData.SetNotifyUrl(config.NotifyUrl);
            requestData.SetReturnUrl(config.QuitUrl);
            requestData.SetBizModel(request);

            return(await client.PageExecute(requestData, accessToken, method));
        }
Example #14
0
        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);
            }
        }
Example #15
0
        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;
            }
        }
Example #16
0
        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;
            }
        }
Example #17
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            var builder = BuildPayContent();
            var request = new AlipayTradeWapPayRequest();

            request.BizContent = JsonConvert.SerializeObject(builder);


            string apiVersion = null;

            if (!string.IsNullOrEmpty(request.GetApiVersion()))
            {
                apiVersion = request.GetApiVersion();
            }
            else
            {
                apiVersion = "1.0";
            }

            // 添加协议级请求参数
            var txtParams = new AopDictionary(request.GetParameters());

            txtParams.Add("method", request.GetApiName());
            txtParams.Add("version", apiVersion);
            txtParams.Add("app_id", Config.app_id);
            txtParams.Add("format", "json");
            txtParams.Add("timestamp", DateTime.Now);
            txtParams.Add("auth_token", null);
            txtParams.Add("sign_type", Config.sign_type);
            txtParams.Add("terminal_type", request.GetTerminalType());
            txtParams.Add("terminal_info", request.GetTerminalInfo());
            txtParams.Add("prod_code", request.GetProdCode());
            txtParams.Add("charset", Config.charset);


            if (!string.IsNullOrEmpty(request.GetNotifyUrl()))
            {
                txtParams.Add("notify_url", request.GetNotifyUrl());
            }

            // 添加签名参数
            txtParams.Add("sign",
                          AlipaySignature.RSASign(txtParams, Config.merchant_private_key, Config.charset, false, Config.sign_type));

            //建立请求
            var sHtmlText = Submit.BuildRequest(txtParams, "get", "确认");


            return(View("Index", sHtmlText));
        }
Example #18
0
        public bool Wappay(AlipayOrderOptions options, out string msg)
        {
            //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称如:alipay.open.public.template.message.industry.modify
            AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();

            //SDK已经封装掉了公共参数,这里只需要传入业务参数
            request.SetNotifyUrl(AliPayConfig.NOTIFY_URL);
            request.SetReturnUrl(AliPayConfig.RETURN_URL);
            LogHelper.Logger.Debug(AliPayConfig.NOTIFY_URL);
            request.BizContent = options.ToJson();
            string form = _aopClient.pageExecute(request).Body;

            msg = form;
            return(true);
        }
Example #19
0
        /// <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));
            }
        }
Example #20
0
        /// <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);
        }
Example #21
0
        public string BuildWapPaymentUrl(Dictionary <string, string> map)
        {
            IAopClient alipayClient = GetAopClient();
            AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest();

            alipayRequest.SetReturnUrl(Merchant.ReturnUrl.ToString());
            alipayRequest.SetNotifyUrl(Merchant.NotifyUrl.ToString());
            AlipayTradeWapPayModel model = new AlipayTradeWapPayModel();

            model.Subject        = Order.Subject;
            model.OutTradeNo     = Order.OrderNo;
            model.TimeoutExpress = "30m";
            model.TotalAmount    = Order.OrderAmount.ToString();
            model.ProductCode    = "QUICK_WAP_PAY";
            alipayRequest.SetBizModel(model);
            return(alipayClient.pageExecute(alipayRequest).Body);
        }
        /// <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);
            }
        }
Example #23
0
        public Return AliPay(Models.AliPay payModel)
        {
            var resultReturn = new Return();

            try
            {
                var aopClient = new DefaultAopClient(AliPayConfig.GatewayUrl, AliPayConfig.AppId,
                                                     AliPayConfig.PrivateKey, "json", "1.0", AliPayConfig.SignType, AliPayConfig.AlipayPublicKey,
                                                     AliPayConfig.Charset, false);

                // 组装业务参数model
                var model = new AlipayTradeWapPayModel
                {
                    Body        = payModel.Description,
                    Subject     = payModel.OrderName,
                    TotalAmount = payModel.Amout.ToString(CultureInfo.InvariantCulture),
                    OutTradeNo  = payModel.OrderId.ToString(),
                    ProductCode = "QUICK_WAP_WAY",
                    QuitUrl     = payModel.QuitUrl
                };

                var request = new AlipayTradeWapPayRequest();

                //支付成功回调页面
                request.SetReturnUrl(payModel.ReturnUrl);
                //异步通知接受地址
                request.SetNotifyUrl(AliPayConfig.NotifyUrl);
                //将业务model载入request
                request.SetBizModel(model);

                var response = aopClient.pageExecute(request, null, "post");

                var responseBody = response.Body;

                resultReturn.Content = responseBody;
            }
            catch (AopException aopEx)
            {
                LogService.InsertLog(aopEx);
                resultReturn.SetWrong();
            }

            return(resultReturn);
        }
Example #24
0
        public async Task <IActionResult> WapPay(AlipayTradeWapPayViewModel viewMode)
        {
            var model = new AlipayTradeWapPayModel
            {
                Body        = viewMode.Body,
                Subject     = viewMode.Subject,
                TotalAmount = viewMode.TotalAmount,
                OutTradeNo  = viewMode.OutTradeNo,
                ProductCode = viewMode.ProductCode
            };
            var req = new AlipayTradeWapPayRequest();

            req.SetBizModel(model);
            req.SetNotifyUrl(viewMode.NotifyUrl);
            req.SetReturnUrl(viewMode.ReturnUrl);

            var response = await _client.PageExecuteAsync(req, _optionsAccessor.Value);

            return(Content(response.Body, "text/html", Encoding.UTF8));
        }
Example #25
0
        public async Task <IActionResult> WapPay(string out_trade_no, string subject, string total_amount, string body, string product_code, string notify_url, string return_url)
        {
            var model = new AlipayTradeWapPayModel()
            {
                Body        = body,
                Subject     = subject,
                TotalAmount = total_amount,
                OutTradeNo  = out_trade_no,
                ProductCode = product_code,
            };
            var req = new AlipayTradeWapPayRequest();

            req.SetBizModel(model);
            req.SetNotifyUrl(notify_url);
            req.SetReturnUrl(return_url);

            var response = await _client.PageExecuteAsync(req, null, "GET");

            return(Redirect(response.Body));
        }
Example #26
0
        // 手机网站支付
        public async Task <AlipayTradeWapPayResponse> WapPay(PayRequest request)
        {
            var order = OrderService.Get(request.Id);
            var model = new AlipayTradeWapPayModel
            {
                OutTradeNo  = order.Order_SN,
                Subject     = order.Name,
                TotalAmount = order.Order_Money.ToString("n"),
                Body        = order.Remark,
                ProductCode = "QUICK_WAP_WAY"
            };

            var req = new AlipayTradeWapPayRequest();

            req.SetBizModel(model);
            req.SetNotifyUrl(request.NotifyUrl);
            req.SetReturnUrl(request.ReturnUrl);

            return(await client.PageExecuteAsync(req, options.Value));
        }
Example #27
0
        public async Task <IActionResult> WapPay(AlipayTradeWapPayViewModel viewMode)
        {
            var model = new AlipayTradeWapPayModel()
            {
                Body        = viewMode.Body,
                Subject     = viewMode.Subject,
                TotalAmount = viewMode.TotalAmount,
                OutTradeNo  = viewMode.OutTradeNo,
                ProductCode = viewMode.ProductCode,
            };
            var req = new AlipayTradeWapPayRequest();

            req.SetBizModel(model);
            req.SetNotifyUrl(viewMode.NotifyUrl);
            req.SetReturnUrl(viewMode.ReturnUrl);

            var response = await _client.PageExecuteAsync(req);

            return(Content(response.Body, "text/html;charset=utf-8"));
        }
        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);
        }
Example #29
0
 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);
        }