<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<%=business %>">
<input type="hidden" name="item_name" value="<%=item_name %>">
<input type="hidden" name="amount" value= "<%=amount%>">
<input type="hidden" name="currency_code" value="<%=currency_code%>">
<input type="hidden" name="return" value="<%=returnlocation%>"><input type="hidden" name="quantity" value="<%=quantity %>">
<input type="hidden" name="item_number" value="<%=item_number%>">
<input type="hidden" name="notify_url" value="http://199.180.100.235:8008/paypal/paypalback.aspx"><input type="image" src=" https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif "
border="0" name="submit" alt=" PayPal - The safer, easier way to pay online">
</form>
</body>
</html>
上面是购买的提交页面。
item_number = "itemnumber";
amount = "10.00";
business = "[email protected]";
currency_code = "USD";
item_name = "abc";
quantity = 2;
returnlocation = "http://199.180.100.235:8008/paypal/paypalreturn.aspx";这是赋值。
下面是paypalback.aspx.cs的代码。
protected void Page_Load(object sender, EventArgs e)
{
OrderDataContext lc = new OrderDataContext();
Order l = new Order(); l.orderId = Guid.NewGuid(); l.shipAddress = "pageloadback"; //验证是否能插入 l.date = DateTime.Now;
l.phoneNum = "phonenum"; l.state = "state"; l.total = 100; l.userId = Guid.NewGuid();
l.zip = "d"; lc.Order.InsertOnSubmit(l);
lc.SubmitChanges();
//-----------------------
string strFormValues;
string strNewValue;
string strResponse;
//创建回复的 request
//在 Sandbox 情况下,设置:
// WebRequest.Create("ttps://www.sandbox.paypal.com/cgi-bin/webscr"); //为备注删除了一个h
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://www.sandbox.paypal.com/cgi-bin/webscr"); /* WebRequest.Create("
* ttps://www.paypal.com/cgi-bin/webscr"); */
//为备注删除了一个h
//设置 request 的属性
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] param =HttpContext.Current.Request.BinaryRead(HttpContext.Current.Request.ContentLength);
strFormValues = Encoding.ASCII.GetString(param);
//建议在此将接受到的信息记录到日志文件中以确认是否收到 IPN 信息
strNewValue = strFormValues + "&cmd=_notify-validate";
req.ContentLength = strNewValue.Length;
//发送 request
StreamWriter stOut = new StreamWriter (req.GetRequestStream(),System.Text.Encoding.ASCII);
stOut.Write(strNewValue);
stOut.Close();
//回复 IPN 并接受反馈信息
StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
strResponse = stIn.ReadToEnd();
stIn.Close();
//确认 IPN 是否合法
if (strResponse == "VERIFIED"){
//检查付款状态
//检查 txn_id 是否已经处理过
//检查 receiver_email 是否是您的 PayPal 账户中的 EMAIL 地址
//检查付款金额和货币单位是否正确
//处理这次付款,包括写数据库 l.orderId = Guid.NewGuid(); l.shipAddress = "verified"; //验证是否能插入 l.date = DateTime.Now; l.phoneNum = "phonenum"; l.state = "state"; l.total = 100; l.userId = Guid.NewGuid();
l.zip = "d"; lc.Order.InsertOnSubmit(l);
lc.SubmitChanges(); String itemName = "";
String itemNumber = "";
String paymentStatus = "";
String paymentAmount = "";
String paymentCurrency = "";
String txnId = "";
String receiverEmail ="";
String payerEmail = ""; itemName = Request.QueryString["item_name"];
itemNumber = Request.QueryString["item_number"];
paymentStatus = Request.QueryString["payment_status"];
paymentAmount = Request.QueryString["mc_gross"];
paymentCurrency = Request.QueryString["mc_currency"];
txnId = Request.QueryString["txn_id"];
receiverEmail = Request.QueryString["receiver_email"];
payerEmail = Request.QueryString["payer_email"]; if (paymentStatus.Equals("Completed"))
{ l.orderId = Guid.NewGuid(); l.shipAddress = "complete"; //验证是否能插入 l.date = DateTime.Now;
l.phoneNum = "phonenum"; l.state = "state"; l.total = 100; l.userId = Guid.NewGuid();
l.zip = "d"; lc.Order.InsertOnSubmit(l);
lc.SubmitChanges();
}
else if (paymentStatus.Equals(""))
{
l.orderId = Guid.NewGuid(); l.shipAddress = "nodata"; //验证是否能插入 l.date = DateTime.Now;
l.phoneNum = "phonenum"; l.state = "state"; l.total = 100; l.userId = Guid.NewGuid();
l.zip = "d"; lc.Order.InsertOnSubmit(l);
lc.SubmitChanges();
}
else
{ l.orderId = Guid.NewGuid(); l.shipAddress = "error message"; //验证是否能插入 l.date = DateTime.Now;
l.phoneNum = "phonenum"; l.state = "state"; l.total = 100; l.userId = Guid.NewGuid();
l.zip = "d"; lc.Order.InsertOnSubmit(l);
lc.SubmitChanges();
}
//…
}
}
求大神教育到底哪出问题了。用测试账号支付成功后是能返回return指定的页面的。但是notify_url指向的页面根本没有反应。求大神教育是我理解的有问题还是怎么。
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<%=business %>">
<input type="hidden" name="item_name" value="<%=item_name %>">
<input type="hidden" name="amount" value= "<%=amount%>">
<input type="hidden" name="currency_code" value="<%=currency_code%>">
<input type="hidden" name="return" value="<%=returnlocation%>"><input type="hidden" name="quantity" value="<%=quantity %>">
<input type="hidden" name="item_number" value="<%=item_number%>">
<input type="hidden" name="notify_url" value="http://199.180.100.235:8008/paypal/paypalback.aspx"><input type="image" src=" https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif "
border="0" name="submit" alt=" PayPal - The safer, easier way to pay online">
</form>
</body>
</html>
上面是购买的提交页面。
item_number = "itemnumber";
amount = "10.00";
business = "[email protected]";
currency_code = "USD";
item_name = "abc";
quantity = 2;
returnlocation = "http://199.180.100.235:8008/paypal/paypalreturn.aspx";这是赋值。
下面是paypalback.aspx.cs的代码。
protected void Page_Load(object sender, EventArgs e)
{
OrderDataContext lc = new OrderDataContext();
Order l = new Order(); l.orderId = Guid.NewGuid(); l.shipAddress = "pageloadback"; //验证是否能插入 l.date = DateTime.Now;
l.phoneNum = "phonenum"; l.state = "state"; l.total = 100; l.userId = Guid.NewGuid();
l.zip = "d"; lc.Order.InsertOnSubmit(l);
lc.SubmitChanges();
//-----------------------
string strFormValues;
string strNewValue;
string strResponse;
//创建回复的 request
//在 Sandbox 情况下,设置:
// WebRequest.Create("ttps://www.sandbox.paypal.com/cgi-bin/webscr"); //为备注删除了一个h
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://www.sandbox.paypal.com/cgi-bin/webscr"); /* WebRequest.Create("
* ttps://www.paypal.com/cgi-bin/webscr"); */
//为备注删除了一个h
//设置 request 的属性
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] param =HttpContext.Current.Request.BinaryRead(HttpContext.Current.Request.ContentLength);
strFormValues = Encoding.ASCII.GetString(param);
//建议在此将接受到的信息记录到日志文件中以确认是否收到 IPN 信息
strNewValue = strFormValues + "&cmd=_notify-validate";
req.ContentLength = strNewValue.Length;
//发送 request
StreamWriter stOut = new StreamWriter (req.GetRequestStream(),System.Text.Encoding.ASCII);
stOut.Write(strNewValue);
stOut.Close();
//回复 IPN 并接受反馈信息
StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
strResponse = stIn.ReadToEnd();
stIn.Close();
//确认 IPN 是否合法
if (strResponse == "VERIFIED"){
//检查付款状态
//检查 txn_id 是否已经处理过
//检查 receiver_email 是否是您的 PayPal 账户中的 EMAIL 地址
//检查付款金额和货币单位是否正确
//处理这次付款,包括写数据库 l.orderId = Guid.NewGuid(); l.shipAddress = "verified"; //验证是否能插入 l.date = DateTime.Now; l.phoneNum = "phonenum"; l.state = "state"; l.total = 100; l.userId = Guid.NewGuid();
l.zip = "d"; lc.Order.InsertOnSubmit(l);
lc.SubmitChanges(); String itemName = "";
String itemNumber = "";
String paymentStatus = "";
String paymentAmount = "";
String paymentCurrency = "";
String txnId = "";
String receiverEmail ="";
String payerEmail = ""; itemName = Request.QueryString["item_name"];
itemNumber = Request.QueryString["item_number"];
paymentStatus = Request.QueryString["payment_status"];
paymentAmount = Request.QueryString["mc_gross"];
paymentCurrency = Request.QueryString["mc_currency"];
txnId = Request.QueryString["txn_id"];
receiverEmail = Request.QueryString["receiver_email"];
payerEmail = Request.QueryString["payer_email"]; if (paymentStatus.Equals("Completed"))
{ l.orderId = Guid.NewGuid(); l.shipAddress = "complete"; //验证是否能插入 l.date = DateTime.Now;
l.phoneNum = "phonenum"; l.state = "state"; l.total = 100; l.userId = Guid.NewGuid();
l.zip = "d"; lc.Order.InsertOnSubmit(l);
lc.SubmitChanges();
}
else if (paymentStatus.Equals(""))
{
l.orderId = Guid.NewGuid(); l.shipAddress = "nodata"; //验证是否能插入 l.date = DateTime.Now;
l.phoneNum = "phonenum"; l.state = "state"; l.total = 100; l.userId = Guid.NewGuid();
l.zip = "d"; lc.Order.InsertOnSubmit(l);
lc.SubmitChanges();
}
else
{ l.orderId = Guid.NewGuid(); l.shipAddress = "error message"; //验证是否能插入 l.date = DateTime.Now;
l.phoneNum = "phonenum"; l.state = "state"; l.total = 100; l.userId = Guid.NewGuid();
l.zip = "d"; lc.Order.InsertOnSubmit(l);
lc.SubmitChanges();
}
//…
}
}
求大神教育到底哪出问题了。用测试账号支付成功后是能返回return指定的页面的。但是notify_url指向的页面根本没有反应。求大神教育是我理解的有问题还是怎么。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货