如何解决Paypal IPN 400 和 403 错误
Stackoverflow 的各位,大家好,我一直在尝试为我的贝宝支付实现 IPN 功能。我在 localhost 上工作,所以 IPN 不起作用。开始使用 ngrok,现在 IPN 部分正在部分工作。
private class IPNContext
{
public HttpRequestBase IPNRequest { get; set; }
public string RequestBody { get; set; }
public string Verification { get; set; }
}
[Route("paypalipn")]
[HttpPost]
public ActionResult Receive()
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
IPNContext ipnContext = new IPNContext()
{
IPNRequest = Request
};
using (StreamReader reader = new StreamReader(ipnContext.IPNRequest.InputStream,Encoding.ASCII))
{
ipnContext.RequestBody = reader.ReadToEnd();
}
//Store the IPN received from
LogRequest(ipnContext);
//Fire and forget verification task
Task.Run(() => VerifyTask(ipnContext));
//Reply back a 200 code
return new HttpStatusCodeResult(HttpStatusCode.OK);
}
private void VerifyTask(IPNContext ipnContext)
{
try
{
var verificationRequest = (HttpWebRequest)WebRequest.Create("https://ipnpb.sandbox.paypal.com/cgi-bin/webscr");
//Set values for the verification request
verificationRequest.Method = "POST";
verificationRequest.ContentType = "application/x-www-form-urlencoded";
//Add cmd=_notify-validate to the payload
string strRequest = "cmd=_notify-validate&" + ipnContext.RequestBody;
verificationRequest.ContentLength = strRequest.Length;
//verificationRequest.UserAgent = "ASP-IPN-VerificationScript";
//verificationRequest.KeepAlive = false;
//Attach payload to the verification request
using (StreamWriter writer = new StreamWriter(verificationRequest.GetRequestStream(),Encoding.ASCII))
{
writer.Write(strRequest);
}
//Send the request to PayPal and get the response
using (StreamReader reader = new StreamReader(verificationRequest.GetResponse().GetResponseStream()))
{
ipnContext.Verification = reader.ReadToEnd();
}
}
catch (Exception exception)
{
LogErr(exception.ToString());
//Capture exception for manual investigation
}
ProcessVerificationResponse(ipnContext);
}
上面的代码在 VerifyTask 函数中抛出 403-Forbidden 异常。在 Paypal IPN 文档中,它声明并且我引用了 Please ensure you provide a User-Agent header value that describes your IPN listener,such as,PHP-IPN-VerificationScript.
如果我用 verificationRequest.UserAgent = "ASP-IPN-VerificationScript";
取消注释行,那么我开始收到 400-Bad Request。以前有人遇到过这个问题吗?我将非常感谢任何帮助,感谢您阅读到目前为止。
对于 403-禁止:
POST https://ipnpb.sandbox.paypal.com/cgi-bin/webscr HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: ipnpb.sandbox.paypal.com
Content-Length: 1245
cmd=_notify-validate&mc_gross=10.00&invoice=4967920&protection_eligibility=Eligible&address_status=confirmed&item_number1=sku&payer_id=UG9FLUCH489QQ&tax=0.00&address_street=asfasdgdsgsd&payment_date=00%3A36%3A22+Jun+28%2C+2021+PDT&payment_status=Completed&charset=KOI8_R&address_zip=365555&mc_shipping=0.00&first_name=%E1%CC%C5%CB%D3%C1%CE%C4%D2&mc_fee=10.00&address_country_code=RU&address_name=%E4%CF%D3%D4%CF%C5%D7%D3%CB%C9%CA+%E1%CC%C5%CB%D3%C1%CE%C4%D2¬ify_version=3.9&custom=latios%3A1000001&payer_status=verified&business=sb-fyb3f6626939%40business.example.com&address_country=Russia&num_cart_items=1&address_city=sggdsgdsgsdgf&verify_sign=As7YjUf-EtwWTklniO1RIaVMU-GLAbAN64Awhlx16OwPRDGAMxNV1f-B&payer_email=sb-mjmkt6611016%40personal.example.com&txn_id=4RF57039YW521103B&payment_type=instant&last_name=%E4%CF%D3%D4%CF%C5%D7%D3%CB%C9%CA&address_state=fhdhfdhfdh&item_name1=TestPayment&receiver_email=sb-fyb3f6626939%40business.example.com&payment_fee=&shipping_discount=0.00&quantity1=1&insurance_amount=0.00&receiver_id=7W727DS9L36YE&txn_type=cart&discount=0.00&mc_gross_1=10.00&mc_currency=RUB&residence_country=RU&test_ipn=1&shipping_method=Default&transaction_subject=Test+Payment&payment_gross=&ipn_track_id=4d1fa1b02fc27
我收到:
HTTP/1.1 403 Forbidden
Connection: close
Content-Length: 419
Server: Varnish
Retry-After: 0
Content-Type: text/html
Accept-Ranges: bytes
Via: 1.1 varnish,1.1 varnish
Date: Mon,28 Jun 2021 07:36:31 GMT
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
X-Served-By: cache-hhn11549-HHN,cache-ams21035-AMS
X-Cache: MISS,MISS
X-Cache-Hits: 0,0
X-Timer: S1624865791.439206,VS0,VE12
Set-Cookie: x-cdn=fastly:AMS; Domain=paypal.com; Path=/; Secure
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Paypal Error</title>
</head>
<body>
<h1>Access Denied.</h1>
<p>You don't have permission to access "/cgi-bin/webscr" on this server.
<br/>
<p>Reference #16248657919b384e2feca947c115f57
<br/>
<p> Timestamp: 1624865791
</body>
</html>
对于 400 错误请求错误:
POST https://ipnpb.sandbox.paypal.com/cgi-bin/webscr HTTP/1.1
Content-Type: application/x-www-form-urlencoded
User-Agent: ASP-IPN-VerificationScript
Host: ipnpb.sandbox.paypal.com
Content-Length: 1245
cmd=_notify-validate&mc_gross=10.00&invoice=6419605&protection_eligibility=Eligible&address_status=confirmed&item_number1=sku&payer_id=UG9FLUCH489QQ&tax=0.00&address_street=asfasdgdsgsd&payment_date=00%3A31%3A25+Jun+28%2C+2021+PDT&payment_status=Completed&charset=KOI8_R&address_zip=365555&mc_shipping=0.00&first_name=%E1%CC%C5%CB%D3%C1%CE%C4%D2&mc_fee=10.00&address_country_code=RU&address_name=%E4%CF%D3%D4%CF%C5%D7%D3%CB%C9%CA+%E1%CC%C5%CB%D3%C1%CE%C4%D2¬ify_version=3.9&custom=latios%3A1000001&payer_status=verified&business=sb-fyb3f6626939%40business.example.com&address_country=Russia&num_cart_items=1&address_city=sggdsgdsgsdgf&verify_sign=AX8Qhp1KduwF1PenaWfGM32xmlvMAhGJ2G8kcZxf1Y2LyqJwTyF9J-zn&payer_email=sb-mjmkt6611016%40personal.example.com&txn_id=4H0466721N516441A&payment_type=instant&last_name=%E4%CF%D3%D4%CF%C5%D7%D3%CB%C9%CA&address_state=fhdhfdhfdh&item_name1=TestPayment&receiver_email=sb-fyb3f6626939%40business.example.com&payment_fee=&shipping_discount=0.00&quantity1=1&insurance_amount=0.00&receiver_id=7W727DS9L36YE&txn_type=cart&discount=0.00&mc_gross_1=10.00&mc_currency=RUB&residence_country=RU&test_ipn=1&shipping_method=Default&transaction_subject=Test+Payment&payment_gross=&ipn_track_id=38f99419954c7
我收到:
HTTP/1.1 400 Bad Request
Connection: close
Content-Length: 226
Content-Type: text/html; charset=iso-8859-1
Cache-Control: max-age=0,no-cache,no-store,must-revalidate
Paypal-Debug-Id: 1dc58fdccb02b
Set-Cookie: Cookie 1
Set-Cookie: Cookie 2
Accept-Ranges: bytes
Via: 1.1 varnish,28 Jun 2021 07:31:39 GMT
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
X-Served-By: cache-hhn11528-HHN,cache-ams21054-AMS
X-Cache: MISS,0
X-Timer: S1624865500.675648,VE150
Set-Cookie: x-cdn=fastly:AMS; Domain=paypal.com; Path=/; Secure
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>
针对将来会发现此主题的人的解决方案:
我的问题是,我的两个测试帐户都有西里尔文名称。为了解决这个问题,我需要登录我的企业帐户(将接受付款的帐户)
- 帐户设置
- 网站付款
- PayPal 付款按钮的语言编码
- 附加功能
- 将编码更改为“UTF-8”。
现在它可以正常工作了。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。