0

为什么当我将用户从我的本地主机重定向到 PAYPAL 的沙箱(https://www.sandbox.paypal.com)然后返回到 .aspx 页面(successful.aspx)后,它会丢失会话,

例如 SESSION["tempUser"],它适用于每个页面,但不适用于 Success.aspx 页面,它返回 null,我正在处理这个错误 2 周,但没有进展,我尝试了不同的浏览器,甚至不同的系统,更改了代码有点,但没有任何帮助,已经 1 个月以上,在几个表格上发表了几篇文章后,没有任何帮助,甚至 cookie 也有同样的问题,返回时为空,我之前的帖子。

重定向页面代码:

<body>
    <form id="form1" runat="server">
<div>
 <h4> Congrats <b> <%# Session["tempSubAdminName"]%>  </b>, Your basic informaton has been submitted , For full activation you need to pay via paypal. Please click the PayPal icon given below. </h4>
</div>
<div>
 <asp:HyperLink ID="homeBtnImage" runat="server" ImageUrl="~/btnPayPal.gif"
      NavigateUrl= "https://www.sandbox.paypal.com/us/cgi-bin/webscr?cmd=_xclick&business=smile2_1355775057_biz@yahoo.com&item_name=MemberShip&amount=20&currency=USD&return=http://127.0.0.1:57135/Online%20Recruitment%20System-Final/paymentSuccessful.aspx?emailAdmin='1234' &cancel_return=https://www.google.com/" >PayPal</asp:HyperLink>
</div>
<h6>Or if you don't have paypal account, click <asp:HyperLink ID="paypalSite" runat="server"
    NavigateUrl="https://www.sandbox.paypal.com/" >here</asp:HyperLink> </h6>
</form>

如果成功返回这个年龄

</head>
 <body>
   <form id="form1" runat="server">
   <div>
     <h5> Dear <%# Session["tempSubAdmin"] %>, You have successfully registered ,   Please wait for the approval by admin. </h5>
</div>
</form>

4

2 回答 2

0

我正在解释我实施的方式。它可能因人而异。

  1. 首先,您必须在开发人员 paypal api上创建一个帐户。帐户。
  2. 然后创建两个测试帐户,一个用于客户,另一个用于业务(商家)。
  3. 在web.config文件中声明这些值。

     <appSettings>    
        <!--these keys are for Paypal-->
        <add key="paypalURL" value="https://www.sandbox.paypal.com" />
        <add key="paypalAccount" value="arshad_Mer_biz@gmail.com" />
        <add key="websiteUrl" value="http://www.yourstie.com" />
      </appSettings>
    
  4. 现在您必须相应地设置 paypal html 变量,有关详细信息Paypal 变量

  5. 在button_click事件中编写以下代码

    string redirectUrl = ConfigurationManager.AppSettings["paypalURL"]+"/cgi-bin/webscr?cmd=_xclick";
    string sellersEmail = "&business=";
    string buyersEmail = "&email=";
    string productName = "&item_name=";
    string amount = "&amount=";
    string shippingOption = "&no_shipping=";
    string noteOpton = "&no_note=";
    string returnUrl = "&return=";
    string cancelUrl = "&cancel_return=";
    string rmOption = "&rm=";
    string notifyUrl = "&notify_url=";
    string custom = "&custom=";
    
    // Merchant account
    sellersEmail += ConfigurationManager.AppSettings["paypalAccount"];
    
    //calling a method that will return current user email id.
    buyersEmail += GeneralClass.GetUserEmail();
    
    //optional value if you want to carry
    custom += GeneralClass.GetUseriD();
    
    productName += lblProdeutName.Text;
    amount +=lblAmount.Text ;
    
    shippingOption += "1";                      //1 means no shipping option;
    noteOpton += "1";                           //1 means no note option;
    rmOption += "1";                            
    
    returnUrl +=ConfigurationManager.AppSettings["websiteUrl"]+"/PaypalThankYou.aspx";
    cancelUrl +=ConfigurationManager.AppSettings["websiteUrl"] + "/PaypalCancel.aspx";
    notifyUrl += ConfigurationManager.AppSettings["websiteUrl"] + "/PaypalNotifyUrl.aspx";
    
    redirectUrl += sellersEmail + buyersEmail + productName + amount + shippingOption +    noteOpton + returnUrl + cancelUrl + notifyUrl + rmOption + custom;
    Response.Redirect(redirectUrl);
    

取消页面:- 如果用户从 paypal 取消交易。它也适用于 localhost。
感谢页面:付款后paypal会跳转到该页面。
通知网址:有时称为 IPN(即时付款通知)。这是您将从贝宝获得价值的地方。它仅适用于托管页面。它不适用于本地主机

Notifyurl页面的代码
添加这些namespaces

 using System.Net;
 using System.IO;
 using System.Text;
 using System.Collections.Specialized;

page_load

  protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
         //Post back to either sandbox or live
        string strURL =ConfigurationManager.AppSettings["paypalURL"]+ "/cgi-bin/webscr";

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strURL);

        //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);
        string strResponse_copy = strRequest;  //Save a copy of the initial info sent by PayPal
        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
            // pull the values passed on the initial message from PayPal

            NameValueCollection these_argies = HttpUtility.ParseQueryString(strResponse_copy);

            string pay_stat = these_argies["payment_status"];

            //.
            //.  more args as needed look at the list from paypal IPN doc
            //.


            if (pay_stat.Equals("Completed"))
            {
            //inserting the database
                int intUserID;
                int.TryParse(these_argies["custom"],out intUserID);
                objUserEntity.UserID=intUserID;
                objPapalPayment.strTransactionID = these_argies["txn_id"];
                objPapalPayment.dblPaymentAmount = Convert.ToDouble(these_argies["payment_gross"]);
                objPapalPayment.strBuyerMail = these_argies["payer_email"];
                objPapalPayment.dtmDateAppliedOn = DateTime.Now;
                objPapalPayment.blnIsGlobalAdvertisement = true;
                objSubscription.blnIsPaid = false;
                objSubscription.blnSubscriptionWithHeld = true;
                objUserFunction.AddPaypalPayment(objUserEntity, objPapalPayment, objSubscription, enmSubscriptionType.Global);                         
            }


            // more checks needed here specially your account number and related stuff
        }
        else if (strResponse == "INVALID")
        {
            //log for manual investigation
        }
        else
        {
            //log response/ipn data for manual investigation
        }
        }
    }

那么你将如何在 localhost 上进行调试呢?使用价值rm=2;并将相同的代码粘贴到感谢页面的 page_load 事件中。它会起作用的。

更多详情: http: //www.codeproject.com/Articles/42894/Introduction-to-PayPal-for-C-ASP-NET-developers
Paypal 变量及其用法
希望对您有所帮助。

于 2012-12-30T19:51:44.647 回答
0

我认为您正在本地计算机上对此进行测试。

在重定向之前检查 cookie ASP.NET_SessionId 的值。

然后检查success.aspx调用后的值。

如果 cookie 丢失:Paypal 无法对您的 cookie 做任何事情。它只能在同一个域(本地主机)上更改。

我会在没有贝宝的情况下对此进行测试:只需一个简单的页面即可重定向到您的successful.aspx。如果 cookie 丢失,您可能配置了非常短的 Session Timeout,或者运行了一些删除 cookie 的代码(检查 global.asax)

于 2012-12-30T20:26:09.777 回答