回复 paypal 后仍然收到相同的 ipn 消息

Still receiving the same ipn message after response back to paypal

根据 paypal ipn 文档,我需要在收到 ipn 消息后回复 paypal。问题是,即使我从 paypal 服务器收到 "VERIFIED",我仍然收到相同的 ipn 消息。我做的有什么问题吗?我正在使用 responseBackIpnMessage 来回复 ipn 消息。我总是收到 "VERIFIED".

 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 上按照本指南中的步骤进行操作,您应该能够找到问题所在。