随着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帐户。获取便利器密码和签名将其作为参数传递
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,错误不再存在。