gpt4 book ai didi

c# - ASP.NET C# 从 Paypal 获取 referer

转载 作者:太空宇宙 更新时间:2023-11-03 16:30:36 28 4
gpt4 key购买 nike

我有一个大麻烦。我几个月前做过一个电子商务网站,现在我想在用户购买后这样做,paypal 将用户重定向到一个网站,用电子邮件确认购买。

很明显,返回页面有refererpage的控制,因为它不能给所有写页面地址的人发送确认邮件,但是命令:

Request.ServerVariables["HTTP_REFERER"]

不起作用,因为 paypal 是一个 https 网页。那么,我该如何解决呢?

谢谢你!

最佳答案

你好,你可以试试下面的代码:

首先在您的网站中设置“notify_url”

 <input type="hidden" name="notify_url" value="http://www.your-website-url.com/notifypaypal.aspx" />

之后创建 notifypaypal.aspx 页面。

notifypaypal.aspx:这里不需要任何代码..

notifypaypal.aspx.cs :

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using System.Threading;
using System.Net;
using BLL;

public partial class notifypaypal : System.Web.UI.Page
{

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";//For localhost
string strLive = "https://www.paypal.com/cgi-bin/webscr";//For live server
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);
string ipnPost = strRequest;
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();

// logging ipn messages... be sure that you give write permission to process executing this code
string logPathDir = ResolveUrl("Messages");
string logPath = string.Format("{0}\\{1}.txt",Server.MapPath(logPathDir), DateTime.Now.Ticks);
File.WriteAllText(logPath, ipnPost);


if (strResponse == "VERIFIED")
{

#region [Update Order Status]
string txn_id = HttpContext.Current.Request["txn_id"]; //txn_id= Unique transaction number.
string payment_status = HttpContext.Current.Request["payment_status"]; //payment_status=Payment state(Completed,Pending,Failed,Denied,Refunded)
string pending_reason = HttpContext.Current.Request["pending_reason"]; //pending_reason=Reason of payment delay(echeck,multi_currency,intl,verify,...)
string item_number = HttpContext.Current.Request["item_number"]; //item_number=order number


if (HttpContext.Current.Request["payment_status"].ToString() == "Completed")
{
try
{
//update in database that particular "item_number"(Order number) is successfully Completed

}
catch
{
}
}
else
{
if (HttpContext.Current.Request["payment_status"].ToString() == "Pending")
{
try
{
//update in database that particular "item_number"(Order number) is Pending
}
catch
{
}
}
else
{

}
}
#endregion


}
else if (strResponse == "INVALID")
{

}
else
{


}
}

}

关于c# - ASP.NET C# 从 Paypal 获取 referer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24516642/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com