|
|
@@ -234,7 +234,6 @@ public class AlipayController {
|
|
|
public void notifyUrl(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
Map<String, String> params = AlipayApi.toMap(request);
|
|
|
String data = AlipayApi.getRequestData(request); // data json格式
|
|
|
- System.out.print(data);
|
|
|
//1.商户系统接收到异步通知以后,必须通过验签(验证通知中的sign参数)来确保支付通知是由支付宝发送的。详细验签规则参考异步通知验签
|
|
|
boolean signVerified = false;
|
|
|
try {
|
|
|
@@ -242,6 +241,7 @@ public class AlipayController {
|
|
|
} catch (AlipayApiException e) {
|
|
|
e.printStackTrace();
|
|
|
response.getWriter().write("fail");
|
|
|
+ return;
|
|
|
}
|
|
|
//2.接受到异步通知并验签通过后,一定要检查通知内容,包括通知中的app_id, out_trade_no, total_amount是否与请求中的一致,并根据trade_status进行后续业务处理。
|
|
|
|
|
|
@@ -260,20 +260,13 @@ public class AlipayController {
|
|
|
String notifySellerId = params.get("seller_id") == null ? "" : params.get("seller_id");
|
|
|
String notifySellerEmail = params.get("seller_email") == null ? "" : params.get("seller_id");
|
|
|
|
|
|
- //商户系统订单支付状态
|
|
|
- short projectRecodePayStatus = 1;
|
|
|
- if ("TRADE_SUCCESS".equals(notifyTradeStatus)) {
|
|
|
- projectRecodePayStatus = 2;
|
|
|
- } else {
|
|
|
- projectRecodePayStatus = 3;
|
|
|
- }
|
|
|
-
|
|
|
ProjectRecode projectRecode = projectRecodeService.findOne(Long.parseLong(notifyOutTradeNo));
|
|
|
if (projectRecode == null) {
|
|
|
//1、需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,
|
|
|
//TODO 单号非商户系统中创建的订单号情况处理
|
|
|
saveAlipayOrder(data, (short) 1);
|
|
|
response.getWriter().write("fail");
|
|
|
+ return;
|
|
|
} else {
|
|
|
//判断该笔订单是否在商户网站中已经做过处理
|
|
|
AlipayOrder oldAlipayOrder = alipayOrderService.getByOutTradeNo(notifyOutTradeNo);
|
|
|
@@ -281,30 +274,35 @@ public class AlipayController {
|
|
|
//有做过处理,不执行商户的业务程序
|
|
|
logger.info("系统已对该笔交易进行处理,交易订单号" + oldAlipayOrder.getOut_trade_no() + "支付宝订单号号" + oldAlipayOrder.getTrade_no());
|
|
|
response.getWriter().write("success");
|
|
|
+ return;
|
|
|
} else {
|
|
|
- projectRecode.setStatus(projectRecodePayStatus);
|
|
|
-
|
|
|
if (!(Double.parseDouble(notifyTotalAmount) == projectRecode.getAmount())) {
|
|
|
//2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
|
|
|
//TODO 金额不相等情况处理 金额
|
|
|
projectRecode.setExceptionMsg("{'AmountMsg' : '支付宝返回金额与订单金额不相等', 'notifyTotalAmount' : " + notifyTotalAmount + "}");
|
|
|
+ projectRecode.setStatus((short) 3);
|
|
|
projectRecodeService.update(projectRecode);
|
|
|
saveAlipayOrder(data, null);
|
|
|
response.getWriter().write("fail");
|
|
|
+ return;
|
|
|
} else {
|
|
|
if (!(AlipayConfig.SELLER_ID.equals(notifySellerId) || AlipayConfig.SELLER_EMAIL.equals(notifySellerEmail))) {
|
|
|
//TODO 操作方不相等情况处理 操作方
|
|
|
projectRecode.setExceptionMsg("{'SellerMsg' : '支付宝返回操作方不相等', 'notifySellerId' : " + notifySellerId + ", 'notifySellerEmail' : " + notifySellerEmail + "}");
|
|
|
+ projectRecode.setStatus((short) 3);
|
|
|
projectRecodeService.update(projectRecode);
|
|
|
saveAlipayOrder(data, null);
|
|
|
response.getWriter().write("fail");
|
|
|
+ return;
|
|
|
} else {
|
|
|
if (!AlipayConfig.APPID.equals(notifyAppId)) {
|
|
|
//TODO 商户(服务商)不相当情况处理
|
|
|
projectRecode.setExceptionMsg("{'AppIdMsg' : '支付宝返回商户(服务商)不相当等', 'notifyAppId' : " + notifyAppId + "}");
|
|
|
+ projectRecode.setStatus((short) 3);
|
|
|
projectRecodeService.update(projectRecode);
|
|
|
saveAlipayOrder(data, null);
|
|
|
response.getWriter().write("fail");
|
|
|
+ return;
|
|
|
} else {
|
|
|
if ("TRADE_FINISHED".equals(notifyTradeStatus)) {
|
|
|
//交易结束,不可退款 注意:退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
|
|
|
@@ -326,7 +324,7 @@ public class AlipayController {
|
|
|
}
|
|
|
|
|
|
//交易支付成功 注:付款完成后,支付宝系统发送该交易状态通知
|
|
|
- projectRecode.setStatus(projectRecodePayStatus);
|
|
|
+ projectRecode.setStatus((short) 2);
|
|
|
projectRecodeService.update(projectRecode);
|
|
|
saveAlipayOrder(data, null);
|
|
|
logger.info("异步通知支付成功处理结束:商户订单状态:" + projectRecode.getStatus());
|
|
|
@@ -334,6 +332,7 @@ public class AlipayController {
|
|
|
}
|
|
|
}
|
|
|
response.getWriter().write("success");
|
|
|
+ return;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -554,10 +553,10 @@ public class AlipayController {
|
|
|
|
|
|
if (!StringUtils.isEmpty(imid)) {
|
|
|
jsonObject.remove("imid");
|
|
|
- //TODO 通过imid获取uuid
|
|
|
- Object uuidObj = userService.getUserByImId(Long.parseLong(imid));
|
|
|
- if (uuidObj != null) {
|
|
|
- uuid = (Long)uuidObj;
|
|
|
+ Object userObj = userService.getUserByImId(Long.parseLong(imid));
|
|
|
+ if (userObj != null) {
|
|
|
+ User userForImId = (User)userObj;
|
|
|
+ uuid = userForImId.getUserUU();
|
|
|
logger.info("移动端imid转为uuid,uuid=" + uuid);
|
|
|
}
|
|
|
}
|