PayPal Sandbox API SSL 握手错误 HTTPS 请求

标签 paypal paypal-sandbox

随着 paypal 的新变化,它开始抛出那些使用旧系统的 SSL 握手异常。 “PayPal SSL 证书变更https://devblog.paypal.com/paypal-ssl-certificate-changes/

这可能对某人有帮助。在我得到 SSL 握手异常之后,我花了很多时间来解决它。

这里是异常:

javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

解决方案:

解决此问题的要求:

从 1 月 19 日开始,所有沙盒 API 端点都需要

 1.) Use TLS 1.2 and HTTP/1.1 connection

 2.) Upgrade to SHA-256 and use the G5 root certificate to make the HTTPS connection

第 1 点解决方案:

If you are using java 6 then better upgrade it to java 7

https://blogs.oracle.com/java-platform-group/entry/diagnosing_tls_ssl_and_https

For my case i am using java 7 so TLSv1 (default) for JDK 7.

We have to enable it manually while starting server 

**-Dhttps.protocols=TLSv1.2** passed as vm argument.

第 2 点解决方案:

https://knowledge.verisign.com/support/mpki-for-ssl-support/index?page=content&actp=CROSSLINK&id=SO5624

G5 cerificate import: Save it as test.cer

Go to java home/bin then run this command 

keytool -importcert   -file C:/test.cer

创建沙箱帐户。获取服务商密码和签名作为参数传递

String encodedData = "USER=XXX-facilitator_api1.XXX.XXX"
                         + "&PWD=XXXXXXXXXXXX"
                         + "&SIGNATURE=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-"
                         + "&VERSION=95"                         
                         + "&METHOD=SetExpressCheckout"
                         + "&PAYMENTREQUEST_0_PAYMENTACTION=Authorization"
                         + "&L_PAYMENTREQUEST_0_NAME0="+URLEncoder.encode("Testing","UTF-8")
                         + "&L_PAYMENTREQUEST_0_DESC0="+URLEncoder.encode("Testing","UTF-8")
                         + "&L_PAYMENTREQUEST_0_AMT0="+URLEncoder.encode("99","UTF-8")
                         + "&PAYMENTREQUEST_0_AMT="+URLEncoder.encode("99","UTF-8")
                         + "&PAYMENTREQUEST_0_CURRENCYCODE="+URLEncoder.encode("USD","UTF-8")
                         + "&LOCALECODE=en_GB"                        
                         + "&RETURNURL=google.com"
                         + "&CANCELURL=google.co.in"
                         + "&LOGOIMG=imageurl"; 

String responsepaypal = getHTMLcontent("https://api-3t.sandbox.paypal.com/nvp",encodedData ,"UTF-8");
String token = responsepaypal.toString().replaceAll("TOKEN=(.*?)&TIMESTAMP.*", "$1");//***Token for post request on paypal***




public static String getHTMLcontent(String url,String urlParameters, String encodingDef) throws IOException  {      

            URL obj = new URL(url);     
            HttpsURLConnection con = (HttpsURLConnection) obj.openConnection(); 
            con.setRequestMethod("POST");       
            con.setRequestProperty("Content-length", String.valueOf(urlParameters.length())); 
            con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36"); 
            con.setRequestProperty("Host", "api-3t.sandbox.paypal.com"); 
            con.setRequestProperty("Upgrade-Insecure-Requests", "1"); 
            con.setRequestProperty("Pragma", "no-cache"); 
            //con.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
            con.setRequestProperty("Accept-Encoding", "gzip, deflate, sdch");
            con.setRequestProperty("Accept-Language", "en-US,en;q=0.8");
            con.setRequestProperty("Connection", "keep-alive");     
            con.setDoOutput(true); 
            con.setDoInput(true); 
            DataOutputStream output = new DataOutputStream(con.getOutputStream());  
            output.writeBytes(urlParameters);
            output.close();

            DataInputStream input = new DataInputStream( con.getInputStream() ); 

            StringBuffer sb = new StringBuffer();

            String line;
            while ((line = input.readLine()) != null) {
                sb.append(line);
            }

            input.close(); 


            return sb.toString();
        }}

按照此处明确提到的步骤进行操作:

https://developer.paypal.com/docs/classic/express-checkout/ht_ec-singleAuthPayment-curl-etc/

最佳答案

我正在使用沙盒帐户测试 Paypal ,但我遇到了同样的错误。我升级到 Java 8,错误不再存在。

关于PayPal Sandbox API SSL 握手错误 HTTPS 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35075456/

相关文章:

paypal - PayPal IPN机制如何调用连续的多个URL?

android - paypal android sdk 货币错误错误

php - Paypal IPN 有效,但不更新数据库。不确定如何调试

paypal - 无法获得 PayPal/Braintree SDK 访问 token

HTML 电子邮件 - 按钮作为电子邮件中的表单

paypal - Paypal 沙箱 merchantpaymentweb : no style and JS errors 问题

带信用卡的 PayPal IPN/PDT

PayPal webhooks 不工作

laravel-4 - 如何使用 OmniPay 获得 PayPal_Express 响应?

PayPal Payments Pro 直接支付 API