根据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");
}
答案 0 :(得分:1)
如果您获得重复的IPN,这意味着您的脚本以某种方式失败,并且没有将200 OK响应返回给PayPal的服务器。
验证过程实际上与此无关。这简单地验证了来自PayPal的数据。它没有验证脚本是否成功完成。
如果您按照how to test PayPal IPN中本指南中的步骤操作,则应该能够找到问题。