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();
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值