【问题标题】:Still receiving the same ipn message after response back to paypal回复贝宝后仍然收到相同的ipn消息
【发布时间】:2015-09-23 18:26:28
【问题描述】:

根据paypal ipn文档,我需要在收到ipn消息后回复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");
}

【问题讨论】:

  • 问题是我没有响应 200。

标签: paypal paypal-ipn


【解决方案1】:

如果您收到重复的 IPN,这意味着您的脚本以某种方式失败,并且没有向 PayPal 的服务器返回 200 OK 响应。

验证过程确实与此无关。这只是验证数据来自 PayPal。它不验证脚本是否成功完成。

如果您在how to test PayPal IPN 上按照本指南中的步骤操作,您应该能够找到问题所在。

【讨论】:

    猜你喜欢
    • 2011-03-12
    • 2016-06-11
    • 2015-10-16
    • 2012-03-13
    • 2016-05-27
    • 1970-01-01
    • 2013-05-16
    • 2012-07-22
    • 2015-06-16
    相关资源
    最近更新 更多