Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (Request["oid"] == null)
                {
                    Response.Write("订单无效");
                    Response.End();
                }
                int OrderId;
                if (!int.TryParse(Request["oid"], out OrderId))
                {
                    Response.Write("订单无效");
                    Response.End();
                }
                Order = bllMall.GetOrderInfo(Request["oid"]);
                if (Order == null)
                {
                    Response.Write("订单无效");
                    Response.End();
                }
                if (!Order.PaymentStatus.Equals(0))
                {
                    Response.Write("订单不是未付款状态");
                    Response.End();
                }
                if (!Order.PaymentType.Equals(1))
                {
                    Response.Write("订单不属于支付宝支付");
                    Response.End();
                }
                if (string.IsNullOrEmpty(Order.PaymentTypeAutoId))
                {
                    Response.Write("无效支付方式");
                    Response.End();
                }
                WXMallPaymentType paymentType = bllMall.GetPaymentType(int.Parse(Order.PaymentTypeAutoId));
                if (paymentType == null)
                {
                    Response.Write("无效支付方式");
                    Response.End();
                }


                //支付宝网关地址
                string GATEWAY_NEW = "http://wappaygw.alipay.com/service/rest.htm?";

                ////////////////////////////////////////////调用授权接口alipay.wap.trade.create.direct获取授权码token////////////////////////////////////////////

                //返回格式
                string format = "xml";
                //必填,不需要修改

                //返回格式
                string v = "2.0";
                //必填,不需要修改

                //请求号
                string req_id = DateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(0, 99999);
                //必填,须保证每次请求都是唯一

                //req_data详细信息

                //服务器异步通知页面路径
                string notify_url = string.Format("http://{0}/alipay/mallnotifyurl.aspx", Request.Url.Host);
                //需http://格式的完整路径,不允许加?id=123这类自定义参数

                //页面跳转同步通知页面路径
                string call_back_url = string.Format("http://{0}/alipay/mallcall_back_url.aspx", Request.Url.Host);
                //需http://格式的完整路径,不允许加?id=123这类自定义参数

                //操作中断返回地址
                string merchant_url = string.Format("http://{0}/alipay/merchanturl.aspx", Request.Url.Host);
                //用户付款中途退出返回商户的地址。需http://格式的完整路径,不允许加?id=123这类自定义参数

                //卖家支付宝帐户
                //string seller_email = "*****@*****.**";

                string seller_email = paymentType.AlipaySeller_Account_Name;
                //必填

                //商户订单号
                string out_trade_no = Order.OrderID;
                //商户网站订单系统中唯一订单号,必填

                //订单名称
                string subject = string.Format("订单{0}", Order.OrderID);
                //必填

                //付款金额
                string total_fee = Order.TotalAmount.ToString();
                //必填

                //请求业务参数详细
                string req_dataToken = "<direct_trade_create_req><notify_url>" + notify_url + "</notify_url><call_back_url>" + call_back_url + "</call_back_url><seller_account_name>" + seller_email + "</seller_account_name><out_trade_no>" + out_trade_no + "</out_trade_no><subject>" + subject + "</subject><total_fee>" + total_fee + "</total_fee><merchant_url>" + merchant_url + "</merchant_url></direct_trade_create_req>";
                //必填

                //把请求参数打包成数组
                Dictionary <string, string> sParaTempToken = new Dictionary <string, string>();
                sParaTempToken.Add("partner", paymentType.AlipayPartner);
                sParaTempToken.Add("_input_charset", Config.Input_charset.ToLower());
                sParaTempToken.Add("sec_id", Config.Sign_type.ToUpper());
                sParaTempToken.Add("service", "alipay.wap.trade.create.direct");
                sParaTempToken.Add("format", format);
                sParaTempToken.Add("v", v);
                sParaTempToken.Add("req_id", req_id);
                sParaTempToken.Add("req_data", req_dataToken);

                //建立请求
                string sHtmlTextToken = Submit.BuildRequestMall(GATEWAY_NEW, sParaTempToken, paymentType.AlipayPartnerKey);
                //URLDECODE返回的信息
                Encoding code = Encoding.GetEncoding("utf-8");
                sHtmlTextToken = HttpUtility.UrlDecode(sHtmlTextToken, code);
                //using (System.IO.StreamWriter sr = new StreamWriter("D:\\MonitorHandlerException.txt"))
                //{
                //    sr.Write(sHtmlTextToken);
                //}
                //解析远程模拟提交后返回的信息
                Dictionary <string, string> dicHtmlTextToken = Submit.ParseResponse(sHtmlTextToken);

                //获取token
                string request_token = dicHtmlTextToken["request_token"];

                ////////////////////////////////////////////根据授权码token调用交易接口alipay.wap.auth.authAndExecute////////////////////////////////////////////


                //业务详细
                string req_data = "<auth_and_execute_req><request_token>" + request_token + "</request_token></auth_and_execute_req>";
                //必填

                //把请求参数打包成数组
                Dictionary <string, string> sParaTemp = new Dictionary <string, string>();
                sParaTemp.Add("partner", paymentType.AlipayPartner);
                sParaTemp.Add("_input_charset", Config.Input_charset.ToLower());
                sParaTemp.Add("sec_id", Config.Sign_type.ToUpper());
                sParaTemp.Add("service", "alipay.wap.auth.authAndExecute");
                sParaTemp.Add("format", format);
                sParaTemp.Add("v", v);
                sParaTemp.Add("req_data", req_data);

                //建立请求
                string sHtmlText = Submit.BuildRequestMall(GATEWAY_NEW, sParaTemp, "get", "确认", paymentType.AlipayPartnerKey);
                Response.Write(sHtmlText);
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
                Response.End();
            }
        }