[英]setExpressCheckout and SSL/TLS error
我正在嘗試開發一個簡單的應用程序,使用戶能夠通過Paypal API從網站上購買服務。 此應用程序在帶有C#的ASP.NET上運行。
我試圖讓Paypal API合作的運氣很少。 我正在調用的方法是SetExpressCheckout,包含所有適當的變量。
我做了我的研究,發現由於我在Localhost中測試,它可能會影響Paypal與應用程序通信的能力。 所以我接下來嘗試的是通過開放端口和可公開訪問的IP地址訪問我的應用程序,但是在調用SetExpressCheckout時會出現同樣的錯誤。
這是錯誤:
Exception Details: System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
Source Error:
Line 1790: [return: System.Xml.Serialization.XmlElementAttribute("SetExpressCheckoutResponse", Namespace="urn:ebay:api:PayPalAPI")]
Line 1791: public SetExpressCheckoutResponseType SetExpressCheckout([System.Xml.Serialization.XmlElementAttribute(Namespace="urn:ebay:api:PayPalAPI")] SetExpressCheckoutReq SetExpressCheckoutReq) {
Line 1792: object[] results = this.Invoke("SetExpressCheckout", new object[] {
Line 1793: SetExpressCheckoutReq});
Line 1794: return ((SetExpressCheckoutResponseType)(results[0]));
Source File: c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\anan_p2\730602d6\31a8d74e\App_WebReferences.c8vgyrf8.2.cs Line: 1792
我也嘗試使用OpenSSL生成證書並將其上傳到Paypal帳戶的加密賣家選項,但仍然沒有效果。
非常感謝您閱讀我的問題!
更新:這里要求的是正在使用的代碼。
String hostingOn = ConfigurationManager.AppSettings["default_site_url"];
reqDetails.ReturnURL = hostingOn + "marketplace_confirm.aspx";
reqDetails.CancelURL = hostingOn + "marketplace.aspx";
reqDetails.NoShipping = "1";
reqDetails.ReqConfirmShipping = "0";
reqDetails.OrderTotal = new BasicAmountType()
{
currencyID = CurrencyCodeType.CAD,
Value = payment_amt.Value,
};
SetExpressCheckoutReq req = new SetExpressCheckoutReq()
{
SetExpressCheckoutRequest = new SetExpressCheckoutRequestType()
{
Version = UtilPayPalAPI.Version,
SetExpressCheckoutRequestDetails = reqDetails
}
};
PayPalAPIAASoapBinding paypal = new PayPalAPIAASoapBinding();
paypal.SetExpressCheckout(req);
我也使用https://api-aa-3t.paypal.com/2.0/ url來訪問API
自2016年初以來,Paypal開始要求TLS 1.2協議用於Sandbox中的通信,並將從6月17日開始為實時環境強制執行。請參閱此處以供參考。
在大多數.NET應用程序中,默認情況下 TLS 1.2將被禁用 ,因此您需要啟用它。
您需要添加以下行,例如,在Application_Start
方法的開頭:
public class Site : HttpApplication
{
protected void Application_Start()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// other configuration
}
}
您可能正在連接到api.paypal.com或api.sandbox.paypal.com,而不是發送您的API證書。 API證書是用於完成SSL鏈的客戶端SSL證書。
如果您沒有或未使用API證書,則應分別連接到api-3t.paypal.com或api-3t.sandbox.paypal.com以獲取Live或Sandbox。
我一直在使用PayPal(NVP /簽名)Express Checkout集成,並且遇到此SSL / TLS錯誤。
我沒有做任何事情似乎繞過它,但后來我發現以下代碼添加到我的請求之上。 作為參考,我使用的是MVC3 / .NET 4,因此默認情況下Tls1.2不可用(例如在.NET 4.5 +中)。 這段代碼的前三行就是這樣的。 我希望它能幫到人們!
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
ServicePointManager.DefaultConnectionLimit = 9999;
var url = "https://[paypal-api-url]/nvp";
var uri = new Uri(url);
var request = WebRequest.Create(uri);
var encoding = new UTF8Encoding();
var requestData = encoding.GetBytes(data);
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.Timeout = (300 * 1000);
request.ContentLength = requestData.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(requestData, 0, requestData.Length);
}
var response = request.GetResponse();
...
非常感謝真的幫助我。
這里是我在VB.NET中建立接口的代碼
'Create a service Binding in code
Dim ppEndpointAddress As New System.ServiceModel.EndpointAddress("https://api-3t.sandbox.paypal.com/2.0/")
Dim ppBinding As New System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.Transport)
Dim ppIface As New PayPalAPI.PayPalAPIAAInterfaceClient(ppBinding, ppEndpointAddress)
Dim ppPaymentReq As New PayPalAPI.DoDirectPaymentReq()
ppPaymentReq.DoDirectPaymentRequest = ppRequest
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.