根据 paypal ipn 文档,我需要在收到 ipn 消息后回复 paypal。问题是即使我从 paypal 服务器收到“已验证”后,我仍然收到相同的 ipn 消息。我做的有什么问题吗?我正在使用 responseBackIpnMessage 来回复 ipn 消息。而且我总是收到“已验证”。
public void handlePaypalIpnMessage(HttpServletRequest request) {
Map<String, String> configMap = new HashMap<String, String>();
IPNMessage message = new IPNMessage(request, configMap);
boolean isIpnVerified = responseBackIpnMessage(request);
Map<String, String> map = message.getIpnMap();
......
}
private boolean responseBackIpnMessage(HttpServletRequest request) {
HttpClient httpClient = new DefaultHttpClient();
HttpParams clientParams = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(clientParams, 40000);
HttpConnectionParams.setSoTimeout(clientParams, 40000);
HttpPost httppost = new HttpPost(paypalIpnUrl); // https://www.paypal.com/cgi-bin/webscr
httppost.setHeader("Content-Type", "application/x-www-form-urlencoded");
try {
Map<String, String> params = new HashMap<String, String>();
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("cmd", "_notify-validate"));
Enumeration<String> names = request.getParameterNames();
while (names.hasMoreElements()) {
String param = names.nextElement();
String value = request.getParameter(param);
nameValuePairs.add(new BasicNameValuePair(param, value));
params.put(param, value);
}
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
if (!verifyIpnResponse(httpClient.execute(httppost))) {
logger.error("Previous message is invalid according to paypal server.");
return false;
} else {
logger.info("Previous message is verified by paypal server");
return true;
}
} catch ( UnsupportedEncodingException e ) {
e.printStackTrace();
} catch ( ClientProtocolException e ) {
e.printStackTrace();
} catch ( IOException e ) {
e.printStackTrace();
}
return true;
}
private boolean verifyIpnResponse(HttpResponse response) throws IllegalStateException, IOException {
InputStream is = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String responseText = reader.readLine();
is.close();
logger.debug("Paypal server ipn response: " + responseText);
return responseText.equals("VERIFIED");
}
最佳答案
如果您收到重复的 IPN,这意味着您的脚本以某种方式失败并且没有向 PayPal 服务器返回 200 OK 响应。
验证过程确实与此无关。这只是验证数据来自 PayPal。它不会验证脚本是否已成功完成。
如果您在 how to test PayPal IPN 上按照本指南中的步骤操作你应该能够找到问题。
关于paypal - 回复 paypal 后仍然收到相同的 ipn 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31248702/