|
@@ -1,5 +1,6 @@
|
|
|
package com.jeesite.modules.report.service;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alipay.api.AlipayApiException;
|
|
|
import com.alipay.api.internal.util.AlipaySignature;
|
|
@@ -16,6 +17,8 @@ import com.jeesite.modules.report.entity.WebsiteUserOrder;
|
|
|
import com.jeesite.modules.report.entity.WebsiteUserOrderDown;
|
|
|
import com.jeesite.modules.report.util.AlipayUtil;
|
|
|
import com.jeesite.modules.sys.utils.R;
|
|
|
+import com.wechat.pay.java.core.notification.NotificationParser;
|
|
|
+import com.wechat.pay.java.core.notification.RequestParam;
|
|
|
import com.wechat.pay.java.service.payments.model.Transaction;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -44,6 +47,8 @@ public class WebsiteUserOrderService extends CrudService<WebsiteUserOrderDao, We
|
|
|
private WxPayService wxPayService;
|
|
|
@Resource
|
|
|
private WxPayH5Service wxPayH5Service;
|
|
|
+ @Resource
|
|
|
+ private NotificationParser notificationParser;
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(WebsiteUserOrderService.class);
|
|
|
/**
|
|
@@ -194,22 +199,7 @@ public class WebsiteUserOrderService extends CrudService<WebsiteUserOrderDao, We
|
|
|
if (signVerified) {
|
|
|
// TODO 验签成功后,按照支付结果异步通知中的描述,对支付结果中的业务内容进行二次校验,校验成功后在response中返回success并继续商户自身业务处理,校验失败返回failure
|
|
|
if ("TRADE_SUCCESS".equals(trade_status) || "TRADE_FINISHED".equals(trade_status)) {
|
|
|
- WebsiteUserOrder where = new WebsiteUserOrder();
|
|
|
- where.setOrderNumber(out_trade_no);
|
|
|
- where.setPayStatus(Constants.orderPayStatus.WAIT);
|
|
|
- WebsiteUserOrder websiteUserOrder = dao.get(where);
|
|
|
- if (websiteUserOrder == null) {
|
|
|
- logger.error("zfb payAsyncNotify error {}订单不存在未支付", out_trade_no);
|
|
|
- } else {
|
|
|
- if (!total_amount.equals(websiteUserOrder.getPayPrice().toString())) {
|
|
|
- logger.error("zfb payAsyncNotify amount不相等 {} {}", total_amount, websiteUserOrder.getPayPrice().toString());
|
|
|
- return "failure";
|
|
|
- }
|
|
|
- websiteUserOrder.setPayStatus(Constants.orderPayStatus.PAY_SUCCESS);
|
|
|
- websiteUserOrder.setPayDate(DateUtils.parseDateByFormat(gmt_payment, "yyyy-MM-dd HH:mm:ss"));
|
|
|
- super.update(websiteUserOrder);
|
|
|
- }
|
|
|
- return "success";
|
|
|
+ return payUpdate(out_trade_no, total_amount, DateUtils.parseDateByFormat(gmt_payment, "yyyy-MM-dd HH:mm:ss"));
|
|
|
}
|
|
|
}
|
|
|
} catch (AlipayApiException e) {
|
|
@@ -219,6 +209,25 @@ public class WebsiteUserOrderService extends CrudService<WebsiteUserOrderDao, We
|
|
|
return "failure";
|
|
|
}
|
|
|
|
|
|
+ private String payUpdate(String out_trade_no, String total_amount, Date date) {
|
|
|
+ WebsiteUserOrder where = new WebsiteUserOrder();
|
|
|
+ where.setOrderNumber(out_trade_no);
|
|
|
+ where.setPayStatus(Constants.orderPayStatus.WAIT);
|
|
|
+ WebsiteUserOrder websiteUserOrder = dao.get(where);
|
|
|
+ if (websiteUserOrder == null) {
|
|
|
+ logger.error("payAsyncNotify error {}订单不存在未支付", out_trade_no);
|
|
|
+ } else {
|
|
|
+ if (!total_amount.equals(websiteUserOrder.getPayPrice().toString())) {
|
|
|
+ logger.error("payAsyncNotify amount不相等 {} {}", total_amount, websiteUserOrder.getPayPrice().toString());
|
|
|
+ return "failure";
|
|
|
+ }
|
|
|
+ websiteUserOrder.setPayStatus(Constants.orderPayStatus.PAY_SUCCESS);
|
|
|
+ websiteUserOrder.setPayDate(date);
|
|
|
+ super.update(websiteUserOrder);
|
|
|
+ }
|
|
|
+ return "success";
|
|
|
+ }
|
|
|
+
|
|
|
//定时任务会调用此方法
|
|
|
// @Scheduled(cron ="0 0/5 * * * ?")
|
|
|
public void zfbPayQuery() {
|
|
@@ -309,4 +318,37 @@ public class WebsiteUserOrderService extends CrudService<WebsiteUserOrderDao, We
|
|
|
public WebsiteUserOrder getOne(WebsiteUserOrder orderWhere) {
|
|
|
return super.get(orderWhere);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public String wxpayAsyncNotify(String requestBody, HttpServletRequest request) {
|
|
|
+ try {
|
|
|
+ logger.info("wx wxpayAsyncNotify 进来了 {}", requestBody);
|
|
|
+ // 随机串
|
|
|
+ String nonceStr = request.getHeader("Wechatpay-Nonce");
|
|
|
+ // 微信传递过来的签名
|
|
|
+ String signature = request.getHeader("Wechatpay-Signature");
|
|
|
+ // 证书序列号(微信平台)
|
|
|
+ String serialNo = request.getHeader("Wechatpay-Serial");
|
|
|
+ // 时间戳
|
|
|
+ String timestamp = request.getHeader("Wechatpay-Timestamp");
|
|
|
+ RequestParam requestParam = new RequestParam.Builder()
|
|
|
+ .serialNumber(serialNo)
|
|
|
+ .nonce(nonceStr)
|
|
|
+ .signature(signature)
|
|
|
+ .timestamp(timestamp)
|
|
|
+ .body(requestBody)
|
|
|
+ .build();
|
|
|
+ // 以支付通知回调为例,验签、解密并转换成 Transaction
|
|
|
+ Transaction transaction = notificationParser.parse(requestParam, Transaction.class);
|
|
|
+ logger.info("wx wxpayAsyncNotify transaction:{}", JSON.toJSONString(transaction));
|
|
|
+ Transaction.TradeStateEnum tradeState = transaction.getTradeState();
|
|
|
+ if (Transaction.TradeStateEnum.SUCCESS.equals(tradeState)){
|
|
|
+ int amount = transaction.getAmount().getPayerTotal() / 100;
|
|
|
+ return payUpdate(transaction.getOutTradeNo(), String.valueOf(amount), DateUtils.parseDateISOByFormat(transaction.getSuccessTime()));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("wxpayAsyncNotify error", e);
|
|
|
+ }
|
|
|
+ return "failure";
|
|
|
+ }
|
|
|
}
|