-1

我正在尝试使用 Adaptive Payments API 进行简单的 Pay 调用。我收到以下异常:

java.security.AccessControlException: access denied (java.net.SocketPermission svcs.sandbox.paypal.com resolve)

这是我的一些 Java 代码,可以让您了解我在做什么。

HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("https://svcs.sandbox.paypal.com/AdaptivePayments/Pay");
httpPost.setHeader("X-PAYPAL-SECURITY-USERID", USER_ID);
httpPost.setHeader("X-PAYPAL-SECURITY-PASSWORD", PASSWORD);
httpPost.setHeader("X-PAYPAL-SECURITY-SIGNATURE", SIGNATURE);

httpPost.setHeader("X-PAYPAL-APPLICATION-ID", APPLICATION_ID);

httpPost.setHeader("X-PAYPAL-REQUEST-DATA-FORMAT", "JSON");
httpPost.setHeader("X-PAYPAL-RESPONSE-DATA-FORMAT", "JSON");

/* Bunch of stuff to build my JSON and put it in an Entity */

httpPost.setEntity(entity);

HttpResponse httpResponse = httpClient.execute(httpPost);

这会引发异常。但是,当我尝试建议的 cURL 命令时,它可以正常工作:

curl -s --insecure -H "X-PAYPAL-SECURITY-USERID: My_USERID" -H "X-PAYPAL-SECURITY-PASSWORD: My_PASSWORD" -H "X-PAYPAL-SECURITY-SIGNATURE: My_SIGNATURE" -H "X-PAYPAL-REQUEST-DATA-FORMAT: JSON" -H "X-PAYPAL-RESPONSE-DATA-FORMAT: JSON" -H "X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T" https://svcs.sandbox.paypal.com/AdaptivePayments/Pay -d "{\"actionType\":\"PAY\", \"currencyCode\":\"USD\", \"receiverList\":{\"receiver\":[{\"amount\":\"1.00\",\"email\":\"rec1_1312486368_biz@gmail.com\"}]}, \"returnUrl\":\"http://www.example.com/success.html\", \"cancelUrl\":\"http://www.example.com/failure.html\", \"requestEnvelope\":{\"errorLanguage\":\"en_US\", \"detailLevel\":\"ReturnAll\"}}"

{"responseEnvelope":{"timestamp":"2013-08-07T13:00:11.846-07:00","ack":"Success","correlationId":"0f33d4304a29b","build":"6941298"},"payKey":"AP-5GA81571BX790024K","paymentExecStatus":"CREATED"}

关于我为什么收到此异常的任何想法?

4

2 回答 2

0

谷歌有争议地阻止 PayPal。一个名为PaypalX的新系统充当了一个 paypal API,并在封锁 2 年后发布。您可以阅读这篇文章及其链接的更多信息。也就是说,它需要较少的 URL 操作,而是使用有关事务的更高级别的操作。

于 2013-08-07T20:42:18.727 回答
0

按照

https://developers.google.com/appengine/docs/java/#The_Sandbox

GAE 应用程序不能直接与其他主机通信。他们必须使用 GAE 的 URL 获取服务,而不是像我一样使用 Apache HttpClient。

https://developers.google.com/appengine/docs/java/urlfetch/

使用上面的链接,我能够建立连接并从 PayPal 沙箱服务器获得响应。如果对任何人有帮助,这是我的最终代码:

URL url = new URL(PAY_ENDPOINT);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");

connection.setRequestProperty("X-PAYPAL-SECURITY-USERID", USER_ID);
connection.setRequestProperty("X-PAYPAL-SECURITY-PASSWORD", PASSWORD);
connection.setRequestProperty("X-PAYPAL-SECURITY-SIGNATURE", SIGNATURE);

connection.setRequestProperty("X-PAYPAL-APPLICATION-ID", APPLICATION_ID);

connection.setRequestProperty("X-PAYPAL-REQUEST-DATA-FORMAT", "JSON");
connection.setRequestProperty("X-PAYPAL-RESPONSE-DATA-FORMAT", "JSON");

/* Form JSON into "requestStr" */

OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
writer.write(requestStr);
writer.close();

// Read response into StringBuffer
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuffer stringBuffer = new StringBuffer();
String line = "";
while((line = reader.readLine()) != null){
    stringBuffer.append(line);
}
reader.close();
于 2013-08-07T21:48:11.460 回答