PayPal Sandbox API SSL握手错误HTTPS请求

时间:2016-01-29 01:37:59

标签: paypal paypal-sandbox

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

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

以下是例外:

  

javax.net.ssl.SSLHandshakeException:收到致命警报:   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

创建sanbox帐户。获取facilator密码并将签名作为参数传递

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/

1 个答案:

答案 0 :(得分:0)

我正在使用沙盒帐户测试paypal,我得到了同样的错误。我升级到java 8,错误不再存在。