Paypal IPN代码

public static String validateNotify(final HttpServletRequest request) {
String status = null;
final Log log = LogFactory.getLog("IPNListner");
final String txn_id = request.getParameter("txn_id");
if (txn_id != null && txn_id.trim().length() > 0)
log.info("Received IPN,  TX ID : " + txn_id);
try {
final PostMethod post = new PostMethod(PROPS
.getValue("paypal_host"));
post.addParameter("cmd", "_notify-validate");
for (final Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
final String name = (String) e.nextElement();
final String value = request.getParameter(name);
post.addParameter(name, value);
}
status = PaymentUtils.executePost(post);
log.info("Received IPN Values: " + status);

} catch (final Exception e) {
}
return status;
}

public final static String executePost(final PostMethod post) throws Exception {
String retValue = null;
try {
final HttpClient client = new HttpClient();

if("Y".equals(PROPS.getValue("isUsedProxy"))){
client.getHostConfiguration().setProxy(PROPS.getValue("proxy_host"), Integer.parseInt(PROPS.getValue("proxy_port")));         
Credentials defaultcreds = new UsernamePasswordCredentials(PROPS.getValue("proxy_username"),PROPS.getValue("proxy_password"));           
client.getState().setProxyCredentials(new AuthScope(PROPS.getValue("proxy_host"), Integer.parseInt(PROPS.getValue("proxy_port")), null), defaultcreds);
}
final int statusCode = client.executeMethod(post);
if (statusCode != HttpStatus.SC_OK)
return null;
final InputStream responseBody = post.getResponseBodyAsStream();

// deal response
final BufferedReader br = new BufferedReader(new InputStreamReader(responseBody));
String tempbf;
final StringBuffer html = new StringBuffer();
while ((tempbf = br.readLine()) != null)
html.append(tempbf);
// return msg
retValue = html.toString();
responseBody.close();
return retValue;
} finally {
post.releaseConnection();
}
}

你可能感兴趣的:(html)