隐藏

paypal集成到自己购物网站,支付成功,notify_url调用正常,INVALID状态获取成功,但是return页面需要手工点击按钮才能返回自己网站,怎么自动跳回?

发布:2015/1/6 13:43:47作者:管理员 来源:本站 浏览次数:1561

1)支付页面pay.aspx代码:
protected void Button1_Click(object sender, EventArgs e)
        {           
            Response.Write("<form action='https://www.paypal.com/cgi-bin/webscr' method='post' name='paypal'>");
            Response.Write("<input name='cmd' value='_xclick' type='hidden'>");
            Response.Write("<input type='hidden' name='notify_url' value='http://www.maiding.com/pp/notify.aspx/'>");
            Response.Write("<input name='business' value='"+email.Text+"' type='hidden'>");
            Response.Write("<input name='item_name' value='"+ordername.Text+"' type='hidden'>");
            Response.Write("<input name='return' value='http://www.maiding.com/pp/pay_ok_return.aspx/' type='hidden'>");
            Response.Write("<input type='hidden' name='cancel_return' value='http://www.maiding.com/pp/pay_fail_return.aspx/'>");
            Response.Write("<input name='item_number' value='" + number.Text + "' type='hidden'>");
            Response.Write("<input name='buyer_credit_promo_code' value='' type='hidden'>"); 
            Response.Write("<input name='buyer_credit_product_category' value='' type='hidden'>");
            Response.Write("<input name='buyer_credit_shipping_method' value='' type='hidden'>");
            Response.Write("<input name='buyer_credit_user_address_change' value='' type='hidden'>");
            Response.Write("<input name='no_shipping' value='0' type='hidden'>"); 
            Response.Write("<input name='cn' value='Information' type='hidden'>");
            Response.Write("<input name='no_note' value='0' type='hidden'>"); 
            Response.Write("<input name='currency_code' value='USD' type='hidden'>");
            Response.Write("<input name='bn' value='PP-BuyNowBF' type='hidden'>"); 
            Response.Write("<input value='"+why.Text+"' name='on0'>"); 
            Response.Write("<input value='Sender will be verified by telephone.' name='on1' type='hidden'>");
            Response.Write("<input name='os0' type='hidden'>");
            Response.Write("<input type='hidden' name='amount' value='"+money.Text+"'>");
            Response.Write("<input name='os1' type='hidden'><br>");
            Response.Write("<input src='https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif' name='submit' alt='Make payments with PayPal - it's fast, free and secure!' border='0' height='26' type='image' width='107'>");
            Response.Write("<img alt='' src='../../../pixel.gif' border='0' height='1' width='1'>");
            Response.Write("</form>");
        }

//======================================================
2)notify.aspx.cs 代码:
protected void Page_Load(object sender, EventArgs e)
        {
            //Post back to either sandbox or live
            //string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
            string strLive = "https://www.paypal.com/cgi-bin/webscr";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strLive);

            // Set values for the request back
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
            string strRequest = Encoding.ASCII.GetString(param);

            //////////
            StreamWriter w1 = new StreamWriter(Server.MapPath("recv1.txt"));
            w1.Write(strRequest);
            w1.Close();
            //////////

            strRequest += "&cmd=_notify-validate";
            req.ContentLength = strRequest.Length;

            //for proxy
            //WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
            //req.Proxy = proxy;

            //Send the request to PayPal and get the response
            StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
            streamOut.Write(strRequest);
            streamOut.Close();
            StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
            string strResponse = streamIn.ReadToEnd();
            streamIn.Close();

            if (strResponse == "VERIFIED")
            {
            // check the payment_status is Completed
            // check that txn_id has not been previously processed
            // check that receiver_email is your Primary PayPal email
            // check that payment_amount/payment_currency are correct
            // process payment
                StreamWriter w2 = new StreamWriter(Server.MapPath("VERIFIED.txt"));
                w2.Write("VERIFIED");
                w2.Close();


            }
            else if (strResponse == "INVALID")
            {
            // log for manual investigation
                StreamWriter w3 = new StreamWriter(Server.MapPath("INVALID.txt"));
                w3.Write("INVALID");
                w3.Close();
            }
            else
            {
            //log response/ipn data for manual investigation
            }
        }


//======================================================
3)pay_ok_return.aspx
<head runat="server">
    <title>支付返回</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        支付成功---------------<br>
    </div>
    </form>
</body>
</html>


现在支付成功,notify_url调用正常,INVALID状态获取也成功,就是return页面需要手工点击按钮才能返回自己网站,怎么自动跳回?