C# setExpressCheckout和SSL/TLS错误
我正在尝试开发一个简单的应用程序,使用户可以通过PayPalAPI从网站上购买服务。此应用程序正在使用C#在ASP.NET上运行 我在尝试让PayPalAPI合作方面几乎没有什么运气。我调用的方法是SetExpressCheckout,其中包含所有适当的变量 我做了研究,发现由于我在Localhost中进行测试,它可能会影响Paypal与应用程序通信的能力。因此,我尝试的下一件事是通过开放端口和可公开访问的IP地址访问我的应用程序,但调用SetExpressCheckout时也会发生相同的错误 以下是错误:C# setExpressCheckout和SSL/TLS错误,c#,asp.net,paypal,paypal-sandbox,C#,Asp.net,Paypal,Paypal Sandbox,我正在尝试开发一个简单的应用程序,使用户可以通过PayPalAPI从网站上购买服务。此应用程序正在使用C#在ASP.NET上运行 我在尝试让PayPalAPI合作方面几乎没有什么运气。我调用的方法是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);
我还使用url访问API您可能正在连接到API.paypal.com或API.sandbox.paypal.com,并且没有发送您的API证书。API证书是用于完成SSL链的客户端SSL证书
如果您没有或没有使用API证书,您应该分别连接到API-3t.paypal.com或API-3t.sandbox.paypal.com以进行Live或sandbox。非常感谢您的帮助 这里是我在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
自2016年初以来,Paypal开始要求在沙箱中使用TLS 1.2协议进行通信,并将从6月17日开始在实时环境中实施该协议。请参阅以供参考 在大多数.NET应用程序中,TLS 1.2在默认情况下将被禁用,因此您需要启用它 例如,您需要在
应用程序\u Start
方法的开头添加以下行:
public class Site : HttpApplication
{
protected void Application_Start()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// other configuration
}
}
我一直在使用PayPal(NVP/Signature)Express Checkout集成,并且遇到了这个SSL/TLS错误 我所做的一切似乎都没有绕过它,但后来我发现下面的代码要添加到我的请求之上。作为参考,我使用的是MVC3/.NET4,因此默认情况下Tls1.2对我不可用(如.NET4.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();
...
你能发布你用来连接的实际代码而不是错误吗?下面我还会发布一些其他问题。问题似乎是,当我使用正确的服务器时,我没有正确调用它。我去了paypal网站,自动生成了paypal函数,使用附带的ShortcutExpressCheckout方法,我成功地获得了一个令牌。生成器在这里:paypal-labs.com主页当前显示“我们正在开发一个新网站”,上面的链接返回一个空白页面。试试这个:C#向导似乎运行正常,我还没有尝试过代码。上帝保佑你!你救了我一天。:)适用于使用旧版本MVC(3)或.NET Framework的用户(