@ResponseBody
@RequestMapping(value = "/alipay/notify", method = RequestMethod.POST)
public String getPayNotify(HttpServletRequest request) throws Exception {
Map<String, String> params = new HashMap<String, String>();
Map requestParams = request.getParameterMap();
for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext(); ) {
String name = (String) iter.next();
String[] values = (String[]) requestParams.get(name);
String valueStr = "";
for (int i = 0; i < values.length; i++) {
valueStr = (i == values.length - 1) ? valueStr + values[i]
: valueStr + values[i] + ",";
}
params.put(name, valueStr);
}
String out_trade_no = new String(
request.getParameter("out_trade_no").getBytes("ISO-8859-1"), "UTF-8");
String trade_no = new String(request.getParameter("trade_no").getBytes("ISO-8859-1"),
"UTF-8");
String total_fee = "0.00";
if (request.getParameter("total_amount") != null) {
total_fee = new String(request.getParameter("total_amount").getBytes("ISO-8859-1"),
"UTF-8");
}
String trade_status = new String(
request.getParameter("trade_status").getBytes("ISO-8859-1"), "UTF-8");
String notify_id = request.getParameter("notify_id");
if (notify_id != null && !"".equals(notify_id)) {
boolean verify_result = AlipaySignature
.rsaCheckV1(params, ALI_PUBLIC_KEY, AppContents.ALI_CHARSET,
ALIPAY_SIGNTYPE);
if (verify_result) {
if (trade_status.equals("TRADE_SUCCESS")) {
boolean result = orderService.getNotify(......)
if (result) {
return "success";
}
}
if (trade_status.equals("TRADE_CLOSED")) {
boolean result = orderService.getCloseNotify(......)
if (result) {
return "success";
}
}
return "fail";
} else {
return "fail";
}
} else {
return "fail";
}
}
`