Example #1
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);

            // 外部订单号,商户网站订单系统中唯一的订单号
            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();

            // 组装业务参数model
            AlipayTradePagePayModel model = new AlipayTradePagePayModel();

            model.Body        = body;
            model.Subject     = subject;
            model.TotalAmount = total_amout;
            model.OutTradeNo  = out_trade_no;
            model.ProductCode = "FAST_INSTANT_TRADE_PAY";

            AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();

            // 设置同步回调地址
            request.SetReturnUrl("http://localhost:57554/Return_url.aspx");
            // 设置异步通知接收地址
            request.SetNotifyUrl("");
            // 将业务model载入到request
            request.SetBizModel(model);

            AlipayTradePagePayResponse response = null;

            try
            {
                response = client.pageExecute(request, null, "post");
                Response.Write(response.Body);
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
Example #2
0
        public ActionResult AliPay(int productId, string payMethod)
        {
            pay_order      order   = this.CreateOrder(productId, payMethod);
            module_product product = entity.module_product.FirstOrDefault(p => p.id == order.product_id);
            var            setting = entity.lay_setting;

            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 = order.number;
            // 订单名称
            string subject = setting.FirstOrDefault(p => p.key == "sitename").value + product.name;
            // 付款金额
            //string total_amout = Math.Ceiling(order.price.Value * 100).ToString();
            string total_amout = 0.01.ToString();
            // 商品描述
            string body = setting.FirstOrDefault(p => p.key == "sitename").value + product.name;
            // 组装业务参数model
            AlipayTradePagePayModel model = new AlipayTradePagePayModel();

            model.Body        = body;
            model.Subject     = subject;
            model.TotalAmount = total_amout;
            model.OutTradeNo  = out_trade_no;
            model.ProductCode = "FAST_INSTANT_TRADE_PAY";
            AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();

            // 设置同步回调地址
            request.SetReturnUrl(HttpContext.Request.Url.Scheme + "://" + HttpContext.Request.Url.Host + "/Member/Index");
            // 设置异步通知接收地址
            request.SetNotifyUrl(HttpContext.Request.Url.Scheme + "://" + HttpContext.Request.Url.Host + "/Pay/AliPayNotify");
            // 将业务model载入到request
            request.SetBizModel(model);
            AlipayTradePagePayResponse response = null;

            try
            {
                response = client.pageExecute(request, null, "post");
                Response.Write(response.Body);
            }
            catch (Exception exp)
            {
                throw exp;
            }
            return(null);
        }
Example #3
0
        public string AlipayTradePagePay(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;

            AlipayTradePagePayResponse response = null;
            //PC访问
            AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();

            // 设置同步回调地址
            request.SetReturnUrl(_webHelper.GetStoreLocation(false) + "Plugins/PaymentAliPay/Return");
            // 设置异步通知接收地址
            request.SetNotifyUrl(_webHelper.GetStoreLocation(false) + "Plugins/PaymentAliPay/Notify");
            // 将业务model载入到request
            request.SetBizModel(new AlipayTradePagePayModel()
            {
                Body        = body,
                Subject     = subject,
                TotalAmount = total_amout,
                OutTradeNo  = out_trade_no,
                ProductCode = "FAST_INSTANT_TRADE_PAY"
            });
            try
            {
                response = client.pageExecute(request, null, "post");
                return(response.Body);
            }
            catch (Exception exp)
            {
                _logger.Information($"{DateTime.Now.ToLocalTime().ToString()}AliPagePay:{exp.Message}");
                return("<script>alert('AlipayTradePagePay Failed!');</script>");
            }
        }
Example #4
0
        public JsonResult TestAPP()
        {
            #region App支付
            //IAopClient client = new DefaultAopClient(AlipayPaymentConfigHelper.Server_Url, AlipayPaymentConfigHelper.App_Id, AlipayPaymentConfigHelper.PrivateKeyPem, AlipayPaymentConfigHelper.Format, AlipayPaymentConfigHelper.Version, AlipayPaymentConfigHelper.Sign_Type, AlipayPaymentConfigHelper.PublicKeyPem, AlipayPaymentConfigHelper.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.Body = "我是测试数据";
            //model.Subject = "App支付测试DoNet";
            //model.TotalAmount = "0.01";
            //model.ProductCode = "QUICK_MSECURITY_PAY";
            //Random rad = new Random();
            //string NoId = rad.Next(1000, 9999).ToString() + Guid.NewGuid().ToString().Split('-')[rad.Next(1, 4)] + rad.Next(1000, 9999) + Guid.NewGuid().ToString().Split('-')[rad.Next(1, 4)];
            //model.OutTradeNo = NoId;
            //model.TimeoutExpress = "30m";
            //request.SetBizModel(model);
            ////这里和普通的接口调用不同,使用的是sdkExecute
            //AlipayTradeAppPayResponse response = client.SdkExecute(request);
            ////HttpUtility.HtmlEncode是为了输出到页面时防止被浏览器将关键参数html转义,实际打印到日志以及http传输不会有这个问题
            //Response.Write(HttpUtility.HtmlEncode(response.Body));
            ////页面输出的response.Body就是orderString 可以直接给客户端请求,无需再做处理。
            #endregion

            #region 电脑网站支付
            Random     rad    = new Random();
            string     NoId   = rad.Next(1000, 9999).ToString() + Guid.NewGuid().ToString().Split('-')[rad.Next(1, 4)] + rad.Next(1000, 9999) + Guid.NewGuid().ToString().Split('-')[rad.Next(1, 4)];
            IAopClient client = new DefaultAopClient(AlipayPaymentConfigHelper.Server_Url, AlipayPaymentConfigHelper.App_Id, AlipayPaymentConfigHelper.PrivateKeyPem, AlipayPaymentConfigHelper.Format, AlipayPaymentConfigHelper.Version, AlipayPaymentConfigHelper.Sign_Type, AlipayPaymentConfigHelper.PublicKeyPem, AlipayPaymentConfigHelper.Charset, false);
            AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
            request.BizContent = "{" +
                                 "    \"body\":\"Iphone6 16G\"," +
                                 "    \"subject\":\"Iphone6 16G\"," +
                                 "    \"out_trade_no\":\"" + NoId + "\"," +
                                 "    \"total_amount\":88.88," +
                                 "    \"product_code\":\"FAST_INSTANT_TRADE_PAY\"" +
                                 "  }";
            AlipayTradePagePayResponse response = client.pageExecute(request);
            //string form = response.Body;
            #endregion

            OperationResult result = new OperationResult(OperationResultType.Success, "", response.Body.ToString());
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Example #5
0
        /// <summary>
        /// 转换参数数组为业务网对象
        /// </summary>
        /// <param name="_sArray"></param>
        public override void ParseToBizModel(Dictionary <string, string> _sArray = null)
        {
            if (null == _sArray)
            {
                _sArray = this.sArray;
            }

            this.BizModel             = new AlipayTradePagePayResponse();
            this.BizModel.OutTradeNo  = _sArray["out_trade_no"];
            this.BizModel.SellerId    = _sArray["seller_id"];
            this.BizModel.TotalAmount = _sArray["total_amount"].ToDecimal();
            this.BizModel.TradeNo     = _sArray["trade_no"];
            if (string.IsNullOrEmpty(this.BizModel.OutTradeNo))
            {
                throw new Exception("out_trade_no is empty!");
            }
            if (string.IsNullOrEmpty(this.BizModel.TradeNo))
            {
                throw new Exception("trade_no is empty!");
            }
        }
Example #6
0
        //private ResultInfo Redirect2Pay(string desc, decimal fee, string payOrderID, string returnUrl, string notifyUrl, Action errorCallBack)
        private ResultInfo Redirect2Pay(string desc, decimal fee, string payOrderID, string returnUrl, string notifyUrl)
        {
            ResultInfo ri = new ResultInfo();

            DefaultAopClient        client      = new DefaultAopClient(AliPayConfig.gatewayUrl, AliPayConfig.app_id, AliPayConfig.private_key, "json", "1.0", AliPayConfig.sign_type, AliPayConfig.alipay_public_key, AliPayConfig.charset, false);
            AlipayTradePagePayModel alipayModel = new AlipayTradePagePayModel();

            alipayModel.Body        = desc;
            alipayModel.Subject     = desc;
            alipayModel.TotalAmount = fee.ToString();
            alipayModel.OutTradeNo  = payOrderID;
            alipayModel.ProductCode = "FAST_INSTANT_TRADE_PAY";

            AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();

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

            AlipayTradePagePayResponse response = null;

            try
            {
                response = client.pageExecute(request, null, "post");
                ri.Ok    = true;
                ri.Url   = "/Pay/PayRedirect";
                Session["AliPayForm" + UserID.ToString()] = response.Body;
            }
            catch
            {
                ri.Msg = "支付过程中出现异常,请重试!";
                //errorCallBack();
            }
            return(ri);
        }
Example #7
0
        /// <summary>
        /// 网页版 提交支付即可
        /// </summary>
        public void PostAlipay(string orderNo, string totalFee, string subject, string body)
        {
            // pr单号,即为订单编号;
            //var url = AliPayHelper.CreateRSASignedOrderString(entity.BPR_CODE, 0.01, entity.BPR_CODE);
            //FileLogHelper.WriteLog("signal:"+ url);

            AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();

            request.SetReturnUrl(AlipayConfig.ReturnUrl);
            request.SetNotifyUrl(AlipayConfig.NotifyUrl);
            AlipayTradePayModel model = new AlipayTradePayModel();

            model.Body        = body;
            model.Subject     = subject;
            model.TotalAmount = totalFee;
            model.ProductCode = "FAST_INSTANT_TRADE_PAY";
            model.OutTradeNo  = orderNo;

            request.SetBizModel(model);
            AlipayTradePagePayResponse response = null;

            try
            {
                System.Web.HttpContext.Current.Response.Write("正在跳转支付宝支付");
                IAopClient client = new DefaultAopClient(AlipayConfig.GatewayUrl, AlipayConfig.AppId,
                                                         AlipayConfig.MerchantPrivateKey, "json", "1.0",
                                                         AlipayConfig.SignType, AlipayConfig.AlipayPublicKey, "utf-8");

                response = client.pageExecute(request);
                System.Web.HttpContext.Current.Response.Clear();
                System.Web.HttpContext.Current.Response.ContentType = "text/html";
                System.Web.HttpContext.Current.Response.Write(response.Body);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public string pay(AlipayTradePagePayModel para)
        {
            try
            {
                AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
                // 设置同步回调地址
                request.SetReturnUrl("");
                // 设置异步通知接收地址
                request.SetNotifyUrl("");
                // 将业务model载入到request

                para.QrPayMode = "2";
                request.SetBizModel(para);

                AlipayTradePagePayResponse response = client.PageExecute(request, null, "post");
                return(response.Body);
            }
            catch (Exception e)
            {
                Logger.Error("失败", e);
                return("支付失败");
            }
        }
Example #9
0
        /// 发起支付请求
        /// </summary>
        /// <param name="tradeno">外部订单号,商户网站订单系统中唯一的订单号</param>
        /// <param name="subject">订单名称</param>
        /// <param name="totalAmout">付款金额</param>
        /// <param name="itemBody">商品描述</param>
        public void PayRequest(string tradeno, string subject, string totalAmout, string itemBody)
        {
            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);

            // 组装业务参数model
            AlipayTradePagePayModel model = new AlipayTradePagePayModel();

            // 商品描述
            model.Body = itemBody;
            // 订单名称
            model.Subject = subject;
            // 付款金额
            model.TotalAmount = totalAmout;
            // 外部订单号,商户网站订单系统中唯一的订单号
            model.OutTradeNo  = tradeno;
            model.ProductCode = "FAST_INSTANT_TRADE_PAY";

            AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();

            // 设置同步回调地址
            request.SetReturnUrl("http://19171zn332.imwork.net:22070/Pay/Callback");
            // 设置异步通知接收地址
            request.SetNotifyUrl("");
            // 将业务model载入到request
            request.SetBizModel(model);
            AlipayTradePagePayResponse response = null;

            try
            {
                response = client.pageExecute(request, null, "post");
                Response.Write(response.Body);
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
        public void PayRequest(string tradeno, string subject, string totalAmout, string itemBody)
        {
            DefaultAopClient client = new DefaultAopClient(Config.Gatewayurl, Config.AppId, Config.PrivateKey, "json", "2.0",
                                                           Config.SignType, Config.AlipayPublicKey, Config.CharSet, false);

            // 组装业务参数model
            AlipayTradePagePayModel model = new AlipayTradePagePayModel();

            model.Body        = itemBody;
            model.Subject     = subject;
            model.TotalAmount = totalAmout;
            model.OutTradeNo  = tradeno;
            model.ProductCode = "FAST_INSTANT_TRADE_PAY";

            AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();

            // 设置同步回调地址
            request.SetReturnUrl("http://localhost:5000/Pay/Callback");
            // 设置异步通知接收地址
            request.SetNotifyUrl("");
            // 将业务model载入到request
            request.SetBizModel(model);

            AlipayTradePagePayResponse response = null;

            try
            {
                response = client.SdkExecute(request);
                Console.WriteLine($"订单支付发起成功,订单号:{tradeno}");
                Response.Redirect(Config.Gatewayurl + "?" + response.Body);
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
Example #11
0
        public ActionResult Index(FormCollection coll)
        {
            double amount = Convert.ToDouble(coll["EnterAmount"]);

            //实例化默认的DefaultAopClient
            DefaultAopClient aop = new DefaultAopClient(AlipayConfig.gateURL, AlipayConfig.APPID, AlipayConfig.private_Key, "json", "1.0", AlipayConfig.sign_Type, AlipayConfig.public_Key, AlipayConfig.charset);//AlipayConfig.charset可写可不写,默认为UTF-8

            AlipayTradePagePayModel model = new AlipayTradePagePayModel();

            model.Body = "叫姐姐姐姐姐姐姐姐姐姐姐姐姐姐";

            model.Subject = "沙箱模拟";
            //精确到小数点后2位
            model.TotalAmount = amount.ToString();
            //商品唯一编号
            model.OutTradeNo = Guid.NewGuid().ToString().ToLower();
            //支付类型
            model.ProductCode = "FAST_INSTANT_TRADE_PAY";

            //支付宝请求
            AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();

            //支付成功后的跳转页面
            request.SetReturnUrl("http://localhost:3322/Home/Success");
            request.SetNotifyUrl("");
            //封装支付宝模型到请求对象中
            request.SetBizModel(model);

            //支付宝响应
            AlipayTradePagePayResponse response = null;

            response = aop.pageExecute(request, null, "post");
            Response.Write(response.Body);

            return(View());
        }
Example #12
0
        /// <summary>
        /// 创建订单
        /// </summary>
        /// <param name="setid"></param>
        /// <param name="paytype"></param>
        /// <returns></returns>
        public string createOrder(int setid, int paytype)
        {
            if (paytype > 2)
            {
                return(JsonConvert.SerializeObject(new repmsg
                {
                    state = 0,
                    msg = "支付方式不正确"
                }));
            }
            int userid = User.userid;

            //创建订单
            using (shhouseEntities ent = new shhouseEntities())
            {
                ObjectParameter ordernum = new ObjectParameter("ordernum", typeof(string));
                ObjectParameter setname  = new ObjectParameter("setname", typeof(string));
                ObjectParameter state    = new ObjectParameter("state", typeof(int));
                ObjectParameter totals   = new ObjectParameter("totals", typeof(int));
                ObjectParameter msg      = new ObjectParameter("msg", typeof(string));
                ent.order_create_jjr2018(userid, DateTime.Now, DateTime.Now.AddHours(2), setid, 1, paytype, ordernum, setname, totals, state, msg);

                int _state = (int)state.Value;
                if (_state == 1)
                {
                    if (paytype == 1)
                    {
                        IAopClient client = new DefaultAopClient(
                            "https://openapi.alipay.com/gateway.do",
                            "APPID",
                            "APP_PRIVATE_KEY",
                            "json",
                            "1.0",
                            "RSA2",
                            "ALIPAY_PUBLIC_KEY",
                            "UTF-8",
                            false
                            );
                        //支付宝支付
                        AlipayTradePagePayModel model = new AlipayTradePagePayModel
                        {
                            Body        = (string)setname.Value,
                            Subject     = (string)setname.Value,
                            TotalAmount = Math.Round((decimal)totals.Value / 100m, 2).ToString(),
                            OutTradeNo  = (string)ordernum.Value,
                            ProductCode = "FAST_INSTANT_TRADE_PAY"
                        };

                        AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
                        // 设置同步回调地址
                        request.SetReturnUrl("");
                        // 设置异步通知接收地址
                        request.SetNotifyUrl("");
                        // 将业务model载入到request
                        request.SetBizModel(model);

                        try
                        {
                            AlipayTradePagePayResponse response = client.SdkExecute(request);
                            //支付宝支付地址
                            string url = "https://openapi.alipay.com/gateway.do?" + response.Body;
                            //Response.Write(response.Body);

                            return(JsonConvert.SerializeObject(new repmsg
                            {
                                state = 1,
                                msg = "",
                                data = new
                                {
                                    tradeno = (string)ordernum.Value,
                                    total = (int)totals.Value,
                                    paytype = paytype,
                                    url = url
                                }
                            }));
                        }
                        catch (Exception exp)
                        {
                            return(JsonConvert.SerializeObject(new repmsg
                            {
                                state = 0,
                                msg = exp.Message
                            }));
                        }
                    }
                    else if (paytype == 2)
                    {
                        try
                        {
                            //微信支付
                            NativePay nativePay = new NativePay();

                            string url = nativePay.GetPayUrl(setid.ToString(), (string)setname.Value, (string)ordernum.Value, (int)totals.Value);

                            if (string.IsNullOrEmpty(url))
                            {
                                return(JsonConvert.SerializeObject(new repmsg
                                {
                                    state = 0,
                                    msg = "订单创建失败"
                                }));
                            }

                            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
                            qrCodeEncoder.QRCodeEncodeMode   = QRCodeEncoder.ENCODE_MODE.BYTE;
                            qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
                            qrCodeEncoder.QRCodeVersion      = 0;
                            qrCodeEncoder.QRCodeScale        = 8;

                            //将字符串生成二维码图片
                            Bitmap image = qrCodeEncoder.Encode(url, Encoding.Default);
                            string _root = Server.MapPath($"~/wxpaycode/{userid}/");
                            if (!System.IO.Directory.Exists(_root))
                            {
                                System.IO.Directory.CreateDirectory(_root);
                            }
                            string _filename = Guid.NewGuid().ToString().Replace("-", "") + ".jpg";
                            image.Save(_root + _filename, System.Drawing.Imaging.ImageFormat.Jpeg);

                            return(JsonConvert.SerializeObject(new repmsg
                            {
                                state = 1,
                                msg = "",
                                data = new
                                {
                                    tradeno = (string)ordernum.Value,
                                    setname = (string)setname.Value,
                                    total = (int)totals.Value,
                                    paytype = paytype,
                                    qrimg = $"/wxpaycode/{userid}/{_filename}"
                                }
                            }));
                        }
                        catch (Exception e)
                        {
                            return(JsonConvert.SerializeObject(new repmsg
                            {
                                state = 0,
                                msg = e.Message
                            }));
                        }
                    }
                    else
                    {
                        return("");
                    }
                }
                else
                {
                    return(JsonConvert.SerializeObject(new repmsg
                    {
                        state = 0,
                        msg = "提交失败,请稍后再试"
                    }));
                }
            }
        }
Example #13
0
        // coupon orderId(流水账号?)
        public void SubmitOrder()
        {
            int       num             = 0;
            string    finalTotalPrice = (string)Request.Form["finalTotalPrice"];
            BookOrder bookOrder       = new BookOrder();

            bookOrder.UserId     = (int)Session["userId"];
            bookOrder.TotalPrice = Double.Parse(finalTotalPrice);
            bookOrder.Status     = 0;
            bookOrder.createDate = System.DateTime.Now;
            int orderId = orderMapper.addBookOrder(bookOrder);

            if (Session["Cart"] != null)
            {
                List <Book> BookList     = (List <Book>)Session["Cart"];
                List <Book> newBookList  = new List <Book>(); //CartRemain
                List <Book> cartItemList = new List <Book>(); //CartSelected
                foreach (Book item in BookList)
                {
                    string fg = Session[item.BookId.ToString() + "select"].ToString();
                    if (fg == "true")
                    {
                        Models.OrderItem orderItem = new Models.OrderItem();
                        orderItem.OrderId  = orderId;
                        orderItem.BookId   = item.BookId;
                        orderItem.quantity = (int)Session[orderItem.BookId.ToString()];
                        orderMapper.addOrderItem(orderItem);
                        Session[item.BookId.ToString() + "select"] = null;
                        cartItemList.Add(item);
                    }
                    else
                    {
                        num += 1;
                        newBookList.Add(item);
                    }
                }
                Session["num"]          = num;
                Session["cartItemList"] = cartItemList;
                Session["Cart"]         = newBookList;
            }



            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 = orderId.ToString() + "-" + DateTime.Now.ToString("yyyyMMddHHmmss");
            // 订单名称
            string subject = "DuangDuangBook";
            // 付款金额
            string total_amout = finalTotalPrice;
            // 商品描述
            string body = "";


            // 组装业务参数model
            AlipayTradePagePayModel model = new AlipayTradePagePayModel();

            model.Body        = body;
            model.Subject     = subject;
            model.TotalAmount = total_amout;
            model.OutTradeNo  = out_trade_no;
            model.ProductCode = "FAST_INSTANT_TRADE_PAY";

            AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();

            // 设置同步回调地址
            request.SetReturnUrl("http://localhost:51372/Pay/ReturnUrl");
            // 设置异步通知接收地址
            request.SetNotifyUrl("");
            // 将业务model载入到request
            request.SetBizModel(model);

            AlipayTradePagePayResponse response = null;

            try
            {
                response = client.pageExecute(request, null, "post");
                Response.Write(response.Body);
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
Example #14
0
        /// <summary>
        /// 统一收单下单并支付页面接口
        /// </summary>
        public void Trade_Page(AlipayConfig config, Trade_PageInput input)
        {
            //AlipayConfig config = new AlipayConfig()
            //{
            //    serverUrl = "https://openapi.alipay.com/gateway.do",
            //    appId= "app_id",
            //    privateKeyPem= "merchant_private_key",
            //    format= "json",
            //    version= "1.0",
            //    signType= "RSA2",
            //    alipayPulicKey= "alipay_public_key",
            //    charset= "GBK",
            //    keyFromFile=false
            //};
            IAopClient client = new DefaultAopClient(config.serverUrl, config.appId, config.privateKeyPem, config.format, config.version, config.signType, config.alipayPulicKey, config.charset, config.keyFromFile);
            AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();

            request.BizContent = "{" +
                                 "\"out_trade_no\":\"20150320010101001\"," +
                                 "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"," +
                                 "\"total_amount\":88.88," +
                                 "\"subject\":\"Iphone6 16G\"," +
                                 "\"body\":\"Iphone6 16G\"," +
                                 "\"time_expire\":\"2016-12-31 10:05\"," +
                                 "      \"goods_detail\":[{" +
                                 "        \"goods_id\":\"apple-01\"," +
                                 "\"alipay_goods_id\":\"20010001\"," +
                                 "\"goods_name\":\"ipad\"," +
                                 "\"quantity\":1," +
                                 "\"price\":2000," +
                                 "\"goods_category\":\"34543238\"," +
                                 "\"body\":\"特价手机\"," +
                                 "\"show_url\":\"http://www.alipay.com/xxx.jpg\"" +
                                 "        }]," +
                                 "\"passback_params\":\"merchantBizType%3d3C%26merchantBizNo%3d2016010101111\"," +
                                 "\"extend_params\":{" +
                                 "\"sys_service_provider_id\":\"2088511833207846\"," +
                                 "\"hb_fq_num\":\"3\"," +
                                 "\"hb_fq_seller_percent\":\"100\"," +
                                 "\"industry_reflux_info\":\"{\\\\\\\"scene_code\\\\\\\":\\\\\\\"metro_tradeorder\\\\\\\",\\\\\\\"channel\\\\\\\":\\\\\\\"xxxx\\\\\\\",\\\\\\\"scene_data\\\\\\\":{\\\\\\\"asset_name\\\\\\\":\\\\\\\"ALIPAY\\\\\\\"}}\"," +
                                 "\"card_type\":\"S0JP0000\"" +
                                 "    }," +
                                 "\"goods_type\":\"0\"," +
                                 "\"timeout_express\":\"90m\"," +
                                 "\"promo_params\":\"{\\\"storeIdType\\\":\\\"1\\\"}\"," +
                                 "\"royalty_info\":{" +
                                 "\"royalty_type\":\"ROYALTY\"," +
                                 "        \"royalty_detail_infos\":[{" +
                                 "          \"serial_no\":1," +
                                 "\"trans_in_type\":\"userId\"," +
                                 "\"batch_no\":\"123\"," +
                                 "\"out_relation_id\":\"20131124001\"," +
                                 "\"trans_out_type\":\"userId\"," +
                                 "\"trans_out\":\"2088101126765726\"," +
                                 "\"trans_in\":\"2088101126708402\"," +
                                 "\"amount\":0.1," +
                                 "\"desc\":\"分账测试1\"," +
                                 "\"amount_percentage\":\"100\"" +
                                 "          }]" +
                                 "    }," +
                                 "\"sub_merchant\":{" +
                                 "\"merchant_id\":\"19023454\"," +
                                 "\"merchant_type\":\"alipay: 支付宝分配的间连商户编号, merchant: 商户端的间连商户编号\"" +
                                 "    }," +
                                 "\"enable_pay_channels\":\"pcredit,moneyFund,debitCardExpress\"," +
                                 "\"store_id\":\"NJ_001\"," +
                                 "\"disable_pay_channels\":\"pcredit,moneyFund,debitCardExpress\"," +
                                 "\"qr_pay_mode\":\"1\"," +
                                 "\"qrcode_width\":100," +
                                 "\"settle_info\":{" +
                                 "        \"settle_detail_infos\":[{" +
                                 "          \"trans_in_type\":\"cardSerialNo\"," +
                                 "\"trans_in\":\"A0001\"," +
                                 "\"summary_dimension\":\"A0001\"," +
                                 "\"settle_entity_id\":\"2088xxxxx;ST_0001\"," +
                                 "\"settle_entity_type\":\"SecondMerchant、Store\"," +
                                 "\"amount\":0.1" +
                                 "          }]" +
                                 "    }," +
                                 "\"invoice_info\":{" +
                                 "\"key_info\":{" +
                                 "\"is_support_invoice\":true," +
                                 "\"invoice_merchant_name\":\"ABC|003\"," +
                                 "\"tax_num\":\"1464888883494\"" +
                                 "      }," +
                                 "\"details\":\"[{\\\"code\\\":\\\"100294400\\\",\\\"name\\\":\\\"服饰\\\",\\\"num\\\":\\\"2\\\",\\\"sumPrice\\\":\\\"200.00\\\",\\\"taxRate\\\":\\\"6%\\\"}]\"" +
                                 "    }," +
                                 "\"agreement_sign_params\":{" +
                                 "\"personal_product_code\":\"GENERAL_WITHHOLDING_P\"," +
                                 "\"sign_scene\":\"INDUSTRY|CARRENTAL\"," +
                                 "\"external_agreement_no\":\"test\"," +
                                 "\"external_logon_id\":\"13852852877\"," +
                                 "\"sign_validity_period\":\"2m\"," +
                                 "\"third_party_type\":\"PARTNER\"," +
                                 "\"buckle_app_id\":\"1001164\"," +
                                 "\"buckle_merchant_id\":\"268820000000414397785\"," +
                                 "\"promo_params\":\"{\\\"key\\\",\\\"value\\\"}\"" +
                                 "    }," +
                                 "\"integration_type\":\"PCWEB\"," +
                                 "\"request_from_url\":\"https://\"," +
                                 "\"business_params\":\"{\\\"data\\\":\\\"123\\\"}\"," +
                                 "\"ext_user_info\":{" +
                                 "\"name\":\"李明\"," +
                                 "\"mobile\":\"16587658765\"," +
                                 "\"cert_type\":\"IDENTITY_CARD\"," +
                                 "\"cert_no\":\"362334768769238881\"," +
                                 "\"min_age\":\"18\"," +
                                 "\"fix_buyer\":\"F\"," +
                                 "\"need_check_info\":\"F\"" +
                                 "    }" +
                                 "  }";
            AlipayTradePagePayResponse response = client.pageExecute(request);

            Console.WriteLine(response.Body);
        }
Example #15
0
        public ActionResult PcPay()
        {
            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);
            AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();

            request.SetNotifyUrl("http://1x687f9296.iok.la/AliPay/Receive_notify");
            request.SetReturnUrl("http://www.baidu.com");



            //-----------------
            //AlipayTradePayModel model = new AlipayTradePayModel();
            //model.OutTradeNo = out_trade_no;
            //model.ProductCode = "FAST_INSTANT_TRADE_PAY";
            //model.TotalAmount = "8.88";
            //model.Subject = "zhifu";
            //model.Body = "zhifu";
            //request.SetBizModel(model);

            ///------------
            //    request.BizContent = "{" +
            //"    \"out_trade_no\":\"" + out_trade_no + "\"," +
            //"    \"product_code\":\"FAST_INSTANT_TRADE_PAY\"," +
            //"    \"total_amount\":88.88," +
            //"    \"subject\":\"Iphone616G\"," +
            //"    \"body\":\"Iphone616G\"," +

            //"  }";//填充业务参数

            //request.BizContent = "{" +
            //    "\"out_trade_no\":\"" + out_trade_no + "\"," +
            //    "\"scene\":\"bar_code\"," +
            //    "\"auth_code\":\"28763443825664394\"," +
            //    "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"," +// FACE_TO_FACE_PAYMENT
            //    "\"subject\":\"Iphone616G\"," +
            //    "\"buyer_id\":\"2088202954065786\"," +
            //    "\"seller_id\":\"2088102146225135\"," +
            //    "\"total_amount\":88.88," +
            //    "\"discountable_amount\":8.88," +
            //    "\"body\":\"Iphone616G\"," +
            //    "\"goods_detail\":[{" +
            //    "\"goods_id\":\"apple-01\"," +
            //    "\"goods_name\":\"ipad\"," +
            //    "\"quantity\":1," +
            //    "\"price\":2000," +
            //    "\"goods_category\":\"34543238\"," +
            //    "\"body\":\"特价手机\"," +
            //    "\"show_url\":\"http://www.alipay.com/xxx.jpg\"" +
            //    "}]," +
            //    "\"operator_id\":\"yx_001\"," +
            //    "\"store_id\":\"NJ_001\"," +
            //    "\"terminal_id\":\"NJ_T_001\"," +
            //    "\"extend_params\":{" +
            //    "\"sys_service_provider_id\":\"2088511833207846\"" +
            //    "}," +
            //    "\"timeout_express\":\"90m\"" +
            //    "}";

            request.BizContent = "{" +
                                 "    \"body\":\"Iphone6 16G\"," +
                                 "    \"subject\":\"Iphone6 16G\"," +
                                 "    \"out_trade_no\":\"" + out_trade_no + "\"," +
                                 "    \"total_amount\":88.88," +
                                 "    \"product_code\":\"FAST_INSTANT_TRADE_PAY\"" +
                                 "  }";
            AlipayTradePagePayResponse response = client.pageExecute(request);

            return(Content(response.Body));
        }
Example #16
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            int    userid          = int.Parse(Session["UserID"].ToString());
            float  goodprice       = float.Parse(this.Label2.Text);
            float  carriageprice   = float.Parse(this.DropDownList1.SelectedValue.ToString());
            float  totalprice      = goodprice + carriageprice;
            string receivername    = this.TextBox4.Text.Trim();
            string receiverphone   = this.TextBox5.Text.Trim();
            string receiveremail   = this.TextBox6.Text.Trim();
            string receiveraddress = this.TextBox7.Text.Trim();
            string remark          = this.TextBox8.Text.Trim();
            string generatetime    = DateTime.Now.ToString();

            string        sql     = "insert into [Order] values('" + userid + "','" + goodprice + "','" + carriageprice + "','" + totalprice + "','" + receivername + "','" + receiveraddress + "','" + receiverphone + "','" + receiveremail + "','待付款','" + generatetime + "',null,null,'" + remark + "') select SCOPE_IDENTITY() as 'OrderID'";
            SqlDataReader dr      = db.redr(sql);
            string        orderid = null;

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    orderid = dr["OrderID"].ToString();
                }
            }
            else
            {
                Response.Write("<script>alert('订单创建失败')</script>");
            }

            int   goodid;
            int   goodnum;
            float singleprice;
            float allprice;

            foreach (GridViewRow gridViewRow in this.GridView1.Rows)
            {
                goodid      = int.Parse(gridViewRow.Cells[1].Text);
                goodnum     = int.Parse(gridViewRow.Cells[3].Text);
                singleprice = float.Parse(gridViewRow.Cells[4].Text);
                allprice    = float.Parse(gridViewRow.Cells[5].Text);
                sql         = "insert into OrderDetail values('" + goodid + "','" + goodnum + "','" + singleprice +
                              "','" + allprice + "','" + orderid + "')";
                if (!db.exsql(sql))
                {
                    Response.Write("<script>alert('订单创建失败')</script>");
                }
            }
            Session["ShoppingCart"] = null;
            Response.Write("<script>alert('下单成功,请尽快支付')</script>");



            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 = orderid.ToString();

            // 订单名称
            string subject = "安徽大学校园物品交易系统结算中心";

            // 付款金额
            string total_amout = totalprice.ToString();

            // 商品描述
            string body = "test";

            // 组装业务参数model
            AlipayTradePagePayModel model = new AlipayTradePagePayModel();

            model.Body        = body;
            model.Subject     = subject;
            model.TotalAmount = total_amout;
            model.OutTradeNo  = out_trade_no;
            model.ProductCode = "FAST_INSTANT_TRADE_PAY";

            AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();

            // 设置同步回调地址
            request.SetReturnUrl(config.nataddress + "/Return_url.aspx");
            // 设置异步通知接收地址
            request.SetNotifyUrl(config.nataddress + "/Notify_url.aspx");
            // 将业务model载入到request
            request.SetBizModel(model);

            AlipayTradePagePayResponse response = null;

            try
            {
                response = client.pageExecute(request, null, "post");
                Response.Write(response.Body);
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }